examples/tap-wifi-dumbbell.cc
author Mirko Banchi <mk.banchi@gmail.com>
Fri, 24 Apr 2009 10:01:41 +0200
changeset 4406 39f119de91ef
parent 4291 141f01bbfa8b
child 4568 8a9c81e59c92
permissions -rw-r--r--
Add WifiMacHelper
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
// Network topology
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
//  +----------+                                                                  
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
//  | external |                                                                  
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
//  |  Linux   |                                                                  
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
//  |   Host   |                                                                  
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    23
//  |          |
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    24
//  | "mytap"  |                                                                  
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
//  +----------+                                                                  
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
//       |           n0                n3                n4
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
//       |       +--------+     +------------+     +------------+
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
//       +-------|  tap   |     |            |     |            |
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
//               | bridge | ... |            |     |            |
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
//               +--------+     +------------+     +------------+
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//               |  Wifi  |     | Wifi | P2P |-----| P2P | CSMA |
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//               +--------+     +------+-----+     +-----+------+
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//                   |              |           ^           |
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
//                 ((*))          ((*))         |           |         
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//                                          P2P 10.1.2      |         
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//                 ((*))          ((*))                     |    n5  n6   n7
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
//                   |              |                       |     |   |    |
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
//                  n1             n2                       ================
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
//                     Wifi 10.1.1                           CSMA LAN 10.1.3
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
// The Wifi device on node zero is:  10.1.1.1
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
// The Wifi device on node one is:   10.1.1.2
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
// The Wifi device on node two is:   10.1.1.3
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
// The Wifi device on node three is: 10.1.1.4
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
// The P2P device on node three is:  10.1.2.1
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
// The P2P device on node four is:   10.1.2.2
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
// The CSMA device on node four is:  10.1.3.1
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
// The CSMA device on node five is:  10.1.3.2
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
// The CSMA device on node six is:   10.1.3.3
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
// The CSMA device on node seven is: 10.1.3.4
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
// Some simple things to do:
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
// 1) Ping one of the simulated nodes on the left side of the topology.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
//    ./waf --run tap-wifi-dumbbell&
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
//    ping 10.1.1.3
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
// 2) Configure a route in the linux host and ping once of the nodes on the 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
//    right, across the point-to-point link.  You will see relatively large
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
//    delays due to CBR background traffic on the point-to-point (see next
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
//    item).
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
//    ./waf --run tap-wifi-dumbbell&
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    65
//    sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
//    ping 10.1.3.4
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
//    Take a look at the pcap traces and note that the timing reflects the 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
//    addition of the significant delay and low bandwidth configured on the 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
//    point-to-point link along with the high traffic.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
// 3) Fiddle with the background CBR traffic across the point-to-point 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
//    link and watch the ping timing change.  The OnOffApplication "DataRate"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
//    attribute defaults to 500kb/s and the "PacketSize" Attribute defaults
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
//    to 512.  The point-to-point "DataRate" is set to 512kb/s in the script,
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
//    so in the default case, the link is pretty full.  This should be 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
//    reflected in large delays seen by ping.  You can crank down the CBR 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
//    traffic data rate and watch the ping timing change dramatically.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
//
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
//    ./waf --run "tap-wifi-dumbbell --ns3::OnOffApplication::DataRate=100kb/s"&
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    81
//    sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
//    ping 10.1.3.4
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
//
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    84
// 4) Try to run this in UseLocal mode.  This allows you to provide an existing
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    85
//    pre-configured tap device to the simulation.  The IP address and MAC 
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    86
//    address in this mode do not have to match those of the ns-3 device.
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    87
//
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    88
//    sudo tunctl -t mytap
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    89
//    sudo ifconfig mytap hw ether 08:00:2e:00:00:01
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    90
//    sudo ifconfig mytap 10.1.1.1 netmask 255.255.255.0 up
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    91
//    ./waf --run "tap-wifi-dumbbell --mode=UseLocal --tapName=mytap"&
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    92
//    ping 10.1.1.3
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    93
//
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    94
// 5) Try to run this in UseBridge mode.  This allows you to bridge an ns-3
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    95
//    simulation to an existing pre-configured bridge.  This uses tap devices
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    96
//    just for illustration, you can create your own bridge if you want.
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    97
//
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    98
//    sudo tunctl -t mytap1
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
    99
//    sudo ifconfig mytap1 0.0.0.0 promisc up
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   100
//    sudo tunctl -t mytap2
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   101
//    sudo ifconfig mytap2 0.0.0.0 promisc up
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   102
//    sudo brctl addbr mybridge
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   103
//    sudo brctl addif mybridge mytap1
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   104
//    sudo brctl addif mybridge mytap2
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   105
//    sudo ifconfig mybridge 10.1.1.5 netmask 255.255.255.0 up
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   106
//    ./waf --run "tap-wifi-dumbbell --mode=UseBridge --tapName=mytap2"&
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   107
//    ping 10.1.1.3
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
#include <iostream>
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
#include <fstream>
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
#include "ns3/simulator-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
#include "ns3/node-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
#include "ns3/core-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
#include "ns3/wifi-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
#include "ns3/helper-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
#include "ns3/global-routing-module.h"
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
using namespace ns3;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
NS_LOG_COMPONENT_DEFINE ("TapDumbbellExample");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
int 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
main (int argc, char *argv[])
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
{
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   126
  std::string mode = "ConfigureLocal";
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   127
  std::string tapName = "thetap";
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   128
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
  CommandLine cmd;
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   130
  cmd.AddValue("mode", "Mode setting of TapBridge", mode);
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   131
  cmd.AddValue("tapName", "Name of the OS tap device", tapName);
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
  cmd.Parse (argc, argv);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
  Config::SetDefault ("ns3::Ipv4L3Protocol::CalcChecksum", BooleanValue (true)); 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
  Config::SetDefault ("ns3::Icmpv4L4Protocol::CalcChecksum", BooleanValue (true)); 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
  Config::SetDefault ("ns3::TcpL4Protocol::CalcChecksum", BooleanValue (true)); 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  Config::SetDefault ("ns3::UdpL4Protocol::CalcChecksum", BooleanValue (true)); 
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
  // The topology has a Wifi network of four nodes on the left side.  We'll make
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
  // node zero the AP and have the other three will be the STAs.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  NodeContainer nodesLeft;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  nodesLeft.Create (4);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
  wifiPhy.SetChannel (wifiChannel.Create ());
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
  Ssid ssid = Ssid ("left");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  WifiHelper wifi = WifiHelper::Default ();
4406
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   154
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
4406
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   157
  wifiMac.SetType ("ns3::NqapWifiMac", 
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   158
                   "Ssid", SsidValue (ssid), 
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   159
                   "BeaconGeneration", BooleanValue (true), 
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   160
                   "BeaconInterval", TimeValue (Seconds (2.5)));
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   161
  NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
4406
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   164
  wifiMac.SetType ("ns3::NqstaWifiMac", 
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   165
                   "Ssid", SsidValue (ssid), 
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   166
                   "ActiveProbing", BooleanValue (false));
39f119de91ef Add WifiMacHelper
Mirko Banchi <mk.banchi@gmail.com>
parents: 4291
diff changeset
   167
  devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  MobilityHelper mobility;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
  mobility.Install (nodesLeft);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
  InternetStackHelper internetLeft;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
  internetLeft.Install (nodesLeft);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  Ipv4AddressHelper ipv4Left;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  ipv4Left.SetBase ("10.1.1.0", "255.255.255.0");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
4290
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   179
  TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1));
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   180
  tapBridge.SetAttribute ("Mode", StringValue (mode));
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   181
  tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
af8a40d5c2cb test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   182
  tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
  // Now, create the right side.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  NodeContainer nodesRight;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  nodesRight.Create (4);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  CsmaHelper csmaRight;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
  csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
  NetDeviceContainer devicesRight = csmaRight.Install (nodesRight);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  InternetStackHelper internetRight;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  internetRight.Install (nodesRight);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
  Ipv4AddressHelper ipv4Right;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  ipv4Right.SetBase ("10.1.3.0", "255.255.255.0");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
  // Stick in the point-to-point line between the sides.
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  PointToPointHelper p2p;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps"));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
  NodeContainer nodes = NodeContainer (nodesLeft.Get(3), nodesRight.Get (0));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  NetDeviceContainer devices = p2p.Install (nodes);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  Ipv4AddressHelper ipv4;
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
  ipv4.SetBase ("10.1.2.0", "255.255.255.192");
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
  Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  // Simulate some CBR traffic over the point-to-point link
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  //
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  uint16_t port = 9;   // Discard port (RFC 863)
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
  ApplicationContainer apps = onoff.Install (nodesLeft.Get (3));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
  apps.Start (Seconds (1.0));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
  // Create a packet sink to receive these packets
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
  apps = sink.Install (nodesRight.Get (0));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
  apps.Start (Seconds (1.0));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4239
diff changeset
   234
  CsmaHelper::EnablePcapAll ("tap-dumbbell", false);
4177
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
  GlobalRouteManager::PopulateRoutingTables ();
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
  Simulator::Stop (Seconds (60.));
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
  Simulator::Run ();
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
  Simulator::Destroy ();
1212830d6f76 add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
}