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