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 * 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 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20#include "ns3/interference-helper.h"
21#include "ns3/log.h"
22#include "ns3/nist-error-rate-model.h"
23#include "ns3/ofdm-phy.h"
24#include "ns3/ofdm-ppdu.h"
25#include "ns3/spectrum-wifi-helper.h"
26#include "ns3/spectrum-wifi-phy.h"
27#include "ns3/test.h"
28#include "ns3/wifi-mac-header.h"
29#include "ns3/wifi-psdu.h"
30#include "ns3/wifi-spectrum-signal-parameters.h"
31#include "ns3/wifi-spectrum-value-helper.h"
32#include "ns3/wifi-utils.h"
33
34using namespace ns3;
35
36NS_LOG_COMPONENT_DEFINE("WifiPhyThresholdsTest");
37
38static const uint8_t CHANNEL_NUMBER = 36;
39static const uint32_t FREQUENCY = 5180; // MHz
40static const uint16_t CHANNEL_WIDTH = 20; // MHz
41
49{
50 public:
56 WifiPhyThresholdsTest(std::string test_name);
60 ~WifiPhyThresholdsTest() override;
61
62 protected:
68 virtual Ptr<SpectrumSignalParameters> MakeWifiSignal(double txPowerWatts);
74 virtual Ptr<SpectrumSignalParameters> MakeForeignSignal(double txPowerWatts);
80 virtual void SendSignal(double txPowerWatts, bool wifiSignal);
88 virtual void RxSuccess(Ptr<const WifiPsdu> psdu,
89 RxSignalInfo rxSignalInfo,
90 WifiTxVector txVector,
91 std::vector<bool> statusPerMpdu);
96 virtual void RxFailure(Ptr<const WifiPsdu> psdu);
109 virtual void PhyStateChanged(Time start, Time duration, WifiPhyState newState);
110
119
120 private:
121 void DoSetup() override;
122 void DoTeardown() override;
123};
124
126 : TestCase(test_name),
127 m_rxSuccess(0),
128 m_rxFailure(0),
129 m_rxDropped(0),
130 m_stateChanged(0),
131 m_rxStateCount(0),
132 m_idleStateCount(0),
133 m_ccabusyStateCount(0)
134{
135}
136
138{
139}
140
143{
144 WifiTxVector txVector =
145 WifiTxVector(OfdmPhy::GetOfdmRate6Mbps(), 0, WIFI_PREAMBLE_LONG, 800, 1, 1, 0, 20, false);
146
147 Ptr<Packet> pkt = Create<Packet>(1000);
148 WifiMacHeader hdr;
149
151 hdr.SetQosTid(0);
152
153 Ptr<WifiPsdu> psdu = Create<WifiPsdu>(pkt, hdr);
154 Time txDuration = m_phy->CalculateTxDuration(psdu->GetSize(), txVector, m_phy->GetPhyBand());
155
156 Ptr<WifiPpdu> ppdu = Create<OfdmPpdu>(psdu, txVector, FREQUENCY, WIFI_PHY_BAND_5GHZ, 0);
157
158 Ptr<SpectrumValue> txPowerSpectrum =
161 txPowerWatts,
163 Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters>();
164 txParams->psd = txPowerSpectrum;
165 txParams->txPhy = nullptr;
166 txParams->duration = txDuration;
167 txParams->ppdu = ppdu;
168 txParams->txWidth = CHANNEL_WIDTH;
169 return txParams;
170}
171
174{
175 Ptr<SpectrumValue> txPowerSpectrum =
178 txPowerWatts,
180 Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters>();
181 txParams->psd = txPowerSpectrum;
182 txParams->txPhy = nullptr;
183 txParams->duration = Seconds(0.5);
184 return txParams;
185}
186
187void
188WifiPhyThresholdsTest::SendSignal(double txPowerWatts, bool wifiSignal)
189{
190 if (wifiSignal)
191 {
192 m_phy->StartRx(MakeWifiSignal(txPowerWatts));
193 }
194 else
195 {
196 m_phy->StartRx(MakeForeignSignal(txPowerWatts));
197 }
198}
199
200void
202 RxSignalInfo rxSignalInfo,
203 WifiTxVector txVector,
204 std::vector<bool> statusPerMpdu)
205{
206 NS_LOG_FUNCTION(this << *psdu << rxSignalInfo << txVector);
207 m_rxSuccess++;
208}
209
210void
212{
213 NS_LOG_FUNCTION(this << *psdu);
214 m_rxFailure++;
215}
216
217void
219{
220 NS_LOG_FUNCTION(this << p << reason);
221 m_rxDropped++;
222}
223
224void
226{
227 NS_LOG_FUNCTION(this << start << duration << newState);
229 if (newState == WifiPhyState::IDLE)
230 {
232 }
233 else if (newState == WifiPhyState::RX)
234 {
236 }
237 else if (newState == WifiPhyState::CCA_BUSY)
238 {
240 }
241}
242
243void
245{
246 m_phy = CreateObject<SpectrumWifiPhy>();
248 Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper>();
249 m_phy->SetInterferenceHelper(interferenceHelper);
250 Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel>();
251 m_phy->SetErrorRateModel(error);
257 m_phy->GetState()->TraceConnectWithoutContext(
258 "State",
260}
261
262void
264{
265 m_phy->Dispose();
266 m_phy = nullptr;
267}
268
279{
280 public:
283 void DoRun() override;
284};
285
287 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak wifi signal reception")
288{
289}
290
292{
293}
294
295void
297{
298 double txPowerWatts = DbmToW(-110);
299
302 this,
303 txPowerWatts,
304 true);
305
308
310 0,
311 "Reception should not have been triggered if packet is weaker than "
312 "RxSensitivity threshold");
314 0,
315 "State should stay idle if reception involves a signal weaker than "
316 "RxSensitivity threshold");
317}
318
329{
330 public:
333 void DoRun() override;
334};
335
337 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak foreign signal reception")
338{
339}
340
342{
343}
344
345void
347{
348 double txPowerWatts = DbmToW(-90);
349
352 this,
353 txPowerWatts,
354 false);
355
358
360 0,
361 "Reception of non-wifi packet should not be triggered");
363 0,
364 "State should stay idle if reception involves a signal weaker than "
365 "RxSensitivity threshold");
366}
367
378{
379 public:
382 void DoRun() override;
383};
384
386 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test strong wifi signal reception")
387{
388}
389
391{
392}
393
394void
396{
397 double txPowerWatts = DbmToW(-60);
398
401 this,
402 txPowerWatts,
403 true);
404
407
409 0,
410 "Packet reception should have been successful");
411 NS_TEST_ASSERT_MSG_EQ(m_rxSuccess, 1, "Packet should have been successfully received");
412 NS_TEST_ASSERT_MSG_EQ(m_ccabusyStateCount, 2, "State should have moved to CCA_BUSY once");
415 4,
416 "State should have moved to CCA_BUSY, then to RX and finally back to IDLE");
417 NS_TEST_ASSERT_MSG_EQ(m_rxStateCount, 1, "State should have moved to RX once");
418 NS_TEST_ASSERT_MSG_EQ(m_idleStateCount, 1, "State should have moved to IDLE once");
419}
420
431{
432 public:
435 void DoRun() override;
436};
437
439 : WifiPhyThresholdsTest("WifiPhy reception thresholds: test weak foreign signal reception")
440{
441}
442
444{
445}
446
447void
449{
450 double txPowerWatts = DbmToW(-60);
451
454 this,
455 txPowerWatts,
456 false);
457
460
462 0,
463 "Reception of non-wifi packet should not be triggered");
465 1,
466 "State should have moved to CCA-BUSY then back to IDLE");
467}
468
476{
477 public:
479};
480
482 : TestSuite("wifi-phy-thresholds", UNIT)
483{
488}
489
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 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
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.
~WifiPhyThresholdsTest() override
Destructor.
uint32_t m_stateChanged
count number of PHY state change
uint32_t m_rxFailure
count number of unsuccessfuly 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 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.
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.
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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:311
void Dispose()
Dispose of this Object.
Definition: object.cc:219
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6 Mbps.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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 void Run()
Run the simulation.
Definition: simulator.cc:176
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: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
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:624
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
Definition: wifi-phy.cc:632
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:448
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:941
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1480
Ptr< WifiPhyStateHelper > GetState() const
Return the WifiPhyStateHelper of this PHY.
Definition: wifi-phy.cc:436
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:1062
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:996
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:442
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:870
static Ptr< SpectrumValue > CreateHeOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth, double minInnerBandDbr=-20, double minOuterbandDbr=-28, double lowestPointDbr=-40, const std::vector< bool > &puncturedSubchannels=std::vector< bool >{})
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:202
#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:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
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:707
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:40
@ WIFI_MAC_QOSDATA
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:70
WifiPhyState
The state of the PHY layer.
static const uint8_t CHANNEL_NUMBER
static WifiPhyThresholdsTestSuite wifiPhyThresholdsTestSuite
the test suite
static const uint16_t CHANNEL_WIDTH
static const uint32_t FREQUENCY