A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nsclick-routing.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Authors: Lalith Suresh <suresh.lalith@gmail.com>
5 */
6
7// Network topology
8//
9//
10// 172.16.1.0/24
11// (1.1) (1.2) (2.1) (2.2)
12//
13// eth0 eth0 eth1 eth0
14// n0 ========= n1 ========= n2
15// LAN 1 LAN 2
16//
17// - UDP flows from n0 to n2 via n1.
18// - All nodes are Click based.
19//
20
21#include "ns3/applications-module.h"
22#include "ns3/click-internet-stack-helper.h"
23#include "ns3/core-module.h"
24#include "ns3/csma-module.h"
25#include "ns3/internet-module.h"
26#include "ns3/ipv4-click-routing.h"
27#include "ns3/ipv4-l3-click-protocol.h"
28#include "ns3/network-module.h"
29
30using namespace ns3;
31
32NS_LOG_COMPONENT_DEFINE("NsclickRouting");
33
34int
35main(int argc, char* argv[])
36{
37 std::string clickConfigFolder = "src/click/examples";
38
39 CommandLine cmd(__FILE__);
40 cmd.AddValue("clickConfigFolder",
41 "Base folder for click configuration files",
42 clickConfigFolder);
43 cmd.Parse(argc, argv);
44
45 //
46 // Explicitly create the nodes required by the topology (shown above).
47 //
48 NS_LOG_INFO("Create nodes.");
50 n.Create(3);
51
52 //
53 // Install Click on the nodes
54 //
56 clickinternet.SetClickFile(n.Get(0), clickConfigFolder + "/nsclick-routing-node0.click");
57 clickinternet.SetClickFile(n.Get(1), clickConfigFolder + "/nsclick-ip-router.click");
58 clickinternet.SetClickFile(n.Get(2), clickConfigFolder + "/nsclick-routing-node2.click");
59 clickinternet.SetRoutingTableElement(n.Get(0), "kernel/rt");
60 clickinternet.SetRoutingTableElement(n.Get(1), "u/rt");
61 clickinternet.SetRoutingTableElement(n.Get(2), "kernel/rt");
62 clickinternet.Install(n);
63
64 NS_LOG_INFO("Create channels.");
65 //
66 // Explicitly create the channels required by the topology (shown above).
67 //
69 csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000)));
70 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
71 csma.SetDeviceAttribute("Mtu", UintegerValue(1400));
72 NetDeviceContainer d01 = csma.Install(NodeContainer(n.Get(0), n.Get(1)));
73 NetDeviceContainer d12 = csma.Install(NodeContainer(n.Get(1), n.Get(2)));
74
76 //
77 // We've got the "hardware" in place. Now we need to add IP addresses.
78 //
79 NS_LOG_INFO("Assign IP Addresses.");
80 ipv4.SetBase("172.16.1.0", "255.255.255.0");
81 Ipv4InterfaceContainer i01 = ipv4.Assign(d01);
82
83 ipv4.SetBase("172.16.2.0", "255.255.255.0");
84 Ipv4InterfaceContainer i12 = ipv4.Assign(d12);
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(2));
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)));
108 apps.Start(Seconds(2.0));
109 apps.Stop(Seconds(10.0));
110
111 csma.EnablePcap("nsclick-routing", d01, false);
112 csma.EnablePcap("nsclick-routing", d12, false);
113
114 //
115 // Now, do the actual simulation.
116 //
117 NS_LOG_INFO("Run Simulation.");
121 NS_LOG_INFO("Done.");
122
123 return 0;
124}
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.