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