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/enum.h"
26#include "ns3/tuple.h"
27#include "ns3/log.h"
28#include "ns3/yans-wifi-helper.h"
29#include "ns3/ssid.h"
30#include "ns3/mobility-helper.h"
31#include "ns3/internet-stack-helper.h"
32#include "ns3/ipv4-address-helper.h"
33#include "ns3/udp-client-server-helper.h"
34#include "ns3/packet-sink-helper.h"
35#include "ns3/ipv4-global-routing-helper.h"
36#include "ns3/yans-wifi-channel.h"
37
38// This is an example to show how to configure an IEEE 802.11 Wi-Fi
39// network where the AP and the station use different 802.11 standards.
40//
41// It outputs the throughput for a given configuration: user can specify
42// the 802.11 versions for the AP and the station as well as their rate
43// adaptation algorithms. It also allows to decide whether the station,
44// the AP or both has/have traffic to send.
45//
46// Example for an IEEE 802.11ac station sending traffic to an 802.11a AP using Ideal rate adaptation algorithm:
47// ./ns3 run "wifi-backward-compatibility --apVersion=80211a --staVersion=80211ac --staRaa=Ideal"
48
49using namespace ns3;
50
51NS_LOG_COMPONENT_DEFINE ("wifi-backward-compatibility");
52
53std::pair<WifiStandard, WifiPhyBand> ConvertStringToStandardAndBand (std::string version)
54{
57 if (version == "80211a")
58 {
59 standard = WIFI_STANDARD_80211a;
60 band = WIFI_PHY_BAND_5GHZ;
61 }
62 else if (version == "80211b")
63 {
64 standard = WIFI_STANDARD_80211b;
66 }
67 else if (version == "80211g")
68 {
69 standard = WIFI_STANDARD_80211g;
71 }
72 else if (version == "80211p")
73 {
74 standard = WIFI_STANDARD_80211p;
75 band = WIFI_PHY_BAND_5GHZ;
76 }
77 else if (version == "80211n_2_4GHZ")
78 {
79 standard = WIFI_STANDARD_80211n;
81 }
82 else if (version == "80211n_5GHZ")
83 {
84 standard = WIFI_STANDARD_80211n;
85 band = WIFI_PHY_BAND_5GHZ;
86 }
87 else if (version == "80211ac")
88 {
89 standard = WIFI_STANDARD_80211ac;
90 band = WIFI_PHY_BAND_5GHZ;
91 }
92 else if (version == "80211ax_2_4GHZ")
93 {
94 standard = WIFI_STANDARD_80211ax;
96 }
97 else if (version == "80211ax_5GHZ")
98 {
99 standard = WIFI_STANDARD_80211ax;
100 band = WIFI_PHY_BAND_5GHZ;
101 }
102 return {standard, band};
103}
104
105int main (int argc, char *argv[])
106{
107 uint32_t payloadSize = 1472; //bytes
108 double simulationTime = 10; //seconds
109 std::string apVersion = "80211a";
110 std::string staVersion = "80211n_5GHZ";
111 std::string apRaa = "Minstrel";
112 std::string staRaa = "MinstrelHt";
113 bool apHasTraffic = false;
114 bool staHasTraffic = true;
115
116 CommandLine cmd (__FILE__);
117 cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
118 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);
119 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);
120 cmd.AddValue ("apRaa", "Rate adaptation algorithm used by the AP", apRaa);
121 cmd.AddValue ("staRaa", "Rate adaptation algorithm used by the station", staRaa);
122 cmd.AddValue ("apHasTraffic", "Enable/disable traffic on the AP", apHasTraffic);
123 cmd.AddValue ("staHasTraffic", "Enable/disable traffic on the station", staHasTraffic);
124 cmd.Parse (argc,argv);
125
126 NodeContainer wifiStaNode;
127 wifiStaNode.Create (1);
129 wifiApNode.Create (1);
130
131 YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
133 phy.SetChannel (channel.Create ());
134
137 Ssid ssid = Ssid ("ns3");
139
140 const auto& [staStandard, staBand] = ConvertStringToStandardAndBand (staVersion);
141 wifi.SetStandard (staStandard);
142 wifi.SetRemoteStationManager ("ns3::" + staRaa + "WifiManager");
143
144 mac.SetType ("ns3::StaWifiMac",
145 "QosSupported", BooleanValue (true),
146 "Ssid", SsidValue (ssid));
147
148 //Workaround needed as long as we do not fully support channel bonding
149 uint16_t width = (staVersion == "80211ac" ? 20 : 0);
150 channelValue.Set (WifiPhy::ChannelTuple {0, width, staBand, 0});
151 phy.Set ("ChannelSettings", channelValue);
152
153 NetDeviceContainer staDevice;
154 staDevice = wifi.Install (phy, mac, wifiStaNode);
155
156 const auto& [apStandard, apBand] = ConvertStringToStandardAndBand (apVersion);
157 wifi.SetStandard (apStandard);
158 wifi.SetRemoteStationManager ("ns3::" + apRaa + "WifiManager");
159
160 mac.SetType ("ns3::ApWifiMac",
161 "QosSupported", BooleanValue (true),
162 "Ssid", SsidValue (ssid));
163
164 //Workaround needed as long as we do not fully support channel bonding
165 width = (apVersion == "80211ac" ? 20 : 0);
166 channelValue.Set (WifiPhy::ChannelTuple {0, width, apBand, 0});
167 phy.Set ("ChannelSettings", channelValue);
168
169 NetDeviceContainer apDevice;
170 apDevice = wifi.Install (phy, mac, wifiApNode);
171
173 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
174 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
175 positionAlloc->Add (Vector (5.0, 0.0, 0.0));
176 mobility.SetPositionAllocator (positionAlloc);
177 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
178 mobility.Install (wifiApNode);
179 mobility.Install (wifiStaNode);
180
182 stack.Install (wifiApNode);
183 stack.Install (wifiStaNode);
184
186 address.SetBase ("192.168.1.0", "255.255.255.0");
187 Ipv4InterfaceContainer staNodeInterface;
188 Ipv4InterfaceContainer apNodeInterface;
189
190 staNodeInterface = address.Assign (staDevice);
191 apNodeInterface = address.Assign (apDevice);
192
193 UdpServerHelper apServer (9);
194 ApplicationContainer apServerApp = apServer.Install (wifiApNode.Get (0));
195 apServerApp.Start (Seconds (0.0));
196 apServerApp.Stop (Seconds (simulationTime + 1));
197
198 UdpServerHelper staServer (5001);
199 ApplicationContainer staServerApp = staServer.Install (wifiStaNode.Get (0));
200 staServerApp.Start (Seconds (0.0));
201 staServerApp.Stop (Seconds (simulationTime + 1));
202
203 if (apHasTraffic)
204 {
205 UdpClientHelper apClient (staNodeInterface.GetAddress (0), 5001);
206 apClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
207 apClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
208 apClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
209 ApplicationContainer apClientApp = apClient.Install (wifiApNode.Get (0));
210 apClientApp.Start (Seconds (1.0));
211 apClientApp.Stop (Seconds (simulationTime + 1));
212 }
213
214 if (staHasTraffic)
215 {
216 UdpClientHelper staClient (apNodeInterface.GetAddress (0), 9);
217 staClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
218 staClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
219 staClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); //bytes
220 ApplicationContainer staClientApp = staClient.Install (wifiStaNode.Get (0));
221 staClientApp.Start (Seconds (1.0));
222 staClientApp.Stop (Seconds (simulationTime + 1));
223 }
224
225 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
226
227 Simulator::Stop (Seconds (simulationTime + 1));
228 Simulator::Run ();
229
230 uint64_t rxBytes;
231 double throughput;
232 bool error = false;
233 if (apHasTraffic)
234 {
235 rxBytes = payloadSize * DynamicCast<UdpServer> (staServerApp.Get (0))->GetReceived ();
236 throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
237 std::cout << "AP Throughput: " << throughput << " Mbit/s" << std::endl;
238 if (throughput == 0)
239 {
240 error = true;
241 }
242 }
243 if (staHasTraffic)
244 {
245 rxBytes = payloadSize * DynamicCast<UdpServer> (apServerApp.Get (0))->GetReceived ();
246 throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
247 std::cout << "STA Throughput: " << throughput << " Mbit/s" << std::endl;
248 if (throughput == 0)
249 {
250 error = true;
251 }
252 }
253
254 Simulator::Destroy ();
255
256 if (error)
257 {
258 NS_LOG_ERROR ("No traffic received!");
259 exit (1);
260 }
261
262 return 0;
263}
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Parse command-line arguments.
Definition: command-line.h:229
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold objects of type std::tuple<Args...>.
Definition: tuple.h:70
void Set(const result_type &value)
Set the stored values.
Definition: tuple.h:325
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Create a server application which waits for input UDP packets and uses the information carried into t...
Hold an unsigned integer type.
Definition: uinteger.h:44
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
create MAC layers for a ns3::WifiNetDevice.
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:832
manage and create wifi channel objects for the YANS model.
Make it easy to create and manage PHY objects for the YANS model.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
string version
Definition: conf.py:51
address
Definition: first.py:44
stack
Definition: first.py:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:35
ssid
Definition: third.py:97
channel
Definition: third.py:92
mac
Definition: third.py:96
wifi
Definition: third.py:99
wifiApNode
Definition: third.py:90
mobility
Definition: third.py:107
phy
Definition: third.py:93
std::pair< WifiStandard, WifiPhyBand > ConvertStringToStandardAndBand(std::string version)