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"
60 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
61 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
62 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
67 main (
int argc,
char *argv[])
71 MpiInterface::Enable (&argc, &argv);
75 cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
77 GlobalValue::Bind (
"SimulatorImplementationType",
80 uint32_t systemId = MpiInterface::GetSystemId ();
81 uint32_t systemCount = MpiInterface::GetSize ();
83 uint32_t nCN = 2, nLANClients = 42;
89 cmd.
AddValue (
"CN",
"Number of total CNs [2]", nCN);
90 cmd.
AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
91 cmd.
AddValue (
"single",
"1 if use single flow", single);
92 cmd.
AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
93 cmd.
AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
94 cmd.
Parse (argc,argv);
98 cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
102 if (systemCount > nCN)
104 cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount ("
105 << systemCount <<
")." << endl;
109 cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << endl;
111 NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
112 nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
113 nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
117 ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
118 ifs3LAN[nCN][5][nLANClients];
120 std::ostringstream oss;
132 list.
Add (staticRouting, 0);
133 list.
Add (nixRouting, 10);
141 for (uint32_t z = 0; z < nCN; ++z)
143 cout <<
"Creating Campus Network " << z <<
":" << endl;
145 cout <<
" SubNet [ 0";
146 for (
int i = 0; i < 3; ++i)
148 Ptr<Node> node = CreateObject<Node> (z % systemCount);
149 nodes_net0[z][i].
Add (node);
150 stack.
Install (nodes_net0[z][i]);
152 nodes_net0[z][0].
Add (nodes_net0[z][1].Get (0));
153 nodes_net0[z][1].
Add (nodes_net0[z][2].Get (0));
154 nodes_net0[z][2].
Add (nodes_net0[z][0].Get (0));
156 for (
int i = 0; i < 3; ++i)
158 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
162 for (
int i = 0; i < 6; ++i)
164 Ptr<Node> node = CreateObject<Node> (z % systemCount);
165 nodes_net1[z][i].
Add (node);
166 stack.
Install (nodes_net1[z][i]);
168 nodes_net1[z][0].
Add (nodes_net1[z][1].Get (0));
169 nodes_net1[z][2].
Add (nodes_net1[z][0].Get (0));
170 nodes_net1[z][3].
Add (nodes_net1[z][0].Get (0));
171 nodes_net1[z][4].
Add (nodes_net1[z][1].Get (0));
172 nodes_net1[z][5].
Add (nodes_net1[z][1].Get (0));
174 for (
int i = 0; i < 6; ++i)
180 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
184 net0_1.
Add (nodes_net0[z][2].Get (0));
185 net0_1.
Add (nodes_net1[z][0].Get (0));
187 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
189 oss << 10 + z <<
".1.252.0";
190 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
191 ifs = address.
Assign (ndc0_1);
194 for (
int i = 0; i < 14; ++i)
196 Ptr<Node> node = CreateObject<Node> (z % systemCount);
197 nodes_net2[z][i].
Add (node);
198 stack.
Install (nodes_net2[z][i]);
200 nodes_net2[z][0].
Add (nodes_net2[z][1].Get (0));
201 nodes_net2[z][2].
Add (nodes_net2[z][0].Get (0));
202 nodes_net2[z][1].
Add (nodes_net2[z][3].Get (0));
203 nodes_net2[z][3].
Add (nodes_net2[z][2].Get (0));
204 nodes_net2[z][4].
Add (nodes_net2[z][2].Get (0));
205 nodes_net2[z][5].
Add (nodes_net2[z][3].Get (0));
206 nodes_net2[z][6].
Add (nodes_net2[z][5].Get (0));
207 nodes_net2[z][7].
Add (nodes_net2[z][2].Get (0));
208 nodes_net2[z][8].
Add (nodes_net2[z][3].Get (0));
209 nodes_net2[z][9].
Add (nodes_net2[z][4].Get (0));
210 nodes_net2[z][10].
Add (nodes_net2[z][5].Get (0));
211 nodes_net2[z][11].
Add (nodes_net2[z][6].Get (0));
212 nodes_net2[z][12].
Add (nodes_net2[z][6].Get (0));
213 nodes_net2[z][13].
Add (nodes_net2[z][6].Get (0));
215 for (
int i = 0; i < 14; ++i)
217 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
220 for (
int i = 0; i < 7; ++i)
223 oss << 10 + z <<
".4." << 15 + i <<
".0";
224 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
225 for (uint32_t j = 0; j < nLANClients; ++j)
227 Ptr<Node> node = CreateObject<Node> (z % systemCount);
228 nodes_net2LAN[z][i][j].
Add (node);
229 stack.
Install (nodes_net2LAN[z][i][j]);
230 nodes_net2LAN[z][i][j].
Add (nodes_net2[z][i + 7].Get (0));
231 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
232 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
236 cout <<
" 3 ]" << endl;
237 for (
int i = 0; i < 9; ++i)
239 Ptr<Node> node = CreateObject<Node> (z % systemCount);
240 nodes_net3[z][i].
Add (node);
241 stack.
Install (nodes_net3[z][i]);
243 nodes_net3[z][0].
Add (nodes_net3[z][1].Get (0));
244 nodes_net3[z][1].
Add (nodes_net3[z][2].Get (0));
245 nodes_net3[z][2].
Add (nodes_net3[z][3].Get (0));
246 nodes_net3[z][3].
Add (nodes_net3[z][1].Get (0));
247 nodes_net3[z][4].
Add (nodes_net3[z][0].Get (0));
248 nodes_net3[z][5].
Add (nodes_net3[z][0].Get (0));
249 nodes_net3[z][6].
Add (nodes_net3[z][2].Get (0));
250 nodes_net3[z][7].
Add (nodes_net3[z][3].Get (0));
251 nodes_net3[z][8].
Add (nodes_net3[z][3].Get (0));
253 for (
int i = 0; i < 9; ++i)
255 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
258 for (
int i = 0; i < 5; ++i)
261 oss << 10 + z <<
".5." << 10 + i <<
".0";
262 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
263 for (uint32_t j = 0; j < nLANClients; ++j)
265 Ptr<Node> node = CreateObject<Node> (z % systemCount);
266 nodes_net3LAN[z][i][j].
Add (node);
267 stack.
Install (nodes_net3LAN[z][i][j]);
268 nodes_net3LAN[z][i][j].
Add (nodes_net3[z][i + 4].Get (0));
269 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
270 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
273 cout <<
" Connecting Subnets..." << endl;
275 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
276 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
277 nodes_netLR[z].
Add (node1);
278 nodes_netLR[z].
Add (node2);
279 stack.
Install (nodes_netLR[z]);
281 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
283 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
284 net0_4.
Add (nodes_netLR[z].Get (0));
285 net0_4.
Add (nodes_net0[z][0].Get (0));
286 net0_5.
Add (nodes_netLR[z].Get (1));
287 net0_5.
Add (nodes_net0[z][1].Get (0));
288 net2_4a.
Add (nodes_netLR[z].Get (0));
289 net2_4a.
Add (nodes_net2[z][0].Get (0));
290 net2_4b.
Add (nodes_netLR[z].Get (1));
291 net2_4b.
Add (nodes_net2[z][1].Get (0));
292 net3_5a.
Add (nodes_netLR[z].Get (1));
293 net3_5a.
Add (nodes_net3[z][0].Get (0));
294 net3_5b.
Add (nodes_netLR[z].Get (1));
295 net3_5b.
Add (nodes_net3[z][1].Get (0));
297 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
299 oss << 10 + z <<
".1.253.0";
300 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
301 ifs = address.
Assign (ndc0_4);
302 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
304 oss << 10 + z <<
".1.254.0";
305 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
306 ifs = address.
Assign (ndc0_5);
307 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
309 oss << 10 + z <<
".4.253.0";
310 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
311 ifs = address.
Assign (ndc2_4a);
312 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
314 oss << 10 + z <<
".4.254.0";
315 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
316 ifs = address.
Assign (ndc2_4b);
317 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
319 oss << 10 + z <<
".5.253.0";
320 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
321 ifs = address.
Assign (ndc3_5a);
322 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
324 oss << 10 + z <<
".5.254.0";
325 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
326 ifs = address.
Assign (ndc3_5b);
328 cout <<
" Assigning IP addresses..." << endl;
329 for (
int i = 0; i < 3; ++i)
332 oss << 10 + z <<
".1." << 1 + i <<
".0";
333 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
334 ifs0[z][i] = address.
Assign (ndc0[i]);
336 for (
int i = 0; i < 6; ++i)
343 oss << 10 + z <<
".2." << 1 + i <<
".0";
344 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
345 ifs1[z][i] = address.
Assign (ndc1[i]);
348 oss << 10 + z <<
".3.1.0";
349 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
350 ifs = address.
Assign (ndcLR);
351 for (
int i = 0; i < 14; ++i)
354 oss << 10 + z <<
".4." << 1 + i <<
".0";
355 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
356 ifs2[z][i] = address.
Assign (ndc2[i]);
358 for (
int i = 0; i < 9; ++i)
361 oss << 10 + z <<
".5." << 1 + i <<
".0";
362 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
363 ifs3[z][i] = address.
Assign (ndc3[i]);
369 cout <<
"Forming Ring Topology..." << endl;
371 for (uint32_t z = 0; z < nCN - 1; ++z)
373 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
374 nodes_ring[z].
Add (nodes_net0[z + 1][0].Get (0));
376 nodes_ring[nCN - 1].
Add (nodes_net0[nCN - 1][0].Get (0));
377 nodes_ring[nCN - 1].
Add (nodes_net0[0][0].Get (0));
379 for (uint32_t z = 0; z < nCN; ++z)
381 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
383 oss <<
"254.1." << z + 1 <<
".0";
384 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
385 ifs = address.
Assign (ndc_ring[z]);
390 cout <<
"Creating UDP Traffic Flows:" << endl;
394 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
396 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
401 if (systemCount == 1)
411 cout <<
"Remote Address is " << ifs1[0][2].
GetAddress (0) << endl;
415 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].
Get (0)));
418 else if (systemId == 1)
424 sinkHelper.
Install (nodes_net1[1][0].Get (0));
428 else if (systemId == 0)
434 cout <<
"Remote Address is " << ifs1[1][0].
GetAddress (0) << endl;
438 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].
Get (0)));
447 for (uint32_t z = 0; z < nCN; ++z)
455 cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
456 for (
int i = 0; i < 7; ++i)
458 for (uint32_t j = 0; j < nLANClients; ++j)
461 if (systemCount == 1)
464 (
"ns3::UdpSocketFactory",
468 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
472 else if (systemId == z % systemCount)
475 (
"ns3::UdpSocketFactory",
479 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
484 if (systemCount == 1)
486 r1 = 2 + (int)(4 * urng->
GetValue ());
498 else if (systemId == x % systemCount)
500 r1 = 2 + (int)(4 * urng->
GetValue ());
515 cout <<
"Net3 ]" << endl;
516 for (
int i = 0; i < 5; ++i)
518 for (uint32_t j = 0; j < nLANClients; ++j)
521 if (systemCount == 1)
524 (
"ns3::UdpSocketFactory",
528 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
532 else if (systemId == z % systemCount)
535 (
"ns3::UdpSocketFactory",
539 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
544 if (systemCount == 1)
546 r1 = 2 + (int)(4 * urng->
GetValue ());
558 else if (systemId == x % systemCount)
560 r1 = 2 + (int)(4 * urng->
GetValue ());
577 cout <<
"Created " << NodeList::GetNNodes () <<
" nodes." << endl;
583 cout <<
"Using Nix-vectors..." << endl;
588 cout <<
"Populating Routing tables..." << endl;
589 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
594 cout <<
"Routing tables population took "
595 <<
TIMER_DIFF (routingEnd, routingStart) << endl;
597 cout <<
"Running simulator..." << endl;
599 Simulator::Stop (
Seconds (100.0));
602 cout <<
"Simulator finished." << endl;
603 Simulator::Destroy ();
605 MpiInterface::Disable ();
607 cout <<
"-----" << endl <<
"Runtime Stats:" << endl;
608 cout <<
"Simulator init time: " << d1 << endl;
609 cout <<
"Simulator run time: " << d2 << endl;
610 cout <<
"Total elapsed time: " << d1 + d2 << endl;
613 NS_FATAL_ERROR (
"Can't use distributed simulator without MPI compiled in");