examples/csma-star.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 26 Jun 2009 15:34:16 +0200
changeset 4616 a84f60b6cd12
parent 4264 9d2e96c4e6e4
permissions -rw-r--r--
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 *
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 */
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/core-module.h"
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/simulator-module.h"
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/node-module.h"
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/helper-module.h"
4210
da9be6abb1b2 bug 486: patches for icc compilation.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3858
diff changeset
    22
#include "ns3/csma-module.h"
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
// Network topology (default)
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
//
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
//            n2     +          +     n3          .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
//             | ... |\        /| ... |           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
//             ======= \      / =======           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
//              CSMA    \    /   CSMA             .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
//                       \  /                     .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//            n1     +--- n0 ---+     n4          .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//             | ... |   /  \   | ... |           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//             =======  /    \  =======           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
//              CSMA   /      \  CSMA             .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//                    /        \                  .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//            n6     +          +     n5          .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
//             | ... |          | ... |           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
//             =======          =======           .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
//              CSMA             CSMA             .
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
using namespace ns3;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
NS_LOG_COMPONENT_DEFINE ("CsmaStar");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
int 
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
main (int argc, char *argv[])
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
{
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  // Set up some default values for the simulation.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  // ??? try and stick 15kb/s into the data rate
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  // Default number of nodes in the star.  Overridable by command line argument.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  uint32_t nNodes = 7;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  CommandLine cmd;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  cmd.Parse (argc, argv);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  NS_LOG_INFO ("Create nodes.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  NodeContainer hubNode;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  NodeContainer spokeNodes;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  hubNode.Create (1);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  Ptr<Node> hub = hubNode.Get (0);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  spokeNodes.Create (nNodes - 1);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  CsmaHelper csma;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  NS_LOG_INFO ("Build star topology.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  NetDeviceContainer hubDevices, spokeDevices;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  csma.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  NodeContainer fillNodes;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  // Just to be nasy, hang some more nodes off of the CSMA channel for each
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  // spoke, so that there are a total of 16 nodes on each channel.  Stash
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
  // all of these new devices into a container.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
  NetDeviceContainer fillDevices;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
  uint32_t nFill = 14;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  for (uint32_t i = 0; i < spokeDevices.GetN (); ++i)
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    {
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
      Ptr<Channel> channel = spokeDevices.Get (i)->GetChannel ();
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
      Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
      NodeContainer newNodes;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
      NetDeviceContainer newDevices;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
      newNodes.Create (nFill);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
      fillNodes.Add (newNodes);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
      fillDevices.Add (csma.Install (newNodes, csmaChannel));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
    }
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  NS_LOG_INFO ("Install internet stack on all nodes.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  InternetStackHelper internet;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  internet.Install (NodeContainer (hubNode, spokeNodes, fillNodes));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  NS_LOG_INFO ("Assign IP Addresses.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  Ipv4AddressHelper address;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  // Assign IPv4 interfaces and IP addresses to the devices we previously
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  // created.  Keep track of the resulting addresses, one for the addresses
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
  // of the hub node, and one for addresses on the spoke nodes.  Despite the
3858
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   114
  // name of the class (Ipv4InterfaceContainer), what is visible to clients 
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   115
  // is really the address not the interface.
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  Ipv4InterfaceContainer hubAddresses;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  Ipv4InterfaceContainer spokeAddresses;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  {
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
    std::ostringstream subnet;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
    subnet << "10.1." << i << ".0";
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
    NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ());
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
    address.SetBase (subnet.str ().c_str (), "255.255.255.0");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
    hubAddresses.Add (address.Assign (hubDevices.Get (i)));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
    spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
3858
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   128
    //
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   129
    // We assigned addresses to the logical hub and the first "drop" of the 
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   130
    // CSMA network that acts as the spoke, but we also have a number of fill
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   131
    // devices (nFill) also hanging off the CSMA network.  We have got to 
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   132
    // assign addresses to them as well.  We put all of the fill devices into
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   133
    // a single device container, so the first nFill devices are associated
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   134
    // with the channel connected to spokeDevices.Get (0), the second nFill
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   135
    // devices afe associated with the channel connected to spokeDevices.Get (1)
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   136
    // etc.
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   137
    //
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   138
    for (uint32_t j = 0; j < nFill; ++j)
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   139
      {
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   140
        address.Assign (fillDevices.Get (i * nFill + j));
6559f390009d fix buggy example
craigdo@ee.washington.edu
parents: 3795
diff changeset
   141
      }
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
  }
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
  NS_LOG_INFO ("Create applications.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  // Create a packet sink on the star "hub" to receive packets.  
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  // 
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  uint16_t port = 50000;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
  hubApp.Start (Seconds (1.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  hubApp.Stop (Seconds (10.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  // Create OnOff applications to send TCP to the hub, one on each spoke node.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
  OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
  onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
  ApplicationContainer spokeApps;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
  for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
    {
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
      AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
      onOffHelper.SetAttribute ("Remote", remoteAddress);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
      spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
    }
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
  spokeApps.Start (Seconds (1.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
  spokeApps.Stop (Seconds (10.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  // Because we are evil, we also add OnOff applications to send TCP to the hub 
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  // from the fill devices on each CSMA link.  The first nFill nodes in the 
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  // fillNodes container are on the CSMA network talking to the zeroth device
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  // on the hub node.  The next nFill nodes are on the CSMA network talking to
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  // the first device on the hub node, etc.  So the ith fillNode is associated
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  // with the hub address found on the (i / nFill)th device on the hub node.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  ApplicationContainer fillApps;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
  for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
    {
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
      AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i / nFill), port));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
      onOffHelper.SetAttribute ("Remote", remoteAddress);
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
      fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
    }
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
  fillApps.Start (Seconds (1.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  fillApps.Stop (Seconds (10.0));
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
  NS_LOG_INFO ("Enable static global routing.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  // Turn on global static routing so we can actually be routed across the star.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  //
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4264
diff changeset
   198
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  NS_LOG_INFO ("Enable pcap tracing.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  //
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  // Do pcap tracing on all devices on all nodes.
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
  //
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4238
diff changeset
   204
  CsmaHelper::EnablePcapAll ("csma-star", false);
3795
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  NS_LOG_INFO ("Run Simulation.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  Simulator::Run ();
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  Simulator::Destroy ();
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  NS_LOG_INFO ("Done.");
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  return 0;
707acdf0f8b3 csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
}