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/network-module.h"
23 #include "ns3/applications-module.h"
24 #include "ns3/wifi-module.h"
25 #include "ns3/mobility-module.h"
26 #include "ns3/ipv4-global-routing-helper.h"
27 #include "ns3/internet-module.h"
28 
29 // This is an example that illustrates how 802.11n aggregation is configured.
30 // It defines 4 independant Wi-Fi networks (working on different channels).
31 // Each network contains one access point and one station. Each station
32 // continously transmits data packets to its respective AP.
33 //
34 // Network topology (numbers in parentheses are channel numbers):
35 //
36 // Network A (36) Network B (40) Network C (44) Network D (48)
37 // * * * * * * * *
38 // | | | | | | | |
39 // AP A STA A AP B STA B AP C STA C AP D STA D
40 //
41 // The aggregation parameters are configured differently on the 4 stations:
42 // - station A uses default aggregation parameter values (A-MSDU disabled, A-MPDU enabled with maximum size of 65 kB);
43 // - station B doesn't use aggregation (both A-MPDU and A-MSDU are disabled);
44 // - station C enables A-MSDU (with maximum size of 8 kB) but disables A-MPDU;
45 // - station C uses two-level aggregation (A-MPDU with maximum size of 32 kB and A-MSDU with maximum size of 4 kB).
46 //
47 // Packets in this simulation aren't marked with a QosTag so they
48 // are considered belonging to BestEffort Access Class (AC_BE).
49 //
50 // The user can select the distance between the stations and the APs and can enable/disable the RTS/CTS mechanism.
51 // Example: ./waf --run "wifi-aggregation --distance=10 --enableRts=0 --simulationTime=20"
52 //
53 // The output prints the throughput measured for the 4 cases/networks decribed above. When default aggregation parameters are enabled, the
54 // maximum A-MPDU size is 65 kB and the throughput is maximal. When aggregation is disabled, the thoughput is about the half of the
55 // physical bitrate as in legacy wifi networks. When only A-MSDU is enabled, the throughput is increased but is not maximal, since the maximum
56 // 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
57 // (= two-level aggregation), the throughput is slightly smaller than the first scenario since we set a smaller maximum A-MPDU size.
58 //
59 // When the distance is increased, the frame error rate gets higher, and the output shows how it affects the throughput for the 4 networks.
60 // 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
61 // augmented, the throughput for the third scenario is more affected than the throughput obtained in other networks.
62 
63 using namespace ns3;
64 
65 NS_LOG_COMPONENT_DEFINE ("SimpleMpduAggregation");
66 
67 int main (int argc, char *argv[])
68 {
69  uint32_t payloadSize = 1472; //bytes
70  uint64_t simulationTime = 10; //seconds
71  double distance = 5; //meters
72  bool enablePcap = 0;
73 
75  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
76  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
77  cmd.AddValue ("distance", "Distance in meters between the station and the access point", distance);
78  cmd.AddValue ("enablePcap", "Enable/disable pcap file generation", enablePcap);
79  cmd.Parse (argc, argv);
80 
81  NodeContainer wifiStaNode;
82  wifiStaNode.Create (4);
84  wifiApNode.Create (4);
85 
89  phy.SetChannel (channel.Create ());
90 
93  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
95 
96  NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
97  Ssid ssid;
98 
99  //Network A
100  ssid = Ssid ("network-A");
101  phy.Set ("ChannelNumber", UintegerValue(36));
102  mac.SetType ("ns3::StaWifiMac",
103  "Ssid", SsidValue (ssid));
104  staDeviceA = wifi.Install (phy, mac, wifiStaNode.Get(0));
105 
106  mac.SetType ("ns3::ApWifiMac",
107  "Ssid", SsidValue (ssid),
108  "BeaconGeneration", BooleanValue (true));
109  apDeviceA = wifi.Install (phy, mac, wifiApNode.Get(0));
110 
111  //Network B
112  ssid = Ssid ("network-B");
113  phy.Set ("ChannelNumber", UintegerValue(40));
114  mac.SetType ("ns3::StaWifiMac",
115  "Ssid", SsidValue (ssid),
116  "BE_MaxAmpduSize", UintegerValue (0)); //Disable A-MPDU
117 
118  staDeviceB = wifi.Install (phy, mac, wifiStaNode.Get(1));
119 
120  mac.SetType ("ns3::ApWifiMac",
121  "Ssid", SsidValue (ssid),
122  "BeaconGeneration", BooleanValue (true));
123  apDeviceB = wifi.Install (phy, mac, wifiApNode.Get(1));
124 
125  //Network C
126  ssid = Ssid ("network-C");
127  phy.Set ("ChannelNumber", UintegerValue(44));
128  mac.SetType ("ns3::StaWifiMac",
129  "Ssid", SsidValue (ssid),
130  "BE_MaxAmpduSize", UintegerValue (0), //Disable A-MPDU
131  "BE_MaxAmsduSize", UintegerValue (7935)); //Enable A-MSDU with the highest maximum size allowed by the standard (7935 bytes)
132 
133  staDeviceC = wifi.Install (phy, mac, wifiStaNode.Get(2));
134 
135  mac.SetType ("ns3::ApWifiMac",
136  "Ssid", SsidValue (ssid),
137  "BeaconGeneration", BooleanValue (true));
138  apDeviceC = wifi.Install (phy, mac, wifiApNode.Get(2));
139 
140  //Network D
141  ssid = Ssid ("network-D");
142  phy.Set ("ChannelNumber", UintegerValue(48));
143  mac.SetType ("ns3::StaWifiMac",
144  "Ssid", SsidValue (ssid),
145  "BE_MaxAmpduSize", UintegerValue (32768), //Enable A-MPDU with a smaller size than the default one
146  "BE_MaxAmsduSize", UintegerValue (3839)); //Enable A-MSDU with the smallest maximum size allowed by the standard (3839 bytes)
147 
148  staDeviceD = wifi.Install (phy, mac, wifiStaNode.Get(3));
149 
150  mac.SetType ("ns3::ApWifiMac",
151  "Ssid", SsidValue (ssid),
152  "BeaconGeneration", BooleanValue (true));
153  apDeviceD = wifi.Install (phy, mac, wifiApNode.Get(3));
154 
155  /* Setting mobility model */
157  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
158  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
159 
160  //Set position for APs
161  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
162  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
163  positionAlloc->Add (Vector (20.0, 0.0, 0.0));
164  positionAlloc->Add (Vector (30.0, 0.0, 0.0));
165  //Set position for STAs
166  positionAlloc->Add (Vector (distance, 0.0, 0.0));
167  positionAlloc->Add (Vector (10 + distance, 0.0, 0.0));
168  positionAlloc->Add (Vector (20 + distance, 0.0, 0.0));
169  positionAlloc->Add (Vector (30 + distance, 0.0, 0.0));
170  //Remark: while we set these positions 10 meters apart, the networks do not interact
171  //and the only variable that affects transmission performance is the distance.
172 
173  mobility.SetPositionAllocator (positionAlloc);
174  mobility.Install (wifiApNode);
175  mobility.Install (wifiStaNode);
176 
177  /* Internet stack */
179  stack.Install (wifiApNode);
180  stack.Install (wifiStaNode);
181 
183 
184  address.SetBase ("192.168.1.0", "255.255.255.0");
185  Ipv4InterfaceContainer StaInterfaceA;
186  StaInterfaceA = address.Assign (staDeviceA);
187  Ipv4InterfaceContainer ApInterfaceA;
188  ApInterfaceA = address.Assign (apDeviceA);
189 
190  address.SetBase ("192.168.2.0", "255.255.255.0");
191  Ipv4InterfaceContainer StaInterfaceB;
192  StaInterfaceB = address.Assign (staDeviceB);
193  Ipv4InterfaceContainer ApInterfaceB;
194  ApInterfaceB = address.Assign (apDeviceB);
195 
196  address.SetBase ("192.168.3.0", "255.255.255.0");
197  Ipv4InterfaceContainer StaInterfaceC;
198  StaInterfaceC = address.Assign (staDeviceC);
199  Ipv4InterfaceContainer ApInterfaceC;
200  ApInterfaceC = address.Assign (apDeviceC);
201 
202  address.SetBase ("192.168.4.0", "255.255.255.0");
203  Ipv4InterfaceContainer StaInterfaceD;
204  StaInterfaceD = address.Assign (staDeviceD);
205  Ipv4InterfaceContainer ApInterfaceD;
206  ApInterfaceD = address.Assign (apDeviceD);
207 
208  /* Setting applications */
209  UdpServerHelper myServerA (9);
210  ApplicationContainer serverAppA = myServerA.Install (wifiStaNode.Get (0));
211  serverAppA.Start (Seconds (0.0));
212  serverAppA.Stop (Seconds (simulationTime + 1));
213 
214  UdpClientHelper myClientA (StaInterfaceA.GetAddress (0), 9);
215  myClientA.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
216  myClientA.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
217  myClientA.SetAttribute ("PacketSize", UintegerValue (payloadSize));
218 
219  ApplicationContainer clientAppA = myClientA.Install (wifiApNode.Get (0));
220  clientAppA.Start (Seconds (1.0));
221  clientAppA.Stop (Seconds (simulationTime + 1));
222 
223  UdpServerHelper myServerB (9);
224  ApplicationContainer serverAppB = myServerB.Install (wifiStaNode.Get (1));
225  serverAppB.Start (Seconds (0.0));
226  serverAppB.Stop (Seconds (simulationTime + 1));
227 
228  UdpClientHelper myClientB (StaInterfaceB.GetAddress (0), 9);
229  myClientB.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
230  myClientB.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
231  myClientB.SetAttribute ("PacketSize", UintegerValue (payloadSize));
232 
233  ApplicationContainer clientAppB = myClientB.Install (wifiApNode.Get (1));
234  clientAppB.Start (Seconds (1.0));
235  clientAppB.Stop (Seconds (simulationTime + 1));
236 
237  UdpServerHelper myServerC (9);
238  ApplicationContainer serverAppC = myServerC.Install (wifiStaNode.Get (2));
239  serverAppC.Start (Seconds (0.0));
240  serverAppC.Stop (Seconds (simulationTime + 1));
241 
242  UdpClientHelper myClientC (StaInterfaceC.GetAddress (0), 9);
243  myClientC.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
244  myClientC.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
245  myClientC.SetAttribute ("PacketSize", UintegerValue (payloadSize));
246 
247  ApplicationContainer clientAppC = myClientC.Install (wifiApNode.Get (2));
248  clientAppC.Start (Seconds (1.0));
249  clientAppC.Stop (Seconds (simulationTime + 1));
250 
251  UdpServerHelper myServerD (9);
252  ApplicationContainer serverAppD = myServerD.Install (wifiStaNode.Get (3));
253  serverAppD.Start (Seconds (0.0));
254  serverAppD.Stop (Seconds (simulationTime + 1));
255 
256  UdpClientHelper myClientD (StaInterfaceD.GetAddress (0), 9);
257  myClientD.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
258  myClientD.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
259  myClientD.SetAttribute ("PacketSize", UintegerValue (payloadSize));
260 
261  ApplicationContainer clientAppD = myClientD.Install (wifiApNode.Get (3));
262  clientAppD.Start (Seconds (1.0));
263  clientAppD.Stop (Seconds (simulationTime + 1));
264 
265  if (enablePcap)
266  {
267  phy.EnablePcap ("AP_A", apDeviceA.Get (0));
268  phy.EnablePcap ("STA_A", staDeviceA.Get (0));
269  phy.EnablePcap ("AP_B", apDeviceB.Get (0));
270  phy.EnablePcap ("STA_B", staDeviceB.Get (0));
271  phy.EnablePcap ("AP_C", apDeviceC.Get (0));
272  phy.EnablePcap ("STA_C", staDeviceC.Get (0));
273  phy.EnablePcap ("AP_D", apDeviceD.Get (0));
274  phy.EnablePcap ("STA_D", staDeviceD.Get (0));
275  }
276 
277  Simulator::Stop (Seconds (simulationTime + 1));
278  Simulator::Run ();
280 
281  /* Show results */
282  uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverAppA.Get (0))->GetReceived ();
283  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
284  std::cout << "Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput << " Mbit/s" << '\n';
285 
286  totalPacketsThrough = DynamicCast<UdpServer> (serverAppB.Get (0))->GetReceived ();
287  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
288  std::cout << "Throughput with aggregation disabled: " << throughput << " Mbit/s" << '\n';
289 
290  totalPacketsThrough = DynamicCast<UdpServer> (serverAppC.Get (0))->GetReceived ();
291  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
292  std::cout << "Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput << " Mbit/s" << '\n';
293 
294  totalPacketsThrough = DynamicCast<UdpServer> (serverAppD.Get (0))->GetReceived ();
295  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
296  std::cout << "Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput << " Mbit/s" << '\n';
297 
298  return 0;
299 }
tuple channel
Definition: third.py:85
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:112
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:34
HT OFDM 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:683
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:201
#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:231
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:530
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
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:957
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:706
Create a server application which waits for input UDP packets and uses the information carried into t...
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:165
tuple wifiApNode
Definition: third.py:83
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:38
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:495
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:209
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:895
AttributeValue implementation for Ssid.
Definition: ssid.h:95
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.
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:117
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