A Discrete-Event Network Simulator
API
wifi-msdu-aggregator-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Dean Armstrong
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: Dean Armstrong <deanarm@gmail.com>
19  */
20 
21 #include "ns3/string.h"
22 #include "ns3/test.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/boolean.h"
25 #include "ns3/double.h"
26 #include "ns3/ssid.h"
27 #include "ns3/packet-sink.h"
28 #include "ns3/yans-wifi-helper.h"
29 #include "ns3/mobility-helper.h"
30 #include "ns3/internet-stack-helper.h"
31 #include "ns3/ipv4-address-helper.h"
32 #include "ns3/packet-sink-helper.h"
33 #include "ns3/on-off-helper.h"
34 
35 using namespace ns3;
36 
38 {
39 public:
41  virtual void DoRun (void);
42 
43 private:
45 };
46 
48  : TestCase ("MsduAggregator throughput test"),
49  m_writeResults (false)
50 {
51 }
52 
53 void
55 {
57  WifiMacHelper wifiMac;
58  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
59  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
60  wifiPhy.SetChannel (wifiChannel.Create ());
61 
62  Ssid ssid = Ssid ("wifi-amsdu-throughput");
63  // It may seem a little farcical running an 802.11n aggregation
64  // scenario with 802.11b rates (transmit rate fixed to 1 Mbps, no
65  // less), but this approach tests the bit we need to without unduly
66  // increasing the complexity of the simulation.
67  std::string phyMode ("DsssRate1Mbps");
68  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
69  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
70  "DataMode", StringValue (phyMode),
71  "ControlMode", StringValue (phyMode));
72 
73  // Setup the AP, which will be the source of traffic for this test
74  // and thus has an aggregator on AC_BE.
75  NodeContainer ap;
76  ap.Create (1);
77  wifiMac.SetType ("ns3::ApWifiMac",
78  "QosSupported", BooleanValue (true),
79  "Ssid", SsidValue (ssid),
80  "BeaconGeneration", BooleanValue (true),
81  "BeaconInterval", TimeValue (MicroSeconds (102400)),
82  "BE_MaxAmsduSize", UintegerValue (4000));
83 
84  NetDeviceContainer apDev = wifi.Install (wifiPhy, wifiMac, ap);
85 
86  // Setup one STA, which will be the sink for traffic in this test.
87  NodeContainer sta;
88  sta.Create (1);
89  wifiMac.SetType ("ns3::StaWifiMac",
90  "QosSupported", BooleanValue (true),
91  "Ssid", SsidValue (ssid),
92  "ActiveProbing", BooleanValue (false));
93  NetDeviceContainer staDev = wifi.Install (wifiPhy, wifiMac, sta);
94 
95  // Our devices will have fixed positions
97  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
98  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
99  "MinX", DoubleValue (0.0),
100  "MinY", DoubleValue (0.0),
101  "DeltaX", DoubleValue (5.0),
102  "DeltaY", DoubleValue (10.0),
103  "GridWidth", UintegerValue (2),
104  "LayoutType", StringValue ("RowFirst"));
105  mobility.Install (sta);
106  mobility.Install (ap);
107 
108  // Now we install internet stacks on our devices
110  stack.Install (ap);
111  stack.Install (sta);
112 
114  address.SetBase ("192.168.0.0", "255.255.255.0");
115  Ipv4InterfaceContainer staNodeInterface, apNodeInterface;
116  staNodeInterface = address.Assign (staDev);
117  apNodeInterface = address.Assign (apDev);
118 
119  // The applications for this test will see a unidirectional UDP
120  // stream from the AP to the STA. The following UDP port will be
121  // used (arbitrary choice).
122  uint16_t udpPort = 50000;
123 
124  // The packet sink application is on the STA device, and is running
125  // right from the start. The traffic source will turn on at 1 second
126  // and then off at 9 seconds, so we turn the sink off at 9 seconds
127  // too in order to measure throughput in a fixed window.
128  PacketSinkHelper packetSink ("ns3::UdpSocketFactory",
129  InetSocketAddress (Ipv4Address::GetAny (),
130  udpPort));
131  ApplicationContainer sinkApp = packetSink.Install (sta.Get (0));
132  sinkApp.Start (Seconds (0));
133  sinkApp.Stop (Seconds (9.0));
134 
135  // The packet source is an on-off application on the AP
136  // device. Given that we have fixed the transmit rate at 1 Mbps
137  // above, a 1 Mbps stream at the transport layer should be sufficient
138  // to determine whether aggregation is working or not.
139  //
140  // We configure this traffic stream to operate between 1 and 9 seconds.
141  OnOffHelper onoff ("ns3::UdpSocketFactory",
142  InetSocketAddress (staNodeInterface.GetAddress (0),
143  udpPort));
144  onoff.SetAttribute ("PacketSize", UintegerValue (100));
145  onoff.SetConstantRate (DataRate ("1Mbps"));
146  ApplicationContainer sourceApp = onoff.Install (ap.Get (0));
147  sourceApp.Start (Seconds (1.0));
148  sourceApp.Stop (Seconds (9.0));
149 
150  // Enable tracing at the AP
151  if (m_writeResults)
152  {
153  wifiPhy.EnablePcap ("wifi-amsdu-throughput", sta.Get (0)->GetId (), 0);
154  }
155 
156  Simulator::Stop (Seconds (10.0));
157  Simulator::Run ();
158  Simulator::Destroy ();
159 
160  // Now the simulation is complete we note the total number of octets
161  // receive at the packet sink so that we can shortly test that this
162  // is plausible.
163  uint32_t totalOctetsThrough =
164  DynamicCast<PacketSink>(sinkApp.Get (0))->GetTotalRx ();
165 
166  // Check that throughput was acceptable. This threshold is set based
167  // on inspection of a trace where things are working. Basically, we
168  // there get 26 UDP packets (of size 100, as specified above)
169  // aggregated per A-MSDU, for which the complete frame exchange
170  // (including RTS/CTS and plus medium access) takes around 32
171  // ms. Over the eight seconds of the test this means we expect about
172  // 650 kilobytes, so a pass threshold of 600000 seems to provide a
173  // fair amount of margin to account for reduced utilisation around
174  // stream startup, and contention around AP beacon transmission.
175  //
176  // If aggregation is turned off, then we get about 350 kilobytes in
177  // the same test, so we'll definitely catch the major failures.
178  NS_TEST_ASSERT_MSG_GT (totalOctetsThrough, 600000,
179  "A-MSDU test fails for low throughput of "
180  << totalOctetsThrough << " octets");
181 }
182 
183 
184 // For now the MSDU Aggregator Test Suite contains only the one test
185 // that is defined in this file, so it's class definition and
186 // instantiation can live here.
188 {
189 public:
191 };
192 
194  : TestSuite ("ns3-wifi-msdu-aggregator", SYSTEM)
195 {
196  AddTestCase (new WifiMsduAggregatorThroughputTest, TestCase::QUICK);
197 }
198 
holds a vector of ns3::Application pointers.
an Inet address class
AttributeValue implementation for Boolean.
Definition: boolean.h:36
uint32_t GetId(void) const
Definition: node.cc:107
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Hold variables of type string.
Definition: string.h:41
Make it easy to create and manage PHY objects for the yans model.
A suite of tests to run.
Definition: test.h:1342
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
encapsulates test code
Definition: test.h:1155
helps to create WifiNetDevice objects
Definition: wifi-helper.h:230
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
stack
Definition: first.py:34
Ptr< YansWifiChannel > Create(void) const
mobility
Definition: third.py:101
Class for representing data rates.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
virtual void DoRun(void)
Implementation to actually run this TestCase.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
AttributeValue implementation for Time.
Definition: nstime.h:1076
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:93
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
keep track of a set of node pointers.
address
Definition: first.py:37
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
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())
wifi
Definition: third.py:89
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...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
AttributeValue implementation for Ssid.
Definition: ssid.h:110
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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:1030
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
#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:997
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
static WifiMsduAggregatorTestSuite wifiMsduAggregatorTestSuite
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.