A Discrete-Event Network Simulator
API
wifi-backward-compatibility.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ns3/core-module.h"
22 #include "ns3/applications-module.h"
23 #include "ns3/wifi-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/internet-module.h"
26 
27 // This is an example to show how to configure an IEEE 802.11 Wi-Fi
28 // network where the AP and the station use different 802.11 standards.
29 //
30 // It outputs the throughput for a given configuration: user can specify
31 // the 802.11 versions for the AT and the station as well as their rate
32 // adaptation algorithms. It also allows to decide whether the station,
33 // the AP or both has/have traffic to send.
34 //
35 // Example for an IEEE 802.11ac station sending traffic to an 802.11a AP using Ideal rate adaptation algorithm:
36 // ./waf --run "wifi-backward-compatibility --apVersion=80211a --staVersion=80211ac --staRaa=Ideal"
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("wifi-backward-compatibility");
41 
43 {
44  WifiPhyStandard standard;
45  if (version == "80211a")
46  {
47  standard = WIFI_PHY_STANDARD_80211a;
48  }
49  else if (version == "80211b")
50  {
51  standard = WIFI_PHY_STANDARD_80211b;
52  }
53  else if (version == "80211g")
54  {
55  standard = WIFI_PHY_STANDARD_80211g;
56  }
57  else if (version == "80211_10MHZ")
58  {
60  }
61  else if (version == "80211_5MHZ")
62  {
64  }
65  else if (version == "holland")
66  {
67  standard = WIFI_PHY_STANDARD_holland;
68  }
69  else if (version == "80211n_2_4GHZ")
70  {
72  }
73  else if (version == "80211n_5GHZ")
74  {
76  }
77  else if (version == "80211ac")
78  {
79  standard = WIFI_PHY_STANDARD_80211ac;
80  }
81  else
82  {
84  }
85  return standard;
86 }
87 
88 int main (int argc, char *argv[])
89 {
90  uint32_t payloadSize = 1472; //bytes
91  double simulationTime = 10; //seconds
92  std::string apVersion = "80211a";
93  std::string staVersion = "80211n_5GHZ";
94  std::string apRaa = "Minstrel";
95  std::string staRaa = "MinstrelHt";
96  bool apHasTraffic = false;
97  bool staHasTraffic = true;
98 
100  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
101  cmd.AddValue ("apVersion", "The standard version used by the AP: 80211a, 80211b, 80211g, 80211_10MHZ, 80211_5MHZ, holland, 80211n_2_4GHZ, 80211n_5GHZ or 80211ac", apVersion);
102  cmd.AddValue ("staVersion", "The standard version used by the station: 80211a, 80211b, 80211g, 80211_10MHZ, 80211_5MHZ, holland, 80211n_2_4GHZ, 80211n_5GHZ or 80211ac", staVersion);
103  cmd.AddValue ("apRaa", "Rate adaptation algorithm used by the AP", apRaa);
104  cmd.AddValue ("staRaa", "Rate adaptation algorithm used by the station", staRaa);
105  cmd.AddValue ("apHasTraffic", "Enable/disable traffic on the AP", apHasTraffic);
106  cmd.AddValue ("staHasTraffic", "Enable/disable traffic on the station", staHasTraffic);
107  cmd.Parse (argc,argv);
108 
109  NodeContainer wifiStaNode;
110  wifiStaNode.Create (1);
112  wifiApNode.Create (1);
113 
116  phy.SetChannel (channel.Create ());
117 
120  Ssid ssid = Ssid ("ns3");
121 
122  wifi.SetStandard (ConvertStringToStandard (staVersion));
123  wifi.SetRemoteStationManager ("ns3::" + staRaa + "WifiManager");
124 
125  mac.SetType ("ns3::StaWifiMac",
126  "Ssid", SsidValue (ssid),
127  "ActiveProbing", BooleanValue (false));
128 
129  NetDeviceContainer staDevice;
130  staDevice = wifi.Install (phy, mac, wifiStaNode);
131 
132  wifi.SetStandard (ConvertStringToStandard (apVersion));
133  wifi.SetRemoteStationManager ("ns3::" + apRaa + "WifiManager");
134 
135  mac.SetType ("ns3::ApWifiMac",
136  "Ssid", SsidValue (ssid));
137 
138  NetDeviceContainer apDevice;
139  apDevice = wifi.Install (phy, mac, wifiApNode);
140 
141  //Workaround needed as long as we do not fully support channel bonding
142  if (staVersion == "80211ac")
143  {
144  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (20));
145  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/Frequency", UintegerValue (5180));
146  }
147  if (apVersion == "80211ac")
148  {
149  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (20));
150  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/Frequency", UintegerValue (5180));
151  }
152 
154  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
155  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
156  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
157  mobility.SetPositionAllocator (positionAlloc);
158  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
159  mobility.Install (wifiApNode);
160  mobility.Install (wifiStaNode);
161 
163  stack.Install (wifiApNode);
164  stack.Install (wifiStaNode);
165 
167  address.SetBase ("192.168.1.0", "255.255.255.0");
168  Ipv4InterfaceContainer staNodeInterface;
169  Ipv4InterfaceContainer apNodeInterface;
170 
171  staNodeInterface = address.Assign (staDevice);
172  apNodeInterface = address.Assign (apDevice);
173 
174  UdpServerHelper apServer (9);
175  ApplicationContainer apServerApp = apServer.Install (wifiApNode.Get (0));
176  apServerApp.Start (Seconds (0.0));
177  apServerApp.Stop (Seconds (simulationTime + 1));
178 
179  UdpServerHelper staServer (5001);
180  ApplicationContainer staServerApp = staServer.Install (wifiStaNode.Get (0));
181  staServerApp.Start (Seconds (0.0));
182  staServerApp.Stop (Seconds (simulationTime + 1));
183 
184  if (apHasTraffic)
185  {
186  UdpClientHelper apClient (staNodeInterface.GetAddress (0), 5001);
187  apClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
188  apClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
189  apClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
190  ApplicationContainer apClientApp = apClient.Install (wifiApNode.Get (0));
191  apClientApp.Start (Seconds (1.0));
192  apClientApp.Stop (Seconds (simulationTime + 1));
193  }
194 
195  if (staHasTraffic)
196  {
197  UdpClientHelper staClient (apNodeInterface.GetAddress (0), 9);
198  staClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
199  staClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
200  staClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
201  ApplicationContainer staClientApp = staClient.Install (wifiStaNode.Get (0));
202  staClientApp.Start (Seconds (1.0));
203  staClientApp.Stop (Seconds (simulationTime + 1));
204  }
205 
207 
208  Simulator::Stop (Seconds (simulationTime + 1));
209  Simulator::Run ();
211 
212  uint64_t rxBytes;
213  double throughput;
214  if (apHasTraffic)
215  {
216  rxBytes = payloadSize * DynamicCast<UdpServer> (staServerApp.Get (0))->GetReceived ();
217  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
218  std::cout << "AP Throughput: " << throughput << " Mbit/s" << std::endl;
219  if (throughput == 0)
220  {
221  NS_LOG_ERROR ("No traffic received!");
222  exit (1);
223  }
224  }
225  if (staHasTraffic)
226  {
227  rxBytes = payloadSize * DynamicCast<UdpServer> (apServerApp.Get (0))->GetReceived ();
228  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
229  std::cout << "STA Throughput: " << throughput << " Mbit/s" << std::endl;
230  if (throughput == 0)
231  {
232  NS_LOG_ERROR ("No traffic received!");
233  exit (1);
234  }
235  }
236  return 0;
237 }
ERP-OFDM PHY (Clause 19, Section 19.5)
tuple channel
Definition: third.py:85
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
AttributeValue implementation for Boolean.
Definition: boolean.h:36
HT PHY for the 5 GHz band (clause 20)
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:719
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
string version
Definition: conf.py:51
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.
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:777
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
aggregate IP/TCP/UDP functionality to existing Nodes.
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
HT PHY for the 2.4 GHz band (clause 20)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
tuple cmd
Definition: second.py:35
void SetChannel(Ptr< YansWifiChannel > channel)
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
tuple phy
Definition: third.py:86
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
AttributeValue implementation for Time.
Definition: nstime.h:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:742
Create a server application which waits for input UDP packets and uses the information carried into t...
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
tuple mac
Definition: third.py:92
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
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
tuple wifiApNode
Definition: third.py:83
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
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
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 Add(Vector v)
Add a position to the list of positions.
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.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:253
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.
tuple address
Definition: first.py:37
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
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
WifiPhyStandard ConvertStringToStandard(std::string version)