A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nms-p2p-nix-distributed.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * (c) 2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
5 */
6
7/**
8 * \file
9 * \ingroup mpi
10 *
11 * DARPA NMS Campus Network Model
12 *
13 * This topology replicates the original NMS Campus Network model
14 * with the exception of chord links (which were never utilized in the
15 * original model)
16 * Link Bandwidths and Delays may not be the same as the original
17 * specifications
18 *
19 * Modified for distributed simulation by Josh Pelkey <jpelkey@gatech.edu>
20 *
21 * The fundamental unit of the NMS model consists of a campus network. The
22 * campus network topology can been seen here:
23 * http://www.nsnam.org/~jpelkey3/nms.png
24 * The number of hosts (default 42) is variable. Finally, an arbitrary
25 * number of these campus networks can be connected together (default 2)
26 * to make very large simulations.
27 */
28
29#include "mpi-test-fixtures.h"
30
31#include "ns3/core-module.h"
32#include "ns3/internet-module.h"
33#include "ns3/mpi-interface.h"
34#include "ns3/network-module.h"
35#include "ns3/nix-vector-helper.h"
36#include "ns3/on-off-helper.h"
37#include "ns3/packet-sink-helper.h"
38#include "ns3/point-to-point-helper.h"
39
40#include <fstream>
41#include <vector>
42
43using namespace ns3;
44
45NS_LOG_COMPONENT_DEFINE("CampusNetworkModelDistributed");
46
47int
48main(int argc, char* argv[])
49{
50 typedef std::vector<NodeContainer> vectorOfNodeContainer;
51 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
52 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
53
54 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
55 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
56 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer>
57 vectorOfVectorOfVectorOfIpv4InterfaceContainer;
58
59 typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
60 typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
61
62 SystemWallClockMs t0; // Total time
63 SystemWallClockMs t1; // Setup time
64 SystemWallClockMs t2; // Run time/
65 t0.Start();
66 t1.Start();
67
68 uint32_t nCN = 2;
69 uint32_t nLANClients = 10;
70 bool single = false;
71 int nPackets = 10; // Packets sent by OnOff applications
72 bool nix = true;
73 Time stop = Seconds(100);
74 bool verbose = false;
75 bool testing = false;
76
77 CommandLine cmd(__FILE__);
78 cmd.AddValue("campuses", "Number of campus networks", nCN);
79 cmd.AddValue("clients", "Number of client nodes per LAN", nLANClients);
80 cmd.AddValue("packets", "Number of packets each on/off app should send", nPackets);
81 cmd.AddValue("nix", "Toggle the use of nix-vector or global routing", nix);
82 cmd.AddValue("stop", "Simulation run time", stop);
83 cmd.AddValue("single", "Use single on/off app per campus network", single);
84 cmd.AddValue("verbose", "Show extra timing information", verbose);
85 cmd.AddValue("test", "Enable regression test output", testing);
86
87 cmd.Parse(argc, argv);
88
89 // Enable parallel simulator with the command line arguments
90 MpiInterface::Enable(&argc, &argv);
91
93
95 uint32_t systemCount = MpiInterface::GetSize();
96
97 RANK0COUT(" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
98
99 GlobalValue::Bind("SimulatorImplementationType", StringValue("ns3::DistributedSimulatorImpl"));
100
101 if (nCN < 2)
102 {
103 RANK0COUT("Number of total CNs (" << nCN << ") lower than minimum of 2" << std::endl);
104 return 1;
105 }
106 if (systemCount > nCN)
107 {
108 RANK0COUT("Number of total CNs (" << nCN << ") should be >= systemCount (" << systemCount
109 << ")." << std::endl);
110 return 1;
111 }
112
113 RANK0COUT("Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl);
114
115 vectorOfNodeContainer nodes_netLR(nCN);
116 vectorOfVectorOfNodeContainer nodes_net0(nCN, vectorOfNodeContainer(3));
117 vectorOfVectorOfNodeContainer nodes_net1(nCN, vectorOfNodeContainer(6));
118 vectorOfVectorOfNodeContainer nodes_net2(nCN, vectorOfNodeContainer(14));
119 vectorOfVectorOfNodeContainer nodes_net3(nCN, vectorOfNodeContainer(9));
120
121 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(
122 nCN,
123 vectorOfVectorOfNodeContainer(7, vectorOfNodeContainer(nLANClients)));
124 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(
125 nCN,
126 vectorOfVectorOfNodeContainer(5, vectorOfNodeContainer(nLANClients)));
127
128 PointToPointHelper p2p_2gb200ms;
129 PointToPointHelper p2p_1gb5ms;
130 PointToPointHelper p2p_100mb1ms;
132
134
135 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN, vectorOfIpv4InterfaceContainer(3));
136 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN, vectorOfIpv4InterfaceContainer(6));
137 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN, vectorOfIpv4InterfaceContainer(14));
138 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN, vectorOfIpv4InterfaceContainer(9));
139 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(
140 nCN,
141 vectorOfVectorOfIpv4InterfaceContainer(7, vectorOfIpv4InterfaceContainer(nLANClients)));
142 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(
143 nCN,
144 vectorOfVectorOfIpv4InterfaceContainer(5, vectorOfIpv4InterfaceContainer(nLANClients)));
145
147 std::ostringstream oss;
148 p2p_1gb5ms.SetDeviceAttribute("DataRate", StringValue("1Gbps"));
149 p2p_1gb5ms.SetChannelAttribute("Delay", StringValue("5ms"));
150 p2p_2gb200ms.SetDeviceAttribute("DataRate", StringValue("2Gbps"));
151 p2p_2gb200ms.SetChannelAttribute("Delay", StringValue("200ms"));
152 p2p_100mb1ms.SetDeviceAttribute("DataRate", StringValue("100Mbps"));
153 p2p_100mb1ms.SetChannelAttribute("Delay", StringValue("1ms"));
154
155 if (nix)
156 {
158 stack.SetRoutingHelper(nixRouting); // has effect on the next Install ()
159 }
160
161 // Create Campus Networks
162 for (uint32_t z = 0; z < nCN; ++z)
163 {
164 RANK0COUT("Creating Campus Network " << z << ":" << std::endl);
165 // Create Net0
166 RANK0COUT(" SubNet [ 0");
167 for (int i = 0; i < 3; ++i)
168 {
169 Ptr<Node> node = CreateObject<Node>(z % systemCount);
170 nodes_net0[z][i].Add(node);
171 stack.Install(nodes_net0[z][i]);
172 }
173 nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
174 nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
175 nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
176 NetDeviceContainer ndc0[3];
177 for (int i = 0; i < 3; ++i)
178 {
179 ndc0[i] = p2p_1gb5ms.Install(nodes_net0[z][i]);
180 }
181 // Create Net1
182 RANK0COUTAPPEND(" 1");
183 for (int i = 0; i < 6; ++i)
184 {
185 Ptr<Node> node = CreateObject<Node>(z % systemCount);
186 nodes_net1[z][i].Add(node);
187 stack.Install(nodes_net1[z][i]);
188 }
189 nodes_net1[z][0].Add(nodes_net1[z][1].Get(0));
190 nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
191 nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
192 nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
193 nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
194 NetDeviceContainer ndc1[6];
195 for (int i = 0; i < 6; ++i)
196 {
197 if (i == 1)
198 {
199 continue;
200 }
201 ndc1[i] = p2p_1gb5ms.Install(nodes_net1[z][i]);
202 }
203 // Connect Net0 <-> Net1
204 NodeContainer net0_1;
205 net0_1.Add(nodes_net0[z][2].Get(0));
206 net0_1.Add(nodes_net1[z][0].Get(0));
207 NetDeviceContainer ndc0_1;
208 ndc0_1 = p2p_1gb5ms.Install(net0_1);
209 oss.str("");
210 oss << 10 + z << ".1.252.0";
211 address.SetBase(oss.str().c_str(), "255.255.255.0");
212 ifs = address.Assign(ndc0_1);
213 // Create Net2
214 RANK0COUTAPPEND(" 2");
215 for (int i = 0; i < 14; ++i)
216 {
217 Ptr<Node> node = CreateObject<Node>(z % systemCount);
218 nodes_net2[z][i].Add(node);
219 stack.Install(nodes_net2[z][i]);
220 }
221 nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
222 nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
223 nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
224 nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
225 nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
226 nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
227 nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
228 nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
229 nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
230 nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
231 nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
232 nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
233 nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
234 nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
235 NetDeviceContainer ndc2[14];
236 for (int i = 0; i < 14; ++i)
237 {
238 ndc2[i] = p2p_1gb5ms.Install(nodes_net2[z][i]);
239 }
240 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
241 for (int i = 0; i < 7; ++i)
242 {
243 oss.str("");
244 oss << 10 + z << ".4." << 15 + i << ".0";
245 address.SetBase(oss.str().c_str(), "255.255.255.0");
246 for (uint32_t j = 0; j < nLANClients; ++j)
247 {
248 Ptr<Node> node = CreateObject<Node>(z % systemCount);
249 nodes_net2LAN[z][i][j].Add(node);
250 stack.Install(nodes_net2LAN[z][i][j]);
251 nodes_net2LAN[z][i][j].Add(nodes_net2[z][i + 7].Get(0));
252 ndc2LAN[i][j] = p2p_100mb1ms.Install(nodes_net2LAN[z][i][j]);
253 ifs2LAN[z][i][j] = address.Assign(ndc2LAN[i][j]);
254 }
255 }
256 // Create Net3
257 RANK0COUTAPPEND(" 3 ]" << std::endl);
258 for (int i = 0; i < 9; ++i)
259 {
260 Ptr<Node> node = CreateObject<Node>(z % systemCount);
261 nodes_net3[z][i].Add(node);
262 stack.Install(nodes_net3[z][i]);
263 }
264 nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
265 nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
266 nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
267 nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
268 nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
269 nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
270 nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
271 nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
272 nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
273 NetDeviceContainer ndc3[9];
274 for (int i = 0; i < 9; ++i)
275 {
276 ndc3[i] = p2p_1gb5ms.Install(nodes_net3[z][i]);
277 }
278 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
279 for (int i = 0; i < 5; ++i)
280 {
281 oss.str("");
282 oss << 10 + z << ".5." << 10 + i << ".0";
283 address.SetBase(oss.str().c_str(), "255.255.255.0");
284 for (uint32_t j = 0; j < nLANClients; ++j)
285 {
286 Ptr<Node> node = CreateObject<Node>(z % systemCount);
287 nodes_net3LAN[z][i][j].Add(node);
288 stack.Install(nodes_net3LAN[z][i][j]);
289 nodes_net3LAN[z][i][j].Add(nodes_net3[z][i + 4].Get(0));
290 ndc3LAN[i][j] = p2p_100mb1ms.Install(nodes_net3LAN[z][i][j]);
291 ifs3LAN[z][i][j] = address.Assign(ndc3LAN[i][j]);
292 }
293 }
294 RANK0COUT(" Connecting Subnets..." << std::endl);
295 // Create Lone Routers (Node 4 & 5)
296 Ptr<Node> node1 = CreateObject<Node>(z % systemCount);
297 Ptr<Node> node2 = CreateObject<Node>(z % systemCount);
298 nodes_netLR[z].Add(node1);
299 nodes_netLR[z].Add(node2);
300 stack.Install(nodes_netLR[z]);
301 NetDeviceContainer ndcLR;
302 ndcLR = p2p_1gb5ms.Install(nodes_netLR[z]);
303 // Connect Net2/Net3 through Lone Routers to Net0
304 NodeContainer net0_4;
305 NodeContainer net0_5;
306 NodeContainer net2_4a;
307 NodeContainer net2_4b;
308 NodeContainer net3_5a;
309 NodeContainer net3_5b;
310 net0_4.Add(nodes_netLR[z].Get(0));
311 net0_4.Add(nodes_net0[z][0].Get(0));
312 net0_5.Add(nodes_netLR[z].Get(1));
313 net0_5.Add(nodes_net0[z][1].Get(0));
314 net2_4a.Add(nodes_netLR[z].Get(0));
315 net2_4a.Add(nodes_net2[z][0].Get(0));
316 net2_4b.Add(nodes_netLR[z].Get(1));
317 net2_4b.Add(nodes_net2[z][1].Get(0));
318 net3_5a.Add(nodes_netLR[z].Get(1));
319 net3_5a.Add(nodes_net3[z][0].Get(0));
320 net3_5b.Add(nodes_netLR[z].Get(1));
321 net3_5b.Add(nodes_net3[z][1].Get(0));
322 NetDeviceContainer ndc0_4;
323 NetDeviceContainer ndc0_5;
324 NetDeviceContainer ndc2_4a;
325 NetDeviceContainer ndc2_4b;
326 NetDeviceContainer ndc3_5a;
327 NetDeviceContainer ndc3_5b;
328 ndc0_4 = p2p_1gb5ms.Install(net0_4);
329 oss.str("");
330 oss << 10 + z << ".1.253.0";
331 address.SetBase(oss.str().c_str(), "255.255.255.0");
332 ifs = address.Assign(ndc0_4);
333 ndc0_5 = p2p_1gb5ms.Install(net0_5);
334 oss.str("");
335 oss << 10 + z << ".1.254.0";
336 address.SetBase(oss.str().c_str(), "255.255.255.0");
337 ifs = address.Assign(ndc0_5);
338 ndc2_4a = p2p_1gb5ms.Install(net2_4a);
339 oss.str("");
340 oss << 10 + z << ".4.253.0";
341 address.SetBase(oss.str().c_str(), "255.255.255.0");
342 ifs = address.Assign(ndc2_4a);
343 ndc2_4b = p2p_1gb5ms.Install(net2_4b);
344 oss.str("");
345 oss << 10 + z << ".4.254.0";
346 address.SetBase(oss.str().c_str(), "255.255.255.0");
347 ifs = address.Assign(ndc2_4b);
348 ndc3_5a = p2p_1gb5ms.Install(net3_5a);
349 oss.str("");
350 oss << 10 + z << ".5.253.0";
351 address.SetBase(oss.str().c_str(), "255.255.255.0");
352 ifs = address.Assign(ndc3_5a);
353 ndc3_5b = p2p_1gb5ms.Install(net3_5b);
354 oss.str("");
355 oss << 10 + z << ".5.254.0";
356 address.SetBase(oss.str().c_str(), "255.255.255.0");
357 ifs = address.Assign(ndc3_5b);
358 // Assign IP addresses
359 RANK0COUT(" Assigning IP addresses..." << std::endl);
360 for (int i = 0; i < 3; ++i)
361 {
362 oss.str("");
363 oss << 10 + z << ".1." << 1 + i << ".0";
364 address.SetBase(oss.str().c_str(), "255.255.255.0");
365 ifs0[z][i] = address.Assign(ndc0[i]);
366 }
367 for (int i = 0; i < 6; ++i)
368 {
369 if (i == 1)
370 {
371 continue;
372 }
373 oss.str("");
374 oss << 10 + z << ".2." << 1 + i << ".0";
375 address.SetBase(oss.str().c_str(), "255.255.255.0");
376 ifs1[z][i] = address.Assign(ndc1[i]);
377 }
378 oss.str("");
379 oss << 10 + z << ".3.1.0";
380 address.SetBase(oss.str().c_str(), "255.255.255.0");
381 ifs = address.Assign(ndcLR);
382 for (int i = 0; i < 14; ++i)
383 {
384 oss.str("");
385 oss << 10 + z << ".4." << 1 + i << ".0";
386 address.SetBase(oss.str().c_str(), "255.255.255.0");
387 ifs2[z][i] = address.Assign(ndc2[i]);
388 }
389 for (int i = 0; i < 9; ++i)
390 {
391 oss.str("");
392 oss << 10 + z << ".5." << 1 + i << ".0";
393 address.SetBase(oss.str().c_str(), "255.255.255.0");
394 ifs3[z][i] = address.Assign(ndc3[i]);
395 }
396 }
397 // Create Ring Links
398 if (nCN > 1)
399 {
400 RANK0COUT("Forming Ring Topology..." << std::endl);
401 vectorOfNodeContainer nodes_ring(nCN);
402 for (uint32_t z = 0; z < nCN - 1; ++z)
403 {
404 nodes_ring[z].Add(nodes_net0[z][0].Get(0));
405 nodes_ring[z].Add(nodes_net0[z + 1][0].Get(0));
406 }
407 nodes_ring[nCN - 1].Add(nodes_net0[nCN - 1][0].Get(0));
408 nodes_ring[nCN - 1].Add(nodes_net0[0][0].Get(0));
409 vectorOfNetDeviceContainer ndc_ring(nCN);
410 for (uint32_t z = 0; z < nCN; ++z)
411 {
412 ndc_ring[z] = p2p_2gb200ms.Install(nodes_ring[z]);
413 oss.str("");
414 oss << "254.1." << z + 1 << ".0";
415 address.SetBase(oss.str().c_str(), "255.255.255.0");
416 ifs = address.Assign(ndc_ring[z]);
417 }
418 }
419
420 // Create Traffic Flows
421 RANK0COUT("Creating UDP Traffic Flows:" << std::endl);
422 Config::SetDefault("ns3::OnOffApplication::MaxBytes", UintegerValue(nPackets * 512));
423 Config::SetDefault("ns3::OnOffApplication::OnTime",
424 StringValue("ns3::ConstantRandomVariable[Constant=1]"));
425 Config::SetDefault("ns3::OnOffApplication::OffTime",
426 StringValue("ns3::ConstantRandomVariable[Constant=0]"));
427
428 if (single)
429 {
430 if (systemCount == 1)
431 {
432 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
434 ApplicationContainer sinkApp = sinkHelper.Install(nodes_net1[0][2].Get(0));
435 sinkApp.Start(Seconds(0.0));
436 if (testing)
437 {
438 sinkApp.Get(0)->TraceConnectWithoutContext("RxWithAddresses",
440 }
441
442 OnOffHelper client("ns3::UdpSocketFactory", Address());
443 AddressValue remoteAddress(InetSocketAddress(ifs1[0][2].GetAddress(0), 9999));
444 RANK0COUT("Remote Address is " << ifs1[0][2].GetAddress(0) << std::endl);
445 client.SetAttribute("Remote", remoteAddress);
446
447 ApplicationContainer clientApp;
448 clientApp.Add(client.Install(nodes_net2LAN[0][0][0].Get(0)));
449 clientApp.Start(Seconds(0));
450 }
451 else if (systemId == 1)
452 {
453 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
455 ApplicationContainer sinkApp = sinkHelper.Install(nodes_net1[1][0].Get(0));
456 sinkApp.Start(Seconds(0.0));
457 if (testing)
458 {
459 sinkApp.Get(0)->TraceConnectWithoutContext("RxWithAddresses",
461 }
462 }
463 else if (systemId == 0)
464 {
465 OnOffHelper client("ns3::UdpSocketFactory", Address());
466 AddressValue remoteAddress(InetSocketAddress(ifs1[1][0].GetAddress(0), 9999));
467
468 RANK0COUT("Remote Address is " << ifs1[1][0].GetAddress(0) << std::endl);
469 client.SetAttribute("Remote", remoteAddress);
470
471 ApplicationContainer clientApp;
472 clientApp.Add(client.Install(nodes_net2LAN[0][0][0].Get(0)));
473 clientApp.Start(Seconds(0));
474 }
475 }
476 else
477 {
479 int r1;
480 double r2;
481 for (uint32_t z = 0; z < nCN; ++z)
482 {
483 uint32_t x = z + 1;
484 if (z == nCN - 1)
485 {
486 x = 0;
487 }
488 // Subnet 2 LANs
489 RANK0COUT(" Campus Network " << z << " Flows [ Net2 ");
490 for (int i = 0; i < 7; ++i)
491 {
492 for (uint32_t j = 0; j < nLANClients; ++j)
493 {
494 // Sinks
495 if (systemCount == 1)
496 {
497 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
499
500 ApplicationContainer sinkApp =
501 sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
502
503 sinkApp.Start(Seconds(0.0));
504 if (testing)
505 {
506 sinkApp.Get(0)->TraceConnectWithoutContext(
507 "RxWithAddresses",
509 }
510 }
511 else if (systemId == z % systemCount)
512 {
513 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
515
516 ApplicationContainer sinkApp =
517 sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
518
519 sinkApp.Start(Seconds(0.0));
520 if (testing)
521 {
522 sinkApp.Get(0)->TraceConnectWithoutContext(
523 "RxWithAddresses",
525 }
526 }
527 // Sources
528 if (systemCount == 1)
529 {
530 r1 = 2 + (int)(4 * urng->GetValue());
531 r2 = 10 * urng->GetValue();
532 OnOffHelper client("ns3::UdpSocketFactory", Address());
533
535 InetSocketAddress(ifs2LAN[z][i][j].GetAddress(0), 9999));
536
537 client.SetAttribute("Remote", remoteAddress);
538 ApplicationContainer clientApp;
539 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
540 clientApp.Start(Seconds(r2));
541 }
542 else if (systemId == x % systemCount)
543 {
544 r1 = 2 + (int)(4 * urng->GetValue());
545 r2 = 10 * urng->GetValue();
546 OnOffHelper client("ns3::UdpSocketFactory", Address());
547
549 InetSocketAddress(ifs2LAN[z][i][j].GetAddress(0), 9999));
550
551 client.SetAttribute("Remote", remoteAddress);
552 ApplicationContainer clientApp;
553 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
554 clientApp.Start(Seconds(r2));
555 }
556 }
557 }
558 // Subnet 3 LANs
559 RANK0COUTAPPEND("Net3 ]" << std::endl);
560 for (int i = 0; i < 5; ++i)
561 {
562 for (uint32_t j = 0; j < nLANClients; ++j)
563 {
564 // Sinks
565 if (systemCount == 1)
566 {
567 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
569
570 ApplicationContainer sinkApp =
571 sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
572 sinkApp.Start(Seconds(0.0));
573 if (testing)
574 {
575 sinkApp.Get(0)->TraceConnectWithoutContext(
576 "RxWithAddresses",
578 }
579 }
580 else if (systemId == z % systemCount)
581 {
582 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
584
585 ApplicationContainer sinkApp =
586 sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
587
588 sinkApp.Start(Seconds(0.0));
589 if (testing)
590 {
591 sinkApp.Get(0)->TraceConnectWithoutContext(
592 "RxWithAddresses",
594 }
595 }
596 // Sources
597 if (systemCount == 1)
598 {
599 r1 = 2 + (int)(4 * urng->GetValue());
600 r2 = 10 * urng->GetValue();
601 OnOffHelper client("ns3::UdpSocketFactory", Address());
602
604 InetSocketAddress(ifs3LAN[z][i][j].GetAddress(0), 9999));
605
606 client.SetAttribute("Remote", remoteAddress);
607 ApplicationContainer clientApp;
608 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
609 clientApp.Start(Seconds(r2));
610 }
611 else if (systemId == x % systemCount)
612 {
613 r1 = 2 + (int)(4 * urng->GetValue());
614 r2 = 10 * urng->GetValue();
615 OnOffHelper client("ns3::UdpSocketFactory", Address());
616
618 InetSocketAddress(ifs3LAN[z][i][j].GetAddress(0), 9999));
619
620 client.SetAttribute("Remote", remoteAddress);
621 ApplicationContainer clientApp;
622 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
623 clientApp.Start(Seconds(r2));
624 }
625 }
626 }
627 }
628 }
629
630 RANK0COUT("Created " << NodeList::GetNNodes() << " nodes." << std::endl);
631 SystemWallClockMs tRouting;
632 tRouting.Start();
633 ;
634
635 if (nix)
636 {
637 RANK0COUT("Using Nix-vectors..." << std::endl);
638 }
639 else
640 {
641 // Calculate routing tables
642 RANK0COUT("Populating Routing tables..." << std::endl);
644 }
645
646 tRouting.End();
647 if (verbose)
648 {
649 RANK0COUT("Routing tables population took " << tRouting.GetElapsedReal() << "ms"
650 << std::endl);
651 }
652
653 RANK0COUT("Running simulator..." << std::endl);
654 t1.End();
655 t2.Start();
656 Simulator::Stop(stop);
658 RANK0COUT("Simulator finished." << std::endl);
660
661 if (testing)
662 {
663 const int numberNodesSending =
664 nCN * (nLANClients * (7 + 5)); // 7 size of Net2, 5 size of Net3
665 const int expectedPacketCount = numberNodesSending * nPackets;
666
667 SinkTracer::Verify(expectedPacketCount);
668 }
669
670 // Exit the parallel execution environment
672 t2.End();
673 RANK0COUT("-----" << std::endl);
674
675 if (verbose)
676 {
677 RANK0COUT("Runtime Stats:\n"
678 << "Simulator init time: " << t1.GetElapsedReal() << "ms\n"
679 << "Simulator run time: " << t2.GetElapsedReal() << "ms\n"
680 << "Total elapsed time: " << t0.GetElapsedReal() << "ms" << std::endl);
681 }
682 return 0;
683}
a polymophic address class
Definition address.h:90
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static uint32_t GetSystemId()
Get the id number of this rank.
static uint32_t GetSize()
Get the number of ranks used by ns-3.
static void Disable()
Clean up the ns-3 parallel communications interface.
static void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface.
holds a vector of ns3::NetDevice pointers
Helper class that adds Nix-vector routing to nodes.
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes()
Definition node-list.cc:247
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of 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)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Smart pointer class similar to boost::intrusive_ptr.
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
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
static void Init()
PacketSink Init.
Hold variables of type string.
Definition string.h:45
Measure elapsed wall clock time in milliseconds.
int64_t End()
Stop measuring the time since Start() was called.
void Start()
Start a measure.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define RANK0COUT(x)
Write to std::cout only from rank 0.
#define RANK0COUTAPPEND(x)
Append to std::cout only from rank 0.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Common methods for MPI examples.
address
Definition first.py:36
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
bool verbose