A Discrete-Event Network Simulator
API
simple-two-level-aggregation.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 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 a simple example in order to show how 802.11n two-level aggregation feature works.
30 // Two-level aggregation is the simultaneous use of MSDU and MPDU aggregation schemes (known as one-level aggregation techniques).
31 //
32 // The throughput is obtained for a given number of aggregated MSDUs and MPDUs.
33 // The number of aggregated MSDUs and MPDUs can be chosen by the user through the nMsdus and nMpdus attibutes, respectively.
34 //
35 // Example: ./waf --run "simple-two-level-aggregation --nMsdus=3 --nMpdus=8"
36 //
37 // Network topology:
38 //
39 // Wifi 192.168.1.0
40 //
41 // AP
42 // * *
43 // | |
44 // n1 n2
45 //
46 // Packets in this simulation aren't marked with a QosTag so they are considered
47 // belonging to BestEffort Access Class (AC_BE).
48 //
49 // Throughput gets higher as either nMsdus or nMpdus is increased (one-level aggregation),
50 // or when both nMsdus and nMpdus are increases (two-level aggregation).
51 // MSDU aggregation offers a better header reduction compare to MPDU aggregation,
52 // while MPDU aggregation is more robust against transmission errors than MSDU aggregation.
53 // The good setting of nMsdu and nMpdus will depends on various factors (payload size, channel conditions, ...).
54 // Since this example considers an ideal channel, the highest throughput is obtained with the largest values for nMsdus and nMpdus parameters.
55 // Users should nevertheless take care that the standard rules limit the maximum MSDU size to 7935 bytes and the MPDU size to 65535 bytes.
56 // Consequently, more packets should be aggregated if their payload is small with standard-compliant parameters.
57 // Users should also note that the maximum duration of the frame is limited by the standard.
58 // As a result, higher values for nMsdus and nMpdus may not always provide throughput improvements.
59 
60 using namespace ns3;
61 
62 NS_LOG_COMPONENT_DEFINE ("SimpleTwoLevelAggregation");
63 
64 int main (int argc, char *argv[])
65 {
66  uint32_t payloadSize = 1472; //bytes
67  uint64_t simulationTime = 10; //seconds
68  uint32_t nMsdus = 1;
69  uint32_t nMpdus = 1;
70  bool enableRts = 0;
71 
72  CommandLine cmd;
73  cmd.AddValue ("nMsdus", "Number of aggregated MSDUs", nMsdus); //number of aggregated MSDUs specified by the user
74  cmd.AddValue ("nMpdus", "Number of aggregated MPDUs", nMpdus); //number of aggregated MPDUs specified by the user
75  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
76  cmd.AddValue ("enableRts", "Enable RTS/CTS", enableRts);
77  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
78  cmd.Parse (argc, argv);
79 
80  if (!enableRts)
81  {
82  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
83  }
84  else
85  {
86  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
87  }
88 
89  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("990000"));
90 
91  NodeContainer wifiStaNode;
92  wifiStaNode.Create (1);
93  NodeContainer wifiApNode;
94  wifiApNode.Create (1);
95 
99  phy.SetChannel (channel.Create ());
100 
103  //We consider a constant bitrate since HT rate adaptation algorithms are not supported yet in the simulator
104  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
105  "DataMode", StringValue ("OfdmRate65MbpsBW20MHz"),
106  "ControlMode", StringValue ("OfdmRate6_5MbpsBW20MHz"));
108 
109  Ssid ssid = Ssid ("simple-two-level-aggregation");
110  mac.SetType ("ns3::StaWifiMac",
111  "Ssid", SsidValue (ssid),
112  "ActiveProbing", BooleanValue (false));
113 
114 
115  //Enable aggregation at the station side
116  if (nMpdus > 1)
117  {
118  mac.SetBlockAckThresholdForAc (AC_BE, 2); //enable BlockAck when A-MPDU is used
119  }
120  if (nMsdus > 0)
121  {
122  mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator",
123  "MaxAmpduSize", UintegerValue (nMpdus * (nMsdus * (payloadSize + 100)))); //Set the maximum size for A-MPDU with regards to the payload size and the number of MSDUs expected in each MPDU.
124  }
125  else //MPDU aggregation only (one-level aggregation)
126  {
127  mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator",
128  "MaxAmpduSize", UintegerValue (nMpdus * (payloadSize + 200))); //Set the maximum size for A-MPDU with regards to the payload size
129  }
130  mac.SetMsduAggregatorForAc (AC_BE,"ns3::MsduStandardAggregator",
131  "MaxAmsduSize", UintegerValue (nMsdus * (payloadSize + 100))); //Set the maximum size for A-MSDU with regards to the payload size
132 
133 
134  NetDeviceContainer staDevice;
135  staDevice = wifi.Install (phy, mac, wifiStaNode);
136 
137  mac.SetType ("ns3::ApWifiMac",
138  "Ssid", SsidValue (ssid),
139  "BeaconInterval", TimeValue (MicroSeconds (102400)),
140  "BeaconGeneration", BooleanValue (true));
141 
142  //Enable aggregation at the AP side
143  if (nMpdus > 1)
144  {
145  mac.SetBlockAckThresholdForAc (AC_BE, 2); //enable BlockAck when A-MPDU is used
146  }
147  if (nMsdus > 0)
148  {
149  mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator",
150  "MaxAmpduSize", UintegerValue (nMpdus * (nMsdus * (payloadSize + 100)))); //Set the maximum size for A-MPDU according to the payload size and the number of MSDUs expected in each MPDU.
151  }
152  else //MPDU aggregation only (one-level aggregation)
153  {
154  mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator",
155  "MaxAmpduSize", UintegerValue (nMpdus * (payloadSize + 200))); //Set the maximum size for A-MPDU with regards to the payload size
156  }
157  mac.SetMsduAggregatorForAc (AC_BE,"ns3::MsduStandardAggregator",
158  "MaxAmsduSize", UintegerValue (nMsdus * (payloadSize + 100))); //Set the maximum size for A-MSDU with regards to the payload size
159 
160  NetDeviceContainer apDevice;
161  apDevice = wifi.Install (phy, mac, wifiApNode);
162 
163  /* Setting mobility model */
164  MobilityHelper mobility;
165  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
166 
167  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
168  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
169  mobility.SetPositionAllocator (positionAlloc);
170 
171  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
172 
173  mobility.Install (wifiApNode);
174  mobility.Install (wifiStaNode);
175 
176  /* Internet stack*/
178  stack.Install (wifiApNode);
179  stack.Install (wifiStaNode);
180 
182 
183  address.SetBase ("192.168.1.0", "255.255.255.0");
184  Ipv4InterfaceContainer StaInterface;
185  StaInterface = address.Assign (staDevice);
186  Ipv4InterfaceContainer ApInterface;
187  ApInterface = address.Assign (apDevice);
188 
189  /* Setting applications */
190  UdpServerHelper myServer (9);
191  ApplicationContainer serverApp = myServer.Install (wifiStaNode.Get (0));
192  serverApp.Start (Seconds (0.0));
193  serverApp.Stop (Seconds (simulationTime + 1));
194 
195  UdpClientHelper myClient (StaInterface.GetAddress (0), 9);
196  myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
197  myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
198  myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize));
199 
200  ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0));
201  clientApp.Start (Seconds (1.0));
202  clientApp.Stop (Seconds (simulationTime + 1));
203 
204  Simulator::Stop (Seconds (simulationTime + 1));
205 
206  Simulator::Run ();
208 
209  uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
210  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
211  std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
212 
213  return 0;
214 }
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
create HT-enabled MAC layers for a ns3::WifiNetDevice.
AttributeValue implementation for Boolean.
Definition: boolean.h:34
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:73
Hold variables of type string.
Definition: string.h:41
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.
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())
Set the underlying type of the MAC and its attributes.
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 SetMsduAggregatorForAc(AcIndex ac, 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())
Set the class, type and attributes for the Msdu aggregator.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:92
Best Effort.
Definition: qos-utils.h:38
Include Radiotap link layer information.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
static HtWifiMacHelper Default(void)
Create a mac helper in a default working state.
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetBlockAckThresholdForAc(enum AcIndex ac, uint8_t threshold)
This method sets value of block ack threshold for a specific access class.
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:928
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetMpduAggregatorForAc(enum AcIndex ac, 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())
Set the class, type and attributes for the Mpdu aggregator.
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:96
Create a server application which waits for input UDP packets and uses the information carried into t...
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
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...
manage and create wifi channel objects for the yans model.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:37
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:866
AttributeValue implementation for Ssid.
Definition: ssid.h:93
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:683
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:882
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 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
static WifiHelper Default(void)
Definition: wifi-helper.cc:65