A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nsclick-routing.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Authors: Lalith Suresh <suresh.lalith@gmail.com>
16 */
17
18// Network topology
19//
20//
21// 172.16.1.0/24
22// (1.1) (1.2) (2.1) (2.2)
23//
24// eth0 eth0 eth1 eth0
25// n0 ========= n1 ========= n2
26// LAN 1 LAN 2
27//
28// - UDP flows from n0 to n2 via n1.
29// - All nodes are Click based.
30//
31
32#include "ns3/applications-module.h"
33#include "ns3/click-internet-stack-helper.h"
34#include "ns3/core-module.h"
35#include "ns3/csma-module.h"
36#include "ns3/internet-module.h"
37#include "ns3/ipv4-click-routing.h"
38#include "ns3/ipv4-l3-click-protocol.h"
39#include "ns3/network-module.h"
40
41using namespace ns3;
42
43NS_LOG_COMPONENT_DEFINE("NsclickRouting");
44
45int
46main(int argc, char* argv[])
47{
48#ifdef NS3_CLICK
49 std::string clickConfigFolder = "src/click/examples";
50
51 CommandLine cmd(__FILE__);
52 cmd.AddValue("clickConfigFolder",
53 "Base folder for click configuration files",
54 clickConfigFolder);
55 cmd.Parse(argc, argv);
56
57 //
58 // Explicitly create the nodes required by the topology (shown above).
59 //
60 NS_LOG_INFO("Create nodes.");
62 n.Create(3);
63
64 //
65 // Install Click on the nodes
66 //
67 ClickInternetStackHelper clickinternet;
68 clickinternet.SetClickFile(n.Get(0), clickConfigFolder + "/nsclick-routing-node0.click");
69 clickinternet.SetClickFile(n.Get(1), clickConfigFolder + "/nsclick-ip-router.click");
70 clickinternet.SetClickFile(n.Get(2), clickConfigFolder + "/nsclick-routing-node2.click");
71 clickinternet.SetRoutingTableElement(n.Get(0), "kernel/rt");
72 clickinternet.SetRoutingTableElement(n.Get(1), "u/rt");
73 clickinternet.SetRoutingTableElement(n.Get(2), "kernel/rt");
74 clickinternet.Install(n);
75
76 NS_LOG_INFO("Create channels.");
77 //
78 // Explicitly create the channels required by the topology (shown above).
79 //
81 csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000)));
82 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
83 csma.SetDeviceAttribute("Mtu", UintegerValue(1400));
84 NetDeviceContainer d01 = csma.Install(NodeContainer(n.Get(0), n.Get(1)));
85 NetDeviceContainer d12 = csma.Install(NodeContainer(n.Get(1), n.Get(2)));
86
88 //
89 // We've got the "hardware" in place. Now we need to add IP addresses.
90 //
91 NS_LOG_INFO("Assign IP Addresses.");
92 ipv4.SetBase("172.16.1.0", "255.255.255.0");
93 Ipv4InterfaceContainer i01 = ipv4.Assign(d01);
94
95 ipv4.SetBase("172.16.2.0", "255.255.255.0");
96 Ipv4InterfaceContainer i12 = ipv4.Assign(d12);
97
98 NS_LOG_INFO("Create Applications.");
99 //
100 // Create one udpServer applications on node one.
101 //
102 uint16_t port = 4000;
103 UdpServerHelper server(port);
104 ApplicationContainer apps = server.Install(n.Get(2));
105 apps.Start(Seconds(1.0));
106 apps.Stop(Seconds(10.0));
107
108 //
109 // Create one UdpClient application to send UDP datagrams from node zero to
110 // node one.
111 //
112 uint32_t MaxPacketSize = 1024;
113 Time interPacketInterval = Seconds(0.05);
114 uint32_t maxPacketCount = 320;
115 UdpClientHelper client(i12.GetAddress(1), port);
116 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
117 client.SetAttribute("Interval", TimeValue(interPacketInterval));
118 client.SetAttribute("PacketSize", UintegerValue(MaxPacketSize));
119 apps = client.Install(NodeContainer(n.Get(0)));
120 apps.Start(Seconds(2.0));
121 apps.Stop(Seconds(10.0));
122
123 csma.EnablePcap("nsclick-routing", d01, false);
124 csma.EnablePcap("nsclick-routing", d12, false);
125
126 //
127 // Now, do the actual simulation.
128 //
129 NS_LOG_INFO("Run Simulation.");
133 NS_LOG_INFO("Done.");
134#else
135 NS_FATAL_ERROR("Can't use ns-3-click without NSCLICK compiled in");
136#endif
137
138 return 0;
139}
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.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
Class for representing data rates.
Definition: data-rate.h:90
AttributeValue implementation for DataRate.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1423
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:45
uint16_t port
Definition: dsdv-manet.cc:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33
ns csma
Definition: second.py:56