A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-backward-compatibility.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20#include "ns3/boolean.h"
21#include "ns3/command-line.h"
22#include "ns3/config.h"
23#include "ns3/enum.h"
24#include "ns3/internet-stack-helper.h"
25#include "ns3/ipv4-address-helper.h"
26#include "ns3/ipv4-global-routing-helper.h"
27#include "ns3/log.h"
28#include "ns3/mobility-helper.h"
29#include "ns3/packet-sink-helper.h"
30#include "ns3/ssid.h"
31#include "ns3/tuple.h"
32#include "ns3/udp-client-server-helper.h"
33#include "ns3/udp-server.h"
34#include "ns3/uinteger.h"
35#include "ns3/yans-wifi-channel.h"
36#include "ns3/yans-wifi-helper.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
47// algorithm:
48// ./ns3 run "wifi-backward-compatibility --apVersion=80211a --staVersion=80211ac --staRaa=Ideal"
49
50using namespace ns3;
51
52NS_LOG_COMPONENT_DEFINE("wifi-backward-compatibility");
53
54/**
55 * Convert a string (e.g., "80211a") to a pair {WifiStandard, WifiPhyBand}
56 *
57 * \param version The WiFi standard version.
58 * \return a pair of WifiStandard, WifiPhyBand
59 */
60std::pair<WifiStandard, WifiPhyBand>
62{
65 if (version == "80211a")
66 {
67 standard = WIFI_STANDARD_80211a;
68 band = WIFI_PHY_BAND_5GHZ;
69 }
70 else if (version == "80211b")
71 {
72 standard = WIFI_STANDARD_80211b;
74 }
75 else if (version == "80211g")
76 {
77 standard = WIFI_STANDARD_80211g;
79 }
80 else if (version == "80211p")
81 {
82 standard = WIFI_STANDARD_80211p;
83 band = WIFI_PHY_BAND_5GHZ;
84 }
85 else if (version == "80211n_2_4GHZ")
86 {
87 standard = WIFI_STANDARD_80211n;
89 }
90 else if (version == "80211n_5GHZ")
91 {
92 standard = WIFI_STANDARD_80211n;
93 band = WIFI_PHY_BAND_5GHZ;
94 }
95 else if (version == "80211ac")
96 {
97 standard = WIFI_STANDARD_80211ac;
98 band = WIFI_PHY_BAND_5GHZ;
99 }
100 else if (version == "80211ax_2_4GHZ")
101 {
102 standard = WIFI_STANDARD_80211ax;
104 }
105 else if (version == "80211ax_5GHZ")
106 {
107 standard = WIFI_STANDARD_80211ax;
108 band = WIFI_PHY_BAND_5GHZ;
109 }
110 return {standard, band};
111}
112
113int
114main(int argc, char* argv[])
115{
116 uint32_t payloadSize = 1472; // bytes
117 double simulationTime = 10; // seconds
118 std::string apVersion = "80211a";
119 std::string staVersion = "80211n_5GHZ";
120 std::string apRaa = "Minstrel";
121 std::string staRaa = "MinstrelHt";
122 bool apHasTraffic = false;
123 bool staHasTraffic = true;
124
125 CommandLine cmd(__FILE__);
126 cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime);
127 cmd.AddValue("apVersion",
128 "The standard version used by the AP: 80211a, 80211b, 80211g, 80211p, "
129 "80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ",
130 apVersion);
131 cmd.AddValue("staVersion",
132 "The standard version used by the station: 80211a, 80211b, 80211g, 80211_10MHZ, "
133 "80211_5MHZ, 80211n_2_4GHZ, 80211n_5GHZ, 80211ac, 80211ax_2_4GHZ or 80211ax_5GHZ",
134 staVersion);
135 cmd.AddValue("apRaa", "Rate adaptation algorithm used by the AP", apRaa);
136 cmd.AddValue("staRaa", "Rate adaptation algorithm used by the station", staRaa);
137 cmd.AddValue("apHasTraffic", "Enable/disable traffic on the AP", apHasTraffic);
138 cmd.AddValue("staHasTraffic", "Enable/disable traffic on the station", staHasTraffic);
139 cmd.Parse(argc, argv);
140
141 NodeContainer wifiStaNode;
142 wifiStaNode.Create(1);
144 wifiApNode.Create(1);
145
148 phy.SetChannel(channel.Create());
149
152 Ssid ssid = Ssid("ns3");
154
155 const auto& [staStandard, staBand] = ConvertStringToStandardAndBand(staVersion);
156 wifi.SetStandard(staStandard);
157 wifi.SetRemoteStationManager("ns3::" + staRaa + "WifiManager");
158
159 mac.SetType("ns3::StaWifiMac", "QosSupported", BooleanValue(true), "Ssid", SsidValue(ssid));
160
161 // Workaround needed as long as we do not fully support channel bonding
162 uint16_t width = (staVersion == "80211ac" ? 20 : 0);
163 channelValue.Set(WifiPhy::ChannelTuple{0, width, staBand, 0});
164 phy.Set("ChannelSettings", channelValue);
165
166 NetDeviceContainer staDevice;
167 staDevice = wifi.Install(phy, mac, wifiStaNode);
168
169 const auto& [apStandard, apBand] = ConvertStringToStandardAndBand(apVersion);
170 wifi.SetStandard(apStandard);
171 wifi.SetRemoteStationManager("ns3::" + apRaa + "WifiManager");
172
173 mac.SetType("ns3::ApWifiMac", "QosSupported", BooleanValue(true), "Ssid", SsidValue(ssid));
174
175 // Workaround needed as long as we do not fully support channel bonding
176 width = (apVersion == "80211ac" ? 20 : 0);
177 channelValue.Set(WifiPhy::ChannelTuple{0, width, apBand, 0});
178 phy.Set("ChannelSettings", channelValue);
179
180 NetDeviceContainer apDevice;
181 apDevice = wifi.Install(phy, mac, wifiApNode);
182
184 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
185 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
186 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
187 mobility.SetPositionAllocator(positionAlloc);
188 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
189 mobility.Install(wifiApNode);
190 mobility.Install(wifiStaNode);
191
193 stack.Install(wifiApNode);
194 stack.Install(wifiStaNode);
195
197 address.SetBase("192.168.1.0", "255.255.255.0");
198 Ipv4InterfaceContainer staNodeInterface;
199 Ipv4InterfaceContainer apNodeInterface;
200
201 staNodeInterface = address.Assign(staDevice);
202 apNodeInterface = address.Assign(apDevice);
203
204 UdpServerHelper apServer(9);
205 ApplicationContainer apServerApp = apServer.Install(wifiApNode.Get(0));
206 apServerApp.Start(Seconds(0.0));
207 apServerApp.Stop(Seconds(simulationTime + 1));
208
209 UdpServerHelper staServer(5001);
210 ApplicationContainer staServerApp = staServer.Install(wifiStaNode.Get(0));
211 staServerApp.Start(Seconds(0.0));
212 staServerApp.Stop(Seconds(simulationTime + 1));
213
214 if (apHasTraffic)
215 {
216 UdpClientHelper apClient(staNodeInterface.GetAddress(0), 5001);
217 apClient.SetAttribute("MaxPackets", UintegerValue(4294967295U));
218 apClient.SetAttribute("Interval", TimeValue(Time("0.00001"))); // packets/s
219 apClient.SetAttribute("PacketSize", UintegerValue(payloadSize)); // bytes
220 ApplicationContainer apClientApp = apClient.Install(wifiApNode.Get(0));
221 apClientApp.Start(Seconds(1.0));
222 apClientApp.Stop(Seconds(simulationTime + 1));
223 }
224
225 if (staHasTraffic)
226 {
227 UdpClientHelper staClient(apNodeInterface.GetAddress(0), 9);
228 staClient.SetAttribute("MaxPackets", UintegerValue(4294967295U));
229 staClient.SetAttribute("Interval", TimeValue(Time("0.00001"))); // packets/s
230 staClient.SetAttribute("PacketSize", UintegerValue(payloadSize)); // bytes
231 ApplicationContainer staClientApp = staClient.Install(wifiStaNode.Get(0));
232 staClientApp.Start(Seconds(1.0));
233 staClientApp.Stop(Seconds(simulationTime + 1));
234 }
235
237
238 Simulator::Stop(Seconds(simulationTime + 1));
240
241 uint64_t rxBytes;
242 double throughput;
243 bool error = false;
244 if (apHasTraffic)
245 {
246 rxBytes = payloadSize * DynamicCast<UdpServer>(staServerApp.Get(0))->GetReceived();
247 throughput = (rxBytes * 8) / (simulationTime * 1000000.0); // Mbit/s
248 std::cout << "AP Throughput: " << throughput << " Mbit/s" << std::endl;
249 if (throughput == 0)
250 {
251 error = true;
252 }
253 }
254 if (staHasTraffic)
255 {
256 rxBytes = payloadSize * DynamicCast<UdpServer>(apServerApp.Get(0))->GetReceived();
257 throughput = (rxBytes * 8) / (simulationTime * 1000000.0); // Mbit/s
258 std::cout << "STA Throughput: " << throughput << " Mbit/s" << std::endl;
259 if (throughput == 0)
260 {
261 error = true;
262 }
263 }
264
266
267 if (error)
268 {
269 NS_LOG_ERROR("No traffic received!");
270 exit(1);
271 }
272
273 return 0;
274}
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
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:232
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
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:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Definition: ssid.h:96
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1406
AttributeValue implementation for Tuple.
Definition: tuple.h:78
void Set(const result_type &value)
Set the stored values.
Definition: tuple.h:340
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:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
create MAC layers for a ns3::WifiNetDevice.
std::tuple< uint8_t, uint16_t, WifiPhyBand, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:903
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
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:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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
ns address
Definition: first.py:47
ns stack
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:40
ns wifi
Definition: third.py:95
ns ssid
Definition: third.py:93
ns mac
Definition: third.py:92
ns wifiApNode
Definition: third.py:86
ns channel
Definition: third.py:88
ns mobility
Definition: third.py:105
ns phy
Definition: third.py:89
std::ofstream throughput
std::pair< WifiStandard, WifiPhyBand > ConvertStringToStandardAndBand(std::string version)
Convert a string (e.g., "80211a") to a pair {WifiStandard, WifiPhyBand}.