author | Tom Henderson <tomh@tomh.org> |
Fri, 20 Aug 2010 12:17:19 -0700 | |
changeset 6589 | 9c325569fb01 |
parent 6309 | 8d46400b959e |
permissions | -rw-r--r-- |
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 |
// |
5444
d55c479666ac
remove comment referencing non-working use case
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
84 |
// 4) Try to run this in UseBridge mode. This allows you to bridge an ns-3 |
4290
af8a40d5c2cb
test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents:
4239
diff
changeset
|
85 |
// 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
|
86 |
// 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
|
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 mytap1 |
af8a40d5c2cb
test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents:
4239
diff
changeset
|
89 |
// 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
|
90 |
// 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
|
91 |
// 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
|
92 |
// 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
|
93 |
// 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
|
94 |
// 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
|
95 |
// 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
|
96 |
// ./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
|
97 |
// ping 10.1.1.3 |
4177
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
#include <iostream> |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
#include <fstream> |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
#include "ns3/simulator-module.h" |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
#include "ns3/node-module.h" |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
#include "ns3/core-module.h" |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
#include "ns3/wifi-module.h" |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
#include "ns3/helper-module.h" |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
using namespace ns3; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
NS_LOG_COMPONENT_DEFINE ("TapDumbbellExample"); |
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 |
int |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
main (int argc, char *argv[]) |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
{ |
4290
af8a40d5c2cb
test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents:
4239
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
|
4177
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
CommandLine cmd; |
4290
af8a40d5c2cb
test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents:
4239
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
cmd.Parse (argc, argv); |
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 |
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); |
4568
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4406
diff
changeset
|
124 |
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); |
4177
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
// 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
|
128 |
// 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
|
129 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
NodeContainer nodesLeft; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
nodesLeft.Create (4); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
Ssid ssid = Ssid ("left"); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
WifiHelper wifi = WifiHelper::Default (); |
4406 | 139 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
4177
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
|
4406 | 142 |
wifiMac.SetType ("ns3::NqapWifiMac", |
6309 | 143 |
"Ssid", SsidValue (ssid)); |
4406 | 144 |
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
|
145 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
|
4406 | 147 |
wifiMac.SetType ("ns3::NqstaWifiMac", |
148 |
"Ssid", SsidValue (ssid), |
|
149 |
"ActiveProbing", BooleanValue (false)); |
|
150 |
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
|
151 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
MobilityHelper mobility; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
mobility.Install (nodesLeft); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
InternetStackHelper internetLeft; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
internetLeft.Install (nodesLeft); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
Ipv4AddressHelper ipv4Left; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
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
|
160 |
Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
|
4290
af8a40d5c2cb
test out the tap-bridge modes and update the example
Craig Dowell <craigdo@ee.washington.edu>
parents:
4239
diff
changeset
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
// Now, create the right side. |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
169 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
NodeContainer nodesRight; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
171 |
nodesRight.Create (4); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
CsmaHelper csmaRight; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000)); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
NetDeviceContainer devicesRight = csmaRight.Install (nodesRight); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
179 |
InternetStackHelper internetRight; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
internetRight.Install (nodesRight); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
Ipv4AddressHelper ipv4Right; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
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
|
184 |
Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
|
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 |
// 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
|
188 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
PointToPointHelper p2p; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps")); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
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
|
194 |
NetDeviceContainer devices = p2p.Install (nodes); |
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 |
Ipv4AddressHelper ipv4; |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
197 |
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
|
198 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
// 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
|
202 |
// |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
206 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
207 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
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
|
209 |
apps.Start (Seconds (1.0)); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
210 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
211 |
// 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
|
212 |
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
|
213 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
214 |
apps = sink.Install (nodesRight.Get (0)); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
215 |
apps.Start (Seconds (1.0)); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
216 |
|
5829
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5444
diff
changeset
|
217 |
wifiPhy.EnablePcapAll ("tap-wifi-dumbbell"); |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5829
diff
changeset
|
218 |
|
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5829
diff
changeset
|
219 |
csmaRight.EnablePcapAll ("tap-wifi-dumbbell", false); |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4578
diff
changeset
|
220 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
4177
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
|
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
Simulator::Stop (Seconds (60.)); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
223 |
Simulator::Run (); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
224 |
Simulator::Destroy (); |
1212830d6f76
add a wifi example for the tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
225 |
} |