A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-issue-211-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020
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 * Authors: Stefano Avallone <stavallo@unina.it>
18 * Rémy Grünblatt <remy@grunblatt.org>
19 */
20
21#include "ns3/ap-wifi-mac.h"
22#include "ns3/boolean.h"
23#include "ns3/config.h"
24#include "ns3/internet-stack-helper.h"
25#include "ns3/ipv4-address-helper.h"
26#include "ns3/mobility-helper.h"
27#include "ns3/multi-model-spectrum-channel.h"
28#include "ns3/packet.h"
29#include "ns3/qos-utils.h"
30#include "ns3/queue-size.h"
31#include "ns3/rng-seed-manager.h"
32#include "ns3/spectrum-wifi-helper.h"
33#include "ns3/string.h"
34#include "ns3/test.h"
35#include "ns3/udp-client-server-helper.h"
36#include "ns3/wifi-net-device.h"
37
38using namespace ns3;
39
57class Issue211Test : public TestCase
58{
59 public:
64 ~Issue211Test() override;
65
66 void DoRun() override;
67
68 private:
73 void CalcThroughput(Ptr<UdpServer> server);
74
75 std::vector<double> m_tputValues;
76 uint64_t m_lastRxBytes;
79};
80
82 : TestCase("Test case for resuming data transmission when the recipient moves back"),
83 m_lastRxBytes(0),
84 m_lastCheckPointTime(Seconds(0)),
85 m_payloadSize(2000)
86{
87}
88
90{
91}
92
93void
95{
96 uint64_t rxBytes = m_payloadSize * server->GetReceived();
97 double tput = (rxBytes - m_lastRxBytes) * 8. /
98 (Simulator::Now() - m_lastCheckPointTime).ToDouble(Time::US); // Mb/s
99 m_tputValues.push_back(tput);
100 m_lastRxBytes = rxBytes;
102}
103
104void
106{
107 Time simulationTime(Seconds(6.0));
108 Time moveAwayTime(Seconds(2.0));
109 Time moveBackTime(Seconds(4.0));
110
113 int64_t streamNumber = 100;
114
115 NodeContainer wifiApNode;
116 wifiApNode.Create(1);
117
118 NodeContainer wifiStaNode;
119 wifiStaNode.Create(1);
120
121 Ptr<MultiModelSpectrumChannel> spectrumChannel = CreateObject<MultiModelSpectrumChannel>();
122 Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel>();
123 spectrumChannel->AddPropagationLossModel(lossModel);
125 CreateObject<ConstantSpeedPropagationDelayModel>();
126 spectrumChannel->SetPropagationDelayModel(delayModel);
127
129 phy.SetChannel(spectrumChannel);
130
131 WifiHelper wifi;
132 wifi.SetStandard(WIFI_STANDARD_80211n);
133 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
134 "DataMode",
135 StringValue("HtMcs0"),
136 "ControlMode",
137 StringValue("HtMcs0"));
138
139 Config::SetDefault("ns3::WifiMacQueue::MaxSize", QueueSizeValue(QueueSize("50p")));
140
141 WifiMacHelper mac;
142 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(Ssid("issue211-test")));
143
144 NetDeviceContainer staDevices = wifi.Install(phy, mac, wifiStaNode);
145
146 mac.SetType("ns3::ApWifiMac",
147 "Ssid",
148 SsidValue(Ssid("issue211-test")),
149 "EnableBeaconJitter",
150 BooleanValue(false));
151
152 NetDeviceContainer apDevices = wifi.Install(phy, mac, wifiApNode);
153
154 // Assign fixed streams to random variables in use
155 wifi.AssignStreams(apDevices, streamNumber);
156
157 MobilityHelper mobility;
158 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
159
160 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
161 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
162 mobility.SetPositionAllocator(positionAlloc);
163
164 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
165 mobility.Install(wifiApNode);
166 mobility.Install(wifiStaNode);
167
168 /* Internet stack*/
170 stack.Install(wifiApNode);
171 stack.Install(wifiStaNode);
172
173 Ipv4AddressHelper address;
174 address.SetBase("192.168.1.0", "255.255.255.0");
175 Ipv4InterfaceContainer staNodeInterface;
176 Ipv4InterfaceContainer apNodeInterface;
177
178 staNodeInterface = address.Assign(staDevices.Get(0));
179 apNodeInterface = address.Assign(apDevices.Get(0));
180
181 ApplicationContainer serverApp;
182 Time warmup(Seconds(1.0)); // to account for association
183
184 uint16_t port = 9;
185 UdpServerHelper server(port);
186 serverApp = server.Install(wifiStaNode.Get(0));
187 serverApp.Start(Seconds(0.0));
188 serverApp.Stop(warmup + simulationTime);
189
190 UdpClientHelper client(staNodeInterface.GetAddress(0), port);
191 client.SetAttribute("MaxPackets", UintegerValue(4294967295U));
192 client.SetAttribute("Interval", TimeValue(MilliSeconds(1)));
193 client.SetAttribute("PacketSize", UintegerValue(m_payloadSize)); // 16 Mb/s
194 ApplicationContainer clientApp = client.Install(wifiApNode.Get(0));
195 clientApp.Start(warmup);
196 clientApp.Stop(warmup + simulationTime);
197
198 Ptr<MobilityModel> staMobility = wifiStaNode.Get(0)->GetObject<MobilityModel>();
199
200 // First check-point: station moves away
201 Simulator::Schedule(warmup + moveAwayTime,
203 staMobility,
204 Vector(10000.0, 0.0, 0.0));
205 Simulator::Schedule(warmup + moveAwayTime + MilliSeconds(10),
207 this,
208 DynamicCast<UdpServer>(serverApp.Get(0)));
209
210 // Second check-point: station moves back
211 Simulator::Schedule(warmup + moveBackTime,
213 staMobility,
214 Vector(5.0, 0.0, 0.0));
215 Simulator::Schedule(warmup + moveBackTime,
217 this,
218 DynamicCast<UdpServer>(serverApp.Get(0)));
219
220 // Last check-point: simulation finish time
221 Simulator::Schedule(warmup + simulationTime,
223 this,
224 DynamicCast<UdpServer>(serverApp.Get(0)));
225
226 Simulator::Stop(warmup + simulationTime);
228
229 NS_TEST_EXPECT_MSG_EQ(m_tputValues.size(), 3, "Unexpected number of throughput values");
231 0,
232 "Throughput must be non null before station moves away");
233 NS_TEST_EXPECT_MSG_EQ(m_tputValues[1], 0, "Throughput must be null while the station is away");
235 0,
236 "Throughput must be non null when the station is back");
237
238 // Print throughput values when the test is run through test-runner
239 for (const auto& t : m_tputValues)
240 {
241 std::cout << "Throughput = " << t << " Mb/s" << std::endl;
242 }
243
245}
246
254{
255 public:
257};
258
260 : TestSuite("wifi-issue-211", UNIT)
261{
263}
264
Test for issue 211 (https://gitlab.com/nsnam/ns-3-dev/-/issues/211)
std::vector< double > m_tputValues
throughput in sub-intervals
Time m_lastCheckPointTime
time of last check-point
Issue211Test()
Constructor.
uint32_t m_payloadSize
payload size in bytes
void DoRun() override
Implementation to actually run this TestCase.
uint64_t m_lastRxBytes
RX bytes at last check-point.
void CalcThroughput(Ptr< UdpServer > server)
Compute the average throughput since the last check-point.
Block Ack Test Suite.
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.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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.
Keep track of the current position and velocity of an object.
void SetPosition(const Vector &position)
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Class for representing queue sizes.
Definition: queue-size.h:96
AttributeValue implementation for QueueSize.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Make it easy to create and manage PHY objects for the spectrum model.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
@ US
microsecond
Definition: nstime.h:118
AttributeValue implementation for Time.
Definition: nstime.h:1423
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
ApplicationContainer Install(NodeContainer c)
Create a server application which waits for input UDP packets and uses the information carried into t...
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:325
create MAC layers for a ns3::WifiNetDevice.
uint16_t port
Definition: dsdv-manet.cc:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report if not.
Definition: test.h:956
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:251
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
@ WIFI_STANDARD_80211n
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Issue211TestSuite g_issue211TestSuite
the test suite