A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-aggregation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Sébastien Deronne
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: Sébastien 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/internet-stack-helper.h"
24#include "ns3/ipv4-address-helper.h"
25#include "ns3/log.h"
26#include "ns3/mobility-helper.h"
27#include "ns3/packet-sink-helper.h"
28#include "ns3/ssid.h"
29#include "ns3/string.h"
30#include "ns3/udp-client-server-helper.h"
31#include "ns3/uinteger.h"
32#include "ns3/wifi-mac.h"
33#include "ns3/wifi-net-device.h"
34#include "ns3/yans-wifi-channel.h"
35#include "ns3/yans-wifi-helper.h"
36
37// This is an example that illustrates how 802.11n aggregation is configured.
38// It defines 4 independent Wi-Fi networks (working on different channels).
39// Each network contains one access point and one station. Each station
40// continuously transmits data packets to its respective AP.
41//
42// Network topology (numbers in parentheses are channel numbers):
43//
44// Network A (36) Network B (40) Network C (44) Network D (48)
45// * * * * * * * *
46// | | | | | | | |
47// AP A STA A AP B STA B AP C STA C AP D STA D
48//
49// The aggregation parameters are configured differently on the 4 stations:
50// - station A uses default aggregation parameter values (A-MSDU disabled, A-MPDU enabled with
51// maximum size of 65 kB);
52// - station B doesn't use aggregation (both A-MPDU and A-MSDU are disabled);
53// - station C enables A-MSDU (with maximum size of 8 kB) but disables A-MPDU;
54// - station D uses two-level aggregation (A-MPDU with maximum size of 32 kB and A-MSDU with maximum
55// size of 4 kB).
56//
57// Packets in this simulation belong to BestEffort Access Class (AC_BE).
58//
59// The user can select the distance between the stations and the APs and can enable/disable the
60// RTS/CTS mechanism. Example: ./ns3 run "wifi-aggregation --distance=10 --enableRts=0
61// --simulationTime=20"
62//
63// The output prints the throughput measured for the 4 cases/networks described above. When default
64// aggregation parameters are enabled, the maximum A-MPDU size is 65 kB and the throughput is
65// maximal. When aggregation is disabled, the throughput is about the half of the physical bitrate.
66// When only A-MSDU is enabled, the throughput is increased but is not maximal, since the maximum
67// A-MSDU size is limited to 7935 bytes (whereas the maximum A-MPDU size is limited to 65535 bytes).
68// When A-MSDU and A-MPDU are both enabled (= two-level aggregation), the throughput is slightly
69// smaller than the first scenario since we set a smaller maximum A-MPDU size.
70//
71// When the distance is increased, the frame error rate gets higher, and the output shows how it
72// affects the throughput for the 4 networks. Even through A-MSDU has less overheads than A-MPDU,
73// A-MSDU is less robust against transmission errors than A-MPDU. When the distance is augmented,
74// the throughput for the third scenario is more affected than the throughput obtained in other
75// networks.
76
77using namespace ns3;
78
79NS_LOG_COMPONENT_DEFINE("SimpleMpduAggregation");
80
81int
82main(int argc, char* argv[])
83{
84 uint32_t payloadSize = 1472; // bytes
85 double simulationTime = 10; // seconds
86 double distance = 5; // meters
87 bool enableRts = 0;
88 bool enablePcap = 0;
89 bool verifyResults = 0; // used for regression
90
91 CommandLine cmd(__FILE__);
92 cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize);
93 cmd.AddValue("enableRts", "Enable or disable RTS/CTS", enableRts);
94 cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime);
95 cmd.AddValue("distance",
96 "Distance in meters between the station and the access point",
97 distance);
98 cmd.AddValue("enablePcap", "Enable/disable pcap file generation", enablePcap);
99 cmd.AddValue("verifyResults",
100 "Enable/disable results verification at the end of the simulation",
101 verifyResults);
102 cmd.Parse(argc, argv);
103
104 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",
105 enableRts ? StringValue("0") : StringValue("999999"));
106
108 wifiStaNodes.Create(4);
109 NodeContainer wifiApNodes;
110 wifiApNodes.Create(4);
111
114 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
115 phy.SetChannel(channel.Create());
116
118 wifi.SetStandard(WIFI_STANDARD_80211n);
119 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
120 "DataMode",
121 StringValue("HtMcs7"),
122 "ControlMode",
123 StringValue("HtMcs0"));
125
126 NetDeviceContainer staDeviceA;
127 NetDeviceContainer staDeviceB;
128 NetDeviceContainer staDeviceC;
129 NetDeviceContainer staDeviceD;
130 NetDeviceContainer apDeviceA;
131 NetDeviceContainer apDeviceB;
132 NetDeviceContainer apDeviceC;
133 NetDeviceContainer apDeviceD;
134 Ssid ssid;
135
136 // Network A
137 ssid = Ssid("network-A");
138 phy.Set("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
139 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
140 staDeviceA = wifi.Install(phy, mac, wifiStaNodes.Get(0));
141
142 mac.SetType("ns3::ApWifiMac",
143 "Ssid",
144 SsidValue(ssid),
145 "EnableBeaconJitter",
146 BooleanValue(false));
147 apDeviceA = wifi.Install(phy, mac, wifiApNodes.Get(0));
148
149 // Network B
150 ssid = Ssid("network-B");
151 phy.Set("ChannelSettings", StringValue("{40, 0, BAND_5GHZ, 0}"));
152 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
153
154 staDeviceB = wifi.Install(phy, mac, wifiStaNodes.Get(1));
155
156 // Disable A-MPDU
157 Ptr<NetDevice> dev = wifiStaNodes.Get(1)->GetDevice(0);
158 Ptr<WifiNetDevice> wifi_dev = DynamicCast<WifiNetDevice>(dev);
159 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(0));
160
161 mac.SetType("ns3::ApWifiMac",
162 "Ssid",
163 SsidValue(ssid),
164 "EnableBeaconJitter",
165 BooleanValue(false));
166 apDeviceB = wifi.Install(phy, mac, wifiApNodes.Get(1));
167
168 // Disable A-MPDU
169 dev = wifiApNodes.Get(1)->GetDevice(0);
170 wifi_dev = DynamicCast<WifiNetDevice>(dev);
171 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(0));
172
173 // Network C
174 ssid = Ssid("network-C");
175 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
176 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
177
178 staDeviceC = wifi.Install(phy, mac, wifiStaNodes.Get(2));
179
180 // Disable A-MPDU and enable A-MSDU with the highest maximum size allowed by the standard (7935
181 // bytes)
182 dev = wifiStaNodes.Get(2)->GetDevice(0);
183 wifi_dev = DynamicCast<WifiNetDevice>(dev);
184 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(0));
185 wifi_dev->GetMac()->SetAttribute("BE_MaxAmsduSize", UintegerValue(7935));
186
187 mac.SetType("ns3::ApWifiMac",
188 "Ssid",
189 SsidValue(ssid),
190 "EnableBeaconJitter",
191 BooleanValue(false));
192 apDeviceC = wifi.Install(phy, mac, wifiApNodes.Get(2));
193
194 // Disable A-MPDU and enable A-MSDU with the highest maximum size allowed by the standard (7935
195 // bytes)
196 dev = wifiApNodes.Get(2)->GetDevice(0);
197 wifi_dev = DynamicCast<WifiNetDevice>(dev);
198 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(0));
199 wifi_dev->GetMac()->SetAttribute("BE_MaxAmsduSize", UintegerValue(7935));
200
201 // Network D
202 ssid = Ssid("network-D");
203 phy.Set("ChannelSettings", StringValue("{48, 0, BAND_5GHZ, 0}"));
204 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
205
206 staDeviceD = wifi.Install(phy, mac, wifiStaNodes.Get(3));
207
208 // Enable A-MPDU with a smaller size than the default one and
209 // enable A-MSDU with the smallest maximum size allowed by the standard (3839 bytes)
210 dev = wifiStaNodes.Get(3)->GetDevice(0);
211 wifi_dev = DynamicCast<WifiNetDevice>(dev);
212 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(32768));
213 wifi_dev->GetMac()->SetAttribute("BE_MaxAmsduSize", UintegerValue(3839));
214
215 mac.SetType("ns3::ApWifiMac",
216 "Ssid",
217 SsidValue(ssid),
218 "EnableBeaconJitter",
219 BooleanValue(false));
220 apDeviceD = wifi.Install(phy, mac, wifiApNodes.Get(3));
221
222 // Enable A-MPDU with a smaller size than the default one and
223 // enable A-MSDU with the smallest maximum size allowed by the standard (3839 bytes)
224 dev = wifiApNodes.Get(3)->GetDevice(0);
225 wifi_dev = DynamicCast<WifiNetDevice>(dev);
226 wifi_dev->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(32768));
227 wifi_dev->GetMac()->SetAttribute("BE_MaxAmsduSize", UintegerValue(3839));
228
229 // Setting mobility model
231 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
232 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
233
234 // Set position for APs
235 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
236 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
237 positionAlloc->Add(Vector(20.0, 0.0, 0.0));
238 positionAlloc->Add(Vector(30.0, 0.0, 0.0));
239 // Set position for STAs
240 positionAlloc->Add(Vector(distance, 0.0, 0.0));
241 positionAlloc->Add(Vector(10 + distance, 0.0, 0.0));
242 positionAlloc->Add(Vector(20 + distance, 0.0, 0.0));
243 positionAlloc->Add(Vector(30 + distance, 0.0, 0.0));
244
245 mobility.SetPositionAllocator(positionAlloc);
246 mobility.Install(wifiApNodes);
247 mobility.Install(wifiStaNodes);
248
249 // Internet stack
251 stack.Install(wifiApNodes);
252 stack.Install(wifiStaNodes);
253
255 address.SetBase("192.168.1.0", "255.255.255.0");
256 Ipv4InterfaceContainer StaInterfaceA;
257 StaInterfaceA = address.Assign(staDeviceA);
258 Ipv4InterfaceContainer ApInterfaceA;
259 ApInterfaceA = address.Assign(apDeviceA);
260
261 address.SetBase("192.168.2.0", "255.255.255.0");
262 Ipv4InterfaceContainer StaInterfaceB;
263 StaInterfaceB = address.Assign(staDeviceB);
264 Ipv4InterfaceContainer ApInterfaceB;
265 ApInterfaceB = address.Assign(apDeviceB);
266
267 address.SetBase("192.168.3.0", "255.255.255.0");
268 Ipv4InterfaceContainer StaInterfaceC;
269 StaInterfaceC = address.Assign(staDeviceC);
270 Ipv4InterfaceContainer ApInterfaceC;
271 ApInterfaceC = address.Assign(apDeviceC);
272
273 address.SetBase("192.168.4.0", "255.255.255.0");
274 Ipv4InterfaceContainer StaInterfaceD;
275 StaInterfaceD = address.Assign(staDeviceD);
276 Ipv4InterfaceContainer ApInterfaceD;
277 ApInterfaceD = address.Assign(apDeviceD);
278
279 // Setting applications
280 uint16_t port = 9;
281 UdpServerHelper serverA(port);
282 ApplicationContainer serverAppA = serverA.Install(wifiStaNodes.Get(0));
283 serverAppA.Start(Seconds(0.0));
284 serverAppA.Stop(Seconds(simulationTime + 1));
285
286 UdpClientHelper clientA(StaInterfaceA.GetAddress(0), port);
287 clientA.SetAttribute("MaxPackets", UintegerValue(4294967295U));
288 clientA.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
289 clientA.SetAttribute("PacketSize", UintegerValue(payloadSize));
290
291 ApplicationContainer clientAppA = clientA.Install(wifiApNodes.Get(0));
292 clientAppA.Start(Seconds(1.0));
293 clientAppA.Stop(Seconds(simulationTime + 1));
294
295 UdpServerHelper serverB(port);
296 ApplicationContainer serverAppB = serverB.Install(wifiStaNodes.Get(1));
297 serverAppB.Start(Seconds(0.0));
298 serverAppB.Stop(Seconds(simulationTime + 1));
299
300 UdpClientHelper clientB(StaInterfaceB.GetAddress(0), port);
301 clientB.SetAttribute("MaxPackets", UintegerValue(4294967295U));
302 clientB.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
303 clientB.SetAttribute("PacketSize", UintegerValue(payloadSize));
304
305 ApplicationContainer clientAppB = clientB.Install(wifiApNodes.Get(1));
306 clientAppB.Start(Seconds(1.0));
307 clientAppB.Stop(Seconds(simulationTime + 1));
308
309 UdpServerHelper serverC(port);
310 ApplicationContainer serverAppC = serverC.Install(wifiStaNodes.Get(2));
311 serverAppC.Start(Seconds(0.0));
312 serverAppC.Stop(Seconds(simulationTime + 1));
313
314 UdpClientHelper clientC(StaInterfaceC.GetAddress(0), port);
315 clientC.SetAttribute("MaxPackets", UintegerValue(4294967295U));
316 clientC.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
317 clientC.SetAttribute("PacketSize", UintegerValue(payloadSize));
318
319 ApplicationContainer clientAppC = clientC.Install(wifiApNodes.Get(2));
320 clientAppC.Start(Seconds(1.0));
321 clientAppC.Stop(Seconds(simulationTime + 1));
322
323 UdpServerHelper serverD(port);
324 ApplicationContainer serverAppD = serverD.Install(wifiStaNodes.Get(3));
325 serverAppD.Start(Seconds(0.0));
326 serverAppD.Stop(Seconds(simulationTime + 1));
327
328 UdpClientHelper clientD(StaInterfaceD.GetAddress(0), port);
329 clientD.SetAttribute("MaxPackets", UintegerValue(4294967295U));
330 clientD.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
331 clientD.SetAttribute("PacketSize", UintegerValue(payloadSize));
332
333 ApplicationContainer clientAppD = clientD.Install(wifiApNodes.Get(3));
334 clientAppD.Start(Seconds(1.0));
335 clientAppD.Stop(Seconds(simulationTime + 1));
336
337 if (enablePcap)
338 {
339 phy.EnablePcap("AP_A", apDeviceA.Get(0));
340 phy.EnablePcap("STA_A", staDeviceA.Get(0));
341 phy.EnablePcap("AP_B", apDeviceB.Get(0));
342 phy.EnablePcap("STA_B", staDeviceB.Get(0));
343 phy.EnablePcap("AP_C", apDeviceC.Get(0));
344 phy.EnablePcap("STA_C", staDeviceC.Get(0));
345 phy.EnablePcap("AP_D", apDeviceD.Get(0));
346 phy.EnablePcap("STA_D", staDeviceD.Get(0));
347 }
348
349 Simulator::Stop(Seconds(simulationTime + 1));
351
352 // Show results
353 uint64_t totalPacketsThroughA = DynamicCast<UdpServer>(serverAppA.Get(0))->GetReceived();
354 uint64_t totalPacketsThroughB = DynamicCast<UdpServer>(serverAppB.Get(0))->GetReceived();
355 uint64_t totalPacketsThroughC = DynamicCast<UdpServer>(serverAppC.Get(0))->GetReceived();
356 uint64_t totalPacketsThroughD = DynamicCast<UdpServer>(serverAppD.Get(0))->GetReceived();
357
359
360 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
361 std::cout << "Throughput with default configuration (A-MPDU aggregation enabled, 65kB): "
362 << throughput << " Mbit/s" << '\n';
363 if (verifyResults && (throughput < 59.0 || throughput > 60.0))
364 {
365 NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
366 exit(1);
367 }
368
369 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
370 std::cout << "Throughput with aggregation disabled: " << throughput << " Mbit/s" << '\n';
371 if (verifyResults && (throughput < 30 || throughput > 31))
372 {
373 NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
374 exit(1);
375 }
376
377 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
378 std::cout << "Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput
379 << " Mbit/s" << '\n';
380 if (verifyResults && (throughput < 51 || throughput > 52))
381 {
382 NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
383 exit(1);
384 }
385
386 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
387 std::cout << "Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput
388 << " Mbit/s" << '\n';
389 if (verifyResults && (throughput < 58 || throughput > 59))
390 {
391 NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
392 exit(1);
393 }
394
395 return 0;
396}
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.
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
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
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.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:152
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Hold variables of type string.
Definition: string.h:56
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1423
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.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:178
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.
uint16_t port
Definition: dsdv-manet.cc:44
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#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:1336
@ WIFI_STANDARD_80211n
ns address
Definition: first.py:40
ns stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33
ns wifi
Definition: third.py:88
ns ssid
Definition: third.py:86
ns mac
Definition: third.py:85
ns channel
Definition: third.py:81
ns mobility
Definition: third.py:96
ns wifiStaNodes
Definition: third.py:77
ns phy
Definition: third.py:82