examples/csma/csma-bridge.cc
author Tom Henderson <tomh@tomh.org>
Fri, 20 Aug 2010 12:17:19 -0700
changeset 6589 9c325569fb01
parent 6014 d251d4a44fde
permissions -rw-r--r--
Help waf to guess release versions of nsc and pybindgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
/*
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
 *
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
 * GNU General Public License for more details.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
 *
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
 */
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
// Network topology
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
//
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
//        n0     n1  
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
//        |      | 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
//       ----------
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
//       | Switch |
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
//       ----------
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
//        |      | 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
//        n2     n3  
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
//
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
//
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
// - CBR/UDP flows from n0 to n1 and from n3 to n0
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
// - DropTail queues 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
// - Tracing of queues and packet receptions to file "csma-bridge.tr"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
#include <iostream>
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
#include <fstream>
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
#include "ns3/simulator-module.h"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
#include "ns3/node-module.h"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
#include "ns3/core-module.h"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
#include "ns3/helper-module.h"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
#include "ns3/bridge-module.h"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
using namespace ns3;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
NS_LOG_COMPONENT_DEFINE ("CsmaBridgeExample");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
int 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
main (int argc, char *argv[])
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
{
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
  // Users may find it convenient to turn on explicit debugging
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
  // for selected modules; the below lines suggest how to do this
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
#if 0 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
  LogComponentEnable ("CsmaBridgeExample", LOG_LEVEL_INFO);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
#endif
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
  // Allow the user to override any of the defaults and the above Bind() at
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
  // run-time, via command-line arguments
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
  CommandLine cmd;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
  cmd.Parse (argc, argv);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
  // Explicitly create the nodes required by the topology (shown above).
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
  NS_LOG_INFO ("Create nodes.");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
  NodeContainer terminals;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
  terminals.Create (4);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
  NodeContainer csmaSwitch;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
  csmaSwitch.Create (1);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
  NS_LOG_INFO ("Build Topology");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
  CsmaHelper csma;
3451
4e4cb6a885ca Adapt to evil API breakage
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3440
diff changeset
    75
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
4e4cb6a885ca Adapt to evil API breakage
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3440
diff changeset
    76
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
  // Create the csma links, from each terminal to the switch
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
  NetDeviceContainer terminalDevices;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
  NetDeviceContainer switchDevices;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
  for (int i = 0; i < 4; i++)
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
    {
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
      NetDeviceContainer link = csma.Install (NodeContainer (terminals.Get (i), csmaSwitch));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
      terminalDevices.Add (link.Get (0));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
      switchDevices.Add (link.Get (1));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    }
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
  // Create the bridge netdevice, which will do the packet switching
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
  Ptr<Node> switchNode = csmaSwitch.Get (0);
3524
028b7de98fb1 bug 276: bridge netdevice has no helper class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3451
diff changeset
    92
  BridgeHelper bridge;
028b7de98fb1 bug 276: bridge netdevice has no helper class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3451
diff changeset
    93
  bridge.Install (switchNode, switchDevices);
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
  // Add internet stack to the terminals
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
  InternetStackHelper internet;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
  internet.Install (terminals);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
  // We've got the "hardware" in place.  Now we need to add IP addresses.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
  NS_LOG_INFO ("Assign IP Addresses.");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
  Ipv4AddressHelper ipv4;
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
  ipv4.Assign (terminalDevices);
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
  // Create an OnOff application to send UDP datagrams from node zero to node 1.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
  NS_LOG_INFO ("Create Applications.");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
  uint16_t port = 9;   // Discard port (RFC 863)
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
  ApplicationContainer app = onoff.Install (terminals.Get (0));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
  // Start the application
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
  app.Start (Seconds (1.0));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
  app.Stop (Seconds (10.0));
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
  // Create an optional packet sink to receive these packets
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
3715
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   125
  app = sink.Install (terminals.Get (1));
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   126
  app.Start (Seconds (0.0));
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
  // 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
  onoff.SetAttribute ("Remote", 
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
                      AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));
3715
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   133
  app = onoff.Install (terminals.Get (3));
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   134
  app.Start (Seconds (1.1));
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   135
  app.Stop (Seconds (10.0));
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
3715
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   137
  app = sink.Install (terminals.Get (0));
594e2052e5b2 make sure that the sinks are started
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3524
diff changeset
   138
  app.Start (Seconds (0.0));
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
6014
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   140
  NS_LOG_INFO ("Configure Tracing.");
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
  // Trace output will be sent to the file "csma-bridge.tr"
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
  //
6014
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   146
  AsciiTraceHelper ascii;
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   147
  csma.EnableAsciiAll (ascii.CreateFileStream ("csma-bridge.tr"));
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
  // Also configure some tcpdump traces; each interface will be traced.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
  // The output files will be named:
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4225
diff changeset
   152
  //     csma-bridge-<nodeId>-<interfaceId>.pcap
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
  // and can be read by the "tcpdump -r" command (use "-tt" option to
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
  // display timestamps correctly)
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
  //
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5369
diff changeset
   156
  csma.EnablePcapAll ("csma-bridge", false);
3440
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
  // Now, do the actual simulation.
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
  //
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
  NS_LOG_INFO ("Run Simulation.");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
  Simulator::Run ();
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
  Simulator::Destroy ();
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
  NS_LOG_INFO ("Done.");
4cedf996375d Start of a BridgeNetDevice example, using csma (basically an Ethernet Switch).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
}