A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-msdu-aggregator-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Dean Armstrong
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Dean Armstrong <deanarm@gmail.com>
7 */
8
9#include "ns3/boolean.h"
10#include "ns3/double.h"
11#include "ns3/internet-stack-helper.h"
12#include "ns3/ipv4-address-helper.h"
13#include "ns3/mobility-helper.h"
14#include "ns3/on-off-helper.h"
15#include "ns3/packet-sink-helper.h"
16#include "ns3/packet-sink.h"
17#include "ns3/ssid.h"
18#include "ns3/string.h"
19#include "ns3/test.h"
20#include "ns3/uinteger.h"
21#include "ns3/yans-wifi-helper.h"
22
23using namespace ns3;
24
25/**
26 * \ingroup wifi-test
27 * \ingroup tests
28 *
29 * \brief Throughput test for MsduAggregator
30 */
32{
33 public:
35 void DoRun() override;
36
37 private:
38 bool m_writeResults; //!< flag whether to generate pcap
39};
40
42 : TestCase("MsduAggregator throughput test"),
43 m_writeResults(false)
44{
45}
46
47void
49{
50 WifiHelper wifi;
51 WifiMacHelper wifiMac;
52 YansWifiPhyHelper wifiPhy;
54 wifiPhy.SetChannel(wifiChannel.Create());
55
56 Ssid ssid = Ssid("wifi-amsdu-throughput");
57 // It may seem a little farcical running an 802.11n aggregation
58 // scenario with 802.11b rates (transmit rate fixed to 1 Mbps, no
59 // less), but this approach tests the bit we need to without unduly
60 // increasing the complexity of the simulation.
61 std::string phyMode("DsssRate1Mbps");
62 wifi.SetStandard(WIFI_STANDARD_80211b);
63 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
64 "DataMode",
65 StringValue(phyMode),
66 "ControlMode",
67 StringValue(phyMode));
68
69 // Setup the AP, which will be the source of traffic for this test
70 // and thus has an aggregator on AC_BE.
72 ap.Create(1);
73 wifiMac.SetType("ns3::ApWifiMac",
74 "QosSupported",
75 BooleanValue(true),
76 "Ssid",
77 SsidValue(ssid),
78 "BeaconGeneration",
79 BooleanValue(true),
80 "BeaconInterval",
81 TimeValue(MicroSeconds(102400)),
82 "BE_MaxAmsduSize",
83 UintegerValue(4000));
84
85 NetDeviceContainer apDev = wifi.Install(wifiPhy, wifiMac, ap);
86
87 // Setup one STA, which will be the sink for traffic in this test.
88 NodeContainer sta;
89 sta.Create(1);
90 wifiMac.SetType("ns3::StaWifiMac",
91 "QosSupported",
92 BooleanValue(true),
93 "Ssid",
94 SsidValue(ssid),
95 "ActiveProbing",
96 BooleanValue(false));
97 NetDeviceContainer staDev = wifi.Install(wifiPhy, wifiMac, sta);
98
99 // Our devices will have fixed positions
100 MobilityHelper mobility;
101 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
102 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
103 "MinX",
104 DoubleValue(0.0),
105 "MinY",
106 DoubleValue(0.0),
107 "DeltaX",
108 DoubleValue(5.0),
109 "DeltaY",
110 DoubleValue(10.0),
111 "GridWidth",
112 UintegerValue(2),
113 "LayoutType",
114 StringValue("RowFirst"));
115 mobility.Install(sta);
116 mobility.Install(ap);
117
118 // Now we install internet stacks on our devices
120 stack.Install(ap);
121 stack.Install(sta);
122
123 Ipv4AddressHelper address;
124 address.SetBase("192.168.0.0", "255.255.255.0");
125 Ipv4InterfaceContainer staNodeInterface;
126 Ipv4InterfaceContainer apNodeInterface;
127 staNodeInterface = address.Assign(staDev);
128 apNodeInterface = address.Assign(apDev);
129
130 // The applications for this test will see a unidirectional UDP
131 // stream from the AP to the STA. The following UDP port will be
132 // used (arbitrary choice).
133 uint16_t udpPort = 50000;
134
135 // The packet sink application is on the STA device, and is running
136 // right from the start. The traffic source will turn on at 1 second
137 // and then off at 9 seconds, so we turn the sink off at 9 seconds
138 // too in order to measure throughput in a fixed window.
139 PacketSinkHelper packetSink("ns3::UdpSocketFactory",
141 ApplicationContainer sinkApp = packetSink.Install(sta.Get(0));
142 sinkApp.Start(Seconds(0));
143 sinkApp.Stop(Seconds(9.0));
144
145 // The packet source is an on-off application on the AP
146 // device. Given that we have fixed the transmit rate at 1 Mbps
147 // above, a 1 Mbps stream at the transport layer should be sufficient
148 // to determine whether aggregation is working or not.
149 //
150 // We configure this traffic stream to operate between 1 and 9 seconds.
151 OnOffHelper onoff("ns3::UdpSocketFactory",
152 InetSocketAddress(staNodeInterface.GetAddress(0), udpPort));
153 onoff.SetAttribute("PacketSize", UintegerValue(100));
154 onoff.SetConstantRate(DataRate("1Mbps"));
155 ApplicationContainer sourceApp = onoff.Install(ap.Get(0));
156 sourceApp.Start(Seconds(1.0));
157 sourceApp.Stop(Seconds(9.0));
158
159 // Enable tracing at the AP
160 if (m_writeResults)
161 {
163 wifiPhy.EnablePcap("wifi-amsdu-throughput", sta.Get(0)->GetId(), 0);
164 }
165
169
170 // Now the simulation is complete we note the total number of octets
171 // receive at the packet sink so that we can shortly test that this
172 // is plausible.
173 uint32_t totalOctetsThrough = DynamicCast<PacketSink>(sinkApp.Get(0))->GetTotalRx();
174
175 // Check that throughput was acceptable. This threshold is set based
176 // on inspection of a trace where things are working. Basically, we
177 // there get 26 UDP packets (of size 100, as specified above)
178 // aggregated per A-MSDU, for which the complete frame exchange
179 // (including RTS/CTS and plus medium access) takes around 32
180 // ms. Over the eight seconds of the test this means we expect about
181 // 650 kilobytes, so a pass threshold of 600000 seems to provide a
182 // fair amount of margin to account for reduced utilisation around
183 // stream startup, and contention around AP beacon transmission.
184 //
185 // If aggregation is turned off, then we get about 350 kilobytes in
186 // the same test, so we'll definitely catch the major failures.
187 NS_TEST_ASSERT_MSG_GT(totalOctetsThrough,
188 600000,
189 "A-MSDU test fails for low throughput of " << totalOctetsThrough
190 << " octets");
191}
192
193/**
194 * \ingroup wifi-test
195 * \ingroup tests
196 *
197 * \brief MsduAggregator Test Suite
198 *
199 * For now the MSDU Aggregator Test Suite contains only the one test
200 * that is defined in this file, so it's class definition and
201 * instantiation can live here.
202 */
204{
205 public:
207};
208
210 : TestSuite("wifi-msdu-aggregator", Type::SYSTEM)
211{
212 AddTestCase(new WifiMsduAggregatorThroughputTest, TestCase::Duration::QUICK);
213}
214
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.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
Class for representing data rates.
Definition data-rate.h:78
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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.
static Ipv4Address GetAny()
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:106
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
helps to create WifiNetDevice objects
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.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
#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:864
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
@ WIFI_STANDARD_80211b
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
static WifiMsduAggregatorTestSuite wifiMsduAggregatorTestSuite