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