|
|
|
|
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/nist-error-rate-model.h" |
| 27 |
#include "ns3/wifi-mac-header.h" |
| 28 |
#include "ns3/wifi-mac-trailer.h" |
| 29 |
#include "ns3/wifi-phy-tag.h" |
| 30 |
#include "ns3/wifi-spectrum-signal-parameters.h" |
| 31 |
#include "ns3/wifi-utils.h" |
| 32 |
|
| 33 |
using namespace ns3; |
| 34 |
|
| 35 |
NS_LOG_COMPONENT_DEFINE ("WifiPhyThresholdsTest"); |
| 36 |
|
| 37 |
static const uint8_t CHANNEL_NUMBER = 36; |
| 38 |
static const uint32_t FREQUENCY = 5180; //MHz |
| 39 |
static const uint16_t CHANNEL_WIDTH = 20; //MHz |
| 40 |
|
| 41 |
/** |
| 42 |
* \ingroup wifi-test |
| 43 |
* \ingroup tests |
| 44 |
* |
| 45 |
* \brief Wifi Phy Threshold Test base class |
| 46 |
*/ |
| 47 |
class WifiPhyThresholdsTest : public TestCase |
| 48 |
{ |
| 49 |
public: |
| 50 |
WifiPhyThresholdsTest (std::string test_name); |
| 51 |
virtual ~WifiPhyThresholdsTest (); |
| 52 |
|
| 53 |
protected: |
| 54 |
/** |
| 55 |
* Make wifi signal function |
| 56 |
* \param txPowerWatts the transmit power in watts |
| 57 |
* \returns Ptr<SpectrumSignalParameters> |
| 58 |
*/ |
| 59 |
virtual Ptr<SpectrumSignalParameters> MakeWifiSignal (double txPowerWatts); |
| 60 |
/** |
| 61 |
* Make foreign signal function |
| 62 |
* \param txPowerWatts the transmit power in watts |
| 63 |
* \returns Ptr<SpectrumSignalParameters> |
| 64 |
*/ |
| 65 |
virtual Ptr<SpectrumSignalParameters> MakeForeignSignal (double txPowerWatts); |
| 66 |
/** |
| 67 |
* Send signal function |
| 68 |
* \param txPowerWatts the transmit power in watts |
| 69 |
* \param wifiSignal whether the signal is a wifi signal or not |
| 70 |
*/ |
| 71 |
virtual void SendSignal (double txPowerWatts, bool wifiSignal); |
| 72 |
/** |
| 73 |
* PHY receive success callback function |
| 74 |
* \param p the packet |
| 75 |
* \param snr the SNR |
| 76 |
* \param txVector the transmit vector |
| 77 |
*/ |
| 78 |
virtual void RxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector); |
| 79 |
/** |
| 80 |
* PHY receive failure callback function |
| 81 |
*/ |
| 82 |
virtual void RxFailure (void); |
| 83 |
/** |
| 84 |
* PHY dropped packet callback function |
| 85 |
* \param p the packet |
| 86 |
*/ |
| 87 |
virtual void RxDropped (Ptr<const Packet> p); |
| 88 |
/** |
| 89 |
* PHY state changed callback function |
| 90 |
* \param start the start time of the new state |
| 91 |
* \param duration the duration of the new state |
| 92 |
* \param newState the new state |
| 93 |
*/ |
| 94 |
virtual void PhyStateChanged (Time start, Time duration, WifiPhyState newState); |
| 95 |
|
| 96 |
Ptr<SpectrumWifiPhy> m_phy; ///< PHY object |
| 97 |
uint32_t m_rxSuccess; ///< count number of successfully received packets |
| 98 |
uint32_t m_rxFailure; ///< count number of unsuccessfully received packets |
| 99 |
uint32_t m_rxDropped; ///< count number of dropped packets |
| 100 |
uint32_t m_stateChanged; ///< count number of PHY state change |
| 101 |
uint32_t m_rxStateCount; ///< count number of PHY state change to RX state |
| 102 |
uint32_t m_idleStateCount; ///< count number of PHY state change to IDLE state |
| 103 |
uint32_t m_ccabusyStateCount; ///< count number of PHY state change to CCA_BUSY state |
| 104 |
|
| 105 |
private: |
| 106 |
virtual void DoSetup (void); |
| 107 |
}; |
| 108 |
|
| 109 |
WifiPhyThresholdsTest::WifiPhyThresholdsTest (std::string test_name) |
| 110 |
: TestCase (test_name), |
| 111 |
m_rxSuccess (0), |
| 112 |
m_rxFailure (0), |
| 113 |
m_rxDropped (0), |
| 114 |
m_stateChanged (0), |
| 115 |
m_rxStateCount (0), |
| 116 |
m_idleStateCount (0), |
| 117 |
m_ccabusyStateCount (0) |
| 118 |
{ |
| 119 |
} |
| 120 |
|
| 121 |
WifiPhyThresholdsTest::~WifiPhyThresholdsTest () |
| 122 |
{ |
| 123 |
} |
| 124 |
|
| 125 |
Ptr<SpectrumSignalParameters> |
| 126 |
WifiPhyThresholdsTest::MakeWifiSignal (double txPowerWatts) |
| 127 |
{ |
| 128 |
WifiTxVector txVector = WifiTxVector (WifiPhy::GetOfdmRate6Mbps (), 0, WIFI_PREAMBLE_LONG, false, 1, 1, 0, 20, false, false); |
| 129 |
MpduType mpdutype = NORMAL_MPDU; |
| 130 |
|
| 131 |
Ptr<Packet> pkt = Create<Packet> (1000); |
| 132 |
WifiMacHeader hdr; |
| 133 |
WifiMacTrailer trailer; |
| 134 |
|
| 135 |
hdr.SetType (WIFI_MAC_QOSDATA); |
| 136 |
hdr.SetQosTid (0); |
| 137 |
uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize (); |
| 138 |
Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFrequency (), mpdutype, 0); |
| 139 |
hdr.SetDuration (txDuration); |
| 140 |
|
| 141 |
pkt->AddHeader (hdr); |
| 142 |
pkt->AddTrailer (trailer); |
| 143 |
WifiPhyTag tag (txVector, mpdutype, 1); |
| 144 |
pkt->AddPacketTag (tag); |
| 145 |
Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH); |
| 146 |
Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> (); |
| 147 |
txParams->psd = txPowerSpectrum; |
| 148 |
txParams->txPhy = 0; |
| 149 |
txParams->duration = txDuration; |
| 150 |
txParams->packet = pkt; |
| 151 |
return txParams; |
| 152 |
} |
| 153 |
|
| 154 |
Ptr<SpectrumSignalParameters> |
| 155 |
WifiPhyThresholdsTest::MakeForeignSignal (double txPowerWatts) |
| 156 |
{ |
| 157 |
Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH); |
| 158 |
Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> (); |
| 159 |
txParams->psd = txPowerSpectrum; |
| 160 |
txParams->txPhy = 0; |
| 161 |
txParams->duration = Seconds (0.5); |
| 162 |
return txParams; |
| 163 |
} |
| 164 |
|
| 165 |
void |
| 166 |
WifiPhyThresholdsTest::SendSignal (double txPowerWatts, bool wifiSignal) |
| 167 |
{ |
| 168 |
if (wifiSignal) |
| 169 |
{ |
| 170 |
m_phy->StartRx (MakeWifiSignal (txPowerWatts)); |
| 171 |
} |
| 172 |
else |
| 173 |
{ |
| 174 |
m_phy->StartRx (MakeForeignSignal (txPowerWatts)); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
void |
| 179 |
WifiPhyThresholdsTest::RxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector) |
| 180 |
{ |
| 181 |
NS_LOG_FUNCTION (this << p << snr << txVector); |
| 182 |
m_rxSuccess++; |
| 183 |
} |
| 184 |
|
| 185 |
void |
| 186 |
WifiPhyThresholdsTest::RxFailure (void) |
| 187 |
{ |
| 188 |
NS_LOG_FUNCTION (this); |
| 189 |
m_rxFailure++; |
| 190 |
} |
| 191 |
|
| 192 |
void |
| 193 |
WifiPhyThresholdsTest::RxDropped (Ptr<const Packet> p) |
| 194 |
{ |
| 195 |
NS_LOG_FUNCTION (this << p); |
| 196 |
m_rxDropped++; |
| 197 |
} |
| 198 |
|
| 199 |
void |
| 200 |
WifiPhyThresholdsTest::PhyStateChanged (Time start, Time duration, WifiPhyState newState) |
| 201 |
{ |
| 202 |
NS_LOG_FUNCTION (this << start << duration << newState); |
| 203 |
m_stateChanged++; |
| 204 |
if (newState == WifiPhyState::IDLE) |
| 205 |
{ |
| 206 |
m_idleStateCount++; |
| 207 |
} |
| 208 |
else if (newState == WifiPhyState::RX) |
| 209 |
{ |
| 210 |
m_rxStateCount++; |
| 211 |
} |
| 212 |
else if (newState == WifiPhyState::CCA_BUSY) |
| 213 |
{ |
| 214 |
m_ccabusyStateCount++; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
void |
| 219 |
WifiPhyThresholdsTest::DoSetup (void) |
| 220 |
{ |
| 221 |
m_phy = CreateObject<SpectrumWifiPhy> (); |
| 222 |
m_phy->ConfigureStandard (WIFI_PHY_STANDARD_80211ax_5GHZ); |
| 223 |
Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> (); |
| 224 |
m_phy->SetErrorRateModel (error); |
| 225 |
m_phy->SetChannelNumber (CHANNEL_NUMBER); |
| 226 |
m_phy->SetFrequency (FREQUENCY); |
| 227 |
m_phy->SetReceiveOkCallback (MakeCallback (&WifiPhyThresholdsTest::RxSuccess, this)); |
| 228 |
m_phy->SetReceiveErrorCallback (MakeCallback (&WifiPhyThresholdsTest::RxFailure, this)); |
| 229 |
m_phy->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&WifiPhyThresholdsTest::RxDropped, this)); |
| 230 |
m_phy->GetState ()->TraceConnectWithoutContext ("State", MakeCallback (&WifiPhyThresholdsTest::PhyStateChanged, this)); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* \ingroup wifi-test |
| 235 |
* \ingroup tests |
| 236 |
* |
| 237 |
* \brief Wifi Phy Threshold Weak Wifi Signal Test |
| 238 |
* |
| 239 |
* This test makes sure PHY ignores a Wi-Fi signal |
| 240 |
* if its received power lower than RxSensitivity. |
| 241 |
*/ |
| 242 |
class WifiPhyThresholdsWeakWifiSignalTest : public WifiPhyThresholdsTest |
| 243 |
{ |
| 244 |
public: |
| 245 |
WifiPhyThresholdsWeakWifiSignalTest (); |
| 246 |
virtual ~WifiPhyThresholdsWeakWifiSignalTest (); |
| 247 |
virtual void DoRun (void); |
| 248 |
}; |
| 249 |
|
| 250 |
WifiPhyThresholdsWeakWifiSignalTest::WifiPhyThresholdsWeakWifiSignalTest () |
| 251 |
: WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak wifi signal reception") |
| 252 |
{ |
| 253 |
} |
| 254 |
|
| 255 |
WifiPhyThresholdsWeakWifiSignalTest::~WifiPhyThresholdsWeakWifiSignalTest () |
| 256 |
{ |
| 257 |
} |
| 258 |
|
| 259 |
void |
| 260 |
WifiPhyThresholdsWeakWifiSignalTest::DoRun (void) |
| 261 |
{ |
| 262 |
WifiHelper::EnableLogComponents (); |
| 263 |
|
| 264 |
double txPowerWatts = DbmToW (-110); |
| 265 |
|
| 266 |
Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakWifiSignalTest::SendSignal, this, txPowerWatts, true); |
| 267 |
|
| 268 |
Simulator::Run (); |
| 269 |
Simulator::Destroy (); |
| 270 |
|
| 271 |
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"); |
| 272 |
NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold"); |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* \ingroup wifi-test |
| 277 |
* \ingroup tests |
| 278 |
* |
| 279 |
* \brief Wifi Phy Threshold Weak Foreign Signal Test |
| 280 |
* |
| 281 |
* This test makes sure PHY keeps the state as IDLE if reception involves |
| 282 |
* a foreign signal with a received power lower than CcaEdThreshold. |
| 283 |
*/ |
| 284 |
class WifiPhyThresholdsWeakForeignSignalTest : public WifiPhyThresholdsTest |
| 285 |
{ |
| 286 |
public: |
| 287 |
WifiPhyThresholdsWeakForeignSignalTest (); |
| 288 |
virtual ~WifiPhyThresholdsWeakForeignSignalTest (); |
| 289 |
virtual void DoRun (void); |
| 290 |
}; |
| 291 |
|
| 292 |
WifiPhyThresholdsWeakForeignSignalTest::WifiPhyThresholdsWeakForeignSignalTest () |
| 293 |
: WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception") |
| 294 |
{ |
| 295 |
} |
| 296 |
|
| 297 |
WifiPhyThresholdsWeakForeignSignalTest::~WifiPhyThresholdsWeakForeignSignalTest () |
| 298 |
{ |
| 299 |
} |
| 300 |
|
| 301 |
void |
| 302 |
WifiPhyThresholdsWeakForeignSignalTest::DoRun (void) |
| 303 |
{ |
| 304 |
WifiHelper::EnableLogComponents (); |
| 305 |
|
| 306 |
double txPowerWatts = DbmToW (-90); |
| 307 |
|
| 308 |
Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakForeignSignalTest::SendSignal, this, txPowerWatts, false); |
| 309 |
|
| 310 |
Simulator::Run (); |
| 311 |
Simulator::Destroy (); |
| 312 |
|
| 313 |
NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered"); |
| 314 |
NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold"); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* \ingroup wifi-test |
| 319 |
* \ingroup tests |
| 320 |
* |
| 321 |
* \brief Wifi Phy Threshold Strong Wifi Signal Test |
| 322 |
* |
| 323 |
* This test makes sure PHY processes a Wi-Fi signal |
| 324 |
* with a received power higher than RxSensitivity. |
| 325 |
*/ |
| 326 |
class WifiPhyThresholdsStrongWifiSignalTest : public WifiPhyThresholdsTest |
| 327 |
{ |
| 328 |
public: |
| 329 |
WifiPhyThresholdsStrongWifiSignalTest (); |
| 330 |
virtual ~WifiPhyThresholdsStrongWifiSignalTest (); |
| 331 |
virtual void DoRun (void); |
| 332 |
}; |
| 333 |
|
| 334 |
WifiPhyThresholdsStrongWifiSignalTest::WifiPhyThresholdsStrongWifiSignalTest () |
| 335 |
: WifiPhyThresholdsTest ("WifiPhy reception thresholds: test strong wifi signal reception") |
| 336 |
{ |
| 337 |
} |
| 338 |
|
| 339 |
WifiPhyThresholdsStrongWifiSignalTest::~WifiPhyThresholdsStrongWifiSignalTest () |
| 340 |
{ |
| 341 |
} |
| 342 |
|
| 343 |
void |
| 344 |
WifiPhyThresholdsStrongWifiSignalTest::DoRun (void) |
| 345 |
{ |
| 346 |
WifiHelper::EnableLogComponents (); |
| 347 |
|
| 348 |
double txPowerWatts = DbmToW (-60); |
| 349 |
|
| 350 |
Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongWifiSignalTest::SendSignal, this, txPowerWatts, true); |
| 351 |
|
| 352 |
Simulator::Run (); |
| 353 |
Simulator::Destroy (); |
| 354 |
|
| 355 |
NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxFailure, 0, "Packet reception should have been successfull"); |
| 356 |
NS_TEST_ASSERT_MSG_EQ (m_rxSuccess, 1, "Packet should have been successfully received"); |
| 357 |
NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 2, "State should have moved to RX then back to IDLE"); |
| 358 |
NS_TEST_ASSERT_MSG_EQ (m_rxStateCount, 1, "State should have moved to RX once"); |
| 359 |
NS_TEST_ASSERT_MSG_EQ (m_idleStateCount, 1, "State should have moved to IDLE once"); |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* \ingroup wifi-test |
| 364 |
* \ingroup tests |
| 365 |
* |
| 366 |
* \brief Wifi Phy Threshold Strong Foreign Signal Test |
| 367 |
* |
| 368 |
* This test makes sure PHY declare the state as CCA_BUSY if reception involves |
| 369 |
* a foreign signal with a received power higher than CcaEdThreshold. |
| 370 |
*/ |
| 371 |
class WifiPhyThresholdsStrongForeignSignalTest : public WifiPhyThresholdsTest |
| 372 |
{ |
| 373 |
public: |
| 374 |
WifiPhyThresholdsStrongForeignSignalTest (); |
| 375 |
virtual ~WifiPhyThresholdsStrongForeignSignalTest (); |
| 376 |
virtual void DoRun (void); |
| 377 |
}; |
| 378 |
|
| 379 |
WifiPhyThresholdsStrongForeignSignalTest::WifiPhyThresholdsStrongForeignSignalTest () |
| 380 |
: WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception") |
| 381 |
{ |
| 382 |
} |
| 383 |
|
| 384 |
WifiPhyThresholdsStrongForeignSignalTest::~WifiPhyThresholdsStrongForeignSignalTest () |
| 385 |
{ |
| 386 |
} |
| 387 |
|
| 388 |
void |
| 389 |
WifiPhyThresholdsStrongForeignSignalTest::DoRun (void) |
| 390 |
{ |
| 391 |
WifiHelper::EnableLogComponents (); |
| 392 |
|
| 393 |
double txPowerWatts = DbmToW (-60); |
| 394 |
|
| 395 |
Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongForeignSignalTest::SendSignal, this, txPowerWatts, false); |
| 396 |
|
| 397 |
Simulator::Run (); |
| 398 |
Simulator::Destroy (); |
| 399 |
|
| 400 |
NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered"); |
| 401 |
NS_TEST_ASSERT_MSG_EQ (m_ccabusyStateCount, 1, "State should have moved to CCA-BUSY"); |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* \ingroup wifi-test |
| 406 |
* \ingroup tests |
| 407 |
* |
| 408 |
* \brief Wifi Phy Thresholds Test Suite |
| 409 |
*/ |
| 410 |
class WifiPhyThresholdsTestSuite : public TestSuite |
| 411 |
{ |
| 412 |
public: |
| 413 |
WifiPhyThresholdsTestSuite (); |
| 414 |
}; |
| 415 |
|
| 416 |
WifiPhyThresholdsTestSuite::WifiPhyThresholdsTestSuite () |
| 417 |
: TestSuite ("wifi-phy-thresholds", UNIT) |
| 418 |
{ |
| 419 |
AddTestCase (new WifiPhyThresholdsWeakWifiSignalTest, TestCase::QUICK); |
| 420 |
AddTestCase (new WifiPhyThresholdsWeakForeignSignalTest, TestCase::QUICK); |
| 421 |
AddTestCase (new WifiPhyThresholdsStrongWifiSignalTest, TestCase::QUICK); |
| 422 |
AddTestCase (new WifiPhyThresholdsStrongForeignSignalTest, TestCase::QUICK); |
| 423 |
} |
| 424 |
|
| 425 |
static WifiPhyThresholdsTestSuite wifiPhyThresholdsTestSuite; ///< the test suite |