A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tap-wifi-dumbbell.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 // Network topology
18 //
19 // +----------+
20 // | external |
21 // | Linux |
22 // | Host |
23 // | |
24 // | "mytap" |
25 // +----------+
26 // | n0 n3 n4
27 // | +--------+ +------------+ +------------+
28 // +-------| tap | | | | |
29 // | bridge | ... | | | |
30 // +--------+ +------------+ +------------+
31 // | Wifi | | Wifi | P2P |-----| P2P | CSMA |
32 // +--------+ +------+-----+ +-----+------+
33 // | | ^ |
34 // ((*)) ((*)) | |
35 // P2P 10.1.2 |
36 // ((*)) ((*)) | n5 n6 n7
37 // | | | | | |
38 // n1 n2 ================
39 // Wifi 10.1.1 CSMA LAN 10.1.3
40 //
41 // The Wifi device on node zero is: 10.1.1.1
42 // The Wifi device on node one is: 10.1.1.2
43 // The Wifi device on node two is: 10.1.1.3
44 // The Wifi device on node three is: 10.1.1.4
45 // The P2P device on node three is: 10.1.2.1
46 // The P2P device on node four is: 10.1.2.2
47 // The CSMA device on node four is: 10.1.3.1
48 // The CSMA device on node five is: 10.1.3.2
49 // The CSMA device on node six is: 10.1.3.3
50 // The CSMA device on node seven is: 10.1.3.4
51 //
52 // Some simple things to do:
53 //
54 // 1) Ping one of the simulated nodes on the left side of the topology.
55 //
56 // ./waf --run tap-wifi-dumbbell&
57 // ping 10.1.1.3
58 //
59 // 2) Configure a route in the linux host and ping once of the nodes on the
60 // right, across the point-to-point link. You will see relatively large
61 // delays due to CBR background traffic on the point-to-point (see next
62 // item).
63 //
64 // ./waf --run tap-wifi-dumbbell&
65 // sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
66 // ping 10.1.3.4
67 //
68 // Take a look at the pcap traces and note that the timing reflects the
69 // addition of the significant delay and low bandwidth configured on the
70 // point-to-point link along with the high traffic.
71 //
72 // 3) Fiddle with the background CBR traffic across the point-to-point
73 // link and watch the ping timing change. The OnOffApplication "DataRate"
74 // attribute defaults to 500kb/s and the "PacketSize" Attribute defaults
75 // to 512. The point-to-point "DataRate" is set to 512kb/s in the script,
76 // so in the default case, the link is pretty full. This should be
77 // reflected in large delays seen by ping. You can crank down the CBR
78 // traffic data rate and watch the ping timing change dramatically.
79 //
80 // ./waf --run "tap-wifi-dumbbell --ns3::OnOffApplication::DataRate=100kb/s"&
81 // sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
82 // ping 10.1.3.4
83 //
84 // 4) Try to run this in UseBridge mode. This allows you to bridge an ns-3
85 // simulation to an existing pre-configured bridge. This uses tap devices
86 // just for illustration, you can create your own bridge if you want.
87 //
88 // sudo tunctl -t mytap1
89 // sudo ifconfig mytap1 0.0.0.0 promisc up
90 // sudo tunctl -t mytap2
91 // sudo ifconfig mytap2 0.0.0.0 promisc up
92 // sudo brctl addbr mybridge
93 // sudo brctl addif mybridge mytap1
94 // sudo brctl addif mybridge mytap2
95 // sudo ifconfig mybridge 10.1.1.5 netmask 255.255.255.0 up
96 // ./waf --run "tap-wifi-dumbbell --mode=UseBridge --tapName=mytap2"&
97 // ping 10.1.1.3
98 
99 #include <iostream>
100 #include <fstream>
101 
102 #include "ns3/core-module.h"
103 #include "ns3/network-module.h"
104 #include "ns3/mobility-module.h"
105 #include "ns3/point-to-point-module.h"
106 #include "ns3/wifi-module.h"
107 #include "ns3/internet-module.h"
108 #include "ns3/csma-module.h"
109 #include "ns3/applications-module.h"
110 #include "ns3/ipv4-global-routing-helper.h"
111 #include "ns3/tap-bridge-module.h"
112 
113 using namespace ns3;
114 
115 NS_LOG_COMPONENT_DEFINE ("TapDumbbellExample");
116 
117 int
118 main (int argc, char *argv[])
119 {
120  std::string mode = "ConfigureLocal";
121  std::string tapName = "thetap";
122 
123  CommandLine cmd;
124  cmd.AddValue ("mode", "Mode setting of TapBridge", mode);
125  cmd.AddValue ("tapName", "Name of the OS tap device", tapName);
126  cmd.Parse (argc, argv);
127 
128  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
129  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
130 
131  //
132  // The topology has a Wifi network of four nodes on the left side. We'll make
133  // node zero the AP and have the other three will be the STAs.
134  //
135  NodeContainer nodesLeft;
136  nodesLeft.Create (4);
137 
140  wifiPhy.SetChannel (wifiChannel.Create ());
141 
142  Ssid ssid = Ssid ("left");
145  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
146 
147  wifiMac.SetType ("ns3::ApWifiMac",
148  "Ssid", SsidValue (ssid));
149  NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
150 
151 
152  wifiMac.SetType ("ns3::StaWifiMac",
153  "Ssid", SsidValue (ssid),
154  "ActiveProbing", BooleanValue (false));
155  devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
156 
157  MobilityHelper mobility;
158  mobility.Install (nodesLeft);
159 
160  InternetStackHelper internetLeft;
161  internetLeft.Install (nodesLeft);
162 
163  Ipv4AddressHelper ipv4Left;
164  ipv4Left.SetBase ("10.1.1.0", "255.255.255.0");
165  Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
166 
167  TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1));
168  tapBridge.SetAttribute ("Mode", StringValue (mode));
169  tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
170  tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
171 
172  //
173  // Now, create the right side.
174  //
175  NodeContainer nodesRight;
176  nodesRight.Create (4);
177 
178  CsmaHelper csmaRight;
179  csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000));
180  csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
181 
182  NetDeviceContainer devicesRight = csmaRight.Install (nodesRight);
183 
184  InternetStackHelper internetRight;
185  internetRight.Install (nodesRight);
186 
187  Ipv4AddressHelper ipv4Right;
188  ipv4Right.SetBase ("10.1.3.0", "255.255.255.0");
189  Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight);
190 
191  //
192  // Stick in the point-to-point line between the sides.
193  //
194  PointToPointHelper p2p;
195  p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps"));
196  p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
197 
198  NodeContainer nodes = NodeContainer (nodesLeft.Get (3), nodesRight.Get (0));
199  NetDeviceContainer devices = p2p.Install (nodes);
200 
201  Ipv4AddressHelper ipv4;
202  ipv4.SetBase ("10.1.2.0", "255.255.255.192");
203  Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
204 
205  //
206  // Simulate some CBR traffic over the point-to-point link
207  //
208  uint16_t port = 9; // Discard port (RFC 863)
209  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port));
210  onoff.SetConstantRate (DataRate ("500kb/s"));
211 
212  ApplicationContainer apps = onoff.Install (nodesLeft.Get (3));
213  apps.Start (Seconds (1.0));
214 
215  // Create a packet sink to receive these packets
216  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
217 
218  apps = sink.Install (nodesRight.Get (0));
219  apps.Start (Seconds (1.0));
220 
221  wifiPhy.EnablePcapAll ("tap-wifi-dumbbell");
222 
223  csmaRight.EnablePcapAll ("tap-wifi-dumbbell", false);
225 
226  Simulator::Stop (Seconds (60.));
227  Simulator::Run ();
229 }
void SetAttribute(std::string n1, const AttributeValue &v1)
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:69
Hold a bool native type.
Definition: boolean.h:38
tuple devices
Definition: first.py:32
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:73
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
NetDeviceContainer Install(NodeContainer c)
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:215
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:88
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
uint16_t port
Definition: dsdv-manet.cc:44
tuple nodes
Definition: first.py:25
Class for representing data rates.
Definition: data-rate.h:71
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
hold objects of type ns3::Time
Definition: nstime.h:961
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
tuple interfaces
Definition: first.py:40
holds a vector of ns3::NetDevice pointers
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state.
static void Bind(std::string name, const AttributeValue &value)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
Parse command-line arguments.
Definition: command-line.h:152
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
keep track of a set of node pointers.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
manage and create wifi channel objects for the yans model.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Helper class used to assign positions and mobility models to nodes.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
hold objects of type ns3::DataRate
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
hold objects of type ns3::Ssid
int main(int argc, char *argv[])
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
build TapBridge to allow ns-3 simulations to interact with Linux tap devices and processes on the Lin...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static WifiHelper Default(void)
Definition: wifi-helper.cc:65