A Discrete-Event Network Simulator
API
spectrum-wifi-phy-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 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 
19 #include "ns3/test.h"
20 #include "ns3/spectrum-wifi-helper.h"
21 #include "ns3/wifi-spectrum-value-helper.h"
22 #include "ns3/spectrum-wifi-phy.h"
23 #include "ns3/nist-error-rate-model.h"
24 #include "ns3/wifi-mac-header.h"
25 #include "ns3/wifi-mac-trailer.h"
26 #include "ns3/wifi-phy-tag.h"
27 #include "ns3/wifi-spectrum-signal-parameters.h"
28 
29 using namespace ns3;
30 
31 static const uint8_t CHANNEL_NUMBER = 36;
32 static const uint32_t FREQUENCY = 5180; // MHz
33 static const uint8_t CHANNEL_WIDTH = 20; // MHz
34 static const uint8_t GUARD_WIDTH = 10; // MHz
35 
43 {
44 public:
51  SpectrumWifiPhyBasicTest (std::string name);
52  virtual ~SpectrumWifiPhyBasicTest ();
53 protected:
54  virtual void DoSetup (void);
56 
61  Ptr<SpectrumSignalParameters> MakeSignal (double txPowerWatts);
66  void SendSignal (double txPowerWatts);
73  void SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector);
79  void SpectrumWifiPhyRxFailure (Ptr<Packet> p, double snr);
80  uint32_t m_count;
81 private:
82  virtual void DoRun (void);
83 };
84 
86  : TestCase ("SpectrumWifiPhy test case receives one packet"),
87  m_count (0)
88 {
89 }
90 
92  : TestCase (name),
93  m_count (0)
94 {
95 }
96 
97 // Make a Wi-Fi signal to inject directly to the StartRx() method
100 {
101  WifiTxVector txVector = WifiTxVector (WifiPhy::GetOfdmRate6Mbps (), 0, 0, WIFI_PREAMBLE_LONG, false, 1, 1, 0, 20, false, false);
102  MpduType mpdutype = NORMAL_MPDU;
103 
104  Ptr<Packet> pkt = Create<Packet> (1000);
105  WifiMacHeader hdr;
106  WifiMacTrailer trailer;
107 
108  hdr.SetType (WIFI_MAC_QOSDATA);
109  hdr.SetQosTid (0);
110  uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize ();
111  Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFrequency (), mpdutype, 0);
112  hdr.SetDuration (txDuration);
113 
114  pkt->AddHeader (hdr);
115  pkt->AddTrailer (trailer);
116  WifiPhyTag tag (txVector, mpdutype);
117  pkt->AddPacketTag (tag);
118  Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, GUARD_WIDTH);
119  Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> ();
120  txParams->psd = txPowerSpectrum;
121  txParams->txPhy = 0;
122  txParams->duration = txDuration;
123  txParams->packet = pkt;
124  return txParams;
125 }
126 
127 // Make a Wi-Fi signal to inject directly to the StartRx() method
128 void
130 {
131  m_phy->StartRx (MakeSignal (txPowerWatts));
132 }
133 
134 void
136 {
137  m_count++;
138 }
139 
140 void
142 {
143  m_count++;
144 }
145 
147 {
148 }
149 
150 // Create necessary objects, and inject signals. Test that the expected
151 // number of packet receptions occur.
152 void
154 {
155  m_phy = CreateObject<SpectrumWifiPhy> ();
157  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
158  m_phy->SetErrorRateModel (error);
163  //Bug 2460: CcaMode1Threshold default should be set to -62 dBm when using Spectrum
164  m_phy->SetCcaMode1Threshold (-62.0);
165 }
166 
167 // Test that the expected number of packet receptions occur.
168 void
170 {
171  double txPowerWatts = 0.010;
172  // Send packets spaced 1 second apart; all should be received
173  Simulator::Schedule (Seconds (1), &SpectrumWifiPhyBasicTest::SendSignal, this, txPowerWatts);
174  Simulator::Schedule (Seconds (2), &SpectrumWifiPhyBasicTest::SendSignal, this, txPowerWatts);
175  Simulator::Schedule (Seconds (3), &SpectrumWifiPhyBasicTest::SendSignal, this, txPowerWatts);
176  // Send packets spaced 1 microsecond second apart; only one should be received
177  Simulator::Schedule (MicroSeconds (4000000), &SpectrumWifiPhyBasicTest::SendSignal, this, txPowerWatts);
178  Simulator::Schedule (MicroSeconds (4000001), &SpectrumWifiPhyBasicTest::SendSignal, this, txPowerWatts);
179  Simulator::Run ();
180  Simulator::Destroy ();
181 
182  NS_TEST_ASSERT_MSG_EQ (m_count, 4, "Didn't receive right number of packets");
183 }
184 
192 {
193 public:
199  : m_notifyRxStart (0),
200  m_notifyRxEndOk (0),
201  m_notifyRxEndError (0),
203  {
204  }
205  virtual ~TestPhyListener ()
206  {
207  }
208  virtual void NotifyRxStart (Time duration)
209  {
210  ++m_notifyRxStart;
211  }
212  virtual void NotifyRxEndOk (void)
213  {
214  ++m_notifyRxEndOk;
215  }
216  virtual void NotifyRxEndError (void)
217  {
219  }
220  virtual void NotifyTxStart (Time duration, double txPowerDbm)
221  {
222  }
223  virtual void NotifyMaybeCcaBusyStart (Time duration)
224  {
226  }
227  virtual void NotifySwitchingStart (Time duration)
228  {
229  }
230  virtual void NotifySleep (void)
231  {
232  }
233  virtual void NotifyWakeup (void)
234  {
235  }
236  uint32_t m_notifyRxStart;
237  uint32_t m_notifyRxEndOk;
240 private:
241 };
242 
250 {
251 public:
253  virtual ~SpectrumWifiPhyListenerTest ();
254 private:
255  virtual void DoSetup (void);
256  virtual void DoRun (void);
258 };
259 
261  : SpectrumWifiPhyBasicTest ("SpectrumWifiPhy test operation of WifiPhyListener")
262 {
263 }
264 
266 {
267 }
268 
269 void
271 {
275 }
276 
277 void
279 {
280  double txPowerWatts = 0.010;
281  Simulator::Schedule (Seconds (1), &SpectrumWifiPhyListenerTest::SendSignal, this, txPowerWatts);
282  Simulator::Run ();
283 
284  NS_TEST_ASSERT_MSG_EQ (m_count, 1, "Didn't receive right number of packets");
285  NS_TEST_ASSERT_MSG_EQ (m_listener->m_notifyRxStart, 1, "Didn't receive NotifyRxStart");
286  NS_TEST_ASSERT_MSG_EQ (m_listener->m_notifyRxEndOk, 1, "Didn't receive NotifyRxEnd");
287  NS_TEST_ASSERT_MSG_EQ (m_listener->m_notifyMaybeCcaBusyStart, 0, "Received NotifyMaybeCcaBusyStart unexpectedly");
288 
289  Simulator::Destroy ();
290  delete m_listener;
291 }
292 
300 {
301 public:
303 };
304 
306  : TestSuite ("spectrum-wifi-phy", UNIT)
307 {
308  AddTestCase (new SpectrumWifiPhyBasicTest, TestCase::QUICK);
309  AddTestCase (new SpectrumWifiPhyListenerTest, TestCase::QUICK);
310 }
311 
static SpectrumWifiPhyTestSuite spectrumWifiPhyTestSuite
the test suite
uint32_t m_notifyMaybeCcaBusyStart
notify maybe CCA busy start
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
The MPDU is not part of an A-MPDU.
Definition: wifi-phy.h:59
HT PHY for the 5 GHz band (clause 20)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level Phy interface to this Sp...
A suite of tests to run.
Definition: test.h:1342
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:814
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
virtual void NotifySleep(void)
Notify listeners that we went to sleep.
uint32_t m_notifyRxEndError
notify receive end error
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:434
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:796
static const uint32_t FREQUENCY
Test Phy Listener.
encapsulates test code
Definition: test.h:1155
virtual void NotifyMaybeCcaBusyStart(Time duration)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SpectrumWifiPhyRxFailure(Ptr< Packet > p, double snr)
Spectrum wifi receive failure function.
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1270
virtual void SetChannelNumber(uint8_t id)
Set channel number.
Spectrum Wifi Phy Basic Test.
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:2262
uint32_t m_notifyRxEndOk
notify receive end OK
void SendSignal(double txPowerWatts)
Send signal function.
virtual void NotifyWakeup(void)
Notify listeners that we woke up.
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void SpectrumWifiPhyRxSuccess(Ptr< Packet > p, double snr, WifiTxVector txVector)
Spectrum wifi receive success function.
receive notifications about phy events.
Definition: wifi-phy.h:83
Ptr< SpectrumSignalParameters > MakeSignal(double txPowerWatts)
Make signal function.
virtual void NotifySwitchingStart(Time duration)
#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:168
virtual void NotifyRxStart(Time duration)
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
TestPhyListener * m_listener
listener
virtual void NotifyRxEndError(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
virtual void DoRun(void)
Implementation to actually run this TestCase.
static const uint8_t CHANNEL_WIDTH
virtual void NotifyRxEndOk(void)
We have received the last bit of a packet for which NotifyRxStart was invoked first and...
virtual void SetFrequency(uint16_t freq)
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:701
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:284
void SetCcaMode1Threshold(double threshold)
Sets the CCA threshold (dBm).
Definition: wifi-phy.cc:499
Ptr< Packet > packet
The packet being transmitted with this signal.
Ptr< SpectrumWifiPhy > m_phy
Phy.
Spectrum Wifi Phy Test Suite.
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:428
void RegisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:440
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.
static const uint8_t GUARD_WIDTH
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
TestPhyListener(void)
Create a test PhyListener.
Tag for WifiTxVector and WifiPreamble information to be embedded in outgoing transmissions as a Packe...
Definition: wifi-phy-tag.h:35
Time duration
The duration of the packet transmission.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
Spectrum Wifi Phy Listener Test.
virtual void NotifyTxStart(Time duration, double txPowerDbm)
MpduType
This enumeration defines the type of an MPDU.
Definition: wifi-phy.h:56
uint32_t m_notifyRxStart
notify receive start
static const uint8_t CHANNEL_NUMBER
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Implements the IEEE 802.11 MAC header.
Implements the IEEE 802.11 MAC trailer.
uint32_t GetSerializedSize(void) const