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 // for timing functions
42 #include <cstdlib>
43 #include <sys/time.h>
44 #include <fstream>
45 
46 #include "ns3/core-module.h"
47 #include "ns3/internet-module.h"
48 #include "ns3/network-module.h"
49 #include "ns3/point-to-point-module.h"
50 #include "ns3/applications-module.h"
51 #include "ns3/onoff-application.h"
52 #include "ns3/packet-sink.h"
53 #include "ns3/simulator.h"
54 #include "ns3/nix-vector-helper.h"
55 
56 using namespace ns3;
57 
58 typedef struct timeval TIMER_TYPE;
59 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
60 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
61 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1)-TIMER_SECONDS (_t2))
62 
63 NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
64 
65 void Progress ()
66 {
68 }
69 
74 template <typename T>
75 class Array2D
76 {
77 public:
83  Array2D (const size_t x, const size_t y) :
84  p (new T*[x]), m_xMax (x)
85  {
86  for (size_t i = 0; i < m_xMax; i++)
87  p[i] = new T[y];
88  }
89 
90  ~Array2D (void)
91  {
92  for (size_t i = 0; i < m_xMax; i++)
93  delete[] p[i];
94  delete[] p;
95  p = 0;
96  }
97 
103  T* operator[] (const size_t i)
104  {
105  return p[i];
106  }
107 private:
108  T** p;
109  const size_t m_xMax;
110 };
111 
116 template <typename T>
117 class Array3D
118 {
119 public:
126  Array3D (const size_t x, const size_t y, const size_t z) : p (new Array2D<T>*[x]), m_xMax (x)
127  {
128  for (size_t i = 0; i < m_xMax; i++)
129  p[i] = new Array2D<T> (y, z);
130  }
131 
132  ~Array3D (void)
133  {
134  for (size_t i = 0; i < m_xMax; i++)
135  {
136  delete p[i];
137  p[i] = 0;
138  }
139  delete[] p;
140  p = 0;
141  }
142 
148  Array2D<T>& operator[] (const size_t i)
149  {
150  return *(p[i]);
151  }
152 private:
154  const size_t m_xMax;
155 };
156 
157 int
158 main (int argc, char *argv[])
159 {
160  TIMER_TYPE t0, t1, t2;
161  TIMER_NOW (t0);
162  std::cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
163  // LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
164 
165  int nCN = 2, nLANClients = 42;
166  bool nix = true;
167  bool useIpv6 = false;
168 
169  CommandLine cmd (__FILE__);
170  cmd.AddValue ("useIPv6", "Use IPv6 instead of IPv4", useIpv6);
171  cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
172  cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
173  cmd.AddValue ("NIX", "Toggle nix-vector routing", nix);
174  cmd.Parse (argc,argv);
175 
176  if (useIpv6 && !nix)
177  {
178  std::cout << "This script can work in IPv6 only by using NIX"
179  << std::endl;
180  return 1;
181  }
182  if (nCN < 2)
183  {
184  std::cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
185  << std::endl;
186  return 1;
187  }
188 
189  std::cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl;
190 
191  Array2D<NodeContainer> nodes_net0(nCN, 3);
192  Array2D<NodeContainer> nodes_net1(nCN, 6);
193  NodeContainer* nodes_netLR = new NodeContainer[nCN];
194  Array2D<NodeContainer> nodes_net2(nCN, 14);
195  Array3D<NodeContainer> nodes_net2LAN(nCN, 7, nLANClients);
196  Array2D<NodeContainer> nodes_net3(nCN, 9);
197  Array3D<NodeContainer> nodes_net3LAN(nCN, 5, nLANClients);
198 
199  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
201  Array3D<Address> ifs2LanRemoteAddress(nCN, 7, nLANClients);
202  Array3D<Address> ifs3LanRemoteAddress(nCN, 5, nLANClients);
203 
204  Ipv4AddressHelper addressHelperv4;
205  Ipv6AddressHelper addressHelperv6;
206  std::ostringstream oss;
207  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
208  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
209  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
210  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
211  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
212  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
213 
214  // Setup NixVector Routing
215  if (nix)
216  {
217  if (!useIpv6)
218  {
219  Ipv4NixVectorHelper nixRouting;
220  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
221  }
222  else
223  {
224  Ipv6NixVectorHelper nixRouting;
225  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
226  }
227  }
228 
229  // Create Campus Networks
230  for (int z = 0; z < nCN; ++z)
231  {
232  std::cout << "Creating Campus Network " << z << ":" << std::endl;
233  // Create Net0
234  std::cout << " SubNet [ 0";
235  for (int i = 0; i < 3; ++i)
236  {
237  nodes_net0[z][i].Create (1);
238  stack.Install (nodes_net0[z][i]);
239  }
240  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
241  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
242  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
243  NetDeviceContainer ndc0[3];
244  for (int i = 0; i < 3; ++i)
245  {
246  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
247  }
248  // Create Net1
249  std::cout << " 1";
250  for (int i = 0; i < 6; ++i)
251  {
252  nodes_net1[z][i].Create (1);
253  stack.Install (nodes_net1[z][i]);
254  }
255  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
256  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
257  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
258  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
259  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
260  NetDeviceContainer ndc1[6];
261  for (int i = 0; i < 6; ++i)
262  {
263  if (i == 1)
264  {
265  continue;
266  }
267  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
268  }
269  // Connect Net0 <-> Net1
270  NodeContainer net0_1;
271  net0_1.Add (nodes_net0[z][2].Get (0));
272  net0_1.Add (nodes_net1[z][0].Get (0));
273  NetDeviceContainer ndc0_1;
274  ndc0_1 = p2p_1gb5ms.Install (net0_1);
275  oss.str ("");
276  if (!useIpv6)
277  {
278  oss << 10 + z << ".1.252.0";
279  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
280  addressHelperv4.Assign (ndc0_1);
281  }
282  else
283  {
284  oss << 2001 + z << ":1:252::";
285  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
286  addressHelperv6.Assign (ndc0_1);
287  }
288  // Create Net2
289  std::cout << " 2";
290  for (int i = 0; i < 14; ++i)
291  {
292  nodes_net2[z][i].Create (1);
293  stack.Install (nodes_net2[z][i]);
294  }
295  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
296  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
297  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
298  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
299  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
300  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
301  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
302  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
303  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
304  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
305  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
306  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
307  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
308  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
309  NetDeviceContainer ndc2[14];
310  for (int i = 0; i < 14; ++i)
311  {
312  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
313  }
314  Array2D<NetDeviceContainer> ndc2LAN(7, nLANClients);
315  for (int i = 0; i < 7; ++i)
316  {
317  oss.str ("");
318  if (!useIpv6)
319  {
320  oss << 10 + z << ".4." << 15 + i << ".0";
321  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
322  }
323  else
324  {
325  oss << 2001 + z << ":4:" << 15 + i << "::";
326  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
327  }
328  for (int j = 0; j < nLANClients; ++j)
329  {
330  nodes_net2LAN[z][i][j].Create (1);
331  stack.Install (nodes_net2LAN[z][i][j]);
332  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
333  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
334  if (!useIpv6)
335  {
336  ifs2LanRemoteAddress[z][i][j] = InetSocketAddress (addressHelperv4.Assign (ndc2LAN[i][j]).GetAddress (0), 9999);
337  }
338  else
339  {
340  ifs2LanRemoteAddress[z][i][j] = Inet6SocketAddress (addressHelperv6.Assign (ndc2LAN[i][j]).GetAddress (0,1), 9999);
341  }
342  }
343  }
344  // Create Net3
345  std::cout << " 3 ]" << std::endl;
346  for (int i = 0; i < 9; ++i)
347  {
348  nodes_net3[z][i].Create (1);
349  stack.Install (nodes_net3[z][i]);
350  }
351  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
352  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
353  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
354  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
355  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
356  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
357  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
358  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
359  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
360  NetDeviceContainer ndc3[9];
361  for (int i = 0; i < 9; ++i)
362  {
363  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
364  }
365  Array2D<NetDeviceContainer> ndc3LAN(5, nLANClients);
366  for (int i = 0; i < 5; ++i)
367  {
368  oss.str ("");
369  if (!useIpv6)
370  {
371  oss << 10 + z << ".5." << 10 + i << ".0";
372  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
373  }
374  else
375  {
376  oss << 2001 + z << ":5:" << 10 + i << "::";
377  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
378 
379  }
380  for (int j = 0; j < nLANClients; ++j)
381  {
382  nodes_net3LAN[z][i][j].Create (1);
383  stack.Install (nodes_net3LAN[z][i][j]);
384  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
385  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
386  if (!useIpv6)
387  {
388  ifs3LanRemoteAddress[z][i][j] = InetSocketAddress (addressHelperv4.Assign (ndc3LAN[i][j]).GetAddress (0), 9999);
389  }
390  else
391  {
392  ifs3LanRemoteAddress[z][i][j] = Inet6SocketAddress (addressHelperv6.Assign (ndc3LAN[i][j]).GetAddress (0, 1), 9999);
393  }
394  }
395  }
396  std::cout << " Connecting Subnets..." << std::endl;
397  // Create Lone Routers (Node 4 & 5)
398  nodes_netLR[z].Create (2);
399  stack.Install (nodes_netLR[z]);
400  NetDeviceContainer ndcLR;
401  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
402  // Connect Net2/Net3 through Lone Routers to Net0
403  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
404  net0_4.Add (nodes_netLR[z].Get (0));
405  net0_4.Add (nodes_net0[z][0].Get (0));
406  net0_5.Add (nodes_netLR[z].Get (1));
407  net0_5.Add (nodes_net0[z][1].Get (0));
408  net2_4a.Add (nodes_netLR[z].Get (0));
409  net2_4a.Add (nodes_net2[z][0].Get (0));
410  net2_4b.Add (nodes_netLR[z].Get (1));
411  net2_4b.Add (nodes_net2[z][1].Get (0));
412  net3_5a.Add (nodes_netLR[z].Get (1));
413  net3_5a.Add (nodes_net3[z][0].Get (0));
414  net3_5b.Add (nodes_netLR[z].Get (1));
415  net3_5b.Add (nodes_net3[z][1].Get (0));
416  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
417  ndc0_4 = p2p_1gb5ms.Install (net0_4);
418  ndc0_5 = p2p_1gb5ms.Install (net0_5);
419  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
420  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
421  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
422  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
423 
424  // Assign IP addresses
425 
426  if (!useIpv6)
427  {
428  // ndc0_4
429  oss.str ("");
430  oss << 10 + z << ".1.253.0";
431  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
432  addressHelperv4.Assign (ndc0_4);
433  // ndc0_5
434  oss.str ("");
435  oss << 10 + z << ".1.254.0";
436  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
437  addressHelperv4.Assign (ndc0_5);
438  // ndc2_4a
439  oss.str ("");
440  oss << 10 + z << ".4.253.0";
441  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
442  addressHelperv4.Assign (ndc2_4a);
443  // ndc2_4b
444  oss.str ("");
445  oss << 10 + z << ".4.254.0";
446  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
447  addressHelperv4.Assign (ndc2_4b);
448  // ndc3_5a
449  oss.str ("");
450  oss << 10 + z << ".5.253.0";
451  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
452  addressHelperv4.Assign (ndc3_5a);
453  // ndc3_5b
454  oss.str ("");
455  oss << 10 + z << ".5.254.0";
456  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
457  addressHelperv4.Assign (ndc3_5b);
458  }
459  else
460  {
461  // ndc0_4
462  oss.str ("");
463  oss << 2001 + z << ":1:253::";
464  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
465  addressHelperv6.Assign (ndc0_4);
466  // ndc0_5
467  oss.str ("");
468  oss << 2001 + z << ":1:254::";
469  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
470  addressHelperv6.Assign (ndc0_5);
471  // ndc2_4a
472  oss.str ("");
473  oss << 2001 + z << ":4:253::";
474  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
475  addressHelperv6.Assign (ndc2_4a);
476  // ndc2_4b
477  oss.str ("");
478  oss << 2001 + z << ":4:254::";
479  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
480  addressHelperv6.Assign (ndc2_4b);
481  // ndc3_5a
482  oss.str ("");
483  oss << 2001 + z << ":5:253::";
484  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
485  addressHelperv6.Assign (ndc3_5a);
486  // ndc3_5b
487  oss.str ("");
488  oss << 2001 + z << ":5:254::";
489  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
490  addressHelperv6.Assign (ndc3_5b);
491 
492  }
493 
494  std::cout << " Assigning IP addresses..." << std::endl;
495  for (int i = 0; i < 3; ++i)
496  {
497  oss.str ("");
498  if (!useIpv6)
499  {
500  oss << 10 + z << ".1." << 1 + i << ".0";
501  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
502  addressHelperv4.Assign (ndc0[i]);
503  }
504  else
505  {
506  oss << 2001 + z << ":1:" << 1 + i << "::";
507  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
508  addressHelperv6.Assign (ndc0[i]);
509  }
510  }
511  for (int i = 0; i < 6; ++i)
512  {
513  if (i == 1)
514  {
515  continue;
516  }
517  oss.str ("");
518  if (!useIpv6)
519  {
520  oss << 10 + z << ".2." << 1 + i << ".0";
521  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
522  addressHelperv4.Assign (ndc1[i]);
523  }
524  else
525  {
526  oss << 2001 + z << ":2:" << 1 + i << "::";
527  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
528  addressHelperv6.Assign (ndc1[i]);
529  }
530  }
531  oss.str ("");
532  if (!useIpv6)
533  {
534  oss << 10 + z << ".3.1.0";
535  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
536  addressHelperv4.Assign (ndcLR);
537  }
538  else
539  {
540  oss << 2001 + z << ":3:1::";
541  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
542  addressHelperv6.Assign (ndcLR);
543 
544  }
545  for (int i = 0; i < 14; ++i)
546  {
547  oss.str ("");
548  if (!useIpv6)
549  {
550  oss << 10 + z << ".4." << 1 + i << ".0";
551  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
552  addressHelperv4.Assign (ndc2[i]);
553  }
554  else
555  {
556  oss << 2001 + z << ":4:" << 1 + i << "::";
557  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
558  addressHelperv6.Assign (ndc2[i]);
559 
560  }
561  }
562  for (int i = 0; i < 9; ++i)
563  {
564  oss.str ("");
565  if (!useIpv6)
566  {
567  oss << 10 + z << ".5." << 1 + i << ".0";
568  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
569  addressHelperv4.Assign (ndc3[i]);
570  }
571  else
572  {
573  oss << 2001 + z << ":5:" << 1 + i << "::";
574  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
575  addressHelperv6.Assign (ndc3[i]);
576  }
577  }
578  }
579  // Create Ring Links
580  if (nCN > 1)
581  {
582  std::cout << "Forming Ring Topology..." << std::endl;
583  NodeContainer* nodes_ring = new NodeContainer[nCN];
584  for (int z = 0; z < nCN-1; ++z)
585  {
586  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
587  nodes_ring[z].Add (nodes_net0[z+1][0].Get (0));
588  }
589  nodes_ring[nCN-1].Add (nodes_net0[nCN-1][0].Get (0));
590  nodes_ring[nCN-1].Add (nodes_net0[0][0].Get (0));
591  NetDeviceContainer* ndc_ring = new NetDeviceContainer[nCN];
592  for (int z = 0; z < nCN; ++z)
593  {
594  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
595  oss.str ("");
596  if (!useIpv6)
597  {
598  oss << "254.1." << z + 1 << ".0";
599  addressHelperv4.SetBase (oss.str ().c_str (), "255.255.255.0");
600  addressHelperv4.Assign (ndc_ring[z]);
601  }
602  else
603  {
604  oss << "254:1:" << z + 1 << "::";
605  addressHelperv6.SetBase (oss.str ().c_str (), Ipv6Prefix (64));
606  addressHelperv6.Assign (ndc_ring[z]);
607  }
608  }
609  delete[] ndc_ring;
610  delete[] nodes_ring;
611  }
612 
613  // Create Traffic Flows
614  std::cout << "Creating TCP Traffic Flows:" << std::endl;
615  Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
616  Config::SetDefault ("ns3::OnOffApplication::OnTime",
617  StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
618  Config::SetDefault ("ns3::OnOffApplication::OffTime",
619  StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
620  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
621 
622  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
623  int r1;
624  double r2;
625 
626  Address sinkAddress;
627  if (!useIpv6)
628  {
629  sinkAddress = InetSocketAddress (Ipv4Address::GetAny (), 9999);
630  }
631  else
632  {
633  sinkAddress = Inet6SocketAddress (Ipv6Address::GetAny (), 9999);
634  }
635 
636  for (int z = 0; z < nCN; ++z)
637  {
638  int x = z + 1;
639  if (z == nCN - 1)
640  {
641  x = 0;
642  }
643  // Subnet 2 LANs
644  std::cout << " Campus Network " << z << " Flows [ Net2 ";
645  for (int i = 0; i < 7; ++i)
646  {
647  for (int j = 0; j < nLANClients; ++j)
648  {
649  // Sinks
650  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkAddress);
651  ApplicationContainer sinkApp = sinkHelper.Install (
652  nodes_net2LAN[z][i][j].Get (0));
653  sinkApp.Start (Seconds (0.0));
654  // Sources
655  r1 = 2 + (int)(4 * urng->GetValue ());
656  r2 = 10 * urng->GetValue ();
657  OnOffHelper client ("ns3::TcpSocketFactory", Address ());
658  AddressValue remoteAddress (ifs2LanRemoteAddress[z][i][j]);
659  client.SetAttribute ("Remote", remoteAddress);
660  ApplicationContainer clientApp;
661  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
662  clientApp.Start (Seconds (r2));
663  }
664  }
665  // Subnet 3 LANs
666  std::cout << "Net3 ]" << std::endl;
667  for (int i = 0; i < 5; ++i)
668  {
669  for (int j = 0; j < nLANClients; ++j)
670  {
671  // Sinks
672  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkAddress);
673  ApplicationContainer sinkApp = sinkHelper.Install (
674  nodes_net3LAN[z][i][j].Get (0));
675  sinkApp.Start (Seconds (0.0));
676  // Sources
677  r1 = 2 + (int)(4 * urng->GetValue ());
678  r2 = 10 * urng->GetValue ();
679  OnOffHelper client ("ns3::TcpSocketFactory", Address ());
680  AddressValue remoteAddress (ifs3LanRemoteAddress[z][i][j]);
681  client.SetAttribute ("Remote", remoteAddress);
682  ApplicationContainer clientApp;
683  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
684  clientApp.Start (Seconds (r2));
685  }
686  }
687  }
688 
689  std::cout << "Created " << NodeList::GetNNodes () << " nodes." << std::endl;
690  TIMER_TYPE routingStart;
691  TIMER_NOW (routingStart);
692 
693  if (nix)
694  {
695  // Calculate routing tables
696  std::cout << "Using Nix-vectors..." << std::endl;
697  }
698  else
699  {
700  // Calculate routing tables
701  std::cout << "Populating Global Static Routing Tables..." << std::endl;
703  }
704 
705  TIMER_TYPE routingEnd;
706  TIMER_NOW (routingEnd);
707  std::cout << "Routing tables population took "
708  << TIMER_DIFF (routingEnd, routingStart) << std::endl;
709 
711  std::cout << "Running simulator..." << std::endl;
712  TIMER_NOW (t1);
713  Simulator::Stop (Seconds (100.0));
714  Simulator::Run ();
715  TIMER_NOW (t2);
716  std::cout << "Simulator finished." << std::endl;
718 
719  double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
720  std::cout << "-----" << std::endl << "Runtime Stats:" << std::endl;
721  std::cout << "Simulator init time: " << d1 << std::endl;
722  std::cout << "Simulator run time: " << d2 << std::endl;
723  std::cout << "Total elapsed time: " << d1+d2 << std::endl;
724 
725  delete[] nodes_netLR;
726  return 0;
727 }
Array3D::p
Array2D< T > ** p
Stored elements.
Definition: nms-p2p-nix.cc:153
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
TIMER_NOW
#define TIMER_NOW(_t)
Definition: nms-p2p-nix.cc:59
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
Array2D::p
T ** p
Stored elements.
Definition: nms-p2p-nix.cc:108
Array3D::m_xMax
const size_t m_xMax
maximum number of rows
Definition: nms-p2p-nix.cc:154
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
TIMER_TYPE
struct timeval TIMER_TYPE
Definition: nms-p2p-nix.cc:58
ns3::PointToPointHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
Definition: point-to-point-helper.cc:69
ns3::PointToPointHelper::SetChannelAttribute
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Definition: point-to-point-helper.cc:75
ns3::AddressValue
AttributeValue implementation for Address.
Definition: address.h:278
ns3::NodeList::GetNNodes
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
ns3::PointToPointHelper::Install
NetDeviceContainer Install(NodeContainer c)
Definition: point-to-point-helper.cc:222
ns3::Ipv6AddressHelper::SetBase
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Definition: ipv6-address-helper.cc:69
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
ns3::Ipv6AddressHelper
Helper class to auto-assign global IPv6 unicast addresses.
Definition: ipv6-address-helper.h:83
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
Array3D::~Array3D
~Array3D(void)
Definition: nms-p2p-nix.cc:132
ns3::ApplicationContainer::Add
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Definition: application-container.cc:67
ns3::NodeContainer::Add
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Definition: node-container.cc:114
ns3::Ipv4AddressHelper::SetBase
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Definition: ipv4-address-helper.cc:64
ns3::Ipv6AddressHelper::Assign
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Definition: ipv6-address-helper.cc:210
ns3::Ptr< UniformRandomVariable >
Array2D::~Array2D
~Array2D(void)
Definition: nms-p2p-nix.cc:90
ns3::NixVectorHelper
Helper class that adds Nix-vector routing to nodes.
Definition: nix-vector-helper.h:51
ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Definition: ipv4-global-routing-helper.cc:61
first.stack
stack
Definition: first.py:41
TIMER_DIFF
#define TIMER_DIFF(_t1, _t2)
Definition: nms-p2p-nix.cc:61
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
ns3::Ipv6InterfaceContainer::GetAddress
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Definition: ipv6-interface-container.cc:57
Array2D
2D array used in nix-vector-routing example "nms-p2p-nix.cc"
Definition: nms-p2p-nix.cc:76
Array3D
3D array used in nix-vector-routing example "nms-p2p-nix.cc"
Definition: nms-p2p-nix.cc:118
second.cmd
cmd
Definition: second.py:35
Array3D::Array3D
Array3D(const size_t x, const size_t y, const size_t z)
Constructor.
Definition: nms-p2p-nix.cc:126
Array2D::Array2D
Array2D(const size_t x, const size_t y)
Constructor.
Definition: nms-p2p-nix.cc:83
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition: packet-sink-helper.h:36
Array2D::m_xMax
const size_t m_xMax
maximum number of rows
Definition: nms-p2p-nix.cc:109
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny(void)
Definition: ipv4-address.cc:395
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Inet6SocketAddress
An Inet6 address class.
Definition: inet6-socket-address.h:37
ns3::Ipv4AddressHelper::Assign
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Definition: ipv4-address-helper.cc:135
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
ns3::Ipv6Address::GetAny
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Definition: ipv6-address.cc:897
sample-rng-plot.x
list x
Definition: sample-rng-plot.py:34
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition: point-to-point-helper.h:45
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::UniformRandomVariable::GetValue
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
Definition: random-variable-stream.cc:182
ns3::Simulator::ScheduleNow
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:587
Progress
void Progress()
Definition: nms-p2p-nix.cc:65