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/boolean.h"
25 #include "ns3/log.h"
26 #include "ns3/yans-wifi-helper.h"
27 #include "ns3/ssid.h"
28 #include "ns3/mobility-helper.h"
29 #include "ns3/internet-stack-helper.h"
30 #include "ns3/ipv4-address-helper.h"
31 #include "ns3/udp-client-server-helper.h"
32 #include "ns3/packet-sink-helper.h"
33 #include "ns3/ipv4-global-routing-helper.h"
34 #include "ns3/yans-wifi-channel.h"
35 
36 // This is an example to show how to configure an IEEE 802.11 Wi-Fi
37 // network where the AP and the station use different 802.11 standards.
38 //
39 // It outputs the throughput for a given configuration: user can specify
40 // the 802.11 versions for the AT and the station as well as their rate
41 // adaptation algorithms. It also allows to decide whether the station,
42 // the AP or both has/have traffic to send.
43 //
44 // Example for an IEEE 802.11ac station sending traffic to an 802.11a AP using Ideal rate adaptation algorithm:
45 // ./waf --run "wifi-backward-compatibility --apVersion=80211a --staVersion=80211ac --staRaa=Ideal"
46 
47 using namespace ns3;
48 
49 NS_LOG_COMPONENT_DEFINE ("wifi-backward-compatibility");
50 
52 {
54  if (version == "80211a")
55  {
56  standard = WIFI_STANDARD_80211a;
57  }
58  else if (version == "80211b")
59  {
60  standard = WIFI_STANDARD_80211b;
61  }
62  else if (version == "80211g")
63  {
64  standard = WIFI_STANDARD_80211g;
65  }
66  else if (version == "80211p")
67  {
68  standard = WIFI_STANDARD_80211p;
69  }
70  else if (version == "80211n_2_4GHZ")
71  {
72  standard = WIFI_STANDARD_80211n_2_4GHZ;
73  }
74  else if (version == "80211n_5GHZ")
75  {
76  standard = WIFI_STANDARD_80211n_5GHZ;
77  }
78  else if (version == "80211ac")
79  {
80  standard = WIFI_STANDARD_80211ac;
81  }
82  else if (version == "80211ax_2_4GHZ")
83  {
85  }
86  else if (version == "80211ax_5GHZ")
87  {
88  standard = WIFI_STANDARD_80211ax_5GHZ;
89  }
90  return standard;
91 }
92 
93 int main (int argc, char *argv[])
94 {
95  uint32_t payloadSize = 1472; //bytes
96  double simulationTime = 10; //seconds
97  std::string apVersion = "80211a";
98  std::string staVersion = "80211n_5GHZ";
99  std::string apRaa = "Minstrel";
100  std::string staRaa = "MinstrelHt";
101  bool apHasTraffic = false;
102  bool staHasTraffic = true;
103 
104  CommandLine cmd (__FILE__);
105  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
106  cmd.AddValue ("apVersion", "The standard version used by the AP: 80211a, 80211b, 80211g, 80211p, 80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ", apVersion);
107  cmd.AddValue ("staVersion", "The standard version used by the station: 80211a, 80211b, 80211g, 80211_10MHZ, 80211_5MHZ, 80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ", staVersion);
108  cmd.AddValue ("apRaa", "Rate adaptation algorithm used by the AP", apRaa);
109  cmd.AddValue ("staRaa", "Rate adaptation algorithm used by the station", staRaa);
110  cmd.AddValue ("apHasTraffic", "Enable/disable traffic on the AP", apHasTraffic);
111  cmd.AddValue ("staHasTraffic", "Enable/disable traffic on the station", staHasTraffic);
112  cmd.Parse (argc,argv);
113 
114  NodeContainer wifiStaNode;
115  wifiStaNode.Create (1);
117  wifiApNode.Create (1);
118 
121  phy.SetChannel (channel.Create ());
122 
125  Ssid ssid = Ssid ("ns3");
126 
127  wifi.SetStandard (ConvertStringToStandard (staVersion));
128  wifi.SetRemoteStationManager ("ns3::" + staRaa + "WifiManager");
129 
130  mac.SetType ("ns3::StaWifiMac",
131  "QosSupported", BooleanValue (true),
132  "Ssid", SsidValue (ssid));
133 
134  //Workaround needed as long as we do not fully support channel bonding
135  if (staVersion == "80211ac")
136  {
137  phy.Set ("ChannelWidth", UintegerValue (20));
138  phy.Set ("Frequency", UintegerValue (5180));
139  }
140 
141  NetDeviceContainer staDevice;
142  staDevice = wifi.Install (phy, mac, wifiStaNode);
143 
144  wifi.SetStandard (ConvertStringToStandard (apVersion));
145  wifi.SetRemoteStationManager ("ns3::" + apRaa + "WifiManager");
146 
147  mac.SetType ("ns3::ApWifiMac",
148  "QosSupported", BooleanValue (true),
149  "Ssid", SsidValue (ssid));
150 
151  //Workaround needed as long as we do not fully support channel bonding
152  if (apVersion == "80211ac")
153  {
154  phy.Set ("ChannelWidth", UintegerValue (20));
155  phy.Set ("Frequency", UintegerValue (5180));
156  }
157 
158  NetDeviceContainer apDevice;
159  apDevice = wifi.Install (phy, mac, wifiApNode);
160 
162  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
163  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
164  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
165  mobility.SetPositionAllocator (positionAlloc);
166  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
167  mobility.Install (wifiApNode);
168  mobility.Install (wifiStaNode);
169 
171  stack.Install (wifiApNode);
172  stack.Install (wifiStaNode);
173 
175  address.SetBase ("192.168.1.0", "255.255.255.0");
176  Ipv4InterfaceContainer staNodeInterface;
177  Ipv4InterfaceContainer apNodeInterface;
178 
179  staNodeInterface = address.Assign (staDevice);
180  apNodeInterface = address.Assign (apDevice);
181 
182  UdpServerHelper apServer (9);
183  ApplicationContainer apServerApp = apServer.Install (wifiApNode.Get (0));
184  apServerApp.Start (Seconds (0.0));
185  apServerApp.Stop (Seconds (simulationTime + 1));
186 
187  UdpServerHelper staServer (5001);
188  ApplicationContainer staServerApp = staServer.Install (wifiStaNode.Get (0));
189  staServerApp.Start (Seconds (0.0));
190  staServerApp.Stop (Seconds (simulationTime + 1));
191 
192  if (apHasTraffic)
193  {
194  UdpClientHelper apClient (staNodeInterface.GetAddress (0), 5001);
195  apClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
196  apClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
197  apClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
198  ApplicationContainer apClientApp = apClient.Install (wifiApNode.Get (0));
199  apClientApp.Start (Seconds (1.0));
200  apClientApp.Stop (Seconds (simulationTime + 1));
201  }
202 
203  if (staHasTraffic)
204  {
205  UdpClientHelper staClient (apNodeInterface.GetAddress (0), 9);
206  staClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
207  staClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
208  staClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
209  ApplicationContainer staClientApp = staClient.Install (wifiStaNode.Get (0));
210  staClientApp.Start (Seconds (1.0));
211  staClientApp.Stop (Seconds (simulationTime + 1));
212  }
213 
215 
216  Simulator::Stop (Seconds (simulationTime + 1));
217  Simulator::Run ();
218 
219  uint64_t rxBytes;
220  double throughput;
221  bool error = false;
222  if (apHasTraffic)
223  {
224  rxBytes = payloadSize * DynamicCast<UdpServer> (staServerApp.Get (0))->GetReceived ();
225  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
226  std::cout << "AP Throughput: " << throughput << " Mbit/s" << std::endl;
227  if (throughput == 0)
228  {
229  error = true;
230  }
231  }
232  if (staHasTraffic)
233  {
234  rxBytes = payloadSize * DynamicCast<UdpServer> (apServerApp.Get (0))->GetReceived ();
235  throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
236  std::cout << "STA Throughput: " << throughput << " Mbit/s" << std::endl;
237  if (throughput == 0)
238  {
239  error = true;
240  }
241  }
242 
244 
245  if (error)
246  {
247  NS_LOG_ERROR ("No traffic received!");
248  exit (1);
249  }
250 
251  return 0;
252 }
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
AttributeValue implementation for Boolean.
Definition: boolean.h:36
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.
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
helps to create WifiNetDevice objects
Definition: wifi-helper.h:326
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:1353
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:227
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:1289
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.