|
|
|
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2018 University of Washington |
| 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/pointer.h" |
| 24 |
#include "ns3/spectrum-wifi-helper.h" |
| 25 |
#include "ns3/wifi-spectrum-value-helper.h" |
| 26 |
#include "ns3/spectrum-wifi-phy.h" |
| 27 |
#include "ns3/nist-error-rate-model.h" |
| 28 |
#include "ns3/wifi-mac-header.h" |
| 29 |
#include "ns3/wifi-mac-trailer.h" |
| 30 |
#include "ns3/wifi-phy-tag.h" |
| 31 |
#include "ns3/wifi-spectrum-signal-parameters.h" |
| 32 |
#include "ns3/wifi-utils.h" |
| 33 |
#include "ns3/threshold-preamble-detection-model.h" |
| 34 |
|
| 35 |
using namespace ns3; |
| 36 |
|
| 37 |
NS_LOG_COMPONENT_DEFINE ("TestThresholdPreambleDetectionWithoutFrameCapture"); |
| 38 |
|
| 39 |
static const uint8_t CHANNEL_NUMBER = 36; |
| 40 |
static const uint32_t FREQUENCY = 5180; // MHz |
| 41 |
static const uint16_t CHANNEL_WIDTH = 20; // MHz |
| 42 |
static const uint16_t GUARD_WIDTH = CHANNEL_WIDTH; // MHz (expanded to channel width to model spectrum mask) |
| 43 |
|
| 44 |
/** |
| 45 |
* \ingroup wifi-test |
| 46 |
* \ingroup tests |
| 47 |
* |
| 48 |
* \brief Wifi Preamble Detection Test |
| 49 |
*/ |
| 50 |
class TestThresholdPreambleDetectionWithoutFrameCapture : public TestCase |
| 51 |
{ |
| 52 |
public: |
| 53 |
TestThresholdPreambleDetectionWithoutFrameCapture (); |
| 54 |
virtual ~TestThresholdPreambleDetectionWithoutFrameCapture (); |
| 55 |
|
| 56 |
protected: |
| 57 |
virtual void DoSetup (void); |
| 58 |
Ptr<SpectrumWifiPhy> m_phy; ///< Phy |
| 59 |
/** |
| 60 |
* Send packet function |
| 61 |
* \param txPowerDbm the transmit power in dBm |
| 62 |
*/ |
| 63 |
void SendPacket (double txPowerDbm); |
| 64 |
/** |
| 65 |
* Spectrum wifi receive success function |
| 66 |
* \param p the packet |
| 67 |
* \param snr the SNR |
| 68 |
* \param txVector the transmit vector |
| 69 |
*/ |
| 70 |
void SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector); |
| 71 |
/** |
| 72 |
* Spectrum wifi receive failure function |
| 73 |
*/ |
| 74 |
void SpectrumWifiPhyRxFailure (void); |
| 75 |
uint32_t m_countRxSuccess; ///< count RX success |
| 76 |
uint32_t m_countRxFailure; ///< count RX failure |
| 77 |
|
| 78 |
private: |
| 79 |
virtual void DoRun (void); |
| 80 |
|
| 81 |
/** |
| 82 |
* Check the PHY state |
| 83 |
* \param expectedState the expected PHY state |
| 84 |
*/ |
| 85 |
void CheckPhyState (WifiPhyState expectedState); |
| 86 |
/** |
| 87 |
* Check the number of received packets |
| 88 |
* \param expectedSuccessCount the number of successfully received packets |
| 89 |
* \param expectedFailureCount the number of unsuccessfully received packets |
| 90 |
*/ |
| 91 |
void CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount); |
| 92 |
}; |
| 93 |
|
| 94 |
TestThresholdPreambleDetectionWithoutFrameCapture::TestThresholdPreambleDetectionWithoutFrameCapture () |
| 95 |
: TestCase ("Threshold preamble detection model test when no frame capture model is applied"), |
| 96 |
m_countRxSuccess (0), |
| 97 |
m_countRxFailure (0) |
| 98 |
{ |
| 99 |
} |
| 100 |
|
| 101 |
void |
| 102 |
TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket (double txPowerDbm) |
| 103 |
{ |
| 104 |
WifiTxVector txVector = WifiTxVector (WifiPhy::GetHeMcs11 (), 0, WIFI_PREAMBLE_HE_SU, 800, 1, 1, 0, 20, false, false); |
| 105 |
MpduType mpdutype = NORMAL_MPDU; |
| 106 |
|
| 107 |
Ptr<Packet> pkt = Create<Packet> (1000); |
| 108 |
WifiMacHeader hdr; |
| 109 |
WifiMacTrailer trailer; |
| 110 |
|
| 111 |
hdr.SetType (WIFI_MAC_QOSDATA); |
| 112 |
hdr.SetQosTid (0); |
| 113 |
uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize (); |
| 114 |
Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFrequency (), mpdutype, 0); |
| 115 |
hdr.SetDuration (txDuration); |
| 116 |
|
| 117 |
pkt->AddHeader (hdr); |
| 118 |
pkt->AddTrailer (trailer); |
| 119 |
WifiPhyTag tag (txVector, mpdutype, 1); |
| 120 |
pkt->AddPacketTag (tag); |
| 121 |
Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, DbmToW (txPowerDbm), GUARD_WIDTH); |
| 122 |
Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> (); |
| 123 |
txParams->psd = txPowerSpectrum; |
| 124 |
txParams->txPhy = 0; |
| 125 |
txParams->duration = txDuration; |
| 126 |
txParams->packet = pkt; |
| 127 |
|
| 128 |
m_phy->StartRx (txParams); |
| 129 |
} |
| 130 |
|
| 131 |
void |
| 132 |
TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState (WifiPhyState expectedState) |
| 133 |
{ |
| 134 |
WifiPhyState currentState; |
| 135 |
PointerValue ptr; |
| 136 |
m_phy->GetAttribute ("State", ptr); |
| 137 |
Ptr <WifiPhyStateHelper> state = DynamicCast <WifiPhyStateHelper> (ptr.Get<WifiPhyStateHelper> ()); |
| 138 |
currentState = state->GetState (); |
| 139 |
NS_TEST_ASSERT_MSG_EQ (currentState, expectedState, "PHY State " << currentState << " does not match expected state " << expectedState << " at " << Simulator::Now ()); |
| 140 |
} |
| 141 |
|
| 142 |
void |
| 143 |
TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount) |
| 144 |
{ |
| 145 |
NS_TEST_ASSERT_MSG_EQ (m_countRxSuccess, expectedSuccessCount, "Didn't receive right number of successful packets"); |
| 146 |
NS_TEST_ASSERT_MSG_EQ (m_countRxFailure, expectedFailureCount, "Didn't receive right number of unsuccessful packets"); |
| 147 |
} |
| 148 |
|
| 149 |
void |
| 150 |
TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector) |
| 151 |
{ |
| 152 |
NS_LOG_FUNCTION (this << p << snr << txVector); |
| 153 |
m_countRxSuccess++; |
| 154 |
} |
| 155 |
|
| 156 |
void |
| 157 |
TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxFailure (void) |
| 158 |
{ |
| 159 |
NS_LOG_FUNCTION (this); |
| 160 |
m_countRxFailure++; |
| 161 |
} |
| 162 |
|
| 163 |
TestThresholdPreambleDetectionWithoutFrameCapture::~TestThresholdPreambleDetectionWithoutFrameCapture () |
| 164 |
{ |
| 165 |
} |
| 166 |
|
| 167 |
void |
| 168 |
TestThresholdPreambleDetectionWithoutFrameCapture::DoSetup (void) |
| 169 |
{ |
| 170 |
m_phy = CreateObject<SpectrumWifiPhy> (); |
| 171 |
m_phy->ConfigureStandard (WIFI_PHY_STANDARD_80211ax_5GHZ); |
| 172 |
Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> (); |
| 173 |
m_phy->SetErrorRateModel (error); |
| 174 |
m_phy->SetChannelNumber (CHANNEL_NUMBER); |
| 175 |
m_phy->SetFrequency (FREQUENCY); |
| 176 |
m_phy->SetReceiveOkCallback (MakeCallback (&TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxSuccess, this)); |
| 177 |
m_phy->SetReceiveErrorCallback (MakeCallback (&TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxFailure, this)); |
| 178 |
m_phy->SetCcaMode1Threshold (-62.0); //to be removed once merged! |
| 179 |
|
| 180 |
Ptr<ThresholdPreambleDetectionModel> preambleDetectionModel = CreateObject<ThresholdPreambleDetectionModel> (); |
| 181 |
m_phy->SetPreambleDetectionModel (preambleDetectionModel); |
| 182 |
} |
| 183 |
|
| 184 |
// Test that the expected number of packet receptions occur. |
| 185 |
void |
| 186 |
TestThresholdPreambleDetectionWithoutFrameCapture::DoRun (void) |
| 187 |
{ |
| 188 |
double txPowerDbm = -30; |
| 189 |
|
| 190 |
//CASE 1: send one packet and check PHY state: packet reception should succeed |
| 191 |
|
| 192 |
Simulator::Schedule (Seconds (1.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 193 |
// At 4us, STA PHY STATE should be IDLE |
| 194 |
Simulator::Schedule (Seconds (1.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 195 |
// At 5us, STA PHY STATE should be RX |
| 196 |
Simulator::Schedule (Seconds (1.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX); |
| 197 |
// Packet should have been successfully received |
| 198 |
Simulator::Schedule (Seconds (1.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 0); |
| 199 |
|
| 200 |
//CASE 2: send two packets with same power within the 4us window and check PHY state: PHY preamble detection should fail |
| 201 |
|
| 202 |
Simulator::Schedule (Seconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 203 |
Simulator::Schedule (Seconds (2.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 204 |
Simulator::Schedule (Seconds (2.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 205 |
Simulator::Schedule (Seconds (2.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 206 |
// No more packet should have been successfully received, and since preamble detection did not pass the packet should not have been counted as a failure |
| 207 |
Simulator::Schedule (Seconds (2.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 0); |
| 208 |
|
| 209 |
//CASE 3: send two packets with second one 3 dB weaker within the 4us window and check PHY state: PHY preamble detection should succeed and packet reception should fail |
| 210 |
|
| 211 |
Simulator::Schedule (Seconds (3.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 212 |
Simulator::Schedule (Seconds (3.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm - 3); |
| 213 |
Simulator::Schedule (Seconds (3.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 214 |
Simulator::Schedule (Seconds (3.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX); |
| 215 |
// In this case, the first packet should be marked as a failure |
| 216 |
Simulator::Schedule (Seconds (3.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 1); |
| 217 |
|
| 218 |
//CASE 4: send two packets with second one 3 dB higher within the 4us window and check PHY state: PHY preamble detection should fail and no packets should enter the reception stage |
| 219 |
Simulator::Schedule (Seconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 220 |
Simulator::Schedule (Seconds (4.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm + 3); |
| 221 |
Simulator::Schedule (Seconds (4.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 222 |
Simulator::Schedule (Seconds (4.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 223 |
Simulator::Schedule (Seconds (4.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 1); |
| 224 |
|
| 225 |
//CASE 5: idem but send the second packet after the 4us window: PHY preamble detection should succeed and packet reception should fail |
| 226 |
|
| 227 |
Simulator::Schedule (Seconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm); |
| 228 |
Simulator::Schedule (Seconds (5.0) + MicroSeconds (6.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm + 3); |
| 229 |
Simulator::Schedule (Seconds (5.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE); |
| 230 |
Simulator::Schedule (Seconds (5.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX); |
| 231 |
Simulator::Schedule (Seconds (5.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 2); |
| 232 |
|
| 233 |
Simulator::Run (); |
| 234 |
Simulator::Destroy (); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* \ingroup wifi-test |
| 239 |
* \ingroup tests |
| 240 |
* |
| 241 |
* \brief Preamble Detection Test Suite |
| 242 |
*/ |
| 243 |
class PreambleDetectionTestSuite : public TestSuite |
| 244 |
{ |
| 245 |
public: |
| 246 |
PreambleDetectionTestSuite (); |
| 247 |
}; |
| 248 |
|
| 249 |
PreambleDetectionTestSuite::PreambleDetectionTestSuite () |
| 250 |
: TestSuite ("wifi-preamble-detection", UNIT) |
| 251 |
{ |
| 252 |
AddTestCase (new TestThresholdPreambleDetectionWithoutFrameCapture, TestCase::QUICK); |
| 253 |
} |
| 254 |
|
| 255 |
static PreambleDetectionTestSuite preambleDetectionTestSuite; ///< the test suite |