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