41 #include "ns3/core-module.h"
42 #include "ns3/internet-module.h"
43 #include "ns3/network-module.h"
44 #include "ns3/on-off-helper.h"
45 #include "ns3/packet-sink-helper.h"
46 #include "ns3/point-to-point-helper.h"
47 #include "ns3/mpi-interface.h"
48 #include "ns3/ipv4-static-routing-helper.h"
49 #include "ns3/ipv4-list-routing-helper.h"
50 #include "ns3/ipv4-nix-vector-helper.h"
58 typedef struct timeval TIMER_TYPE;
59 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
60 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
61 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
66 main (
int argc,
char *argv[])
72 TIMER_TYPE t0, t1, t2;
74 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
84 #define nLANClients (42)
93 cmd.
AddValue (
"single",
"1 if use single flow", single);
94 cmd.
AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
95 cmd.
AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
96 cmd.
Parse (argc,argv);
100 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
104 if (systemCount > nCN)
106 std::cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount ("
107 << systemCount <<
")." << std::endl;
111 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
113 NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
114 nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
115 nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
119 ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
120 ifs3LAN[nCN][5][nLANClients];
122 std::ostringstream oss;
134 list.
Add (staticRouting, 0);
135 list.
Add (nixRouting, 10);
143 for (uint32_t z = 0; z < nCN; ++z)
145 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
147 std::cout <<
" SubNet [ 0";
148 for (
int i = 0; i < 3; ++i)
150 Ptr<Node> node = CreateObject<Node> (z % systemCount);
151 nodes_net0[z][i].
Add (node);
152 stack.
Install (nodes_net0[z][i]);
154 nodes_net0[z][0].
Add (nodes_net0[z][1].Get (0));
155 nodes_net0[z][1].
Add (nodes_net0[z][2].Get (0));
156 nodes_net0[z][2].
Add (nodes_net0[z][0].Get (0));
158 for (
int i = 0; i < 3; ++i)
160 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
164 for (
int i = 0; i < 6; ++i)
166 Ptr<Node> node = CreateObject<Node> (z % systemCount);
167 nodes_net1[z][i].
Add (node);
168 stack.
Install (nodes_net1[z][i]);
170 nodes_net1[z][0].
Add (nodes_net1[z][1].Get (0));
171 nodes_net1[z][2].
Add (nodes_net1[z][0].Get (0));
172 nodes_net1[z][3].
Add (nodes_net1[z][0].Get (0));
173 nodes_net1[z][4].
Add (nodes_net1[z][1].Get (0));
174 nodes_net1[z][5].
Add (nodes_net1[z][1].Get (0));
176 for (
int i = 0; i < 6; ++i)
182 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
186 net0_1.
Add (nodes_net0[z][2].Get (0));
187 net0_1.
Add (nodes_net1[z][0].Get (0));
189 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
191 oss << 10 + z <<
".1.252.0";
192 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
193 ifs = address.
Assign (ndc0_1);
196 for (
int i = 0; i < 14; ++i)
198 Ptr<Node> node = CreateObject<Node> (z % systemCount);
199 nodes_net2[z][i].
Add (node);
200 stack.
Install (nodes_net2[z][i]);
202 nodes_net2[z][0].
Add (nodes_net2[z][1].Get (0));
203 nodes_net2[z][2].
Add (nodes_net2[z][0].Get (0));
204 nodes_net2[z][1].
Add (nodes_net2[z][3].Get (0));
205 nodes_net2[z][3].
Add (nodes_net2[z][2].Get (0));
206 nodes_net2[z][4].
Add (nodes_net2[z][2].Get (0));
207 nodes_net2[z][5].
Add (nodes_net2[z][3].Get (0));
208 nodes_net2[z][6].
Add (nodes_net2[z][5].Get (0));
209 nodes_net2[z][7].
Add (nodes_net2[z][2].Get (0));
210 nodes_net2[z][8].
Add (nodes_net2[z][3].Get (0));
211 nodes_net2[z][9].
Add (nodes_net2[z][4].Get (0));
212 nodes_net2[z][10].
Add (nodes_net2[z][5].Get (0));
213 nodes_net2[z][11].
Add (nodes_net2[z][6].Get (0));
214 nodes_net2[z][12].
Add (nodes_net2[z][6].Get (0));
215 nodes_net2[z][13].
Add (nodes_net2[z][6].Get (0));
217 for (
int i = 0; i < 14; ++i)
219 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
222 for (
int i = 0; i < 7; ++i)
225 oss << 10 + z <<
".4." << 15 + i <<
".0";
226 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
227 for (uint32_t j = 0; j < nLANClients; ++j)
229 Ptr<Node> node = CreateObject<Node> (z % systemCount);
230 nodes_net2LAN[z][i][j].
Add (node);
231 stack.
Install (nodes_net2LAN[z][i][j]);
232 nodes_net2LAN[z][i][j].
Add (nodes_net2[z][i + 7].Get (0));
233 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
234 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
238 std::cout <<
" 3 ]" << std::endl;
239 for (
int i = 0; i < 9; ++i)
241 Ptr<Node> node = CreateObject<Node> (z % systemCount);
242 nodes_net3[z][i].
Add (node);
243 stack.
Install (nodes_net3[z][i]);
245 nodes_net3[z][0].
Add (nodes_net3[z][1].Get (0));
246 nodes_net3[z][1].
Add (nodes_net3[z][2].Get (0));
247 nodes_net3[z][2].
Add (nodes_net3[z][3].Get (0));
248 nodes_net3[z][3].
Add (nodes_net3[z][1].Get (0));
249 nodes_net3[z][4].
Add (nodes_net3[z][0].Get (0));
250 nodes_net3[z][5].
Add (nodes_net3[z][0].Get (0));
251 nodes_net3[z][6].
Add (nodes_net3[z][2].Get (0));
252 nodes_net3[z][7].
Add (nodes_net3[z][3].Get (0));
253 nodes_net3[z][8].
Add (nodes_net3[z][3].Get (0));
255 for (
int i = 0; i < 9; ++i)
257 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
260 for (
int i = 0; i < 5; ++i)
263 oss << 10 + z <<
".5." << 10 + i <<
".0";
264 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
265 for (uint32_t j = 0; j < nLANClients; ++j)
267 Ptr<Node> node = CreateObject<Node> (z % systemCount);
268 nodes_net3LAN[z][i][j].
Add (node);
269 stack.
Install (nodes_net3LAN[z][i][j]);
270 nodes_net3LAN[z][i][j].
Add (nodes_net3[z][i + 4].Get (0));
271 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
272 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
275 std::cout <<
" Connecting Subnets..." << std::endl;
277 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
278 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
279 nodes_netLR[z].
Add (node1);
280 nodes_netLR[z].
Add (node2);
281 stack.
Install (nodes_netLR[z]);
283 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
285 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
286 net0_4.
Add (nodes_netLR[z].Get (0));
287 net0_4.
Add (nodes_net0[z][0].Get (0));
288 net0_5.
Add (nodes_netLR[z].Get (1));
289 net0_5.
Add (nodes_net0[z][1].Get (0));
290 net2_4a.
Add (nodes_netLR[z].Get (0));
291 net2_4a.
Add (nodes_net2[z][0].Get (0));
292 net2_4b.
Add (nodes_netLR[z].Get (1));
293 net2_4b.
Add (nodes_net2[z][1].Get (0));
294 net3_5a.
Add (nodes_netLR[z].Get (1));
295 net3_5a.
Add (nodes_net3[z][0].Get (0));
296 net3_5b.
Add (nodes_netLR[z].Get (1));
297 net3_5b.
Add (nodes_net3[z][1].Get (0));
299 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
301 oss << 10 + z <<
".1.253.0";
302 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
303 ifs = address.
Assign (ndc0_4);
304 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
306 oss << 10 + z <<
".1.254.0";
307 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
308 ifs = address.
Assign (ndc0_5);
309 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
311 oss << 10 + z <<
".4.253.0";
312 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
313 ifs = address.
Assign (ndc2_4a);
314 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
316 oss << 10 + z <<
".4.254.0";
317 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
318 ifs = address.
Assign (ndc2_4b);
319 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
321 oss << 10 + z <<
".5.253.0";
322 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
323 ifs = address.
Assign (ndc3_5a);
324 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
326 oss << 10 + z <<
".5.254.0";
327 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
328 ifs = address.
Assign (ndc3_5b);
330 std::cout <<
" Assigning IP addresses..." << std::endl;
331 for (
int i = 0; i < 3; ++i)
334 oss << 10 + z <<
".1." << 1 + i <<
".0";
335 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
336 ifs0[z][i] = address.
Assign (ndc0[i]);
338 for (
int i = 0; i < 6; ++i)
345 oss << 10 + z <<
".2." << 1 + i <<
".0";
346 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
347 ifs1[z][i] = address.
Assign (ndc1[i]);
350 oss << 10 + z <<
".3.1.0";
351 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
352 ifs = address.
Assign (ndcLR);
353 for (
int i = 0; i < 14; ++i)
356 oss << 10 + z <<
".4." << 1 + i <<
".0";
357 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
358 ifs2[z][i] = address.
Assign (ndc2[i]);
360 for (
int i = 0; i < 9; ++i)
363 oss << 10 + z <<
".5." << 1 + i <<
".0";
364 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
365 ifs3[z][i] = address.
Assign (ndc3[i]);
371 std::cout <<
"Forming Ring Topology..." << std::endl;
373 for (uint32_t z = 0; z < nCN - 1; ++z)
375 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
376 nodes_ring[z].
Add (nodes_net0[z + 1][0].Get (0));
378 nodes_ring[nCN - 1].
Add (nodes_net0[nCN - 1][0].Get (0));
379 nodes_ring[nCN - 1].
Add (nodes_net0[0][0].Get (0));
381 for (uint32_t z = 0; z < nCN; ++z)
383 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
385 oss <<
"254.1." << z + 1 <<
".0";
386 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
387 ifs = address.
Assign (ndc_ring[z]);
392 std::cout <<
"Creating UDP Traffic Flows:" << std::endl;
396 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
398 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
403 if (systemCount == 1)
413 std::cout <<
"Remote Address is " << ifs1[0][2].
GetAddress (0) << std::endl;
414 client.SetAttribute (
"Remote", remoteAddress);
417 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].
Get (0)));
420 else if (systemId == 1)
426 sinkHelper.Install (nodes_net1[1][0].Get (0));
430 else if (systemId == 0)
436 std::cout <<
"Remote Address is " << ifs1[1][0].
GetAddress (0) << std::endl;
437 client.SetAttribute (
"Remote", remoteAddress);
440 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].
Get (0)));
449 for (uint32_t z = 0; z < nCN; ++z)
457 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
458 for (
int i = 0; i < 7; ++i)
460 for (uint32_t j = 0; j < nLANClients; ++j)
463 if (systemCount == 1)
466 (
"ns3::UdpSocketFactory",
470 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
474 else if (systemId == z % systemCount)
477 (
"ns3::UdpSocketFactory",
481 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
486 if (systemCount == 1)
488 r1 = 2 + (int)(4 * urng->
GetValue ());
495 client.SetAttribute (
"Remote", remoteAddress);
497 clientApp.
Add (client.Install (nodes_net1[x][r1].
Get (0)));
500 else if (systemId == x % systemCount)
502 r1 = 2 + (int)(4 * urng->
GetValue ());
509 client.SetAttribute (
"Remote", remoteAddress);
511 clientApp.
Add (client.Install (nodes_net1[x][r1].
Get (0)));
517 std::cout <<
"Net3 ]" << std::endl;
518 for (
int i = 0; i < 5; ++i)
520 for (uint32_t j = 0; j < nLANClients; ++j)
523 if (systemCount == 1)
526 (
"ns3::UdpSocketFactory",
530 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
534 else if (systemId == z % systemCount)
537 (
"ns3::UdpSocketFactory",
541 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
546 if (systemCount == 1)
548 r1 = 2 + (int)(4 * urng->
GetValue ());
555 client.SetAttribute (
"Remote", remoteAddress);
557 clientApp.
Add (client.Install (nodes_net1[x][r1].
Get (0)));
560 else if (systemId == x % systemCount)
562 r1 = 2 + (int)(4 * urng->
GetValue ());
569 client.SetAttribute (
"Remote", remoteAddress);
571 clientApp.
Add (client.Install (nodes_net1[x][r1].
Get (0)));
580 TIMER_TYPE routingStart;
581 TIMER_NOW (routingStart);
585 std::cout <<
"Using Nix-vectors..." << std::endl;
590 std::cout <<
"Populating Routing tables..." << std::endl;
594 TIMER_TYPE routingEnd;
595 TIMER_NOW (routingEnd);
596 std::cout <<
"Routing tables population took "
597 << TIMER_DIFF (routingEnd, routingStart) << std::endl;
599 std::cout <<
"Running simulator..." << std::endl;
604 std::cout <<
"Simulator finished." << std::endl;
608 double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
609 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
610 std::cout <<
"Simulator init time: " << d1 << std::endl;
611 std::cout <<
"Simulator run time: " << d2 << std::endl;
612 std::cout <<
"Total elapsed time: " << d1 + d2 << std::endl;
615 NS_FATAL_ERROR (
"Can't use distributed simulator without MPI compiled in");
holds a vector of ns3::Application pointers.
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation. Makes all nodes in the simulation into routers.
hold variables of type string
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
#define NS_LOG_COMPONENT_DEFINE(name)
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
static void Enable(int *pargc, char ***pargv)
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
static void Destroy(void)
void SetDefault(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
void Install(std::string nodeName) const
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
void SetChannelAttribute(std::string name, const AttributeValue &value)
hold objects of type ns3::Address
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetSystemId()
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddValue(const std::string &name, const std::string &help, T &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void Parse(int argc, char *argv[]) const
Helper class that adds ns3::Ipv4ListRouting objects.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static uint32_t GetSize()
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const