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  "ActiveProbing", BooleanValue (false));
105  staDeviceA = wifi.Install (phy, mac, wifiStaNode.Get(0));
106 
107  mac.SetType ("ns3::ApWifiMac",
108  "Ssid", SsidValue (ssid),
109  "BeaconInterval", TimeValue (MicroSeconds (102400)),
110  "BeaconGeneration", BooleanValue (true));
111  apDeviceA = wifi.Install (phy, mac, wifiApNode.Get(0));
112 
113  //Network B
114  ssid = Ssid ("network-B");
115  phy.Set ("ChannelNumber", UintegerValue(40));
116  mac.SetType ("ns3::StaWifiMac",
117  "Ssid", SsidValue (ssid),
118  "ActiveProbing", BooleanValue (false),
119  "BE_MaxAmpduSize", UintegerValue (0)); //Disable A-MPDU
120 
121  staDeviceB = wifi.Install (phy, mac, wifiStaNode.Get(1));
122 
123  mac.SetType ("ns3::ApWifiMac",
124  "Ssid", SsidValue (ssid),
125  "BeaconInterval", TimeValue (MicroSeconds (102400)),
126  "BeaconGeneration", BooleanValue (true));
127  apDeviceB = wifi.Install (phy, mac, wifiApNode.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  "ActiveProbing", BooleanValue (false),
135  "BE_MaxAmpduSize", UintegerValue (0), //Disable A-MPDU
136  "BE_MaxAmsduSize", UintegerValue (7935)); //Enable A-MSDU with the highest maximum size allowed by the standard (7935 bytes)
137 
138  staDeviceC = wifi.Install (phy, mac, wifiStaNode.Get(2));
139 
140  mac.SetType ("ns3::ApWifiMac",
141  "Ssid", SsidValue (ssid),
142  "BeaconInterval", TimeValue (MicroSeconds (102400)),
143  "BeaconGeneration", BooleanValue (true));
144  apDeviceC = wifi.Install (phy, mac, wifiApNode.Get(2));
145 
146  //Network D
147  ssid = Ssid ("network-D");
148  phy.Set ("ChannelNumber", UintegerValue(48));
149  mac.SetType ("ns3::StaWifiMac",
150  "Ssid", SsidValue (ssid),
151  "ActiveProbing", BooleanValue (false),
152  "BE_MaxAmpduSize", UintegerValue (32768), //Enable A-MPDU with a smaller size than the default one
153  "BE_MaxAmsduSize", UintegerValue (3839)); //Enable A-MSDU with the smallest maximum size allowed by the standard (3839 bytes)
154 
155  staDeviceD = wifi.Install (phy, mac, wifiStaNode.Get(3));
156 
157  mac.SetType ("ns3::ApWifiMac",
158  "Ssid", SsidValue (ssid),
159  "BeaconInterval", TimeValue (MicroSeconds (102400)),
160  "BeaconGeneration", BooleanValue (true));
161  apDeviceD = wifi.Install (phy, mac, wifiApNode.Get(3));
162 
163  /* Setting mobility model */
165  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
166  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
167 
168  //Set position for APs
169  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
170  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
171  positionAlloc->Add (Vector (20.0, 0.0, 0.0));
172  positionAlloc->Add (Vector (30.0, 0.0, 0.0));
173  //Set position for STAs
174  positionAlloc->Add (Vector (distance, 0.0, 0.0));
175  positionAlloc->Add (Vector (10 + distance, 0.0, 0.0));
176  positionAlloc->Add (Vector (20 + distance, 0.0, 0.0));
177  positionAlloc->Add (Vector (30 + distance, 0.0, 0.0));
178  //Remark: while we set these positions 10 meters apart, the networks do not interact
179  //and the only variable that affects transmission performance is the distance.
180 
181  mobility.SetPositionAllocator (positionAlloc);
182  mobility.Install (wifiApNode);
183  mobility.Install (wifiStaNode);
184 
185  /* Internet stack */
187  stack.Install (wifiApNode);
188  stack.Install (wifiStaNode);
189 
191 
192  address.SetBase ("192.168.1.0", "255.255.255.0");
193  Ipv4InterfaceContainer StaInterfaceA;
194  StaInterfaceA = address.Assign (staDeviceA);
195  Ipv4InterfaceContainer ApInterfaceA;
196  ApInterfaceA = address.Assign (apDeviceA);
197 
198  address.SetBase ("192.168.2.0", "255.255.255.0");
199  Ipv4InterfaceContainer StaInterfaceB;
200  StaInterfaceB = address.Assign (staDeviceB);
201  Ipv4InterfaceContainer ApInterfaceB;
202  ApInterfaceB = address.Assign (apDeviceB);
203 
204  address.SetBase ("192.168.3.0", "255.255.255.0");
205  Ipv4InterfaceContainer StaInterfaceC;
206  StaInterfaceC = address.Assign (staDeviceC);
207  Ipv4InterfaceContainer ApInterfaceC;
208  ApInterfaceC = address.Assign (apDeviceC);
209 
210  address.SetBase ("192.168.4.0", "255.255.255.0");
211  Ipv4InterfaceContainer StaInterfaceD;
212  StaInterfaceD = address.Assign (staDeviceD);
213  Ipv4InterfaceContainer ApInterfaceD;
214  ApInterfaceD = address.Assign (apDeviceD);
215 
216  /* Setting applications */
217  UdpServerHelper myServerA (9);
218  ApplicationContainer serverAppA = myServerA.Install (wifiStaNode.Get (0));
219  serverAppA.Start (Seconds (0.0));
220  serverAppA.Stop (Seconds (simulationTime + 1));
221 
222  UdpClientHelper myClientA (StaInterfaceA.GetAddress (0), 9);
223  myClientA.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
224  myClientA.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
225  myClientA.SetAttribute ("PacketSize", UintegerValue (payloadSize));
226 
227  ApplicationContainer clientAppA = myClientA.Install (wifiApNode.Get (0));
228  clientAppA.Start (Seconds (1.0));
229  clientAppA.Stop (Seconds (simulationTime + 1));
230 
231  UdpServerHelper myServerB (9);
232  ApplicationContainer serverAppB = myServerB.Install (wifiStaNode.Get (1));
233  serverAppB.Start (Seconds (0.0));
234  serverAppB.Stop (Seconds (simulationTime + 1));
235 
236  UdpClientHelper myClientB (StaInterfaceB.GetAddress (0), 9);
237  myClientB.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
238  myClientB.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
239  myClientB.SetAttribute ("PacketSize", UintegerValue (payloadSize));
240 
241  ApplicationContainer clientAppB = myClientB.Install (wifiApNode.Get (1));
242  clientAppB.Start (Seconds (1.0));
243  clientAppB.Stop (Seconds (simulationTime + 1));
244 
245  UdpServerHelper myServerC (9);
246  ApplicationContainer serverAppC = myServerC.Install (wifiStaNode.Get (2));
247  serverAppC.Start (Seconds (0.0));
248  serverAppC.Stop (Seconds (simulationTime + 1));
249 
250  UdpClientHelper myClientC (StaInterfaceC.GetAddress (0), 9);
251  myClientC.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
252  myClientC.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
253  myClientC.SetAttribute ("PacketSize", UintegerValue (payloadSize));
254 
255  ApplicationContainer clientAppC = myClientC.Install (wifiApNode.Get (2));
256  clientAppC.Start (Seconds (1.0));
257  clientAppC.Stop (Seconds (simulationTime + 1));
258 
259  UdpServerHelper myServerD (9);
260  ApplicationContainer serverAppD = myServerD.Install (wifiStaNode.Get (3));
261  serverAppD.Start (Seconds (0.0));
262  serverAppD.Stop (Seconds (simulationTime + 1));
263 
264  UdpClientHelper myClientD (StaInterfaceD.GetAddress (0), 9);
265  myClientD.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
266  myClientD.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
267  myClientD.SetAttribute ("PacketSize", UintegerValue (payloadSize));
268 
269  ApplicationContainer clientAppD = myClientD.Install (wifiApNode.Get (3));
270  clientAppD.Start (Seconds (1.0));
271  clientAppD.Stop (Seconds (simulationTime + 1));
272 
273  if (enablePcap)
274  {
275  phy.EnablePcap ("AP_A", apDeviceA.Get (0));
276  phy.EnablePcap ("STA_A", staDeviceA.Get (0));
277  phy.EnablePcap ("AP_B", apDeviceB.Get (0));
278  phy.EnablePcap ("STA_B", staDeviceB.Get (0));
279  phy.EnablePcap ("AP_C", apDeviceC.Get (0));
280  phy.EnablePcap ("STA_C", staDeviceC.Get (0));
281  phy.EnablePcap ("AP_D", apDeviceD.Get (0));
282  phy.EnablePcap ("STA_D", staDeviceD.Get (0));
283  }
284 
285  Simulator::Stop (Seconds (simulationTime + 1));
286  Simulator::Run ();
288 
289  /* Show results */
290  uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverAppA.Get (0))->GetReceived ();
291  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
292  std::cout << "Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput << " Mbit/s" << '\n';
293 
294  totalPacketsThrough = DynamicCast<UdpServer> (serverAppB.Get (0))->GetReceived ();
295  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
296  std::cout << "Throughput with aggregation disabled: " << throughput << " Mbit/s" << '\n';
297 
298  totalPacketsThrough = DynamicCast<UdpServer> (serverAppC.Get (0))->GetReceived ();
299  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
300  std::cout << "Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput << " Mbit/s" << '\n';
301 
302  totalPacketsThrough = DynamicCast<UdpServer> (serverAppD.Get (0))->GetReceived ();
303  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
304  std::cout << "Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput << " Mbit/s" << '\n';
305 
306  return 0;
307 }
tuple channel
Definition: third.py:85
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:71
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:200
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:76
Include Radiotap link layer information.
tuple cmd
Definition: second.py:35
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:100
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:94
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:201
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:164
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:491
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:208
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.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
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...
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