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