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 #ifdef NS3_MPI
64 
65  typedef std::vector<NodeContainer> vectorOfNodeContainer;
66  typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
67  typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
68 
69  typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
70  typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
71  typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
72 
73  typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
74  typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
75 
76  // Enable parallel simulator with the command line arguments
77  MpiInterface::Enable (&argc, &argv);
78 
79  TIMER_TYPE t0, t1, t2;
80  TIMER_NOW (t0);
81  std::cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
82 
83  GlobalValue::Bind ("SimulatorImplementationType",
84  StringValue ("ns3::DistributedSimulatorImpl"));
85 
86  uint32_t systemId = MpiInterface::GetSystemId ();
87  uint32_t systemCount = MpiInterface::GetSize ();
88 
89  uint32_t nCN = 2, nLANClients = 42;
90  int32_t single = 0;
91  int nBytes = 500000; // Bytes for each on/off app
92  bool nix = true;
93 
95  cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
96  cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
97  cmd.AddValue ("single", "1 if use single flow", single);
98  cmd.AddValue ("nBytes", "Number of bytes for each on/off app", nBytes);
99  cmd.AddValue ("nix", "Toggle the use of nix-vector or global routing", nix);
100  cmd.Parse (argc,argv);
101 
102  if (nCN < 2)
103  {
104  std::cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
105  << std::endl;
106  return 1;
107  }
108  if (systemCount > nCN)
109  {
110  std::cout << "Number of total CNs (" << nCN << ") should be >= systemCount ("
111  << systemCount << ")." << std::endl;
112  return 1;
113  }
114 
115  std::cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl;
116 
117 
118 
119  vectorOfNodeContainer nodes_netLR(nCN);
120  vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
121  vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
122  vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
123  vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
124 
125  vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
126  vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
127 
128  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
130 
132 
133  vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
134  vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
135  vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
136  vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
137  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
138  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
139 
141  std::ostringstream oss;
142  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
143  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
144  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
145  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
146  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
147  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
148 
149  if (nix)
150  {
151  Ipv4NixVectorHelper nixRouting;
152  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
153  }
154 
155  // Create Campus Networks
156  for (uint32_t z = 0; z < nCN; ++z)
157  {
158  std::cout << "Creating Campus Network " << z << ":" << std::endl;
159  // Create Net0
160  std::cout << " SubNet [ 0";
161  for (int i = 0; i < 3; ++i)
162  {
163  Ptr<Node> node = CreateObject<Node> (z % systemCount);
164  nodes_net0[z][i].Add (node);
165  stack.Install (nodes_net0[z][i]);
166  }
167  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
168  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
169  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
170  NetDeviceContainer ndc0[3];
171  for (int i = 0; i < 3; ++i)
172  {
173  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
174  }
175  // Create Net1
176  std::cout << " 1";
177  for (int i = 0; i < 6; ++i)
178  {
179  Ptr<Node> node = CreateObject<Node> (z % systemCount);
180  nodes_net1[z][i].Add (node);
181  stack.Install (nodes_net1[z][i]);
182  }
183  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
184  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
185  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
186  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
187  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
188  NetDeviceContainer ndc1[6];
189  for (int i = 0; i < 6; ++i)
190  {
191  if (i == 1)
192  {
193  continue;
194  }
195  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
196  }
197  // Connect Net0 <-> Net1
198  NodeContainer net0_1;
199  net0_1.Add (nodes_net0[z][2].Get (0));
200  net0_1.Add (nodes_net1[z][0].Get (0));
201  NetDeviceContainer ndc0_1;
202  ndc0_1 = p2p_1gb5ms.Install (net0_1);
203  oss.str ("");
204  oss << 10 + z << ".1.252.0";
205  address.SetBase (oss.str ().c_str (), "255.255.255.0");
206  ifs = address.Assign (ndc0_1);
207  // Create Net2
208  std::cout << " 2";
209  for (int i = 0; i < 14; ++i)
210  {
211  Ptr<Node> node = CreateObject<Node> (z % systemCount);
212  nodes_net2[z][i].Add (node);
213  stack.Install (nodes_net2[z][i]);
214  }
215  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
216  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
217  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
218  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
219  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
220  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
221  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
222  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
223  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
224  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
225  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
226  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
227  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
228  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
229  NetDeviceContainer ndc2[14];
230  for (int i = 0; i < 14; ++i)
231  {
232  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
233  }
234  vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
235  for (int i = 0; i < 7; ++i)
236  {
237  oss.str ("");
238  oss << 10 + z << ".4." << 15 + i << ".0";
239  address.SetBase (oss.str ().c_str (), "255.255.255.0");
240  for (uint32_t j = 0; j < nLANClients; ++j)
241  {
242  Ptr<Node> node = CreateObject<Node> (z % systemCount);
243  nodes_net2LAN[z][i][j].Add (node);
244  stack.Install (nodes_net2LAN[z][i][j]);
245  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
246  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
247  ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
248  }
249  }
250  // Create Net3
251  std::cout << " 3 ]" << std::endl;
252  for (int i = 0; i < 9; ++i)
253  {
254  Ptr<Node> node = CreateObject<Node> (z % systemCount);
255  nodes_net3[z][i].Add (node);
256  stack.Install (nodes_net3[z][i]);
257  }
258  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
259  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
260  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
261  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
262  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
263  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
264  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
265  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
266  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
267  NetDeviceContainer ndc3[9];
268  for (int i = 0; i < 9; ++i)
269  {
270  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
271  }
272  vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
273  for (int i = 0; i < 5; ++i)
274  {
275  oss.str ("");
276  oss << 10 + z << ".5." << 10 + i << ".0";
277  address.SetBase (oss.str ().c_str (), "255.255.255.255");
278  for (uint32_t j = 0; j < nLANClients; ++j)
279  {
280  Ptr<Node> node = CreateObject<Node> (z % systemCount);
281  nodes_net3LAN[z][i][j].Add (node);
282  stack.Install (nodes_net3LAN[z][i][j]);
283  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
284  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
285  ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
286  }
287  }
288  std::cout << " Connecting Subnets..." << std::endl;
289  // Create Lone Routers (Node 4 & 5)
290  Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
291  Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
292  nodes_netLR[z].Add (node1);
293  nodes_netLR[z].Add (node2);
294  stack.Install (nodes_netLR[z]);
295  NetDeviceContainer ndcLR;
296  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
297  // Connect Net2/Net3 through Lone Routers to Net0
298  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
299  net0_4.Add (nodes_netLR[z].Get (0));
300  net0_4.Add (nodes_net0[z][0].Get (0));
301  net0_5.Add (nodes_netLR[z].Get (1));
302  net0_5.Add (nodes_net0[z][1].Get (0));
303  net2_4a.Add (nodes_netLR[z].Get (0));
304  net2_4a.Add (nodes_net2[z][0].Get (0));
305  net2_4b.Add (nodes_netLR[z].Get (1));
306  net2_4b.Add (nodes_net2[z][1].Get (0));
307  net3_5a.Add (nodes_netLR[z].Get (1));
308  net3_5a.Add (nodes_net3[z][0].Get (0));
309  net3_5b.Add (nodes_netLR[z].Get (1));
310  net3_5b.Add (nodes_net3[z][1].Get (0));
311  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
312  ndc0_4 = p2p_1gb5ms.Install (net0_4);
313  oss.str ("");
314  oss << 10 + z << ".1.253.0";
315  address.SetBase (oss.str ().c_str (), "255.255.255.0");
316  ifs = address.Assign (ndc0_4);
317  ndc0_5 = p2p_1gb5ms.Install (net0_5);
318  oss.str ("");
319  oss << 10 + z << ".1.254.0";
320  address.SetBase (oss.str ().c_str (), "255.255.255.0");
321  ifs = address.Assign (ndc0_5);
322  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
323  oss.str ("");
324  oss << 10 + z << ".4.253.0";
325  address.SetBase (oss.str ().c_str (), "255.255.255.0");
326  ifs = address.Assign (ndc2_4a);
327  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
328  oss.str ("");
329  oss << 10 + z << ".4.254.0";
330  address.SetBase (oss.str ().c_str (), "255.255.255.0");
331  ifs = address.Assign (ndc2_4b);
332  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
333  oss.str ("");
334  oss << 10 + z << ".5.253.0";
335  address.SetBase (oss.str ().c_str (), "255.255.255.0");
336  ifs = address.Assign (ndc3_5a);
337  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
338  oss.str ("");
339  oss << 10 + z << ".5.254.0";
340  address.SetBase (oss.str ().c_str (), "255.255.255.0");
341  ifs = address.Assign (ndc3_5b);
342  // Assign IP addresses
343  std::cout << " Assigning IP addresses..." << std::endl;
344  for (int i = 0; i < 3; ++i)
345  {
346  oss.str ("");
347  oss << 10 + z << ".1." << 1 + i << ".0";
348  address.SetBase (oss.str ().c_str (), "255.255.255.0");
349  ifs0[z][i] = address.Assign (ndc0[i]);
350  }
351  for (int i = 0; i < 6; ++i)
352  {
353  if (i == 1)
354  {
355  continue;
356  }
357  oss.str ("");
358  oss << 10 + z << ".2." << 1 + i << ".0";
359  address.SetBase (oss.str ().c_str (), "255.255.255.0");
360  ifs1[z][i] = address.Assign (ndc1[i]);
361  }
362  oss.str ("");
363  oss << 10 + z << ".3.1.0";
364  address.SetBase (oss.str ().c_str (), "255.255.255.0");
365  ifs = address.Assign (ndcLR);
366  for (int i = 0; i < 14; ++i)
367  {
368  oss.str ("");
369  oss << 10 + z << ".4." << 1 + i << ".0";
370  address.SetBase (oss.str ().c_str (), "255.255.255.0");
371  ifs2[z][i] = address.Assign (ndc2[i]);
372  }
373  for (int i = 0; i < 9; ++i)
374  {
375  oss.str ("");
376  oss << 10 + z << ".5." << 1 + i << ".0";
377  address.SetBase (oss.str ().c_str (), "255.255.255.0");
378  ifs3[z][i] = address.Assign (ndc3[i]);
379  }
380  }
381  // Create Ring Links
382  if (nCN > 1)
383  {
384  std::cout << "Forming Ring Topology..." << std::endl;
385  vectorOfNodeContainer nodes_ring(nCN);
386  for (uint32_t z = 0; z < nCN - 1; ++z)
387  {
388  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
389  nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
390  }
391  nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
392  nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
393  vectorOfNetDeviceContainer ndc_ring(nCN);
394  for (uint32_t z = 0; z < nCN; ++z)
395  {
396  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
397  oss.str ("");
398  oss << "254.1." << z + 1 << ".0";
399  address.SetBase (oss.str ().c_str (), "255.255.255.0");
400  ifs = address.Assign (ndc_ring[z]);
401  }
402  }
403 
404  // Create Traffic Flows
405  std::cout << "Creating UDP Traffic Flows:" << std::endl;
406  Config::SetDefault ("ns3::OnOffApplication::MaxBytes",
407  UintegerValue (nBytes));
408  Config::SetDefault ("ns3::OnOffApplication::OnTime",
409  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
410  Config::SetDefault ("ns3::OnOffApplication::OffTime",
411  StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
412 
413 
414  if (single)
415  {
416  if (systemCount == 1)
417  {
418  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
420  9999));
421  ApplicationContainer sinkApp = sinkHelper.Install (nodes_net1[0][2].Get (0));
422  sinkApp.Start (Seconds (0.0));
423 
424  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
425  AddressValue remoteAddress (InetSocketAddress (ifs1[0][2].GetAddress (0), 9999));
426  std::cout << "Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
427  client.SetAttribute ("Remote", remoteAddress);
428 
429  ApplicationContainer clientApp;
430  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
431  clientApp.Start (Seconds (0));
432  }
433  else if (systemId == 1)
434  {
435  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
437  9999));
438  ApplicationContainer sinkApp =
439  sinkHelper.Install (nodes_net1[1][0].Get (0));
440 
441  sinkApp.Start (Seconds (0.0));
442  }
443  else if (systemId == 0)
444  {
445  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
446  AddressValue remoteAddress
447  (InetSocketAddress (ifs1[1][0].GetAddress (0), 9999));
448 
449  std::cout << "Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
450  client.SetAttribute ("Remote", remoteAddress);
451 
452  ApplicationContainer clientApp;
453  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
454  clientApp.Start (Seconds (0));
455  }
456  }
457  else
458  {
459  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
460  int r1;
461  double r2;
462  for (uint32_t z = 0; z < nCN; ++z)
463  {
464  uint32_t x = z + 1;
465  if (z == nCN - 1)
466  {
467  x = 0;
468  }
469  // Subnet 2 LANs
470  std::cout << " Campus Network " << z << " Flows [ Net2 ";
471  for (int i = 0; i < 7; ++i)
472  {
473  for (uint32_t j = 0; j < nLANClients; ++j)
474  {
475  // Sinks
476  if (systemCount == 1)
477  {
478  PacketSinkHelper sinkHelper
479  ("ns3::UdpSocketFactory",
481 
482  ApplicationContainer sinkApp =
483  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
484 
485  sinkApp.Start (Seconds (0.0));
486  }
487  else if (systemId == z % systemCount)
488  {
489  PacketSinkHelper sinkHelper
490  ("ns3::UdpSocketFactory",
492 
493  ApplicationContainer sinkApp =
494  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
495 
496  sinkApp.Start (Seconds (0.0));
497  }
498  // Sources
499  if (systemCount == 1)
500  {
501  r1 = 2 + (int)(4 * urng->GetValue ());
502  r2 = 10 * urng->GetValue ();
503  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
504 
505  AddressValue remoteAddress
506  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
507 
508  client.SetAttribute ("Remote", remoteAddress);
509  ApplicationContainer clientApp;
510  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
511  clientApp.Start (Seconds (r2));
512  }
513  else if (systemId == x % systemCount)
514  {
515  r1 = 2 + (int)(4 * urng->GetValue ());
516  r2 = 10 * urng->GetValue ();
517  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
518 
519  AddressValue remoteAddress
520  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
521 
522  client.SetAttribute ("Remote", remoteAddress);
523  ApplicationContainer clientApp;
524  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
525  clientApp.Start (Seconds (r2));
526  }
527  }
528  }
529  // Subnet 3 LANs
530  std::cout << "Net3 ]" << std::endl;
531  for (int i = 0; i < 5; ++i)
532  {
533  for (uint32_t j = 0; j < nLANClients; ++j)
534  {
535  // Sinks
536  if (systemCount == 1)
537  {
538  PacketSinkHelper sinkHelper
539  ("ns3::UdpSocketFactory",
541 
542  ApplicationContainer sinkApp =
543  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
544 
545  sinkApp.Start (Seconds (0.0));
546  }
547  else if (systemId == z % systemCount)
548  {
549  PacketSinkHelper sinkHelper
550  ("ns3::UdpSocketFactory",
552 
553  ApplicationContainer sinkApp =
554  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
555 
556  sinkApp.Start (Seconds (0.0));
557  }
558  // Sources
559  if (systemCount == 1)
560  {
561  r1 = 2 + (int)(4 * urng->GetValue ());
562  r2 = 10 * urng->GetValue ();
563  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
564 
565  AddressValue remoteAddress
566  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
567 
568  client.SetAttribute ("Remote", remoteAddress);
569  ApplicationContainer clientApp;
570  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
571  clientApp.Start (Seconds (r2));
572  }
573  else if (systemId == x % systemCount)
574  {
575  r1 = 2 + (int)(4 * urng->GetValue ());
576  r2 = 10 * urng->GetValue ();
577  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
578 
579  AddressValue remoteAddress
580  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
581 
582  client.SetAttribute ("Remote", remoteAddress);
583  ApplicationContainer clientApp;
584  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
585  clientApp.Start (Seconds (r2));
586  }
587  }
588  }
589  }
590  }
591 
592  std::cout << "Created " << NodeList::GetNNodes () << " nodes." << std::endl;
593  TIMER_TYPE routingStart;
594  TIMER_NOW (routingStart);
595 
596  if (nix)
597  {
598  std::cout << "Using Nix-vectors..." << std::endl;
599  }
600  else
601  {
602  // Calculate routing tables
603  std::cout << "Populating Routing tables..." << std::endl;
605  }
606 
607  TIMER_TYPE routingEnd;
608  TIMER_NOW (routingEnd);
609  std::cout << "Routing tables population took "
610  << TIMER_DIFF (routingEnd, routingStart) << std::endl;
611 
612  std::cout << "Running simulator..." << std::endl;
613  TIMER_NOW (t1);
614  Simulator::Stop (Seconds (100.0));
615  Simulator::Run ();
616  TIMER_NOW (t2);
617  std::cout << "Simulator finished." << std::endl;
619  // Exit the parallel execution environment
621  double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
622  std::cout << "-----" << std::endl << "Runtime Stats:" << std::endl;
623  std::cout << "Simulator init time: " << d1 << std::endl;
624  std::cout << "Simulator run time: " << d2 << std::endl;
625  std::cout << "Total elapsed time: " << d1 + d2 << std::endl;
626  return 0;
627 #else
628  NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
629 #endif
630 }
631 
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:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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:34
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:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
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:37
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:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
#define TIMER_NOW(_t)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static uint32_t GetSize()