A Discrete-Event Network Simulator
API
wifi-msdu-aggregator-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Dean Armstrong
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Dean Armstrong <deanarm@gmail.com>
18  */
19 
20 #include "ns3/boolean.h"
21 #include "ns3/double.h"
22 #include "ns3/internet-stack-helper.h"
23 #include "ns3/ipv4-address-helper.h"
24 #include "ns3/mobility-helper.h"
25 #include "ns3/on-off-helper.h"
26 #include "ns3/packet-sink-helper.h"
27 #include "ns3/packet-sink.h"
28 #include "ns3/ssid.h"
29 #include "ns3/string.h"
30 #include "ns3/test.h"
31 #include "ns3/uinteger.h"
32 #include "ns3/yans-wifi-helper.h"
33 
34 using namespace ns3;
35 
43 {
44  public:
46  void DoRun() override;
47 
48  private:
50 };
51 
53  : TestCase("MsduAggregator throughput test"),
54  m_writeResults(false)
55 {
56 }
57 
58 void
60 {
62  WifiMacHelper wifiMac;
63  YansWifiPhyHelper wifiPhy;
64  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
65  wifiPhy.SetChannel(wifiChannel.Create());
66 
67  Ssid ssid = Ssid("wifi-amsdu-throughput");
68  // It may seem a little farcical running an 802.11n aggregation
69  // scenario with 802.11b rates (transmit rate fixed to 1 Mbps, no
70  // less), but this approach tests the bit we need to without unduly
71  // increasing the complexity of the simulation.
72  std::string phyMode("DsssRate1Mbps");
73  wifi.SetStandard(WIFI_STANDARD_80211b);
74  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
75  "DataMode",
76  StringValue(phyMode),
77  "ControlMode",
78  StringValue(phyMode));
79 
80  // Setup the AP, which will be the source of traffic for this test
81  // and thus has an aggregator on AC_BE.
82  NodeContainer ap;
83  ap.Create(1);
84  wifiMac.SetType("ns3::ApWifiMac",
85  "QosSupported",
86  BooleanValue(true),
87  "Ssid",
88  SsidValue(ssid),
89  "BeaconGeneration",
90  BooleanValue(true),
91  "BeaconInterval",
92  TimeValue(MicroSeconds(102400)),
93  "BE_MaxAmsduSize",
94  UintegerValue(4000));
95 
96  NetDeviceContainer apDev = wifi.Install(wifiPhy, wifiMac, ap);
97 
98  // Setup one STA, which will be the sink for traffic in this test.
99  NodeContainer sta;
100  sta.Create(1);
101  wifiMac.SetType("ns3::StaWifiMac",
102  "QosSupported",
103  BooleanValue(true),
104  "Ssid",
105  SsidValue(ssid),
106  "ActiveProbing",
107  BooleanValue(false));
108  NetDeviceContainer staDev = wifi.Install(wifiPhy, wifiMac, sta);
109 
110  // Our devices will have fixed positions
112  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
113  mobility.SetPositionAllocator("ns3::GridPositionAllocator",
114  "MinX",
115  DoubleValue(0.0),
116  "MinY",
117  DoubleValue(0.0),
118  "DeltaX",
119  DoubleValue(5.0),
120  "DeltaY",
121  DoubleValue(10.0),
122  "GridWidth",
123  UintegerValue(2),
124  "LayoutType",
125  StringValue("RowFirst"));
126  mobility.Install(sta);
127  mobility.Install(ap);
128 
129  // Now we install internet stacks on our devices
131  stack.Install(ap);
132  stack.Install(sta);
133 
135  address.SetBase("192.168.0.0", "255.255.255.0");
136  Ipv4InterfaceContainer staNodeInterface;
137  Ipv4InterfaceContainer apNodeInterface;
138  staNodeInterface = address.Assign(staDev);
139  apNodeInterface = address.Assign(apDev);
140 
141  // The applications for this test will see a unidirectional UDP
142  // stream from the AP to the STA. The following UDP port will be
143  // used (arbitrary choice).
144  uint16_t udpPort = 50000;
145 
146  // The packet sink application is on the STA device, and is running
147  // right from the start. The traffic source will turn on at 1 second
148  // and then off at 9 seconds, so we turn the sink off at 9 seconds
149  // too in order to measure throughput in a fixed window.
150  PacketSinkHelper packetSink("ns3::UdpSocketFactory",
151  InetSocketAddress(Ipv4Address::GetAny(), udpPort));
152  ApplicationContainer sinkApp = packetSink.Install(sta.Get(0));
153  sinkApp.Start(Seconds(0));
154  sinkApp.Stop(Seconds(9.0));
155 
156  // The packet source is an on-off application on the AP
157  // device. Given that we have fixed the transmit rate at 1 Mbps
158  // above, a 1 Mbps stream at the transport layer should be sufficient
159  // to determine whether aggregation is working or not.
160  //
161  // We configure this traffic stream to operate between 1 and 9 seconds.
162  OnOffHelper onoff("ns3::UdpSocketFactory",
163  InetSocketAddress(staNodeInterface.GetAddress(0), udpPort));
164  onoff.SetAttribute("PacketSize", UintegerValue(100));
165  onoff.SetConstantRate(DataRate("1Mbps"));
166  ApplicationContainer sourceApp = onoff.Install(ap.Get(0));
167  sourceApp.Start(Seconds(1.0));
168  sourceApp.Stop(Seconds(9.0));
169 
170  // Enable tracing at the AP
171  if (m_writeResults)
172  {
173  wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
174  wifiPhy.EnablePcap("wifi-amsdu-throughput", sta.Get(0)->GetId(), 0);
175  }
176 
177  Simulator::Stop(Seconds(10.0));
178  Simulator::Run();
179  Simulator::Destroy();
180 
181  // Now the simulation is complete we note the total number of octets
182  // receive at the packet sink so that we can shortly test that this
183  // is plausible.
184  uint32_t totalOctetsThrough = DynamicCast<PacketSink>(sinkApp.Get(0))->GetTotalRx();
185 
186  // Check that throughput was acceptable. This threshold is set based
187  // on inspection of a trace where things are working. Basically, we
188  // there get 26 UDP packets (of size 100, as specified above)
189  // aggregated per A-MSDU, for which the complete frame exchange
190  // (including RTS/CTS and plus medium access) takes around 32
191  // ms. Over the eight seconds of the test this means we expect about
192  // 650 kilobytes, so a pass threshold of 600000 seems to provide a
193  // fair amount of margin to account for reduced utilisation around
194  // stream startup, and contention around AP beacon transmission.
195  //
196  // If aggregation is turned off, then we get about 350 kilobytes in
197  // the same test, so we'll definitely catch the major failures.
198  NS_TEST_ASSERT_MSG_GT(totalOctetsThrough,
199  600000,
200  "A-MSDU test fails for low throughput of " << totalOctetsThrough
201  << " octets");
202 }
203 
215 {
216  public:
218 };
219 
221  : TestSuite("wifi-msdu-aggregator", SYSTEM)
222 {
223  AddTestCase(new WifiMsduAggregatorThroughputTest, TestCase::QUICK);
224 }
225 
Throughput test for MsduAggregator.
void DoRun() override
Implementation to actually run this TestCase.
bool m_writeResults
flag whether to generate pcap
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
an Inet address class
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
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.
uint32_t GetId() const
Definition: node.cc:117
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:44
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:543
manage and create wifi channel objects for the YANS model.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:327
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:874
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
@ WIFI_STANDARD_80211b
address
Definition: first.py:47
stack
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ssid
Definition: third.py:93
wifi
Definition: third.py:95
mobility
Definition: third.py:105
static WifiMsduAggregatorTestSuite wifiMsduAggregatorTestSuite