A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-phy-thresholds-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "ns3/interference-helper.h"
10#include "ns3/log.h"
11#include "ns3/multi-model-spectrum-channel.h"
12#include "ns3/nist-error-rate-model.h"
13#include "ns3/ofdm-phy.h"
14#include "ns3/ofdm-ppdu.h"
15#include "ns3/spectrum-phy.h"
16#include "ns3/spectrum-wifi-helper.h"
17#include "ns3/spectrum-wifi-phy.h"
18#include "ns3/test.h"
19#include "ns3/wifi-mac-header.h"
20#include "ns3/wifi-net-device.h"
21#include "ns3/wifi-psdu.h"
22#include "ns3/wifi-spectrum-phy-interface.h"
23#include "ns3/wifi-spectrum-signal-parameters.h"
24#include "ns3/wifi-spectrum-value-helper.h"
25#include "ns3/wifi-utils.h"
26
27using namespace ns3;
28
29NS_LOG_COMPONENT_DEFINE("WifiPhyThresholdsTest");
30
31static const uint8_t CHANNEL_NUMBER = 36;
32static const MHz_u FREQUENCY = 5180;
33static const MHz_u CHANNEL_WIDTH = 20;
34
35/**
36 * \ingroup wifi-test
37 * \ingroup tests
38 *
39 * \brief Wifi Phy Threshold Test base class
40 */
42{
43 public:
44 /**
45 * Constructor
46 *
47 * \param test_name the test name
48 */
49 WifiPhyThresholdsTest(std::string test_name);
50
51 protected:
52 /**
53 * Make wifi signal function
54 * \param txPower the transmit power
55 * \param channel the operating channel of the PHY used for the transmission
56 * \returns Ptr<SpectrumSignalParameters>
57 */
59 const WifiPhyOperatingChannel& channel);
60 /**
61 * Make foreign signal function
62 * \param txPower the transmit power
63 * \returns Ptr<SpectrumSignalParameters>
64 */
66 /**
67 * Send signal function
68 * \param txPower the transmit power
69 * \param wifiSignal whether the signal is a wifi signal or not
70 */
71 virtual void SendSignal(Watt_u txPower, bool wifiSignal);
72 /**
73 * PHY receive success callback function
74 * \param psdu the PSDU
75 * \param rxSignalInfo the info on the received signal (\see RxSignalInfo)
76 * \param txVector the transmit vector
77 * \param statusPerMpdu reception status per MPDU
78 */
79 virtual void RxSuccess(Ptr<const WifiPsdu> psdu,
80 RxSignalInfo rxSignalInfo,
81 WifiTxVector txVector,
82 std::vector<bool> statusPerMpdu);
83 /**
84 * PHY receive failure callback function
85 * \param psdu the PSDU
86 */
87 virtual void RxFailure(Ptr<const WifiPsdu> psdu);
88 /**
89 * PHY dropped packet callback function
90 * \param p the packet
91 * \param reason the reason
92 */
94 /**
95 * PHY state changed callback function
96 * \param start the start time of the new state
97 * \param duration the duration of the new state
98 * \param newState the new state
99 */
100 virtual void PhyStateChanged(Time start, Time duration, WifiPhyState newState);
101
103 uint32_t m_rxSuccess; ///< count number of successfully received packets
104 uint32_t m_rxFailure; ///< count number of unsuccessfuly received packets
105 uint32_t m_rxDropped; ///< count number of dropped packets
106 uint32_t m_stateChanged; ///< count number of PHY state change
107 uint32_t m_rxStateCount; ///< count number of PHY state change to RX state
108 uint32_t m_idleStateCount; ///< count number of PHY state change to IDLE state
109 uint32_t m_ccabusyStateCount; ///< count number of PHY state change to CCA_BUSY state
110
111 private:
112 void DoSetup() override;
113 void DoTeardown() override;
114};
115
117 : TestCase(test_name),
118 m_rxSuccess(0),
119 m_rxFailure(0),
120 m_rxDropped(0),
121 m_stateChanged(0),
122 m_rxStateCount(0),
123 m_idleStateCount(0),
124 m_ccabusyStateCount(0)
125{
126}
127
130{
132 0,
134 NanoSeconds(800),
135 1,
136 1,
137 0,
139 false};
140
141 auto pkt = Create<Packet>(1000);
142 WifiMacHeader hdr;
143
145 hdr.SetQosTid(0);
146
147 auto psdu = Create<WifiPsdu>(pkt, hdr);
148 const auto txDuration =
149 m_phy->CalculateTxDuration(psdu->GetSize(), txVector, m_phy->GetPhyBand());
150
151 auto ppdu = Create<OfdmPpdu>(psdu, txVector, channel, 0);
152
154 channel.GetPrimaryChannelCenterFrequency(CHANNEL_WIDTH),
156 txPower,
158 auto txParams = Create<WifiSpectrumSignalParameters>();
159 txParams->psd = txPowerSpectrum;
160 txParams->txPhy = nullptr;
161 txParams->duration = txDuration;
162 txParams->ppdu = ppdu;
163 return txParams;
164}
165
168{
169 auto txPowerSpectrum =
172 txPower,
174 auto txParams = Create<SpectrumSignalParameters>();
175 txParams->psd = txPowerSpectrum;
176 txParams->txPhy = nullptr;
177 txParams->duration = Seconds(0.5);
178 return txParams;
179}
180
181void
183{
184 if (wifiSignal)
185 {
186 m_phy->StartRx(MakeWifiSignal(txPower, m_phy->GetOperatingChannel()), nullptr);
187 }
188 else
189 {
190 m_phy->StartRx(MakeForeignSignal(txPower), nullptr);
191 }
192}
193
194void
196 RxSignalInfo rxSignalInfo,
197 WifiTxVector txVector,
198 std::vector<bool> statusPerMpdu)
199{
200 NS_LOG_FUNCTION(this << *psdu << rxSignalInfo << txVector);
201 m_rxSuccess++;
202}
203
204void
210
211void
217
218void
220{
221 NS_LOG_FUNCTION(this << start << duration << newState);
223 if (newState == WifiPhyState::IDLE)
224 {
226 }
227 else if (newState == WifiPhyState::RX)
228 {
230 }
231 else if (newState == WifiPhyState::CCA_BUSY)
232 {
234 }
235}
236
237void
239{
240 auto spectrumChannel = CreateObject<MultiModelSpectrumChannel>();
241 auto node = CreateObject<Node>();
242 auto dev = CreateObject<WifiNetDevice>();
244 auto interferenceHelper = CreateObject<InterferenceHelper>();
245 m_phy->SetInterferenceHelper(interferenceHelper);
247 m_phy->SetErrorRateModel(error);
248 m_phy->SetDevice(dev);
249 m_phy->AddChannel(spectrumChannel);
250 m_phy->SetOperatingChannel(WifiPhy::ChannelTuple{CHANNEL_NUMBER, 0, WIFI_PHY_BAND_5GHZ, 0});
251 m_phy->ConfigureStandard(WIFI_STANDARD_80211ax);
252 m_phy->SetReceiveOkCallback(MakeCallback(&WifiPhyThresholdsTest::RxSuccess, this));
253 m_phy->SetReceiveErrorCallback(MakeCallback(&WifiPhyThresholdsTest::RxFailure, this));
254 m_phy->TraceConnectWithoutContext("PhyRxDrop",
256 m_phy->GetState()->TraceConnectWithoutContext(
257 "State",
259 dev->SetPhy(m_phy);
260 node->AddDevice(dev);
261}
262
263void
265{
266 m_phy->Dispose();
267 m_phy = nullptr;
268}
269
270/**
271 * \ingroup wifi-test
272 * \ingroup tests
273 *
274 * \brief Wifi Phy Threshold Weak Wifi Signal Test
275 *
276 * This test makes sure PHY ignores a Wi-Fi signal
277 * if its received power lower than RxSensitivity.
278 */
280{
281 public:
283 void DoRun() override;
284};
285
287 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak wifi signal reception")
288{
289}
290
291void
293{
294 const auto txPower = DbmToW(-110);
295
298 this,
299 txPower,
300 true);
301
304
306 0,
307 "Reception should not have been triggered if packet is weaker than "
308 "RxSensitivity threshold");
310 0,
311 "State should stay idle if reception involves a signal weaker than "
312 "RxSensitivity threshold");
313}
314
315/**
316 * \ingroup wifi-test
317 * \ingroup tests
318 *
319 * \brief Wifi Phy Threshold Weak Foreign Signal Test
320 *
321 * This test makes sure PHY keeps the state as IDLE if reception involves
322 * a foreign signal with a received power lower than CcaEdThreshold.
323 */
331
333 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak foreign signal reception")
334{
335}
336
340
341void
343{
344 const auto txPower = DbmToW(-90);
345
348 this,
349 txPower,
350 false);
351
354
356 0,
357 "Reception of non-wifi packet should not be triggered");
359 0,
360 "State should stay idle if reception involves a signal weaker than "
361 "RxSensitivity threshold");
362}
363
364/**
365 * \ingroup wifi-test
366 * \ingroup tests
367 *
368 * \brief Wifi Phy Threshold Strong Wifi Signal Test
369 *
370 * This test makes sure PHY processes a Wi-Fi signal
371 * with a received power higher than RxSensitivity.
372 */
380
382 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test strong wifi signal reception")
383{
384}
385
389
390void
392{
393 const auto txPower = DbmToW(-60);
394
397 this,
398 txPower,
399 true);
400
403
405 0,
406 "Packet reception should have been successful");
407 NS_TEST_ASSERT_MSG_EQ(m_rxSuccess, 1, "Packet should have been successfully received");
408 NS_TEST_ASSERT_MSG_EQ(m_ccabusyStateCount, 2, "State should have moved to CCA_BUSY once");
411 4,
412 "State should have moved to CCA_BUSY, then to RX and finally back to IDLE");
413 NS_TEST_ASSERT_MSG_EQ(m_rxStateCount, 1, "State should have moved to RX once");
414 NS_TEST_ASSERT_MSG_EQ(m_idleStateCount, 1, "State should have moved to IDLE once");
415}
416
417/**
418 * \ingroup wifi-test
419 * \ingroup tests
420 *
421 * \brief Wifi Phy Threshold Strong Foreign Signal Test
422 *
423 * This test makes sure PHY declare the state as CCA_BUSY if reception involves
424 * a foreign signal with a received power higher than CcaEdThreshold.
425 */
433
435 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak foreign signal reception")
436{
437}
438
442
443void
445{
446 const auto txPower = DbmToW(-60);
447
450 this,
451 txPower,
452 false);
453
456
458 0,
459 "Reception of non-wifi packet should not be triggered");
461 1,
462 "State should have moved to CCA-BUSY then back to IDLE");
463}
464
465/**
466 * \ingroup wifi-test
467 * \ingroup tests
468 *
469 * \brief Wifi Phy Thresholds Test Suite
470 */
472{
473 public:
475};
476
478 : TestSuite("wifi-phy-thresholds", Type::UNIT)
479{
480 AddTestCase(new WifiPhyThresholdsWeakWifiSignalTest, TestCase::Duration::QUICK);
481 AddTestCase(new WifiPhyThresholdsWeakForeignSignalTest, TestCase::Duration::QUICK);
482 AddTestCase(new WifiPhyThresholdsStrongWifiSignalTest, TestCase::Duration::QUICK);
483 AddTestCase(new WifiPhyThresholdsStrongForeignSignalTest, TestCase::Duration::QUICK);
484}
485
Wifi Phy Threshold Strong Foreign Signal Test.
void DoRun() override
Implementation to actually run this TestCase.
Wifi Phy Threshold Strong Wifi Signal Test.
void DoRun() override
Implementation to actually run this TestCase.
Wifi Phy Threshold Test base class.
uint32_t m_rxDropped
count number of dropped packets
virtual void SendSignal(Watt_u txPower, bool wifiSignal)
Send 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 Ptr< SpectrumSignalParameters > MakeForeignSignal(Watt_u txPower)
Make foreign signal function.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
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 unsuccessfuly received packets
virtual Ptr< SpectrumSignalParameters > MakeWifiSignal(Watt_u txPower, const WifiPhyOperatingChannel &channel)
Make wifi signal function.
virtual void RxFailure(Ptr< const WifiPsdu > psdu)
PHY receive failure callback function.
void RxDropped(Ptr< const Packet > p, WifiPhyRxfailureReason reason)
PHY dropped packet callback function.
Ptr< SpectrumWifiPhy > m_phy
PHY object.
void DoSetup() 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.
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.
void DoRun() override
Implementation to actually run this TestCase.
Wifi Phy Threshold Weak Wifi Signal Test.
void DoRun() override
Implementation to actually run this TestCase.
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6 Mbps.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Implements the IEEE 802.11 MAC header.
virtual 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.
std::tuple< uint8_t, MHz_u, WifiPhyBand, uint8_t > ChannelTuple
Tuple identifying a segment of an operating channel.
Definition wifi-phy.h:919
Class that keeps track of all information about the current PHY operating channel.
static Ptr< SpectrumValue > CreateHeOfdmTxPowerSpectralDensity(MHz_u centerFrequency, MHz_u channelWidth, Watt_u txPower, MHz_u guardBandwidth, dBr_u minInnerBand=-20, dBr_u minOuterband=-28, dBr_u lowestPoint=-40, const std::vector< bool > &puncturedSubchannels={})
Create a transmit power spectral density corresponding to OFDM High Efficiency (HE) (802....
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:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:134
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
@ WIFI_STANDARD_80211ax
@ WIFI_PREAMBLE_LONG
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
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:684
@ WIFI_MAC_QOSDATA
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:31
RxSignalInfo structure containing info on the received signal.
Definition wifi-types.h:72
static const uint8_t CHANNEL_NUMBER
static const MHz_u FREQUENCY
static WifiPhyThresholdsTestSuite wifiPhyThresholdsTestSuite
the test suite
static const MHz_u CHANNEL_WIDTH