A Discrete-Event Network Simulator
API
wifi-phy-thresholds-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2018
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: S├ębastien Deronne <sebastien.deronne@gmail.com>
19 */
20
21#include "ns3/log.h"
22#include "ns3/test.h"
23#include "ns3/spectrum-wifi-helper.h"
24#include "ns3/wifi-spectrum-value-helper.h"
25#include "ns3/spectrum-wifi-phy.h"
26#include "ns3/interference-helper.h"
27#include "ns3/nist-error-rate-model.h"
28#include "ns3/wifi-mac-header.h"
29#include "ns3/wifi-spectrum-signal-parameters.h"
30#include "ns3/wifi-utils.h"
31#include "ns3/wifi-psdu.h"
32#include "ns3/ofdm-ppdu.h"
33#include "ns3/ofdm-phy.h"
34
35using namespace ns3;
36
37NS_LOG_COMPONENT_DEFINE ("WifiPhyThresholdsTest");
38
39static const uint8_t CHANNEL_NUMBER = 36;
40static const uint32_t FREQUENCY = 5180; //MHz
41static const uint16_t CHANNEL_WIDTH = 20; //MHz
42
50{
51public:
57 WifiPhyThresholdsTest (std::string test_name);
61 virtual ~WifiPhyThresholdsTest ();
62
63protected:
69 virtual Ptr<SpectrumSignalParameters> MakeWifiSignal (double txPowerWatts);
75 virtual Ptr<SpectrumSignalParameters> MakeForeignSignal (double txPowerWatts);
81 virtual void SendSignal (double txPowerWatts, bool wifiSignal);
89 virtual void RxSuccess (Ptr<const WifiPsdu> psdu, RxSignalInfo rxSignalInfo,
90 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
95 virtual void RxFailure (Ptr<const WifiPsdu> psdu);
108 virtual void PhyStateChanged (Time start, Time duration, WifiPhyState newState);
109
118
119private:
120 void DoSetup (void) override;
121 void DoTeardown (void) override;
122};
123
125 : TestCase (test_name),
126 m_rxSuccess (0),
127 m_rxFailure (0),
128 m_rxDropped (0),
129 m_stateChanged (0),
130 m_rxStateCount (0),
131 m_idleStateCount (0),
132 m_ccabusyStateCount (0)
133{
134}
135
137{
138}
139
142{
143 WifiTxVector txVector = WifiTxVector (OfdmPhy::GetOfdmRate6Mbps (), 0, WIFI_PREAMBLE_LONG, 800, 1, 1, 0, 20, false);
144
145 Ptr<Packet> pkt = Create<Packet> (1000);
146 WifiMacHeader hdr;
147
149 hdr.SetQosTid (0);
150
151 Ptr<WifiPsdu> psdu = Create<WifiPsdu> (pkt, hdr);
152 Time txDuration = m_phy->CalculateTxDuration (psdu->GetSize (), txVector, m_phy->GetPhyBand ());
153
154 Ptr<WifiPpdu> ppdu = Create<OfdmPpdu> (psdu, txVector, FREQUENCY, WIFI_PHY_BAND_5GHZ, 0);
155
156 Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH);
157 Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> ();
158 txParams->psd = txPowerSpectrum;
159 txParams->txPhy = 0;
160 txParams->duration = txDuration;
161 txParams->ppdu = ppdu;
162 return txParams;
163}
164
167{
168 Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH);
169 Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> ();
170 txParams->psd = txPowerSpectrum;
171 txParams->txPhy = 0;
172 txParams->duration = Seconds (0.5);
173 return txParams;
174}
175
176void
177WifiPhyThresholdsTest::SendSignal (double txPowerWatts, bool wifiSignal)
178{
179 if (wifiSignal)
180 {
181 m_phy->StartRx (MakeWifiSignal (txPowerWatts));
182 }
183 else
184 {
185 m_phy->StartRx (MakeForeignSignal (txPowerWatts));
186 }
187}
188
189void
191 WifiTxVector txVector, std::vector<bool> statusPerMpdu)
192{
193 NS_LOG_FUNCTION (this << *psdu << rxSignalInfo << txVector);
194 m_rxSuccess++;
195}
196
197void
199{
200 NS_LOG_FUNCTION (this << *psdu);
201 m_rxFailure++;
202}
203
204void
206{
207 NS_LOG_FUNCTION (this << p << reason);
208 m_rxDropped++;
209}
210
211void
213{
214 NS_LOG_FUNCTION (this << start << duration << newState);
216 if (newState == WifiPhyState::IDLE)
217 {
219 }
220 else if (newState == WifiPhyState::RX)
221 {
223 }
224 else if (newState == WifiPhyState::CCA_BUSY)
225 {
227 }
228}
229
230void
232{
233 m_phy = CreateObject<SpectrumWifiPhy> ();
235 Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper> ();
236 m_phy->SetInterferenceHelper (interferenceHelper);
237 Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
238 m_phy->SetErrorRateModel (error);
243 m_phy->GetState ()->TraceConnectWithoutContext ("State", MakeCallback (&WifiPhyThresholdsTest::PhyStateChanged, this));
244}
245
246void
248{
249 m_phy->Dispose ();
250 m_phy = 0;
251}
252
263{
264public:
267 virtual void DoRun (void);
268};
269
271 : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak wifi signal reception")
272{
273}
274
276{
277}
278
279void
281{
282 double txPowerWatts = DbmToW (-110);
283
284 Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakWifiSignalTest::SendSignal, this, txPowerWatts, true);
285
286 Simulator::Run ();
287 Simulator::Destroy ();
288
289 NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception should not have been triggered if packet is weaker than RxSensitivity threshold");
290 NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold");
291}
292
303{
304public:
307 virtual void DoRun (void);
308};
309
311 : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception")
312{
313}
314
316{
317}
318
319void
321{
322 double txPowerWatts = DbmToW (-90);
323
324 Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakForeignSignalTest::SendSignal, this, txPowerWatts, false);
325
326 Simulator::Run ();
327 Simulator::Destroy ();
328
329 NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered");
330 NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold");
331}
332
343{
344public:
347 virtual void DoRun (void);
348};
349
351 : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test strong wifi signal reception")
352{
353}
354
356{
357}
358
359void
361{
362 double txPowerWatts = DbmToW (-60);
363
364 Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongWifiSignalTest::SendSignal, this, txPowerWatts, true);
365
366 Simulator::Run ();
367 Simulator::Destroy ();
368
369 NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxFailure, 0, "Packet reception should have been successfull");
370 NS_TEST_ASSERT_MSG_EQ (m_rxSuccess, 1, "Packet should have been successfully received");
371 NS_TEST_ASSERT_MSG_EQ (m_ccabusyStateCount, 2, "State should have moved to CCA_BUSY once");
372 NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 4, "State should have moved to CCA_BUSY, then to RX and finally back to IDLE");
373 NS_TEST_ASSERT_MSG_EQ (m_rxStateCount, 1, "State should have moved to RX once");
374 NS_TEST_ASSERT_MSG_EQ (m_idleStateCount, 1, "State should have moved to IDLE once");
375}
376
387{
388public:
391 virtual void DoRun (void);
392};
393
395 : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception")
396{
397}
398
400{
401}
402
403void
405{
406 double txPowerWatts = DbmToW (-60);
407
408 Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongForeignSignalTest::SendSignal, this, txPowerWatts, false);
409
410 Simulator::Run ();
411 Simulator::Destroy ();
412
413 NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered");
414 NS_TEST_ASSERT_MSG_EQ (m_idleStateCount, 1, "State should have moved to CCA-BUSY then back to IDLE");
415}
416
424{
425public:
427};
428
430 : TestSuite ("wifi-phy-thresholds", UNIT)
431{
436}
437
Wifi Phy Threshold Strong Foreign Signal Test.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Wifi Phy Threshold Strong Wifi Signal Test.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Wifi Phy Threshold Test base class.
uint32_t m_rxDropped
count number of dropped packets
virtual Ptr< SpectrumSignalParameters > MakeWifiSignal(double txPowerWatts)
Make wifi signal function.
uint32_t m_ccabusyStateCount
count number of PHY state change to CCA_BUSY state
uint32_t m_idleStateCount
count number of PHY state change to IDLE state
uint32_t m_rxStateCount
count number of PHY state change to RX state
virtual ~WifiPhyThresholdsTest()
Destructor.
virtual void PhyStateChanged(Time start, Time duration, WifiPhyState newState)
PHY state changed callback function.
uint32_t m_stateChanged
count number of PHY state change
uint32_t m_rxFailure
count number of unsuccessfully received packets
virtual void RxFailure(Ptr< const WifiPsdu > psdu)
PHY receive failure callback function.
virtual Ptr< SpectrumSignalParameters > MakeForeignSignal(double txPowerWatts)
Make foreign signal function.
void DoSetup(void) override
Implementation to do any local setup required for this TestCase.
void RxDropped(Ptr< const Packet > p, WifiPhyRxfailureReason reason)
PHY dropped packet callback function.
Ptr< SpectrumWifiPhy > m_phy
PHY object.
void DoTeardown(void) override
Implementation to do any local setup required for this TestCase.
virtual void RxSuccess(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
PHY receive success callback function.
virtual void SendSignal(double txPowerWatts, bool wifiSignal)
Send signal function.
WifiPhyThresholdsTest(std::string test_name)
Constructor.
uint32_t m_rxSuccess
count number of successfully received packets
Wifi Phy Thresholds Test Suite.
Wifi Phy Threshold Weak Foreign Signal Test.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Wifi Phy Threshold Weak Wifi Signal Test.
virtual void DoRun(void)
Implementation to actually run this TestCase.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Implements the IEEE 802.11 MAC header.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
virtual void SetInterferenceHelper(const Ptr< InterferenceHelper > helper)
Sets the interference helper.
Definition: wifi-phy.cc:600
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
Definition: wifi-phy.cc:608
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:938
Ptr< WifiPhyStateHelper > GetState(void) const
Return the WifiPhyStateHelper of this PHY.
Definition: wifi-phy.cc:405
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:417
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:883
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1389
void SetOperatingChannel(const ChannelTuple &channelTuple)
If the standard for this object has not been set yet, store the given channel settings.
Definition: wifi-phy.cc:993
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:411
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:839
uint32_t GetSize(void) const
Return the size of the PSDU in bytes.
Definition: wifi-psdu.cc:260
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
@ WIFI_STANDARD_80211ax
@ WIFI_PREAMBLE_LONG
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:661
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:37
@ WIFI_MAC_QOSDATA
def start()
Definition: core.py:1852
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
Time duration
The duration of the packet transmission.
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ RX
The PHY layer is receiving a packet.
@ IDLE
The PHY layer is IDLE.
static const uint8_t CHANNEL_NUMBER
static WifiPhyThresholdsTestSuite wifiPhyThresholdsTestSuite
the test suite
static const uint16_t CHANNEL_WIDTH
static const uint32_t FREQUENCY