A Discrete-Event Network Simulator
API
wifi-aggregation.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Sébastien Deronne
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: Sébastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ns3/core-module.h"
22 #include "ns3/applications-module.h"
23 #include "ns3/wifi-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/internet-module.h"
26 
27 // This is an example that illustrates how 802.11n aggregation is configured.
28 // It defines 4 independant Wi-Fi networks (working on different channels).
29 // Each network contains one access point and one station. Each station
30 // continously 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 maximum size of 65 kB);
41 // - station B doesn't use aggregation (both A-MPDU and A-MSDU are disabled);
42 // - station C enables A-MSDU (with maximum size of 8 kB) but disables A-MPDU;
43 // - station D uses two-level aggregation (A-MPDU with maximum size of 32 kB and A-MSDU with maximum size of 4 kB).
44 //
45 // Packets in this simulation aren't marked with a QosTag so they
46 // are considered belonging to BestEffort Access Class (AC_BE).
47 //
48 // The user can select the distance between the stations and the APs and can enable/disable the RTS/CTS mechanism.
49 // Example: ./waf --run "wifi-aggregation --distance=10 --enableRts=0 --simulationTime=20"
50 //
51 // The output prints the throughput measured for the 4 cases/networks decribed above. When default aggregation parameters are enabled, the
52 // maximum A-MPDU size is 65 kB and the throughput is maximal. When aggregation is disabled, the throughput is about the half of the
53 // physical bitrate as in legacy wifi networks. When only A-MSDU is enabled, the throughput is increased but is not maximal, since the maximum
54 // A-MSDU size is limited to 7935 bytes (whereas the maximum A-MPDU size is limited to 65535 bytes). When A-MSDU and A-MPDU are both enabled
55 // (= two-level aggregation), the throughput is slightly smaller than the first scenario since we set a smaller maximum A-MPDU size.
56 //
57 // When the distance is increased, the frame error rate gets higher, and the output shows how it affects the throughput for the 4 networks.
58 // Even through A-MSDU has less overheads than A-MPDU, A-MSDU is less robust against transmission errors than A-MPDU. When the distance is
59 // augmented, the throughput for the third scenario is more affected than the throughput obtained in other networks.
60 
61 using namespace ns3;
62 
63 NS_LOG_COMPONENT_DEFINE ("SimpleMpduAggregation");
64 
65 int main (int argc, char *argv[])
66 {
67  uint32_t payloadSize = 1472; //bytes
68  uint64_t simulationTime = 10; //seconds
69  double distance = 5; //meters
70  bool enableRts = 0;
71  bool enablePcap = 0;
72  bool verifyResults = 0; //used for regression
73 
75  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
76  cmd.AddValue ("enableRts", "Enable or disable RTS/CTS", enableRts);
77  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
78  cmd.AddValue ("distance", "Distance in meters between the station and the access point", distance);
79  cmd.AddValue ("enablePcap", "Enable/disable pcap file generation", enablePcap);
80  cmd.AddValue ("verifyResults", "Enable/disable results verification at the end of the simulation", verifyResults);
81  cmd.Parse (argc, argv);
82 
83  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", enableRts ? StringValue ("0") : StringValue ("999999"));
84 
86  wifiStaNodes.Create (4);
87  NodeContainer wifiApNodes;
88  wifiApNodes.Create (4);
89 
93  phy.SetChannel (channel.Create ());
94 
97  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
99 
100  NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
101  Ssid ssid;
102 
103  //Network A
104  ssid = Ssid ("network-A");
105  phy.Set ("ChannelNumber", UintegerValue (36));
106  mac.SetType ("ns3::StaWifiMac",
107  "Ssid", SsidValue (ssid));
108  staDeviceA = wifi.Install (phy, mac, wifiStaNodes.Get (0));
109 
110  mac.SetType ("ns3::ApWifiMac",
111  "Ssid", SsidValue (ssid),
112  "EnableBeaconJitter", BooleanValue (false));
113  apDeviceA = wifi.Install (phy, mac, wifiApNodes.Get (0));
114 
115  //Network B
116  ssid = Ssid ("network-B");
117  phy.Set ("ChannelNumber", UintegerValue (40));
118  mac.SetType ("ns3::StaWifiMac",
119  "Ssid", SsidValue (ssid),
120  "BE_MaxAmpduSize", UintegerValue (0)); //Disable A-MPDU
121 
122  staDeviceB = wifi.Install (phy, mac, wifiStaNodes.Get (1));
123 
124  mac.SetType ("ns3::ApWifiMac",
125  "Ssid", SsidValue (ssid),
126  "EnableBeaconJitter", BooleanValue (false));
127  apDeviceB = wifi.Install (phy, mac, wifiApNodes.Get (1));
128 
129  //Network C
130  ssid = Ssid ("network-C");
131  phy.Set ("ChannelNumber", UintegerValue (44));
132  mac.SetType ("ns3::StaWifiMac",
133  "Ssid", SsidValue (ssid),
134  "BE_MaxAmpduSize", UintegerValue (0), //Disable A-MPDU
135  "BE_MaxAmsduSize", UintegerValue (7935)); //Enable A-MSDU with the highest maximum size allowed by the standard (7935 bytes)
136 
137  staDeviceC = wifi.Install (phy, mac, wifiStaNodes.Get (2));
138 
139  mac.SetType ("ns3::ApWifiMac",
140  "Ssid", SsidValue (ssid),
141  "EnableBeaconJitter", BooleanValue (false));
142  apDeviceC = wifi.Install (phy, mac, wifiApNodes.Get (2));
143 
144  //Network D
145  ssid = Ssid ("network-D");
146  phy.Set ("ChannelNumber", UintegerValue (48));
147  mac.SetType ("ns3::StaWifiMac",
148  "Ssid", SsidValue (ssid),
149  "BE_MaxAmpduSize", UintegerValue (32768), //Enable A-MPDU with a smaller size than the default one
150  "BE_MaxAmsduSize", UintegerValue (3839)); //Enable A-MSDU with the smallest maximum size allowed by the standard (3839 bytes)
151 
152  staDeviceD = wifi.Install (phy, mac, wifiStaNodes.Get (3));
153 
154  mac.SetType ("ns3::ApWifiMac",
155  "Ssid", SsidValue (ssid),
156  "EnableBeaconJitter", BooleanValue (false));
157  apDeviceD = wifi.Install (phy, mac, wifiApNodes.Get (3));
158 
159  /* Setting mobility model */
161  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
162  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
163 
164  //Set position for APs
165  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
166  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
167  positionAlloc->Add (Vector (20.0, 0.0, 0.0));
168  positionAlloc->Add (Vector (30.0, 0.0, 0.0));
169  //Set position for STAs
170  positionAlloc->Add (Vector (distance, 0.0, 0.0));
171  positionAlloc->Add (Vector (10 + distance, 0.0, 0.0));
172  positionAlloc->Add (Vector (20 + distance, 0.0, 0.0));
173  positionAlloc->Add (Vector (30 + distance, 0.0, 0.0));
174 
175  mobility.SetPositionAllocator (positionAlloc);
176  mobility.Install (wifiApNodes);
177  mobility.Install (wifiStaNodes);
178 
179  /* Internet stack */
181  stack.Install (wifiApNodes);
182  stack.Install (wifiStaNodes);
183 
185  address.SetBase ("192.168.1.0", "255.255.255.0");
186  Ipv4InterfaceContainer StaInterfaceA;
187  StaInterfaceA = address.Assign (staDeviceA);
188  Ipv4InterfaceContainer ApInterfaceA;
189  ApInterfaceA = address.Assign (apDeviceA);
190 
191  address.SetBase ("192.168.2.0", "255.255.255.0");
192  Ipv4InterfaceContainer StaInterfaceB;
193  StaInterfaceB = address.Assign (staDeviceB);
194  Ipv4InterfaceContainer ApInterfaceB;
195  ApInterfaceB = address.Assign (apDeviceB);
196 
197  address.SetBase ("192.168.3.0", "255.255.255.0");
198  Ipv4InterfaceContainer StaInterfaceC;
199  StaInterfaceC = address.Assign (staDeviceC);
200  Ipv4InterfaceContainer ApInterfaceC;
201  ApInterfaceC = address.Assign (apDeviceC);
202 
203  address.SetBase ("192.168.4.0", "255.255.255.0");
204  Ipv4InterfaceContainer StaInterfaceD;
205  StaInterfaceD = address.Assign (staDeviceD);
206  Ipv4InterfaceContainer ApInterfaceD;
207  ApInterfaceD = address.Assign (apDeviceD);
208 
209  /* Setting applications */
210  uint16_t port = 9;
211  UdpServerHelper serverA (port);
212  ApplicationContainer serverAppA = serverA.Install (wifiStaNodes.Get (0));
213  serverAppA.Start (Seconds (0.0));
214  serverAppA.Stop (Seconds (simulationTime + 1));
215 
216  UdpClientHelper clientA (StaInterfaceA.GetAddress (0), port);
217  clientA.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
218  clientA.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
219  clientA.SetAttribute ("PacketSize", UintegerValue (payloadSize));
220 
221  ApplicationContainer clientAppA = clientA.Install (wifiApNodes.Get (0));
222  clientAppA.Start (Seconds (1.0));
223  clientAppA.Stop (Seconds (simulationTime + 1));
224 
225  UdpServerHelper serverB (port);
226  ApplicationContainer serverAppB = serverB.Install (wifiStaNodes.Get (1));
227  serverAppB.Start (Seconds (0.0));
228  serverAppB.Stop (Seconds (simulationTime + 1));
229 
230  UdpClientHelper clientB (StaInterfaceB.GetAddress (0), port);
231  clientB.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
232  clientB.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
233  clientB.SetAttribute ("PacketSize", UintegerValue (payloadSize));
234 
235  ApplicationContainer clientAppB = clientB.Install (wifiApNodes.Get (1));
236  clientAppB.Start (Seconds (1.0));
237  clientAppB.Stop (Seconds (simulationTime + 1));
238 
239  UdpServerHelper serverC (port);
240  ApplicationContainer serverAppC = serverC.Install (wifiStaNodes.Get (2));
241  serverAppC.Start (Seconds (0.0));
242  serverAppC.Stop (Seconds (simulationTime + 1));
243 
244  UdpClientHelper clientC (StaInterfaceC.GetAddress (0), port);
245  clientC.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
246  clientC.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
247  clientC.SetAttribute ("PacketSize", UintegerValue (payloadSize));
248 
249  ApplicationContainer clientAppC = clientC.Install (wifiApNodes.Get (2));
250  clientAppC.Start (Seconds (1.0));
251  clientAppC.Stop (Seconds (simulationTime + 1));
252 
253  UdpServerHelper serverD (port);
254  ApplicationContainer serverAppD = serverD.Install (wifiStaNodes.Get (3));
255  serverAppD.Start (Seconds (0.0));
256  serverAppD.Stop (Seconds (simulationTime + 1));
257 
258  UdpClientHelper clientD (StaInterfaceD.GetAddress (0), port);
259  clientD.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
260  clientD.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
261  clientD.SetAttribute ("PacketSize", UintegerValue (payloadSize));
262 
263  ApplicationContainer clientAppD = clientD.Install (wifiApNodes.Get (3));
264  clientAppD.Start (Seconds (1.0));
265  clientAppD.Stop (Seconds (simulationTime + 1));
266 
267  if (enablePcap)
268  {
269  phy.EnablePcap ("AP_A", apDeviceA.Get (0));
270  phy.EnablePcap ("STA_A", staDeviceA.Get (0));
271  phy.EnablePcap ("AP_B", apDeviceB.Get (0));
272  phy.EnablePcap ("STA_B", staDeviceB.Get (0));
273  phy.EnablePcap ("AP_C", apDeviceC.Get (0));
274  phy.EnablePcap ("STA_C", staDeviceC.Get (0));
275  phy.EnablePcap ("AP_D", apDeviceD.Get (0));
276  phy.EnablePcap ("STA_D", staDeviceD.Get (0));
277  }
278 
279  Simulator::Stop (Seconds (simulationTime + 1));
280  Simulator::Run ();
282 
283  /* Show results */
284  uint64_t totalPacketsThrough = DynamicCast<UdpServer> (serverAppA.Get (0))->GetReceived ();
285  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
286  std::cout << "Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput << " Mbit/s" << '\n';
287  if (verifyResults && (throughput < 59 || throughput > 60))
288  {
289  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
290  exit (1);
291  }
292 
293  totalPacketsThrough = DynamicCast<UdpServer> (serverAppB.Get (0))->GetReceived ();
294  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
295  std::cout << "Throughput with aggregation disabled: " << throughput << " Mbit/s" << '\n';
296  if (verifyResults && (throughput < 30 || throughput > 30.5))
297  {
298  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
299  exit (1);
300  }
301 
302  totalPacketsThrough = DynamicCast<UdpServer> (serverAppC.Get (0))->GetReceived ();
303  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
304  std::cout << "Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput << " Mbit/s" << '\n';
305  if (verifyResults && (throughput < 51 || throughput > 52))
306  {
307  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
308  exit (1);
309  }
310 
311  totalPacketsThrough = DynamicCast<UdpServer> (serverAppD.Get (0))->GetReceived ();
312  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
313  std::cout << "Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput << " Mbit/s" << '\n';
314  if (verifyResults && (throughput < 58 || throughput > 59))
315  {
316  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
317  exit (1);
318  }
319 
320  return 0;
321 }
tuple channel
Definition: third.py:85
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:132
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:36
HT PHY for the 5 GHz band (clause 20)
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:719
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
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.
bool enablePcap
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
aggregate IP/TCP/UDP functionality to existing Nodes.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
tuple cmd
Definition: second.py:35
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:566
uint16_t port
Definition: dsdv-manet.cc:44
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
tuple phy
Definition: third.py:86
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:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:742
Create a server application which waits for input UDP packets and uses the information carried into t...
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
tuple mac
Definition: third.py:92
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:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
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.
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
tuple ssid
Definition: third.py:93
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
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...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
void Add(Vector v)
Add a position to the list of positions.
void Parse(int argc, char *argv[])
Parse the program arguments.
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:253
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Include Radiotap link layer information.
Definition: wifi-helper.h:111
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
tuple wifiStaNodes
Definition: third.py:81