LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2015 University of Washington | 3 * Copyright (c) 2015 University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 */ | 17 */ |
18 | 18 |
19 #include "ns3/test.h" | 19 #include "ns3/test.h" |
20 #include "ns3/spectrum-wifi-helper.h" | 20 #include "ns3/spectrum-wifi-helper.h" |
21 #include "ns3/wifi-spectrum-value-helper.h" | 21 #include "ns3/wifi-spectrum-value-helper.h" |
22 #include "ns3/spectrum-wifi-phy.h" | 22 #include "ns3/spectrum-wifi-phy.h" |
23 #include "ns3/nist-error-rate-model.h" | 23 #include "ns3/nist-error-rate-model.h" |
24 #include "ns3/wifi-mac-header.h" | 24 #include "ns3/wifi-mac-header.h" |
25 #include "ns3/wifi-mac-trailer.h" | 25 #include "ns3/wifi-mac-trailer.h" |
26 #include "ns3/wifi-phy-tag.h" | 26 #include "ns3/wifi-phy-tag.h" |
27 #include "ns3/wifi-spectrum-signal-parameters.h" | 27 #include "ns3/wifi-spectrum-signal-parameters.h" |
| 28 #include "ns3/log.h" |
28 | 29 |
29 using namespace ns3; | 30 using namespace ns3; |
| 31 |
| 32 NS_LOG_COMPONENT_DEFINE ("SpectrumWifiPhyBasicTest"); |
30 | 33 |
31 static const uint8_t CHANNEL_NUMBER = 36; | 34 static const uint8_t CHANNEL_NUMBER = 36; |
32 static const uint32_t FREQUENCY = 5180; // MHz | 35 static const uint32_t FREQUENCY = 5180; // MHz |
33 static const uint8_t CHANNEL_WIDTH = 20; // MHz | 36 static const uint8_t CHANNEL_WIDTH = 20; // MHz |
34 static const uint8_t GUARD_WIDTH = CHANNEL_WIDTH; // MHz (expanded to channel wi
dth to model spectrum mask) | 37 static const uint8_t GUARD_WIDTH = CHANNEL_WIDTH; // MHz (expanded to channel wi
dth to model spectrum mask) |
35 | 38 |
36 /** | 39 /** |
37 * \ingroup wifi-test | 40 * \ingroup wifi-test |
38 * \ingroup tests | 41 * \ingroup tests |
39 * | 42 * |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 SpectrumWifiPhyBasicTest::SpectrumWifiPhyBasicTest (std::string name) | 94 SpectrumWifiPhyBasicTest::SpectrumWifiPhyBasicTest (std::string name) |
92 : TestCase (name), | 95 : TestCase (name), |
93 m_count (0) | 96 m_count (0) |
94 { | 97 { |
95 } | 98 } |
96 | 99 |
97 // Make a Wi-Fi signal to inject directly to the StartRx() method | 100 // Make a Wi-Fi signal to inject directly to the StartRx() method |
98 Ptr<SpectrumSignalParameters> | 101 Ptr<SpectrumSignalParameters> |
99 SpectrumWifiPhyBasicTest::MakeSignal (double txPowerWatts) | 102 SpectrumWifiPhyBasicTest::MakeSignal (double txPowerWatts) |
100 { | 103 { |
101 WifiTxVector txVector = WifiTxVector (WifiPhy::GetOfdmRate6Mbps (), 0, 0, WIFI
_PREAMBLE_LONG, false, 1, 1, 0, 20, false, false); | 104 WifiTxVector txVector = WifiTxVector (WifiPhy::GetOfdmRate6Mbps (), 0, WIFI_PR
EAMBLE_LONG, false, 1, 1, 0, 20, false, false); |
102 MpduType mpdutype = NORMAL_MPDU; | 105 MpduType mpdutype = NORMAL_MPDU; |
103 | 106 |
104 Ptr<Packet> pkt = Create<Packet> (1000); | 107 Ptr<Packet> pkt = Create<Packet> (1000); |
105 WifiMacHeader hdr; | 108 WifiMacHeader hdr; |
106 WifiMacTrailer trailer; | 109 WifiMacTrailer trailer; |
107 | 110 |
108 hdr.SetType (WIFI_MAC_QOSDATA); | 111 hdr.SetType (WIFI_MAC_QOSDATA); |
109 hdr.SetQosTid (0); | 112 hdr.SetQosTid (0); |
110 uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize (
); | 113 uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize (
); |
111 Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFreque
ncy (), mpdutype, 0); | 114 Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFreque
ncy (), mpdutype, 0); |
112 hdr.SetDuration (txDuration); | 115 hdr.SetDuration (txDuration); |
113 | 116 |
114 pkt->AddHeader (hdr); | 117 pkt->AddHeader (hdr); |
115 pkt->AddTrailer (trailer); | 118 pkt->AddTrailer (trailer); |
116 WifiPhyTag tag (txVector, mpdutype); | 119 WifiPhyTag tag (txVector, mpdutype, 1); |
117 pkt->AddPacketTag (tag); | 120 pkt->AddPacketTag (tag); |
118 Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateOfdmTxPowe
rSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, GUARD_WIDTH); | 121 Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateOfdmTxPowe
rSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, GUARD_WIDTH); |
119 Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParamete
rs> (); | 122 Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParamete
rs> (); |
120 txParams->psd = txPowerSpectrum; | 123 txParams->psd = txPowerSpectrum; |
121 txParams->txPhy = 0; | 124 txParams->txPhy = 0; |
122 txParams->duration = txDuration; | 125 txParams->duration = txDuration; |
123 txParams->packet = pkt; | 126 txParams->packet = pkt; |
124 return txParams; | 127 return txParams; |
125 } | 128 } |
126 | 129 |
127 // Make a Wi-Fi signal to inject directly to the StartRx() method | 130 // Make a Wi-Fi signal to inject directly to the StartRx() method |
128 void | 131 void |
129 SpectrumWifiPhyBasicTest::SendSignal (double txPowerWatts) | 132 SpectrumWifiPhyBasicTest::SendSignal (double txPowerWatts) |
130 { | 133 { |
131 m_phy->StartRx (MakeSignal (txPowerWatts)); | 134 m_phy->StartRx (MakeSignal (txPowerWatts)); |
132 } | 135 } |
133 | 136 |
134 void | 137 void |
135 SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, W
ifiTxVector txVector) | 138 SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, W
ifiTxVector txVector) |
136 { | 139 { |
| 140 NS_LOG_FUNCTION (this << p << snr << txVector); |
137 m_count++; | 141 m_count++; |
138 } | 142 } |
139 | 143 |
140 void | 144 void |
141 SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxFailure (Ptr<Packet> p, double snr) | 145 SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxFailure (Ptr<Packet> p, double snr) |
142 { | 146 { |
| 147 NS_LOG_FUNCTION (this << p << snr); |
143 m_count++; | 148 m_count++; |
144 } | 149 } |
145 | 150 |
146 SpectrumWifiPhyBasicTest::~SpectrumWifiPhyBasicTest () | 151 SpectrumWifiPhyBasicTest::~SpectrumWifiPhyBasicTest () |
147 { | 152 { |
148 } | 153 } |
149 | 154 |
150 // Create necessary objects, and inject signals. Test that the expected | 155 // Create necessary objects, and inject signals. Test that the expected |
151 // number of packet receptions occur. | 156 // number of packet receptions occur. |
152 void | 157 void |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 m_notifyRxEndOk (0), | 205 m_notifyRxEndOk (0), |
201 m_notifyRxEndError (0), | 206 m_notifyRxEndError (0), |
202 m_notifyMaybeCcaBusyStart (0) | 207 m_notifyMaybeCcaBusyStart (0) |
203 { | 208 { |
204 } | 209 } |
205 virtual ~TestPhyListener () | 210 virtual ~TestPhyListener () |
206 { | 211 { |
207 } | 212 } |
208 virtual void NotifyRxStart (Time duration) | 213 virtual void NotifyRxStart (Time duration) |
209 { | 214 { |
| 215 NS_LOG_FUNCTION (this << duration); |
210 ++m_notifyRxStart; | 216 ++m_notifyRxStart; |
211 } | 217 } |
212 virtual void NotifyRxEndOk (void) | 218 virtual void NotifyRxEndOk (void) |
213 { | 219 { |
| 220 NS_LOG_FUNCTION (this); |
214 ++m_notifyRxEndOk; | 221 ++m_notifyRxEndOk; |
215 } | 222 } |
216 virtual void NotifyRxEndError (void) | 223 virtual void NotifyRxEndError (void) |
217 { | 224 { |
| 225 NS_LOG_FUNCTION (this); |
218 ++m_notifyRxEndError; | 226 ++m_notifyRxEndError; |
219 } | 227 } |
220 virtual void NotifyTxStart (Time duration, double txPowerDbm) | 228 virtual void NotifyTxStart (Time duration, double txPowerDbm) |
221 { | 229 { |
| 230 NS_LOG_FUNCTION (this << duration << txPowerDbm); |
222 } | 231 } |
223 virtual void NotifyMaybeCcaBusyStart (Time duration) | 232 virtual void NotifyMaybeCcaBusyStart (Time duration) |
224 { | 233 { |
| 234 NS_LOG_FUNCTION (this); |
225 ++m_notifyMaybeCcaBusyStart; | 235 ++m_notifyMaybeCcaBusyStart; |
226 } | 236 } |
227 virtual void NotifySwitchingStart (Time duration) | 237 virtual void NotifySwitchingStart (Time duration) |
228 { | 238 { |
229 } | 239 } |
230 virtual void NotifySleep (void) | 240 virtual void NotifySleep (void) |
231 { | 241 { |
232 } | 242 } |
| 243 virtual void NotifyOff (void) |
| 244 { |
| 245 } |
233 virtual void NotifyWakeup (void) | 246 virtual void NotifyWakeup (void) |
| 247 { |
| 248 } |
| 249 virtual void NotifyOn (void) |
234 { | 250 { |
235 } | 251 } |
236 uint32_t m_notifyRxStart; ///< notify receive start | 252 uint32_t m_notifyRxStart; ///< notify receive start |
237 uint32_t m_notifyRxEndOk; ///< notify receive end OK | 253 uint32_t m_notifyRxEndOk; ///< notify receive end OK |
238 uint32_t m_notifyRxEndError; ///< notify receive end error | 254 uint32_t m_notifyRxEndError; ///< notify receive end error |
239 uint32_t m_notifyMaybeCcaBusyStart; ///< notify maybe CCA busy start | 255 uint32_t m_notifyMaybeCcaBusyStart; ///< notify maybe CCA busy start |
240 private: | 256 private: |
241 }; | 257 }; |
242 | 258 |
243 /** | 259 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 }; | 319 }; |
304 | 320 |
305 SpectrumWifiPhyTestSuite::SpectrumWifiPhyTestSuite () | 321 SpectrumWifiPhyTestSuite::SpectrumWifiPhyTestSuite () |
306 : TestSuite ("spectrum-wifi-phy", UNIT) | 322 : TestSuite ("spectrum-wifi-phy", UNIT) |
307 { | 323 { |
308 AddTestCase (new SpectrumWifiPhyBasicTest, TestCase::QUICK); | 324 AddTestCase (new SpectrumWifiPhyBasicTest, TestCase::QUICK); |
309 AddTestCase (new SpectrumWifiPhyListenerTest, TestCase::QUICK); | 325 AddTestCase (new SpectrumWifiPhyListenerTest, TestCase::QUICK); |
310 } | 326 } |
311 | 327 |
312 static SpectrumWifiPhyTestSuite spectrumWifiPhyTestSuite; ///< the test suite | 328 static SpectrumWifiPhyTestSuite spectrumWifiPhyTestSuite; ///< the test suite |
LEFT | RIGHT |