A Discrete-Event Network Simulator
API
wifi-issue-211-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) 2020
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  * Authors: Stefano Avallone <stavallo@unina.it>
19  * Rémy Grünblatt <remy@grunblatt.org>
20  */
21 
22 #include "ns3/test.h"
23 #include "ns3/string.h"
24 #include "ns3/qos-utils.h"
25 #include "ns3/packet.h"
26 #include "ns3/wifi-net-device.h"
27 #include "ns3/ap-wifi-mac.h"
28 #include "ns3/mobility-helper.h"
29 #include "ns3/spectrum-wifi-helper.h"
30 #include "ns3/multi-model-spectrum-channel.h"
31 #include "ns3/udp-client-server-helper.h"
32 #include "ns3/internet-stack-helper.h"
33 #include "ns3/ipv4-address-helper.h"
34 #include "ns3/rng-seed-manager.h"
35 #include "ns3/config.h"
36 #include "ns3/queue-size.h"
37 
38 using namespace ns3;
39 
40 
58 class Issue211Test : public TestCase
59 {
60 public:
64  Issue211Test ();
65  virtual ~Issue211Test ();
66 
67  virtual void DoRun (void);
68 
69 private:
74  void CalcThroughput (Ptr<UdpServer> server);
75 
76  std::vector<double> m_tputValues;
77  uint64_t m_lastRxBytes;
79  uint32_t m_payloadSize;
80 };
81 
83  : TestCase ("Test case for resuming data transmission when the recipient moves back"),
84  m_lastRxBytes (0),
85  m_lastCheckPointTime (Seconds (0)),
86  m_payloadSize (2000)
87 {
88 }
89 
91 {
92 }
93 
94 void
96 {
97  uint64_t rxBytes = m_payloadSize * server->GetReceived ();
98  double tput = (rxBytes - m_lastRxBytes) * 8. / (Simulator::Now () - m_lastCheckPointTime).ToDouble (Time::US); // Mb/s
99  m_tputValues.push_back (tput);
100  m_lastRxBytes = rxBytes;
102 }
103 
104 void
106 {
107  Time simulationTime (Seconds (6.0));
108  Time moveAwayTime (Seconds (2.0));
109  Time moveBackTime (Seconds (4.0));
110 
111  RngSeedManager::SetSeed (1);
112  RngSeedManager::SetRun (40);
113  int64_t streamNumber = 100;
114 
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);
124  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
125  spectrumChannel->SetPropagationDelayModel (delayModel);
126 
128  phy.SetChannel (spectrumChannel);
129 
131  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
132  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
133  "DataMode", StringValue ("HtMcs0"),
134  "ControlMode", StringValue ("HtMcs0"));
135 
136  Config::SetDefault ("ns3::WifiMacQueue::MaxSize", QueueSizeValue (QueueSize ("50p")));
137 
139  mac.SetType ("ns3::StaWifiMac",
140  "Ssid", SsidValue (Ssid ("issue211-test")));
141 
142  NetDeviceContainer staDevices = wifi.Install (phy, mac, wifiStaNode);
143 
144  mac.SetType ("ns3::ApWifiMac",
145  "Ssid", SsidValue (Ssid ("issue211-test")),
146  "EnableBeaconJitter", BooleanValue (false));
147 
149 
150  // Assign fixed streams to random variables in use
151  wifi.AssignStreams (apDevices, streamNumber);
152 
154  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
155 
156  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
157  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
158  mobility.SetPositionAllocator (positionAlloc);
159 
160  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
161  mobility.Install (wifiApNode);
162  mobility.Install (wifiStaNode);
163 
164  /* Internet stack*/
166  stack.Install (wifiApNode);
167  stack.Install (wifiStaNode);
168 
170  address.SetBase ("192.168.1.0", "255.255.255.0");
171  Ipv4InterfaceContainer staNodeInterface;
172  Ipv4InterfaceContainer apNodeInterface;
173 
174  staNodeInterface = address.Assign (staDevices.Get (0));
175  apNodeInterface = address.Assign (apDevices.Get (0));
176 
177  ApplicationContainer serverApp;
178  Time warmup (Seconds (1.0)); // to account for association
179 
180  uint16_t port = 9;
181  UdpServerHelper server (port);
182  serverApp = server.Install (wifiStaNode.Get (0));
183  serverApp.Start (Seconds (0.0));
184  serverApp.Stop (warmup + simulationTime);
185 
186  UdpClientHelper client (staNodeInterface.GetAddress (0), port);
187  client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
188  client.SetAttribute ("Interval", TimeValue (MilliSeconds (1)));
189  client.SetAttribute ("PacketSize", UintegerValue (m_payloadSize)); // 16 Mb/s
190  ApplicationContainer clientApp = client.Install (wifiApNode.Get (0));
191  clientApp.Start (warmup);
192  clientApp.Stop (warmup + simulationTime);
193 
194  Ptr<MobilityModel> staMobility = wifiStaNode.Get (0)->GetObject<MobilityModel> ();
195 
196  // First check-point: station moves away
197  Simulator::Schedule (warmup + moveAwayTime, &MobilityModel::SetPosition, staMobility,
198  Vector (10000.0, 0.0, 0.0));
199  Simulator::Schedule (warmup + moveAwayTime + MilliSeconds (10), &Issue211Test::CalcThroughput, this,
200  DynamicCast<UdpServer> (serverApp.Get (0)));
201 
202  // Second check-point: station moves back
203  Simulator::Schedule (warmup + moveBackTime, &MobilityModel::SetPosition, staMobility,
204  Vector (5.0, 0.0, 0.0));
205  Simulator::Schedule (warmup + moveBackTime, &Issue211Test::CalcThroughput, this,
206  DynamicCast<UdpServer> (serverApp.Get (0)));
207 
208  // Last check-point: simulation finish time
209  Simulator::Schedule (warmup + simulationTime, &Issue211Test::CalcThroughput, this,
210  DynamicCast<UdpServer> (serverApp.Get (0)));
211 
212  Simulator::Stop (warmup + simulationTime);
213  Simulator::Run ();
214 
215  NS_TEST_EXPECT_MSG_EQ (m_tputValues.size (), 3, "Unexpected number of throughput values");
216  NS_TEST_EXPECT_MSG_GT (m_tputValues[0], 0, "Throughput must be non null before station moves away");
217  NS_TEST_EXPECT_MSG_EQ (m_tputValues[1], 0,"Throughput must be null while the station is away");
218  NS_TEST_EXPECT_MSG_GT (m_tputValues[2], 0, "Throughput must be non null when the station is back");
219 
220  // Print throughput values when the test is run through test-runner
221  for (const auto& t : m_tputValues)
222  {
223  std::cout << "Throughput = " << t << " Mb/s" << std::endl;
224  }
225 
226  Simulator::Destroy ();
227 }
228 
236 {
237 public:
239 };
240 
242  : TestSuite ("wifi-issue-211", UNIT)
243 {
244  AddTestCase (new Issue211Test, TestCase::QUICK);
245 }
246 
ns3::SpectrumChannel::SetPropagationDelayModel
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
Definition: spectrum-channel.cc:139
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::WIFI_STANDARD_80211n_5GHZ
@ WIFI_STANDARD_80211n_5GHZ
Definition: wifi-standards.h:132
ns3::ApplicationContainer::Get
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Definition: application-container.cc:62
ns3::UdpClientHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Definition: udp-client-server-helper.cc:87
ns3::UdpClientHelper
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Definition: udp-client-server-helper.h:94
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::UdpServer::GetReceived
uint64_t GetReceived(void) const
Returns the number of received packets.
Definition: udp-server.cc:106
ns3::ListPositionAllocator::Add
void Add(Vector v)
Add a position to the list of positions.
Definition: position-allocator.cc:70
third.staDevices
staDevices
Definition: third.py:103
Issue211Test::~Issue211Test
virtual ~Issue211Test()
Definition: wifi-issue-211-test-suite.cc:90
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
ns3::SpectrumChannel::AddPropagationLossModel
void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add the single-frequency propagation loss model to be used.
Definition: spectrum-channel.cc:117
SetPosition
static void SetPosition(Ptr< Node > node, Vector position)
Definition: wifi-ap.cc:89
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
Issue211Test::m_payloadSize
uint32_t m_payloadSize
payload size in bytes
Definition: wifi-issue-211-test-suite.cc:79
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
third.mac
mac
Definition: third.py:99
Issue211TestSuite::Issue211TestSuite
Issue211TestSuite()
Definition: wifi-issue-211-test-suite.cc:241
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
ns3::UdpServerHelper
Create a server application which waits for input UDP packets and uses the information carried into t...
Definition: udp-client-server-helper.h:38
Issue211Test::m_tputValues
std::vector< double > m_tputValues
throughput in sub-intervals
Definition: wifi-issue-211-test-suite.cc:76
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::QueueSizeValue
Definition: queue-size.h:221
third.apDevices
apDevices
Definition: third.py:106
third.wifi
wifi
Definition: third.py:96
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
NS_TEST_EXPECT_MSG_GT
#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:1088
first.stack
stack
Definition: first.py:41
Issue211Test::m_lastRxBytes
uint64_t m_lastRxBytes
RX bytes at last check-point.
Definition: wifi-issue-211-test-suite.cc:77
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1297
g_issue211TestSuite
static Issue211TestSuite g_issue211TestSuite
the test suite
Definition: wifi-issue-211-test-suite.cc:247
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
first.address
address
Definition: first.py:44
NS_TEST_EXPECT_MSG_EQ
#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:283
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
third.wifiApNode
wifiApNode
Definition: third.py:90
Issue211Test::CalcThroughput
void CalcThroughput(Ptr< UdpServer > server)
Compute the average throughput since the last check-point.
Definition: wifi-issue-211-test-suite.cc:95
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
Issue211Test::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: wifi-issue-211-test-suite.cc:105
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Issue211Test::m_lastCheckPointTime
Time m_lastCheckPointTime
time of last check-point
Definition: wifi-issue-211-test-suite.cc:78
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
ns3::UdpClientHelper::Install
ApplicationContainer Install(NodeContainer c)
Definition: udp-client-server-helper.cc:93
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::UdpServerHelper::Install
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
Definition: udp-client-server-helper.cc:47
Issue211Test::Issue211Test
Issue211Test()
Constructor.
Definition: wifi-issue-211-test-suite.cc:82
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition: mobility-model.h:40
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
ns3::QueueSize
Class for representing queue sizes.
Definition: queue-size.h:95
Issue211Test
Test for issue 211 (https://gitlab.com/nsnam/ns-3-dev/-/issues/211)
Definition: wifi-issue-211-test-suite.cc:59
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
Issue211TestSuite
Block Ack Test Suite.
Definition: wifi-issue-211-test-suite.cc:236
ns3::SpectrumWifiPhyHelper
Make it easy to create and manage PHY objects for the spectrum model.
Definition: spectrum-wifi-helper.h:38
third.mobility
mobility
Definition: third.py:108
third.phy
phy
Definition: third.py:93
port
uint16_t port
Definition: dsdv-manet.cc:45