A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nms-p2p-nix.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, GTech Systems, Inc.
3 * Copyright (c) 2021 NITK Surathkal: Extended to handle IPv6
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Alfred Park <park@gtech-systems.com>
8 * Modified By: Josh Pelkey <jpelkey@gatech.edu> (ported to ns-3)
9 * Modified By: Ameya Deshpande <ameyanrd@outlook.com> (IPv6 extensions)
10 * Tommaso Pecorella <tommaso.pecorella@unifi.it> (IPv6 extensions)
11 */
12/*
13 * DARPA NMS Campus Network Model
14 *
15 * This topology replicates the original NMS Campus Network model
16 * with the exception of chord links (which were never utilized in the
17 * original model)
18 * Link Bandwidths and Delays may not be the same as the original
19 * specifications
20 *
21 * The fundamental unit of the NMS model consists of a campus network. The
22 * campus network topology can been seen in the model manual.
23 *
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 "ns3/applications-module.h"
30#include "ns3/core-module.h"
31#include "ns3/internet-module.h"
32#include "ns3/network-module.h"
33#include "ns3/nix-vector-helper.h"
34#include "ns3/onoff-application.h"
35#include "ns3/packet-sink.h"
36#include "ns3/point-to-point-module.h"
37#include "ns3/simulator.h"
38
39#include <chrono>
40#include <sstream>
41
42using namespace ns3;
43
44NS_LOG_COMPONENT_DEFINE("CampusNetworkModel");
45
46void
51
52/**
53 * \ingroup nix-vector-routing
54 * 2D array used in nix-vector-routing example "nms-p2p-nix.cc"
55 */
56template <typename T>
58{
59 public:
60 /**
61 * Constructor
62 * \param x number of rows
63 * \param y number of columns
64 */
65 Array2D(const size_t x, const size_t y)
66 : p(new T*[x]),
67 m_xMax(x)
68 {
69 for (size_t i = 0; i < m_xMax; i++)
70 {
71 p[i] = new T[y];
72 }
73 }
74
76 {
77 for (size_t i = 0; i < m_xMax; i++)
78 {
79 delete[] p[i];
80 }
81 delete[] p;
82 p = nullptr;
83 }
84
85 /**
86 * Accessor operator
87 * \param i index to be retrieved
88 * \return a pointer to the indexed element
89 */
90 T* operator[](const size_t i)
91 {
92 return p[i];
93 }
94
95 private:
96 T** p; //!< Stored elements
97 const size_t m_xMax; //!< maximum number of rows
98};
99
100/**
101 * \ingroup nix-vector-routing
102 * 3D array used in nix-vector-routing example "nms-p2p-nix.cc"
103 */
104template <typename T>
106{
107 public:
108 /**
109 * Constructor
110 * \param x number of rows
111 * \param y number of columns
112 * \param z number of layers
113 */
114 Array3D(const size_t x, const size_t y, const size_t z)
115 : p(new Array2D<T>*[x]),
116 m_xMax(x)
117 {
118 for (size_t i = 0; i < m_xMax; i++)
119 {
120 p[i] = new Array2D<T>(y, z);
121 }
122 }
123
125 {
126 for (size_t i = 0; i < m_xMax; i++)
127 {
128 delete p[i];
129 p[i] = nullptr;
130 }
131 delete[] p;
132 p = nullptr;
133 }
134
135 /**
136 * Accessor operator
137 * \param i index to be retrieved
138 * \return a reference to an Array2D of the indexed element
139 */
140 Array2D<T>& operator[](const size_t i)
141 {
142 return *(p[i]);
143 }
144
145 private:
146 Array2D<T>** p; //!< Stored elements
147 const size_t m_xMax; //!< maximum number of rows
148};
149
150int
151main(int argc, char* argv[])
152{
153 auto t0 = std::chrono::steady_clock::now();
154
155 std::cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
156 // LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
157
158 int nCN = 2;
159 int nLANClients = 42;
160 bool nix = true;
161 bool useIpv6 = false;
162
163 CommandLine cmd(__FILE__);
164 cmd.AddValue("useIPv6", "Use IPv6 instead of IPv4", useIpv6);
165 cmd.AddValue("CN", "Number of total CNs [2]", nCN);
166 cmd.AddValue("LAN", "Number of nodes per LAN [42]", nLANClients);
167 cmd.AddValue("NIX", "Toggle nix-vector routing", nix);
168 cmd.Parse(argc, argv);
169
170 if (useIpv6 && !nix)
171 {
172 std::cout << "This script can work in IPv6 only by using NIX" << std::endl;
173 return 1;
174 }
175 if (nCN < 2)
176 {
177 std::cout << "Number of total CNs (" << nCN << ") lower than minimum of 2" << std::endl;
178 return 1;
179 }
180
181 std::cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl;
182
183 Array2D<NodeContainer> nodes_net0(nCN, 3);
184 Array2D<NodeContainer> nodes_net1(nCN, 6);
185 auto nodes_netLR = new NodeContainer[nCN];
186 Array2D<NodeContainer> nodes_net2(nCN, 14);
187 Array3D<NodeContainer> nodes_net2LAN(nCN, 7, nLANClients);
188 Array2D<NodeContainer> nodes_net3(nCN, 9);
189 Array3D<NodeContainer> nodes_net3LAN(nCN, 5, nLANClients);
190
191 PointToPointHelper p2p_2gb200ms;
192 PointToPointHelper p2p_1gb5ms;
193 PointToPointHelper p2p_100mb1ms;
195 Array3D<Address> ifs2LanRemoteAddress(nCN, 7, nLANClients);
196 Array3D<Address> ifs3LanRemoteAddress(nCN, 5, nLANClients);
197
198 Ipv4AddressHelper addressHelperv4;
199 Ipv6AddressHelper addressHelperv6;
200 std::ostringstream oss;
201 p2p_1gb5ms.SetDeviceAttribute("DataRate", StringValue("1Gbps"));
202 p2p_1gb5ms.SetChannelAttribute("Delay", StringValue("5ms"));
203 p2p_2gb200ms.SetDeviceAttribute("DataRate", StringValue("2Gbps"));
204 p2p_2gb200ms.SetChannelAttribute("Delay", StringValue("200ms"));
205 p2p_100mb1ms.SetDeviceAttribute("DataRate", StringValue("100Mbps"));
206 p2p_100mb1ms.SetChannelAttribute("Delay", StringValue("1ms"));
207
208 // Setup NixVector Routing
209 if (nix)
210 {
211 if (!useIpv6)
212 {
214 stack.SetRoutingHelper(nixRouting); // has effect on the next Install ()
215 }
216 else
217 {
219 stack.SetRoutingHelper(nixRouting); // has effect on the next Install ()
220 }
221 }
222
223 // Create Campus Networks
224 for (int z = 0; z < nCN; ++z)
225 {
226 std::cout << "Creating Campus Network " << z << ":" << std::endl;
227 // Create Net0
228 std::cout << " SubNet [ 0";
229 for (int i = 0; i < 3; ++i)
230 {
231 nodes_net0[z][i].Create(1);
232 stack.Install(nodes_net0[z][i]);
233 }
234 nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
235 nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
236 nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
237 NetDeviceContainer ndc0[3];
238 for (int i = 0; i < 3; ++i)
239 {
240 ndc0[i] = p2p_1gb5ms.Install(nodes_net0[z][i]);
241 }
242 // Create Net1
243 std::cout << " 1";
244 for (int i = 0; i < 6; ++i)
245 {
246 nodes_net1[z][i].Create(1);
247 stack.Install(nodes_net1[z][i]);
248 }
249 nodes_net1[z][0].Add(nodes_net1[z][1].Get(0));
250 nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
251 nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
252 nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
253 nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
254 NetDeviceContainer ndc1[6];
255 for (int i = 0; i < 6; ++i)
256 {
257 if (i == 1)
258 {
259 continue;
260 }
261 ndc1[i] = p2p_1gb5ms.Install(nodes_net1[z][i]);
262 }
263 // Connect Net0 <-> Net1
264 NodeContainer net0_1;
265 net0_1.Add(nodes_net0[z][2].Get(0));
266 net0_1.Add(nodes_net1[z][0].Get(0));
267 NetDeviceContainer ndc0_1;
268 ndc0_1 = p2p_1gb5ms.Install(net0_1);
269 oss.str("");
270 if (!useIpv6)
271 {
272 oss << 10 + z << ".1.252.0";
273 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
274 addressHelperv4.Assign(ndc0_1);
275 }
276 else
277 {
278 oss << 2001 + z << ":1:252::";
279 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
280 addressHelperv6.Assign(ndc0_1);
281 }
282 // Create Net2
283 std::cout << " 2";
284 for (int i = 0; i < 14; ++i)
285 {
286 nodes_net2[z][i].Create(1);
287 stack.Install(nodes_net2[z][i]);
288 }
289 nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
290 nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
291 nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
292 nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
293 nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
294 nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
295 nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
296 nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
297 nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
298 nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
299 nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
300 nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
301 nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
302 nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
303 NetDeviceContainer ndc2[14];
304 for (int i = 0; i < 14; ++i)
305 {
306 ndc2[i] = p2p_1gb5ms.Install(nodes_net2[z][i]);
307 }
308 Array2D<NetDeviceContainer> ndc2LAN(7, nLANClients);
309 for (int i = 0; i < 7; ++i)
310 {
311 oss.str("");
312 if (!useIpv6)
313 {
314 oss << 10 + z << ".4." << 15 + i << ".0";
315 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
316 }
317 else
318 {
319 oss << 2001 + z << ":4:" << 15 + i << "::";
320 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
321 }
322 for (int j = 0; j < nLANClients; ++j)
323 {
324 nodes_net2LAN[z][i][j].Create(1);
325 stack.Install(nodes_net2LAN[z][i][j]);
326 nodes_net2LAN[z][i][j].Add(nodes_net2[z][i + 7].Get(0));
327 ndc2LAN[i][j] = p2p_100mb1ms.Install(nodes_net2LAN[z][i][j]);
328 if (!useIpv6)
329 {
330 ifs2LanRemoteAddress[z][i][j] =
331 InetSocketAddress(addressHelperv4.Assign(ndc2LAN[i][j]).GetAddress(0),
332 9999);
333 }
334 else
335 {
336 ifs2LanRemoteAddress[z][i][j] =
337 Inet6SocketAddress(addressHelperv6.Assign(ndc2LAN[i][j]).GetAddress(0, 1),
338 9999);
339 }
340 }
341 }
342 // Create Net3
343 std::cout << " 3 ]" << std::endl;
344 for (int i = 0; i < 9; ++i)
345 {
346 nodes_net3[z][i].Create(1);
347 stack.Install(nodes_net3[z][i]);
348 }
349 nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
350 nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
351 nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
352 nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
353 nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
354 nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
355 nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
356 nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
357 nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
358 NetDeviceContainer ndc3[9];
359 for (int i = 0; i < 9; ++i)
360 {
361 ndc3[i] = p2p_1gb5ms.Install(nodes_net3[z][i]);
362 }
363 Array2D<NetDeviceContainer> ndc3LAN(5, nLANClients);
364 for (int i = 0; i < 5; ++i)
365 {
366 oss.str("");
367 if (!useIpv6)
368 {
369 oss << 10 + z << ".5." << 10 + i << ".0";
370 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
371 }
372 else
373 {
374 oss << 2001 + z << ":5:" << 10 + i << "::";
375 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
376 }
377 for (int j = 0; j < nLANClients; ++j)
378 {
379 nodes_net3LAN[z][i][j].Create(1);
380 stack.Install(nodes_net3LAN[z][i][j]);
381 nodes_net3LAN[z][i][j].Add(nodes_net3[z][i + 4].Get(0));
382 ndc3LAN[i][j] = p2p_100mb1ms.Install(nodes_net3LAN[z][i][j]);
383 if (!useIpv6)
384 {
385 ifs3LanRemoteAddress[z][i][j] =
386 InetSocketAddress(addressHelperv4.Assign(ndc3LAN[i][j]).GetAddress(0),
387 9999);
388 }
389 else
390 {
391 ifs3LanRemoteAddress[z][i][j] =
392 Inet6SocketAddress(addressHelperv6.Assign(ndc3LAN[i][j]).GetAddress(0, 1),
393 9999);
394 }
395 }
396 }
397 std::cout << " Connecting Subnets..." << std::endl;
398 // Create Lone Routers (Node 4 & 5)
399 nodes_netLR[z].Create(2);
400 stack.Install(nodes_netLR[z]);
401 NetDeviceContainer ndcLR;
402 ndcLR = p2p_1gb5ms.Install(nodes_netLR[z]);
403 // Connect Net2/Net3 through Lone Routers to Net0
404 NodeContainer net0_4;
405 NodeContainer net0_5;
406 NodeContainer net2_4a;
407 NodeContainer net2_4b;
408 NodeContainer net3_5a;
409 NodeContainer net3_5b;
410 net0_4.Add(nodes_netLR[z].Get(0));
411 net0_4.Add(nodes_net0[z][0].Get(0));
412 net0_5.Add(nodes_netLR[z].Get(1));
413 net0_5.Add(nodes_net0[z][1].Get(0));
414 net2_4a.Add(nodes_netLR[z].Get(0));
415 net2_4a.Add(nodes_net2[z][0].Get(0));
416 net2_4b.Add(nodes_netLR[z].Get(1));
417 net2_4b.Add(nodes_net2[z][1].Get(0));
418 net3_5a.Add(nodes_netLR[z].Get(1));
419 net3_5a.Add(nodes_net3[z][0].Get(0));
420 net3_5b.Add(nodes_netLR[z].Get(1));
421 net3_5b.Add(nodes_net3[z][1].Get(0));
422 NetDeviceContainer ndc0_4;
423 NetDeviceContainer ndc0_5;
424 NetDeviceContainer ndc2_4a;
425 NetDeviceContainer ndc2_4b;
426 NetDeviceContainer ndc3_5a;
427 NetDeviceContainer ndc3_5b;
428 ndc0_4 = p2p_1gb5ms.Install(net0_4);
429 ndc0_5 = p2p_1gb5ms.Install(net0_5);
430 ndc2_4a = p2p_1gb5ms.Install(net2_4a);
431 ndc2_4b = p2p_1gb5ms.Install(net2_4b);
432 ndc3_5a = p2p_1gb5ms.Install(net3_5a);
433 ndc3_5b = p2p_1gb5ms.Install(net3_5b);
434
435 // Assign IP addresses
436
437 if (!useIpv6)
438 {
439 // ndc0_4
440 oss.str("");
441 oss << 10 + z << ".1.253.0";
442 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
443 addressHelperv4.Assign(ndc0_4);
444 // ndc0_5
445 oss.str("");
446 oss << 10 + z << ".1.254.0";
447 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
448 addressHelperv4.Assign(ndc0_5);
449 // ndc2_4a
450 oss.str("");
451 oss << 10 + z << ".4.253.0";
452 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
453 addressHelperv4.Assign(ndc2_4a);
454 // ndc2_4b
455 oss.str("");
456 oss << 10 + z << ".4.254.0";
457 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
458 addressHelperv4.Assign(ndc2_4b);
459 // ndc3_5a
460 oss.str("");
461 oss << 10 + z << ".5.253.0";
462 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
463 addressHelperv4.Assign(ndc3_5a);
464 // ndc3_5b
465 oss.str("");
466 oss << 10 + z << ".5.254.0";
467 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
468 addressHelperv4.Assign(ndc3_5b);
469 }
470 else
471 {
472 // ndc0_4
473 oss.str("");
474 oss << 2001 + z << ":1:253::";
475 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
476 addressHelperv6.Assign(ndc0_4);
477 // ndc0_5
478 oss.str("");
479 oss << 2001 + z << ":1:254::";
480 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
481 addressHelperv6.Assign(ndc0_5);
482 // ndc2_4a
483 oss.str("");
484 oss << 2001 + z << ":4:253::";
485 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
486 addressHelperv6.Assign(ndc2_4a);
487 // ndc2_4b
488 oss.str("");
489 oss << 2001 + z << ":4:254::";
490 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
491 addressHelperv6.Assign(ndc2_4b);
492 // ndc3_5a
493 oss.str("");
494 oss << 2001 + z << ":5:253::";
495 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
496 addressHelperv6.Assign(ndc3_5a);
497 // ndc3_5b
498 oss.str("");
499 oss << 2001 + z << ":5:254::";
500 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
501 addressHelperv6.Assign(ndc3_5b);
502 }
503
504 std::cout << " Assigning IP addresses..." << std::endl;
505 for (int i = 0; i < 3; ++i)
506 {
507 oss.str("");
508 if (!useIpv6)
509 {
510 oss << 10 + z << ".1." << 1 + i << ".0";
511 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
512 addressHelperv4.Assign(ndc0[i]);
513 }
514 else
515 {
516 oss << 2001 + z << ":1:" << 1 + i << "::";
517 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
518 addressHelperv6.Assign(ndc0[i]);
519 }
520 }
521 for (int i = 0; i < 6; ++i)
522 {
523 if (i == 1)
524 {
525 continue;
526 }
527 oss.str("");
528 if (!useIpv6)
529 {
530 oss << 10 + z << ".2." << 1 + i << ".0";
531 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
532 addressHelperv4.Assign(ndc1[i]);
533 }
534 else
535 {
536 oss << 2001 + z << ":2:" << 1 + i << "::";
537 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
538 addressHelperv6.Assign(ndc1[i]);
539 }
540 }
541 oss.str("");
542 if (!useIpv6)
543 {
544 oss << 10 + z << ".3.1.0";
545 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
546 addressHelperv4.Assign(ndcLR);
547 }
548 else
549 {
550 oss << 2001 + z << ":3:1::";
551 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
552 addressHelperv6.Assign(ndcLR);
553 }
554 for (int i = 0; i < 14; ++i)
555 {
556 oss.str("");
557 if (!useIpv6)
558 {
559 oss << 10 + z << ".4." << 1 + i << ".0";
560 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
561 addressHelperv4.Assign(ndc2[i]);
562 }
563 else
564 {
565 oss << 2001 + z << ":4:" << 1 + i << "::";
566 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
567 addressHelperv6.Assign(ndc2[i]);
568 }
569 }
570 for (int i = 0; i < 9; ++i)
571 {
572 oss.str("");
573 if (!useIpv6)
574 {
575 oss << 10 + z << ".5." << 1 + i << ".0";
576 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
577 addressHelperv4.Assign(ndc3[i]);
578 }
579 else
580 {
581 oss << 2001 + z << ":5:" << 1 + i << "::";
582 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
583 addressHelperv6.Assign(ndc3[i]);
584 }
585 }
586 }
587 // Create Ring Links
588 if (nCN > 1)
589 {
590 std::cout << "Forming Ring Topology..." << std::endl;
591 auto nodes_ring = new NodeContainer[nCN];
592 for (int z = 0; z < nCN - 1; ++z)
593 {
594 nodes_ring[z].Add(nodes_net0[z][0].Get(0));
595 nodes_ring[z].Add(nodes_net0[z + 1][0].Get(0));
596 }
597 nodes_ring[nCN - 1].Add(nodes_net0[nCN - 1][0].Get(0));
598 nodes_ring[nCN - 1].Add(nodes_net0[0][0].Get(0));
599 auto ndc_ring = new NetDeviceContainer[nCN];
600 for (int z = 0; z < nCN; ++z)
601 {
602 ndc_ring[z] = p2p_2gb200ms.Install(nodes_ring[z]);
603 oss.str("");
604 if (!useIpv6)
605 {
606 oss << "254.1." << z + 1 << ".0";
607 addressHelperv4.SetBase(oss.str().c_str(), "255.255.255.0");
608 addressHelperv4.Assign(ndc_ring[z]);
609 }
610 else
611 {
612 oss << "254:1:" << z + 1 << "::";
613 addressHelperv6.SetBase(oss.str().c_str(), Ipv6Prefix(64));
614 addressHelperv6.Assign(ndc_ring[z]);
615 }
616 }
617 delete[] ndc_ring;
618 delete[] nodes_ring;
619 }
620
621 // Create Traffic Flows
622 std::cout << "Creating TCP Traffic Flows:" << std::endl;
623 Config::SetDefault("ns3::OnOffApplication::MaxBytes", UintegerValue(500000));
624 Config::SetDefault("ns3::OnOffApplication::OnTime",
625 StringValue("ns3::ConstantRandomVariable[Constant=1.0]"));
626 Config::SetDefault("ns3::OnOffApplication::OffTime",
627 StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
628 Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(512));
629
631 int r1;
632 double r2;
633
634 Address sinkAddress;
635 if (!useIpv6)
636 {
637 sinkAddress = InetSocketAddress(Ipv4Address::GetAny(), 9999);
638 }
639 else
640 {
641 sinkAddress = Inet6SocketAddress(Ipv6Address::GetAny(), 9999);
642 }
643
644 for (int z = 0; z < nCN; ++z)
645 {
646 int x = z + 1;
647 if (z == nCN - 1)
648 {
649 x = 0;
650 }
651 // Subnet 2 LANs
652 std::cout << " Campus Network " << z << " Flows [ Net2 ";
653 for (int i = 0; i < 7; ++i)
654 {
655 for (int j = 0; j < nLANClients; ++j)
656 {
657 // Sinks
658 PacketSinkHelper sinkHelper("ns3::TcpSocketFactory", sinkAddress);
659 ApplicationContainer sinkApp = sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
660 sinkApp.Start(Seconds(0.0));
661 // Sources
662 r1 = 2 + (int)(4 * urng->GetValue());
663 r2 = 10 * urng->GetValue();
664 OnOffHelper client("ns3::TcpSocketFactory", Address());
665 AddressValue remoteAddress(ifs2LanRemoteAddress[z][i][j]);
666 client.SetAttribute("Remote", remoteAddress);
667 ApplicationContainer clientApp;
668 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
669 clientApp.Start(Seconds(r2));
670 }
671 }
672 // Subnet 3 LANs
673 std::cout << "Net3 ]" << std::endl;
674 for (int i = 0; i < 5; ++i)
675 {
676 for (int j = 0; j < nLANClients; ++j)
677 {
678 // Sinks
679 PacketSinkHelper sinkHelper("ns3::TcpSocketFactory", sinkAddress);
680 ApplicationContainer sinkApp = sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
681 sinkApp.Start(Seconds(0.0));
682 // Sources
683 r1 = 2 + (int)(4 * urng->GetValue());
684 r2 = 10 * urng->GetValue();
685 OnOffHelper client("ns3::TcpSocketFactory", Address());
686 AddressValue remoteAddress(ifs3LanRemoteAddress[z][i][j]);
687 client.SetAttribute("Remote", remoteAddress);
688 ApplicationContainer clientApp;
689 clientApp.Add(client.Install(nodes_net1[x][r1].Get(0)));
690 clientApp.Start(Seconds(r2));
691 }
692 }
693 }
694
695 std::cout << "Created " << NodeList::GetNNodes() << " nodes." << std::endl;
696 auto routingStart = std::chrono::steady_clock::now();
697
698 if (nix)
699 {
700 // Calculate routing tables
701 std::cout << "Using Nix-vectors..." << std::endl;
702 }
703 else
704 {
705 // Calculate routing tables
706 std::cout << "Populating Global Static Routing Tables..." << std::endl;
708 }
709
710 auto routingEnd = std::chrono::steady_clock::now();
711 std::cout
712 << "Routing tables population took "
713 << std::chrono::duration_cast<std::chrono::milliseconds>(routingEnd - routingStart).count()
714 << "ms" << std::endl;
715
717 std::cout << "Running simulator..." << std::endl;
718 auto t1 = std::chrono::steady_clock::now();
719 Simulator::Stop(Seconds(100.0));
721 auto t2 = std::chrono::steady_clock::now();
722 std::cout << "Simulator finished." << std::endl;
724
725 auto d1 = std::chrono::duration_cast<std::chrono::seconds>(t1 - t0);
726 auto d2 = std::chrono::duration_cast<std::chrono::seconds>(t2 - t1);
727
728 std::cout << "-----" << std::endl << "Runtime Stats:" << std::endl;
729 std::cout << "Simulator init time: " << d1.count() << "s" << std::endl;
730 std::cout << "Simulator run time: " << d2.count() << "s" << std::endl;
731 std::cout << "Total elapsed time: " << (d1 + d2).count() << "s" << std::endl;
732
733 delete[] nodes_netLR;
734 return 0;
735}
2D array used in nix-vector-routing example "nms-p2p-nix.cc"
Array2D(const size_t x, const size_t y)
Constructor.
T * operator[](const size_t i)
Accessor operator.
const size_t m_xMax
maximum number of rows
T ** p
Stored elements.
3D array used in nix-vector-routing example "nms-p2p-nix.cc"
Array3D(const size_t x, const size_t y, const size_t z)
Constructor.
const size_t m_xMax
maximum number of rows
Array2D< T > ** p
Stored elements.
Array2D< T > & operator[](const size_t i)
Accessor operator.
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.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
An Inet6 address class.
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.
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...
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:594
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
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
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
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Progress()