A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nsclick-udp-client-server-csma.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5// Adaptation of examples/udp/udp-client-server.cc for
6// Click based nodes.
7//
8// Network topology
9//
10// 172.16.1.0/24
11// (1.1) (1.2) (1.3)
12// n0 n1 n2
13// | | |
14// =============
15// LAN
16//
17// - UDP flows from n0 to n1 and n2 to n1
18// - All nodes are Click based.
19// - The single ethernet interface that each node
20// uses is named 'eth0' in the Click file.
21//
22
23#include "ns3/applications-module.h"
24#include "ns3/click-internet-stack-helper.h"
25#include "ns3/core-module.h"
26#include "ns3/csma-module.h"
27#include "ns3/internet-module.h"
28#include "ns3/ipv4-click-routing.h"
29#include "ns3/network-module.h"
30
31#include <fstream>
32
33using namespace ns3;
34
35NS_LOG_COMPONENT_DEFINE("NsclickUdpClientServerCsma");
36
37int
38main(int argc, char* argv[])
39{
40 std::string clickConfigFolder = "src/click/examples";
41
42 CommandLine cmd(__FILE__);
43 cmd.AddValue("clickConfigFolder",
44 "Base folder for click configuration files",
45 clickConfigFolder);
46 cmd.Parse(argc, argv);
47
48 //
49 // Enable logging for UdpClient and
50 //
51 LogComponentEnable("NsclickUdpClientServerCsma", LOG_LEVEL_INFO);
52
53 //
54 // Explicitly create the nodes required by the topology (shown above).
55 //
56 NS_LOG_INFO("Create nodes.");
58 n.Create(3);
59
60 NS_LOG_INFO("Create channels.");
61 //
62 // Explicitly create the channels required by the topology (shown above).
63 //
65 csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000)));
66 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
67 csma.SetDeviceAttribute("Mtu", UintegerValue(1400));
68 NetDeviceContainer d = csma.Install(n);
69
70 //
71 // Install Click on the nodes
72 //
74 clickinternet.SetClickFile(n, clickConfigFolder + "/nsclick-lan-single-interface.click");
75 clickinternet.SetRoutingTableElement(n, "rt");
76 clickinternet.Install(n);
77
79 //
80 // We've got the "hardware" in place. Now we need to add IP addresses.
81 //
82 NS_LOG_INFO("Assign IP Addresses.");
83 ipv4.SetBase("172.16.1.0", "255.255.255.0");
84 Ipv4InterfaceContainer i = ipv4.Assign(d);
85
86 NS_LOG_INFO("Create Applications.");
87 //
88 // Create one udpServer applications on node one.
89 //
90 uint16_t port = 4000;
92 ApplicationContainer apps = server.Install(n.Get(1));
93 apps.Start(Seconds(1.0));
94 apps.Stop(Seconds(10.0));
95
96 //
97 // Create one UdpClient application to send UDP datagrams from node zero to
98 // node one.
99 //
100 uint32_t MaxPacketSize = 1024;
101 Time interPacketInterval = Seconds(0.05);
102 uint32_t maxPacketCount = 320;
104 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
105 client.SetAttribute("Interval", TimeValue(interPacketInterval));
106 client.SetAttribute("PacketSize", UintegerValue(MaxPacketSize));
107 apps = client.Install(NodeContainer(n.Get(0), n.Get(2)));
108 apps.Start(Seconds(2.0));
109 apps.Stop(Seconds(10.0));
110
111 csma.EnablePcap("nsclick-udp-client-server-csma", d, false);
112
113 //
114 // Now, do the actual simulation.
115 //
116 NS_LOG_INFO("Run Simulation.");
120 NS_LOG_INFO("Done.");
121
122 return 0;
123}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Parse command-line arguments.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
Class for representing data rates.
Definition data-rate.h:78
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Create a server application which waits for input UDP packets and uses the information carried into t...
Hold an unsigned integer type.
Definition uinteger.h:34
uint16_t port
Definition dsdv-manet.cc:33
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:291
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93