A Discrete-Event Network Simulator
API
wifi-wired-bridging.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 // Default network topology includes some number of AP nodes specified by
18 // the variable nWifis (defaults to two). Off of each AP node, there are some
19 // number of STA nodes specified by the variable nStas (defaults to two).
20 // Each AP talks to its associated STA nodes. There are bridge net devices
21 // on each AP node that bridge the whole thing into one network.
22 //
23 // +-----+ +-----+ +-----+ +-----+
24 // | STA | | STA | | STA | | STA |
25 // +-----+ +-----+ +-----+ +-----+
26 // 192.168.0.2 192.168.0.3 192.168.0.5 192.168.0.6
27 // -------- -------- -------- --------
28 // WIFI STA WIFI STA WIFI STA WIFI STA
29 // -------- -------- -------- --------
30 // ((*)) ((*)) | ((*)) ((*))
31 // |
32 // ((*)) | ((*))
33 // ------- -------
34 // WIFI AP CSMA ========= CSMA WIFI AP
35 // ------- ---- ---- -------
36 // ############## ##############
37 // BRIDGE BRIDGE
38 // ############## ##############
39 // 192.168.0.1 192.168.0.4
40 // +---------+ +---------+
41 // | AP Node | | AP Node |
42 // +---------+ +---------+
43 
44 #include "ns3/core-module.h"
45 #include "ns3/mobility-module.h"
46 #include "ns3/applications-module.h"
47 #include "ns3/wifi-module.h"
48 #include "ns3/network-module.h"
49 #include "ns3/csma-module.h"
50 #include "ns3/internet-module.h"
51 #include "ns3/bridge-helper.h"
52 
53 using namespace ns3;
54 
55 int main (int argc, char *argv[])
56 {
57  uint32_t nWifis = 2;
58  uint32_t nStas = 2;
59  bool sendIp = true;
60  bool writeMobility = false;
61 
63  cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
64  cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
65  cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
66  cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility);
67  cmd.Parse (argc, argv);
68 
69  NodeContainer backboneNodes;
70  NetDeviceContainer backboneDevices;
71  Ipv4InterfaceContainer backboneInterfaces;
72  std::vector<NodeContainer> staNodes;
73  std::vector<NetDeviceContainer> staDevices;
74  std::vector<NetDeviceContainer> apDevices;
75  std::vector<Ipv4InterfaceContainer> staInterfaces;
76  std::vector<Ipv4InterfaceContainer> apInterfaces;
77 
81  ip.SetBase ("192.168.0.0", "255.255.255.0");
82 
83  backboneNodes.Create (nWifis);
84  stack.Install (backboneNodes);
85 
86  backboneDevices = csma.Install (backboneNodes);
87 
88  double wifiX = 0.0;
89 
92 
93  for (uint32_t i = 0; i < nWifis; ++i)
94  {
95  // calculate ssid for wifi subnetwork
96  std::ostringstream oss;
97  oss << "wifi-default-" << i;
98  Ssid ssid = Ssid (oss.str ());
99 
100  NodeContainer sta;
101  NetDeviceContainer staDev;
102  NetDeviceContainer apDev;
103  Ipv4InterfaceContainer staInterface;
104  Ipv4InterfaceContainer apInterface;
106  BridgeHelper bridge;
108  WifiMacHelper wifiMac;
110  wifiPhy.SetChannel (wifiChannel.Create ());
111 
112  sta.Create (nStas);
113  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
114  "MinX", DoubleValue (wifiX),
115  "MinY", DoubleValue (0.0),
116  "DeltaX", DoubleValue (5.0),
117  "DeltaY", DoubleValue (5.0),
118  "GridWidth", UintegerValue (1),
119  "LayoutType", StringValue ("RowFirst"));
120 
121  // setup the AP.
122  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
123  mobility.Install (backboneNodes.Get (i));
124  wifiMac.SetType ("ns3::ApWifiMac",
125  "Ssid", SsidValue (ssid));
126  apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));
127 
128  NetDeviceContainer bridgeDev;
129  bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
130 
131  // assign AP IP address to bridge, not wifi
132  apInterface = ip.Assign (bridgeDev);
133 
134  // setup the STAs
135  stack.Install (sta);
136  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
137  "Mode", StringValue ("Time"),
138  "Time", StringValue ("2s"),
139  "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
140  "Bounds", RectangleValue (Rectangle (wifiX, wifiX + 5.0,0.0, (nStas + 1) * 5.0)));
141  mobility.Install (sta);
142  wifiMac.SetType ("ns3::StaWifiMac",
143  "Ssid", SsidValue (ssid));
144  staDev = wifi.Install (wifiPhy, wifiMac, sta);
145  staInterface = ip.Assign (staDev);
146 
147  // save everything in containers.
148  staNodes.push_back (sta);
149  apDevices.push_back (apDev);
150  apInterfaces.push_back (apInterface);
151  staDevices.push_back (staDev);
152  staInterfaces.push_back (staInterface);
153 
154  wifiX += 20.0;
155  }
156 
157  Address dest;
158  std::string protocol;
159  if (sendIp)
160  {
161  dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
162  protocol = "ns3::UdpSocketFactory";
163  }
164  else
165  {
167  tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
168  tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
169  tmp.SetProtocol (0x807);
170  dest = tmp;
171  protocol = "ns3::PacketSocketFactory";
172  }
173 
174  OnOffHelper onoff = OnOffHelper (protocol, dest);
175  onoff.SetConstantRate (DataRate ("500kb/s"));
176  ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
177  apps.Start (Seconds (0.5));
178  apps.Stop (Seconds (3.0));
179 
180  wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
181  wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);
182 
183  if (writeMobility)
184  {
185  AsciiTraceHelper ascii;
186  MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob"));
187  }
188 
189  Simulator::Stop (Seconds (5.0));
190  Simulator::Run ();
192 }
holds a vector of ns3::Application pointers.
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
an Inet address class
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
Hold variables of type string.
Definition: string.h:41
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.
an address for a packet socket
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
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:217
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits. ...
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
tuple cmd
Definition: second.py:35
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:566
a polymophic address class
Definition: address.h:90
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
Class for representing data rates.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
tuple staDevices
Definition: third.py:96
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
Definition: bridge-helper.h:37
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Every class exported by the ns3 library is enclosed in the ns3 namespace.
tuple apDevices
Definition: third.py:99
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
void SetPhysicalAddress(const Address address)
Set the destination address.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, 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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
tuple ssid
Definition: third.py:93
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Helper class used to assign positions and mobility models to nodes.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
void SetProtocol(uint16_t protocol)
Set the protocol.
static void EnableAsciiAll(Ptr< OutputStreamWrapper > stream)
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.
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
Include Radiotap link layer information.
Definition: wifi-helper.h:111
a 2d rectangle
Definition: rectangle.h:34
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
tuple csma
Definition: second.py:63