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