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/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/log.h"
25 #include "ns3/yans-wifi-helper.h"
26 #include "ns3/ssid.h"
27 #include "ns3/mobility-helper.h"
28 #include "ns3/internet-stack-helper.h"
29 #include "ns3/ipv4-address-helper.h"
30 #include "ns3/udp-client-server-helper.h"
31 #include "ns3/packet-sink-helper.h"
32 #include "ns3/ipv4-global-routing-helper.h"
33 #include "ns3/yans-wifi-channel.h"
34 
35 // This is an example to show how to configure an IEEE 802.11 Wi-Fi
36 // network where the AP and the station use different 802.11 standards.
37 //
38 // It outputs the throughput for a given configuration: user can specify
39 // the 802.11 versions for the AT and the station as well as their rate
40 // adaptation algorithms. It also allows to decide whether the station,
41 // the AP or both has/have traffic to send.
42 //
43 // Example for an IEEE 802.11ac station sending traffic to an 802.11a AP using Ideal rate adaptation algorithm:
44 // ./waf --run "wifi-backward-compatibility --apVersion=80211a --staVersion=80211ac --staRaa=Ideal"
45 
46 using namespace ns3;
47 
48 NS_LOG_COMPONENT_DEFINE ("wifi-backward-compatibility");
49 
51 {
53  if (version == "80211a")
54  {
55  standard = WIFI_STANDARD_80211a;
56  }
57  else if (version == "80211b")
58  {
59  standard = WIFI_STANDARD_80211b;
60  }
61  else if (version == "80211g")
62  {
63  standard = WIFI_STANDARD_80211g;
64  }
65  else if (version == "80211p")
66  {
67  standard = WIFI_STANDARD_80211p;
68  }
69  else if (version == "holland")
70  {
71  standard = WIFI_STANDARD_holland;
72  }
73  else if (version == "80211n_2_4GHZ")
74  {
75  standard = WIFI_STANDARD_80211n_2_4GHZ;
76  }
77  else if (version == "80211n_5GHZ")
78  {
79  standard = WIFI_STANDARD_80211n_5GHZ;
80  }
81  else if (version == "80211ac")
82  {
83  standard = WIFI_STANDARD_80211ac;
84  }
85  else if (version == "80211ax_2_4GHZ")
86  {
88  }
89  else if (version == "80211ax_5GHZ")
90  {
91  standard = WIFI_STANDARD_80211ax_5GHZ;
92  }
93  return standard;
94 }
95 
96 int main (int argc, char *argv[])
97 {
98  uint32_t payloadSize = 1472; //bytes
99  double simulationTime = 10; //seconds
100  std::string apVersion = "80211a";
101  std::string staVersion = "80211n_5GHZ";
102  std::string apRaa = "Minstrel";
103  std::string staRaa = "MinstrelHt";
104  bool apHasTraffic = false;
105  bool staHasTraffic = true;
106 
107  CommandLine cmd (__FILE__);
108  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
109  cmd.AddValue ("apVersion", "The standard version used by the AP: 80211a, 80211b, 80211g, 80211p, holland, 80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ", apVersion);
110  cmd.AddValue ("staVersion", "The standard version used by the station: 80211a, 80211b, 80211g, 80211_10MHZ, 80211_5MHZ, holland, 80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ", staVersion);
111  cmd.AddValue ("apRaa", "Rate adaptation algorithm used by the AP", apRaa);
112  cmd.AddValue ("staRaa", "Rate adaptation algorithm used by the station", staRaa);
113  cmd.AddValue ("apHasTraffic", "Enable/disable traffic on the AP", apHasTraffic);
114  cmd.AddValue ("staHasTraffic", "Enable/disable traffic on the station", staHasTraffic);
115  cmd.Parse (argc,argv);
116 
117  NodeContainer wifiStaNode;
118  wifiStaNode.Create (1);
120  wifiApNode.Create (1);
121 
124  phy.SetChannel (channel.Create ());
125 
128  Ssid ssid = Ssid ("ns3");
129 
130  wifi.SetStandard (ConvertStringToStandard (staVersion));
131  wifi.SetRemoteStationManager ("ns3::" + staRaa + "WifiManager");
132 
133  mac.SetType ("ns3::StaWifiMac",
134  "Ssid", SsidValue (ssid));
135 
136  NetDeviceContainer staDevice;
137  staDevice = wifi.Install (phy, mac, wifiStaNode);
138 
139  wifi.SetStandard (ConvertStringToStandard (apVersion));
140  wifi.SetRemoteStationManager ("ns3::" + apRaa + "WifiManager");
141 
142  mac.SetType ("ns3::ApWifiMac",
143  "Ssid", SsidValue (ssid));
144 
145  NetDeviceContainer apDevice;
146  apDevice = wifi.Install (phy, mac, wifiApNode);
147 
148  //Workaround needed as long as we do not fully support channel bonding
149  if (staVersion == "80211ac")
150  {
151  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (20));
152  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/Frequency", UintegerValue (5180));
153  }
154  if (apVersion == "80211ac")
155  {
156  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (20));
157  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/Frequency", UintegerValue (5180));
158  }
159 
161  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
162  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
163  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
164  mobility.SetPositionAllocator (positionAlloc);
165  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
166  mobility.Install (wifiApNode);
167  mobility.Install (wifiStaNode);
168 
170  stack.Install (wifiApNode);
171  stack.Install (wifiStaNode);
172 
174  address.SetBase ("192.168.1.0", "255.255.255.0");
175  Ipv4InterfaceContainer staNodeInterface;
176  Ipv4InterfaceContainer apNodeInterface;
177 
178  staNodeInterface = address.Assign (staDevice);
179  apNodeInterface = address.Assign (apDevice);
180 
181  UdpServerHelper apServer (9);
182  ApplicationContainer apServerApp = apServer.Install (wifiApNode.Get (0));
183  apServerApp.Start (Seconds (0.0));
184  apServerApp.Stop (Seconds (simulationTime + 1));
185 
186  UdpServerHelper staServer (5001);
187  ApplicationContainer staServerApp = staServer.Install (wifiStaNode.Get (0));
188  staServerApp.Start (Seconds (0.0));
189  staServerApp.Stop (Seconds (simulationTime + 1));
190 
191  if (apHasTraffic)
192  {
193  UdpClientHelper apClient (staNodeInterface.GetAddress (0), 5001);
194  apClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
195  apClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
196  apClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
197  ApplicationContainer apClientApp = apClient.Install (wifiApNode.Get (0));
198  apClientApp.Start (Seconds (1.0));
199  apClientApp.Stop (Seconds (simulationTime + 1));
200  }
201 
202  if (staHasTraffic)
203  {
204  UdpClientHelper staClient (apNodeInterface.GetAddress (0), 9);
205  staClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
206  staClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
207  staClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
208  ApplicationContainer staClientApp = staClient.Install (wifiStaNode.Get (0));
209  staClientApp.Start (Seconds (1.0));
210  staClientApp.Stop (Seconds (simulationTime + 1));
211  }
212 
214 
215  Simulator::Stop (Seconds (simulationTime + 1));
216  Simulator::Run ();
217 
218  uint64_t rxBytes;
219  double throughput;
220  bool error = false;
221  if (apHasTraffic)
222  {
223  rxBytes = payloadSize * DynamicCast<UdpServer> (staServerApp.Get (0))->GetReceived ();
224  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
225  std::cout << "AP Throughput: " << throughput << " Mbit/s" << std::endl;
226  if (throughput == 0)
227  {
228  error = true;
229  }
230  }
231  if (staHasTraffic)
232  {
233  rxBytes = payloadSize * DynamicCast<UdpServer> (apServerApp.Get (0))->GetReceived ();
234  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
235  std::cout << "STA Throughput: " << throughput << " Mbit/s" << std::endl;
236  if (throughput == 0)
237  {
238  error = true;
239  }
240  }
241 
243 
244  if (error)
245  {
246  NS_LOG_ERROR ("No traffic received!");
247  exit (1);
248  }
249 
250  return 0;
251 }
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
holds a vector of std::pair of Ptr<Ipv4> and interface index.
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:839
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
aggregate IP/TCP/UDP functionality to existing Nodes.
cmd
Definition: second.py:35
static YansWifiPhyHelper Default(void)
Create a PHY helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:318
stack
Definition: first.py:41
channel
Definition: third.py:92
mobility
Definition: third.py:108
phy
Definition: third.py:93
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:1342
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:100
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
Create a server application which waits for input UDP packets and uses the information carried into t...
wifiApNode
Definition: third.py:90
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:226
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiStandard
Identifies the allowed configurations that a Wifi device is configured to use.
keep track of a set of node pointers.
address
Definition: first.py:44
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
wifi
Definition: third.py:96
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...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
AttributeValue implementation for Ssid.
Definition: ssid.h:105
void Add(Vector v)
Add a position to the list of positions.
WifiStandard ConvertStringToStandard(std::string version)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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:257
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.