A Discrete-Event Network Simulator
API
nms-p2p-nix-distributed.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * (c) 2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
17  *
18  * DARPA NMS Campus Network Model
19  *
20  * This topology replicates the original NMS Campus Network model
21  * with the exception of chord links (which were never utilized in the
22  * original model)
23  * Link Bandwidths and Delays may not be the same as the original
24  * specifications
25  *
26  * Modified for distributed simulation by Josh Pelkey <jpelkey@gatech.edu>
27  *
28  * The fundamental unit of the NMS model consists of a campus network. The
29  * campus network topology can been seen here:
30  * http://www.nsnam.org/~jpelkey3/nms.png
31  * The number of hosts (default 42) is variable. Finally, an arbitrary
32  * number of these campus networks can be connected together (default 2)
33  * to make very large simulations.
34  */
35 
36 // for timing functions
37 #include <cstdlib>
38 #include <sys/time.h>
39 #include <fstream>
40 #include <vector>
41 
42 #include "ns3/core-module.h"
43 #include "ns3/internet-module.h"
44 #include "ns3/network-module.h"
45 #include "ns3/on-off-helper.h"
46 #include "ns3/packet-sink-helper.h"
47 #include "ns3/point-to-point-helper.h"
48 #include "ns3/mpi-interface.h"
49 #include "ns3/ipv4-nix-vector-helper.h"
50 
51 using namespace ns3;
52 
53 typedef struct timeval TIMER_TYPE;
54 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
55 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
56 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
57 
58 NS_LOG_COMPONENT_DEFINE ("CampusNetworkModelDistributed");
59 
60 int
61 main (int argc, char *argv[])
62 {
63  typedef std::vector<NodeContainer> vectorOfNodeContainer;
64  typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
65  typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
66 
67  typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
68  typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
69  typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
70 
71  typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
72  typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
73 
74  // Enable parallel simulator with the command line arguments
75  MpiInterface::Enable (&argc, &argv);
76 
77  TIMER_TYPE t0, t1, t2;
78  TIMER_NOW (t0);
79  std::cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
80 
81  GlobalValue::Bind ("SimulatorImplementationType",
82  StringValue ("ns3::DistributedSimulatorImpl"));
83 
84  uint32_t systemId = MpiInterface::GetSystemId ();
85  uint32_t systemCount = MpiInterface::GetSize ();
86 
87  uint32_t nCN = 2, nLANClients = 42;
88  int32_t single = 0;
89  int nBytes = 500000; // Bytes for each on/off app
90  bool nix = true;
91 
92  CommandLine cmd (__FILE__);
93  cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
94  cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
95  cmd.AddValue ("single", "1 if use single flow", single);
96  cmd.AddValue ("nBytes", "Number of bytes for each on/off app", nBytes);
97  cmd.AddValue ("nix", "Toggle the use of nix-vector or global routing", nix);
98  cmd.Parse (argc,argv);
99 
100  if (nCN < 2)
101  {
102  std::cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
103  << std::endl;
104  return 1;
105  }
106  if (systemCount > nCN)
107  {
108  std::cout << "Number of total CNs (" << nCN << ") should be >= systemCount ("
109  << systemCount << ")." << std::endl;
110  return 1;
111  }
112 
113  std::cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl;
114 
115 
116 
117  vectorOfNodeContainer nodes_netLR(nCN);
118  vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
119  vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
120  vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
121  vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
122 
123  vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
124  vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
125 
126  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
128 
130 
131  vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
132  vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
133  vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
134  vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
135  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
136  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
137 
139  std::ostringstream oss;
140  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
141  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
142  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
143  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
144  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
145  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
146 
147  if (nix)
148  {
149  Ipv4NixVectorHelper nixRouting;
150  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
151  }
152 
153  // Create Campus Networks
154  for (uint32_t z = 0; z < nCN; ++z)
155  {
156  std::cout << "Creating Campus Network " << z << ":" << std::endl;
157  // Create Net0
158  std::cout << " SubNet [ 0";
159  for (int i = 0; i < 3; ++i)
160  {
161  Ptr<Node> node = CreateObject<Node> (z % systemCount);
162  nodes_net0[z][i].Add (node);
163  stack.Install (nodes_net0[z][i]);
164  }
165  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
166  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
167  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
168  NetDeviceContainer ndc0[3];
169  for (int i = 0; i < 3; ++i)
170  {
171  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
172  }
173  // Create Net1
174  std::cout << " 1";
175  for (int i = 0; i < 6; ++i)
176  {
177  Ptr<Node> node = CreateObject<Node> (z % systemCount);
178  nodes_net1[z][i].Add (node);
179  stack.Install (nodes_net1[z][i]);
180  }
181  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
182  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
183  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
184  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
185  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
186  NetDeviceContainer ndc1[6];
187  for (int i = 0; i < 6; ++i)
188  {
189  if (i == 1)
190  {
191  continue;
192  }
193  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
194  }
195  // Connect Net0 <-> Net1
196  NodeContainer net0_1;
197  net0_1.Add (nodes_net0[z][2].Get (0));
198  net0_1.Add (nodes_net1[z][0].Get (0));
199  NetDeviceContainer ndc0_1;
200  ndc0_1 = p2p_1gb5ms.Install (net0_1);
201  oss.str ("");
202  oss << 10 + z << ".1.252.0";
203  address.SetBase (oss.str ().c_str (), "255.255.255.0");
204  ifs = address.Assign (ndc0_1);
205  // Create Net2
206  std::cout << " 2";
207  for (int i = 0; i < 14; ++i)
208  {
209  Ptr<Node> node = CreateObject<Node> (z % systemCount);
210  nodes_net2[z][i].Add (node);
211  stack.Install (nodes_net2[z][i]);
212  }
213  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
214  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
215  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
216  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
217  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
218  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
219  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
220  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
221  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
222  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
223  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
224  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
225  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
226  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
227  NetDeviceContainer ndc2[14];
228  for (int i = 0; i < 14; ++i)
229  {
230  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
231  }
232  vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
233  for (int i = 0; i < 7; ++i)
234  {
235  oss.str ("");
236  oss << 10 + z << ".4." << 15 + i << ".0";
237  address.SetBase (oss.str ().c_str (), "255.255.255.0");
238  for (uint32_t j = 0; j < nLANClients; ++j)
239  {
240  Ptr<Node> node = CreateObject<Node> (z % systemCount);
241  nodes_net2LAN[z][i][j].Add (node);
242  stack.Install (nodes_net2LAN[z][i][j]);
243  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
244  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
245  ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
246  }
247  }
248  // Create Net3
249  std::cout << " 3 ]" << std::endl;
250  for (int i = 0; i < 9; ++i)
251  {
252  Ptr<Node> node = CreateObject<Node> (z % systemCount);
253  nodes_net3[z][i].Add (node);
254  stack.Install (nodes_net3[z][i]);
255  }
256  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
257  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
258  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
259  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
260  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
261  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
262  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
263  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
264  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
265  NetDeviceContainer ndc3[9];
266  for (int i = 0; i < 9; ++i)
267  {
268  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
269  }
270  vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
271  for (int i = 0; i < 5; ++i)
272  {
273  oss.str ("");
274  oss << 10 + z << ".5." << 10 + i << ".0";
275  address.SetBase (oss.str ().c_str (), "255.255.255.255");
276  for (uint32_t j = 0; j < nLANClients; ++j)
277  {
278  Ptr<Node> node = CreateObject<Node> (z % systemCount);
279  nodes_net3LAN[z][i][j].Add (node);
280  stack.Install (nodes_net3LAN[z][i][j]);
281  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
282  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
283  ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
284  }
285  }
286  std::cout << " Connecting Subnets..." << std::endl;
287  // Create Lone Routers (Node 4 & 5)
288  Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
289  Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
290  nodes_netLR[z].Add (node1);
291  nodes_netLR[z].Add (node2);
292  stack.Install (nodes_netLR[z]);
293  NetDeviceContainer ndcLR;
294  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
295  // Connect Net2/Net3 through Lone Routers to Net0
296  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
297  net0_4.Add (nodes_netLR[z].Get (0));
298  net0_4.Add (nodes_net0[z][0].Get (0));
299  net0_5.Add (nodes_netLR[z].Get (1));
300  net0_5.Add (nodes_net0[z][1].Get (0));
301  net2_4a.Add (nodes_netLR[z].Get (0));
302  net2_4a.Add (nodes_net2[z][0].Get (0));
303  net2_4b.Add (nodes_netLR[z].Get (1));
304  net2_4b.Add (nodes_net2[z][1].Get (0));
305  net3_5a.Add (nodes_netLR[z].Get (1));
306  net3_5a.Add (nodes_net3[z][0].Get (0));
307  net3_5b.Add (nodes_netLR[z].Get (1));
308  net3_5b.Add (nodes_net3[z][1].Get (0));
309  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
310  ndc0_4 = p2p_1gb5ms.Install (net0_4);
311  oss.str ("");
312  oss << 10 + z << ".1.253.0";
313  address.SetBase (oss.str ().c_str (), "255.255.255.0");
314  ifs = address.Assign (ndc0_4);
315  ndc0_5 = p2p_1gb5ms.Install (net0_5);
316  oss.str ("");
317  oss << 10 + z << ".1.254.0";
318  address.SetBase (oss.str ().c_str (), "255.255.255.0");
319  ifs = address.Assign (ndc0_5);
320  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
321  oss.str ("");
322  oss << 10 + z << ".4.253.0";
323  address.SetBase (oss.str ().c_str (), "255.255.255.0");
324  ifs = address.Assign (ndc2_4a);
325  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
326  oss.str ("");
327  oss << 10 + z << ".4.254.0";
328  address.SetBase (oss.str ().c_str (), "255.255.255.0");
329  ifs = address.Assign (ndc2_4b);
330  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
331  oss.str ("");
332  oss << 10 + z << ".5.253.0";
333  address.SetBase (oss.str ().c_str (), "255.255.255.0");
334  ifs = address.Assign (ndc3_5a);
335  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
336  oss.str ("");
337  oss << 10 + z << ".5.254.0";
338  address.SetBase (oss.str ().c_str (), "255.255.255.0");
339  ifs = address.Assign (ndc3_5b);
340  // Assign IP addresses
341  std::cout << " Assigning IP addresses..." << std::endl;
342  for (int i = 0; i < 3; ++i)
343  {
344  oss.str ("");
345  oss << 10 + z << ".1." << 1 + i << ".0";
346  address.SetBase (oss.str ().c_str (), "255.255.255.0");
347  ifs0[z][i] = address.Assign (ndc0[i]);
348  }
349  for (int i = 0; i < 6; ++i)
350  {
351  if (i == 1)
352  {
353  continue;
354  }
355  oss.str ("");
356  oss << 10 + z << ".2." << 1 + i << ".0";
357  address.SetBase (oss.str ().c_str (), "255.255.255.0");
358  ifs1[z][i] = address.Assign (ndc1[i]);
359  }
360  oss.str ("");
361  oss << 10 + z << ".3.1.0";
362  address.SetBase (oss.str ().c_str (), "255.255.255.0");
363  ifs = address.Assign (ndcLR);
364  for (int i = 0; i < 14; ++i)
365  {
366  oss.str ("");
367  oss << 10 + z << ".4." << 1 + i << ".0";
368  address.SetBase (oss.str ().c_str (), "255.255.255.0");
369  ifs2[z][i] = address.Assign (ndc2[i]);
370  }
371  for (int i = 0; i < 9; ++i)
372  {
373  oss.str ("");
374  oss << 10 + z << ".5." << 1 + i << ".0";
375  address.SetBase (oss.str ().c_str (), "255.255.255.0");
376  ifs3[z][i] = address.Assign (ndc3[i]);
377  }
378  }
379  // Create Ring Links
380  if (nCN > 1)
381  {
382  std::cout << "Forming Ring Topology..." << std::endl;
383  vectorOfNodeContainer nodes_ring(nCN);
384  for (uint32_t z = 0; z < nCN - 1; ++z)
385  {
386  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
387  nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
388  }
389  nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
390  nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
391  vectorOfNetDeviceContainer ndc_ring(nCN);
392  for (uint32_t z = 0; z < nCN; ++z)
393  {
394  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
395  oss.str ("");
396  oss << "254.1." << z + 1 << ".0";
397  address.SetBase (oss.str ().c_str (), "255.255.255.0");
398  ifs = address.Assign (ndc_ring[z]);
399  }
400  }
401 
402  // Create Traffic Flows
403  std::cout << "Creating UDP Traffic Flows:" << std::endl;
404  Config::SetDefault ("ns3::OnOffApplication::MaxBytes",
405  UintegerValue (nBytes));
406  Config::SetDefault ("ns3::OnOffApplication::OnTime",
407  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
408  Config::SetDefault ("ns3::OnOffApplication::OffTime",
409  StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
410 
411 
412  if (single)
413  {
414  if (systemCount == 1)
415  {
416  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
418  9999));
419  ApplicationContainer sinkApp = sinkHelper.Install (nodes_net1[0][2].Get (0));
420  sinkApp.Start (Seconds (0.0));
421 
422  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
423  AddressValue remoteAddress (InetSocketAddress (ifs1[0][2].GetAddress (0), 9999));
424  std::cout << "Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
425  client.SetAttribute ("Remote", remoteAddress);
426 
427  ApplicationContainer clientApp;
428  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
429  clientApp.Start (Seconds (0));
430  }
431  else if (systemId == 1)
432  {
433  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
435  9999));
436  ApplicationContainer sinkApp =
437  sinkHelper.Install (nodes_net1[1][0].Get (0));
438 
439  sinkApp.Start (Seconds (0.0));
440  }
441  else if (systemId == 0)
442  {
443  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
444  AddressValue remoteAddress
445  (InetSocketAddress (ifs1[1][0].GetAddress (0), 9999));
446 
447  std::cout << "Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
448  client.SetAttribute ("Remote", remoteAddress);
449 
450  ApplicationContainer clientApp;
451  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
452  clientApp.Start (Seconds (0));
453  }
454  }
455  else
456  {
457  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
458  int r1;
459  double r2;
460  for (uint32_t z = 0; z < nCN; ++z)
461  {
462  uint32_t x = z + 1;
463  if (z == nCN - 1)
464  {
465  x = 0;
466  }
467  // Subnet 2 LANs
468  std::cout << " Campus Network " << z << " Flows [ Net2 ";
469  for (int i = 0; i < 7; ++i)
470  {
471  for (uint32_t j = 0; j < nLANClients; ++j)
472  {
473  // Sinks
474  if (systemCount == 1)
475  {
476  PacketSinkHelper sinkHelper
477  ("ns3::UdpSocketFactory",
479 
480  ApplicationContainer sinkApp =
481  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
482 
483  sinkApp.Start (Seconds (0.0));
484  }
485  else if (systemId == z % systemCount)
486  {
487  PacketSinkHelper sinkHelper
488  ("ns3::UdpSocketFactory",
490 
491  ApplicationContainer sinkApp =
492  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
493 
494  sinkApp.Start (Seconds (0.0));
495  }
496  // Sources
497  if (systemCount == 1)
498  {
499  r1 = 2 + (int)(4 * urng->GetValue ());
500  r2 = 10 * urng->GetValue ();
501  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
502 
503  AddressValue remoteAddress
504  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
505 
506  client.SetAttribute ("Remote", remoteAddress);
507  ApplicationContainer clientApp;
508  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
509  clientApp.Start (Seconds (r2));
510  }
511  else if (systemId == x % systemCount)
512  {
513  r1 = 2 + (int)(4 * urng->GetValue ());
514  r2 = 10 * urng->GetValue ();
515  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
516 
517  AddressValue remoteAddress
518  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
519 
520  client.SetAttribute ("Remote", remoteAddress);
521  ApplicationContainer clientApp;
522  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
523  clientApp.Start (Seconds (r2));
524  }
525  }
526  }
527  // Subnet 3 LANs
528  std::cout << "Net3 ]" << std::endl;
529  for (int i = 0; i < 5; ++i)
530  {
531  for (uint32_t j = 0; j < nLANClients; ++j)
532  {
533  // Sinks
534  if (systemCount == 1)
535  {
536  PacketSinkHelper sinkHelper
537  ("ns3::UdpSocketFactory",
539 
540  ApplicationContainer sinkApp =
541  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
542 
543  sinkApp.Start (Seconds (0.0));
544  }
545  else if (systemId == z % systemCount)
546  {
547  PacketSinkHelper sinkHelper
548  ("ns3::UdpSocketFactory",
550 
551  ApplicationContainer sinkApp =
552  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
553 
554  sinkApp.Start (Seconds (0.0));
555  }
556  // Sources
557  if (systemCount == 1)
558  {
559  r1 = 2 + (int)(4 * urng->GetValue ());
560  r2 = 10 * urng->GetValue ();
561  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
562 
563  AddressValue remoteAddress
564  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
565 
566  client.SetAttribute ("Remote", remoteAddress);
567  ApplicationContainer clientApp;
568  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
569  clientApp.Start (Seconds (r2));
570  }
571  else if (systemId == x % systemCount)
572  {
573  r1 = 2 + (int)(4 * urng->GetValue ());
574  r2 = 10 * urng->GetValue ();
575  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
576 
577  AddressValue remoteAddress
578  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
579 
580  client.SetAttribute ("Remote", remoteAddress);
581  ApplicationContainer clientApp;
582  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
583  clientApp.Start (Seconds (r2));
584  }
585  }
586  }
587  }
588  }
589 
590  std::cout << "Created " << NodeList::GetNNodes () << " nodes." << std::endl;
591  TIMER_TYPE routingStart;
592  TIMER_NOW (routingStart);
593 
594  if (nix)
595  {
596  std::cout << "Using Nix-vectors..." << std::endl;
597  }
598  else
599  {
600  // Calculate routing tables
601  std::cout << "Populating Routing tables..." << std::endl;
603  }
604 
605  TIMER_TYPE routingEnd;
606  TIMER_NOW (routingEnd);
607  std::cout << "Routing tables population took "
608  << TIMER_DIFF (routingEnd, routingStart) << std::endl;
609 
610  std::cout << "Running simulator..." << std::endl;
611  TIMER_NOW (t1);
612  Simulator::Stop (Seconds (100.0));
613  Simulator::Run ();
614  TIMER_NOW (t2);
615  std::cout << "Simulator finished." << std::endl;
617  // Exit the parallel execution environment
619  double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
620  std::cout << "-----" << std::endl << "Runtime Stats:" << std::endl;
621  std::cout << "Simulator init time: " << d1 << std::endl;
622  std::cout << "Simulator run time: " << d2 << std::endl;
623  std::cout << "Total elapsed time: " << d1 + d2 << std::endl;
624  return 0;
625 }
626 
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
Definition: string.h:41
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
cmd
Definition: second.py:35
static void Disable()
Terminates the parallel environment.
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.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
stack
Definition: first.py:41
a polymophic address class
Definition: address.h:90
static void Enable(int *pargc, char ***pargv)
Sets up parallel communication interface.
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
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...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:226
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
address
Definition: first.py:44
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
#define TIMER_DIFF(_t1, _t2)
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
Definition: address.h:278
struct timeval TIMER_TYPE
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetSystemId()
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
#define TIMER_NOW(_t)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static uint32_t GetSize()