examples/mpi/third-distributed.cc
author Dean Armstrong <deanarm@gmail.com>
Wed, 01 Dec 2010 22:13:26 +0000
changeset 6674 52f8688d6d01
parent 6673 ec22aa763e2d
child 6821 203367ae7433
permissions -rw-r--r--
Bug 978: Run check-style.py on files touched in the reorganisation Cosmetic changes only in this one (hence the reason I wanted them kept separate from the the previous changeset).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     2
/*
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     6
 *
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    11
 *
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    15
 */
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    16
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    17
#include "ns3/core-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    18
#include "ns3/simulator-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    19
#include "ns3/node-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    20
#include "ns3/helper-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    21
#include "ns3/wifi-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    22
#include "ns3/mobility-module.h"
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    23
#include "ns3/mpi-interface.h"
6651
4bd42b7fbb3b add includes for mpi build
Josh Pelkey <jpelkey@gatech.edu>
parents: 6309
diff changeset
    24
#include "ns3/ipv4-global-routing-helper.h"
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    25
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    26
#ifdef NS3_MPI
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    27
#include <mpi.h>
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    28
#endif
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    29
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    30
// Default Network Topology (same as third.cc from tutorial)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    31
// Distributed simulation, split along the p2p link
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    32
// Number of wifi or csma nodes can be increased up to 250
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    33
//
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    34
//   Wifi 10.1.3.0
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    35
//                 AP
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    36
//  *    *    *    *
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    37
//  |    |    |    |    10.1.1.0
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    38
// n5   n6   n7   n0 -------------- n1   n2   n3   n4
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    39
//                   point-to-point  |    |    |    |
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    40
//                                   ================
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    41
//                          |          LAN 10.1.2.0
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    42
//                          |
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    43
//                 Rank 0   |   Rank 1
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    44
// -------------------------|----------------------------
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    45
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    46
using namespace ns3;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    47
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    48
NS_LOG_COMPONENT_DEFINE ("ThirdExampleDistributed");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    49
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    50
int 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    51
main (int argc, char *argv[])
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    52
{
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    53
#ifdef NS3_MPI
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    54
  // Distributed simulation setup
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    55
  MpiInterface::Enable (&argc, &argv);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    56
  GlobalValue::Bind ("SimulatorImplementationType",
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
    57
                     StringValue ("ns3::DistributedSimulatorImpl"));
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    58
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    59
  uint32_t systemId = MpiInterface::GetSystemId ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    60
  uint32_t systemCount = MpiInterface::GetSize ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    61
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    62
  // Check for valid distributed parameters.
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    63
  // Must have 2 and only 2 Logical Processors (LPs)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    64
  if (systemCount != 2)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    65
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    66
      std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    67
      return 1;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    68
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    69
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    70
  bool verbose = true;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    71
  uint32_t nCsma = 3;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    72
  uint32_t nWifi = 3;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    73
  bool tracing = false;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    74
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    75
  CommandLine cmd;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    76
  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    77
  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    78
  cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    79
  cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    80
  cmd.Parse (argc,argv);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    81
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    82
  // Check for valid number of csma or wifi nodes
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    83
  // 250 should be enough, otherwise IP addresses 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    84
  // soon become an issue
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    85
  if (nWifi > 250 || nCsma > 250)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    86
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    87
      std::cout << "Too many wifi or csma nodes, max 200 each." << std::endl;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    88
      return 1;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    89
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    90
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    91
  if (verbose)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    92
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    93
      LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    94
      LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    95
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    96
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    97
  NodeContainer p2pNodes;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    98
  Ptr<Node> p2pNode1 = CreateObject<Node> (0); // Create node with rank 0
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    99
  Ptr<Node> p2pNode2 = CreateObject<Node> (1); // Create node with rank 1
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   100
  p2pNodes.Add (p2pNode1);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   101
  p2pNodes.Add (p2pNode2);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   102
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   103
  PointToPointHelper pointToPoint;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   104
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   105
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   106
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   107
  NetDeviceContainer p2pDevices;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   108
  p2pDevices = pointToPoint.Install (p2pNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   109
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   110
  NodeContainer csmaNodes;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   111
  csmaNodes.Add (p2pNodes.Get (1));
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   112
  csmaNodes.Create (nCsma, 1);  // Create csma nodes with rank 1
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   114
  CsmaHelper csma;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   115
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   116
  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   117
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   118
  NetDeviceContainer csmaDevices;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   119
  csmaDevices = csma.Install (csmaNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   120
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   121
  NodeContainer wifiStaNodes;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   122
  wifiStaNodes.Create (nWifi, 0); // Create wifi nodes with rank 0
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   123
  NodeContainer wifiApNode = p2pNodes.Get (0);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   124
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   125
  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   126
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   127
  phy.SetChannel (channel.Create ());
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   128
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   129
  WifiHelper wifi = WifiHelper::Default ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   130
  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   131
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   132
  NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   133
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   134
  Ssid ssid = Ssid ("ns-3-ssid");
6673
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6651
diff changeset
   135
  mac.SetType ("ns3::StaWifiMac",
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6651
diff changeset
   136
               "Ssid", SsidValue (ssid),
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6651
diff changeset
   137
               "ActiveProbing", BooleanValue (false));
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   138
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   139
  NetDeviceContainer staDevices;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   140
  staDevices = wifi.Install (phy, mac, wifiStaNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   141
6673
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6651
diff changeset
   142
  mac.SetType ("ns3::ApWifiMac",
ec22aa763e2d Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents: 6651
diff changeset
   143
               "Ssid", SsidValue (ssid));
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   144
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   145
  NetDeviceContainer apDevices;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   146
  apDevices = wifi.Install (phy, mac, wifiApNode);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   147
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   148
  MobilityHelper mobility;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   149
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   150
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   151
                                 "MinX", DoubleValue (0.0),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   152
                                 "MinY", DoubleValue (0.0),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   153
                                 "DeltaX", DoubleValue (5.0),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   154
                                 "DeltaY", DoubleValue (5.0),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   155
                                 "GridWidth", UintegerValue (10),
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   156
                                 "LayoutType", StringValue ("RowFirst"));
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   157
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   158
  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
6674
52f8688d6d01 Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents: 6673
diff changeset
   159
                             "Bounds", RectangleValue (Rectangle (-250, 250, -250, 250)));
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   160
  mobility.Install (wifiStaNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   161
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   162
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   163
  mobility.Install (wifiApNode);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   164
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   165
  InternetStackHelper stack;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   166
  stack.Install (csmaNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   167
  stack.Install (wifiApNode);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   168
  stack.Install (wifiStaNodes);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   169
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   170
  Ipv4AddressHelper address;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   171
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   172
  address.SetBase ("10.1.1.0", "255.255.255.0");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   173
  Ipv4InterfaceContainer p2pInterfaces;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   174
  p2pInterfaces = address.Assign (p2pDevices);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   175
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   176
  address.SetBase ("10.1.2.0", "255.255.255.0");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   177
  Ipv4InterfaceContainer csmaInterfaces;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   178
  csmaInterfaces = address.Assign (csmaDevices);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   179
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   180
  address.SetBase ("10.1.3.0", "255.255.255.0");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   181
  address.Assign (staDevices);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   182
  address.Assign (apDevices);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   183
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   184
  // If this simulator has system id 1, then 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   185
  // it should contain the server application, 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   186
  // since it is on one of the csma nodes
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   187
  if (systemId == 1)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   188
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   189
      UdpEchoServerHelper echoServer (9);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   190
      ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   191
      serverApps.Start (Seconds (1.0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   192
      serverApps.Stop (Seconds (10.0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   193
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   194
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 6113
diff changeset
   195
  // If the simulator has system id 0, then 
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   196
  // it should contain the client application, 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   197
  // since it is on one of the wifi nodes
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   198
  if (systemId == 0)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   199
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   200
      UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   201
      echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   202
      echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   203
      echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   204
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   205
      ApplicationContainer clientApps = 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   206
        echoClient.Install (wifiStaNodes.Get (nWifi - 1));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   207
      clientApps.Start (Seconds (2.0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   208
      clientApps.Stop (Seconds (10.0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   209
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   210
 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   211
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   212
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   213
  Simulator::Stop (Seconds (10.0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   214
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   215
  if (tracing == true)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   216
    {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   217
      // Depending on the system Id (rank), the pcap information 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   218
      // traced will be different.  For example, the ethernet pcap
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   219
      // will be empty for rank0, since these nodes are placed on 
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   220
      // on rank 1.  All ethernet traffic will take place on rank 1.
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   221
      // Similar differences are seen in the p2p and wirless pcaps.
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   222
      if (systemId == 0)
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   223
        {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   224
          pointToPoint.EnablePcapAll ("third-distributed-rank0");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   225
          phy.EnablePcap ("third-distributed-rank0", apDevices.Get (0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   226
          csma.EnablePcap ("third-distributed-rank0", csmaDevices.Get (0), true);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   227
        }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   228
      else
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   229
        {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   230
          pointToPoint.EnablePcapAll ("third-distributed-rank1");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   231
          phy.EnablePcap ("third-distributed-rank1", apDevices.Get (0));
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   232
          csma.EnablePcap ("third-distributed-rank1", csmaDevices.Get (0), true);
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   233
        }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   234
    }
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   235
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   236
  Simulator::Run ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   237
  Simulator::Destroy ();
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   238
  return 0;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   239
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   240
#else
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   241
  NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   242
#endif
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   243
}