A Discrete-Event Network Simulator
API
ofdm-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Orange Labs
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  * Authors: Rediet <getachew.redieteab@orange.com>
19  * Sébastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
20  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr> (for logic ported from wifi-phy)
21  */
22 
23 #include "ofdm-phy.h"
24 #include "ofdm-ppdu.h"
25 #include "ns3/wifi-psdu.h"
26 #include "ns3/wifi-phy.h"
27 #include "ns3/wifi-utils.h"
28 #include "ns3/simulator.h"
29 #include "ns3/log.h"
30 #include <array>
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("OfdmPhy");
35 
36 /*******************************************************
37  * OFDM PHY (IEEE 802.11-2016, clause 17)
38  *******************************************************/
39 
40 /* *NS_CHECK_STYLE_OFF* */
45 };
46 
48  // Unique name Code rate Constellation size
49  { "OfdmRate6Mbps", { WIFI_CODE_RATE_1_2, 2 } }, // 20 MHz
50  { "OfdmRate9Mbps", { WIFI_CODE_RATE_3_4, 2 } }, // |
51  { "OfdmRate12Mbps", { WIFI_CODE_RATE_1_2, 4 } }, // V
52  { "OfdmRate18Mbps", { WIFI_CODE_RATE_3_4, 4 } },
53  { "OfdmRate24Mbps", { WIFI_CODE_RATE_1_2, 16 } },
54  { "OfdmRate36Mbps", { WIFI_CODE_RATE_3_4, 16 } },
55  { "OfdmRate48Mbps", { WIFI_CODE_RATE_2_3, 64 } },
56  { "OfdmRate54Mbps", { WIFI_CODE_RATE_3_4, 64 } },
57  { "OfdmRate3MbpsBW10MHz", { WIFI_CODE_RATE_1_2, 2 } }, // 10 MHz
58  { "OfdmRate4_5MbpsBW10MHz", { WIFI_CODE_RATE_3_4, 2 } }, // |
59  { "OfdmRate6MbpsBW10MHz", { WIFI_CODE_RATE_1_2, 4 } }, // V
60  { "OfdmRate9MbpsBW10MHz", { WIFI_CODE_RATE_3_4, 4 } },
61  { "OfdmRate12MbpsBW10MHz", { WIFI_CODE_RATE_1_2, 16 } },
62  { "OfdmRate18MbpsBW10MHz", { WIFI_CODE_RATE_3_4, 16 } },
63  { "OfdmRate24MbpsBW10MHz", { WIFI_CODE_RATE_2_3, 64 } },
64  { "OfdmRate27MbpsBW10MHz", { WIFI_CODE_RATE_3_4, 64 } },
65  { "OfdmRate1_5MbpsBW5MHz", { WIFI_CODE_RATE_1_2, 2 } }, // 5 MHz
66  { "OfdmRate2_25MbpsBW5MHz", { WIFI_CODE_RATE_3_4, 2 } }, // |
67  { "OfdmRate3MbpsBW5MHz", { WIFI_CODE_RATE_1_2, 4 } }, // V
68  { "OfdmRate4_5MbpsBW5MHz", { WIFI_CODE_RATE_3_4, 4 } },
69  { "OfdmRate6MbpsBW5MHz", { WIFI_CODE_RATE_1_2, 16 } },
70  { "OfdmRate9MbpsBW5MHz", { WIFI_CODE_RATE_3_4, 16 } },
71  { "OfdmRate12MbpsBW5MHz", { WIFI_CODE_RATE_2_3, 64 } },
72  { "OfdmRate13_5MbpsBW5MHz", { WIFI_CODE_RATE_3_4, 64 } }
73 };
74 
76 const std::map<uint16_t, std::array<uint64_t, 8> > s_ofdmRatesBpsList =
77  {{ 20, // MHz
78  { 6000000, 9000000, 12000000, 18000000,
79  24000000, 36000000, 48000000, 54000000 }},
80  { 10, // MHz
81  { 3000000, 4500000, 6000000, 9000000,
82  12000000, 18000000, 24000000, 27000000 }},
83  { 5, // MHz
84  { 1500000, 2250000, 3000000, 4500000,
85  6000000, 9000000, 12000000, 13500000 }}};
86 
87 /* *NS_CHECK_STYLE_ON* */
88 
94 const std::map<uint16_t, std::array<uint64_t, 8> >& GetOfdmRatesBpsList (void)
95 {
96  return s_ofdmRatesBpsList;
97 };
98 
99 
100 OfdmPhy::OfdmPhy (OfdmPhyVariant variant /* = OFDM_PHY_DEFAULT */, bool buildModeList /* = true */)
101 {
102  NS_LOG_FUNCTION (this << variant << buildModeList);
103 
104  if (buildModeList)
105  {
106  auto bwRatesMap = GetOfdmRatesBpsList ();
107 
108  switch (variant)
109  {
110  case OFDM_PHY_DEFAULT:
111  for (const auto & rate : bwRatesMap.at (20))
112  {
113  WifiMode mode = GetOfdmRate (rate, 20);
114  NS_LOG_LOGIC ("Add " << mode << " to list");
115  m_modeList.emplace_back (mode);
116  }
117  break;
118  case OFDM_PHY_10_MHZ:
119  for (const auto & rate : bwRatesMap.at (10))
120  {
121  WifiMode mode = GetOfdmRate (rate, 10);
122  NS_LOG_LOGIC ("Add " << mode << " to list");
123  m_modeList.emplace_back (mode);
124  }
125  break;
126  case OFDM_PHY_5_MHZ:
127  for (const auto & rate : bwRatesMap.at (5))
128  {
129  WifiMode mode = GetOfdmRate (rate, 5);
130  NS_LOG_LOGIC ("Add " << mode << " to list");
131  m_modeList.emplace_back (mode);
132  }
133  break;
134  default:
135  NS_ABORT_MSG ("Unsupported 11a OFDM variant");
136  }
137  }
138 }
139 
141 {
142  NS_LOG_FUNCTION (this);
143 }
144 
145 WifiMode
146 OfdmPhy::GetSigMode (WifiPpduField field, const WifiTxVector& txVector) const
147 {
148  switch (field)
149  {
150  case WIFI_PPDU_FIELD_PREAMBLE: //consider header mode for preamble (useful for InterferenceHelper)
152  return GetHeaderMode (txVector);
153  default:
154  return PhyEntity::GetSigMode (field, txVector);
155  }
156 }
157 
158 WifiMode
159 OfdmPhy::GetHeaderMode (const WifiTxVector& txVector) const
160 {
161  switch (txVector.GetChannelWidth ())
162  {
163  case 5:
164  return GetOfdmRate1_5MbpsBW5MHz ();
165  case 10:
166  return GetOfdmRate3MbpsBW10MHz ();
167  case 20:
168  default:
169  //Section 17.3.2 "PPDU frame format"; IEEE Std 802.11-2016.
170  //Actually this is only the first part of the PhyHeader,
171  //because the last 16 bits of the PhyHeader are using the
172  //same mode of the payload
173  return GetOfdmRate6Mbps ();
174  }
175 }
176 
179 {
180  return m_ofdmPpduFormats;
181 }
182 
183 Time
184 OfdmPhy::GetDuration (WifiPpduField field, const WifiTxVector& txVector) const
185 {
186  switch (field)
187  {
189  return GetPreambleDuration (txVector); //L-STF + L-LTF
191  return GetHeaderDuration (txVector); //L-SIG
192  default:
193  return PhyEntity::GetDuration (field, txVector);
194  }
195 }
196 
197 Time
199 {
200  switch (txVector.GetChannelWidth ())
201  {
202  case 20:
203  default:
204  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
205  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
206  return MicroSeconds (16);
207  case 10:
208  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
209  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
210  return MicroSeconds (32);
211  case 5:
212  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
213  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
214  return MicroSeconds (64);
215  }
216 }
217 
218 Time
220 {
221  switch (txVector.GetChannelWidth ())
222  {
223  case 20:
224  default:
225  //Section 17.3.3 "PHY preamble (SYNC)" and Figure 17-4 "OFDM training structure"; IEEE Std 802.11-2016
226  //also Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
227  //We return the duration of the SIGNAL field only, since the
228  //SERVICE field (which strictly speaking belongs to the PHY
229  //header, see Section 17.3.2 and Figure 17-1) is sent using the
230  //payload mode.
231  return MicroSeconds (4);
232  case 10:
233  //Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
234  return MicroSeconds (8);
235  case 5:
236  //Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
237  return MicroSeconds (16);
238  }
239 }
240 
241 Time
242 OfdmPhy::GetPayloadDuration (uint32_t size, const WifiTxVector& txVector, WifiPhyBand band, MpduType /* mpdutype */,
243  bool /* incFlag */, uint32_t & /* totalAmpduSize */, double & /* totalAmpduNumSymbols */,
244  uint16_t /* staId */) const
245 {
246  //(Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
247  //corresponds to T_{SYM} in the table)
248  Time symbolDuration = MicroSeconds (4);
249 
250  double numDataBitsPerSymbol = txVector.GetMode ().GetDataRate (txVector) * symbolDuration.GetNanoSeconds () / 1e9;
251 
252  //The number of OFDM symbols in the data field when BCC encoding
253  //is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
254  double numSymbols = lrint (ceil ((GetNumberServiceBits () + size * 8.0 + 6.0) / (numDataBitsPerSymbol)));
255 
256  Time payloadDuration = FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ()));
257  payloadDuration += GetSignalExtension (band);
258  return payloadDuration;
259 }
260 
261 uint8_t
263 {
264  return 16;
265 }
266 
267 Time
269 {
270  return (band == WIFI_PHY_BAND_2_4GHZ) ? MicroSeconds (6) : MicroSeconds (0);
271 }
272 
274 OfdmPhy::BuildPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, Time /* ppduDuration */)
275 {
276  NS_LOG_FUNCTION (this << psdus << txVector);
277  return Create<OfdmPpdu> (psdus.begin ()->second, txVector, m_wifiPhy->GetPhyBand (),
278  ObtainNextUid (txVector));
279 }
280 
283 {
284  NS_LOG_FUNCTION (this << field << *event);
285  if (field == WIFI_PPDU_FIELD_NON_HT_HEADER)
286  {
287  return EndReceiveHeader (event); //L-SIG
288  }
289  return PhyEntity::DoEndReceiveField (field, event);
290 }
291 
294 {
295  NS_LOG_FUNCTION (this << *event);
297  NS_LOG_DEBUG ("L-SIG: SNR(dB)=" << RatioToDb (snrPer.snr) << ", PER=" << snrPer.per);
298  PhyFieldRxStatus status (GetRandomValue () > snrPer.per);
299  if (status.isSuccess)
300  {
301  NS_LOG_DEBUG ("Received non-HT PHY header");
302  if (!IsAllConfigSupported (WIFI_PPDU_FIELD_NON_HT_HEADER, event->GetPpdu ()))
303  {
304  status = PhyFieldRxStatus (false, UNSUPPORTED_SETTINGS, DROP);
305  }
306  }
307  else
308  {
309  NS_LOG_DEBUG ("Abort reception because non-HT PHY header reception failed");
310  status.reason = L_SIG_FAILURE;
311  status.actionIfFailure = ABORT;
312  }
313  return status;
314 }
315 
316 bool
318 {
319  uint16_t channelWidth = ppdu->GetTxVector ().GetChannelWidth ();
320  if ((channelWidth >= 40) && (channelWidth > m_wifiPhy->GetChannelWidth ()))
321  {
322  NS_LOG_DEBUG ("Packet reception could not be started because not enough channel width (" << channelWidth << " vs " << m_wifiPhy->GetChannelWidth () << ")");
323  return false;
324  }
325  return true;
326 }
327 
328 bool
330 {
331  if (!IsChannelWidthSupported (ppdu))
332  {
333  return false;
334  }
335  return IsConfigSupported (ppdu);
336 }
337 
340 {
341  const WifiTxVector& txVector = ppdu->GetTxVector ();
342  uint16_t centerFrequency = GetCenterFrequencyForChannelWidth (txVector);
343  uint16_t channelWidth = txVector.GetChannelWidth ();
344  NS_LOG_FUNCTION (this << centerFrequency << channelWidth << txPowerW);
345  const auto & txMaskRejectionParams = GetTxMaskRejectionParams ();
346  Ptr<SpectrumValue> v = WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (centerFrequency, channelWidth, txPowerW, GetGuardBandwidth (channelWidth),
347  std::get<0> (txMaskRejectionParams), std::get<1> (txMaskRejectionParams), std::get<2> (txMaskRejectionParams));
348  return v;
349 }
350 
351 void
353 {
354  for (const auto & ratesPerBw : GetOfdmRatesBpsList ())
355  {
356  for (const auto & rate : ratesPerBw.second)
357  {
358  GetOfdmRate (rate, ratesPerBw.first);
359  }
360  }
361 }
362 
363 WifiMode
364 OfdmPhy::GetOfdmRate (uint64_t rate, uint16_t bw)
365 {
366  switch (bw)
367  {
368  case 20:
369  switch (rate)
370  {
371  case 6000000:
372  return GetOfdmRate6Mbps ();
373  case 9000000:
374  return GetOfdmRate9Mbps ();
375  case 12000000:
376  return GetOfdmRate12Mbps ();
377  case 18000000:
378  return GetOfdmRate18Mbps ();
379  case 24000000:
380  return GetOfdmRate24Mbps ();
381  case 36000000:
382  return GetOfdmRate36Mbps ();
383  case 48000000:
384  return GetOfdmRate48Mbps ();
385  case 54000000:
386  return GetOfdmRate54Mbps ();
387  default:
388  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (default)");
389  return WifiMode ();
390  }
391  break;
392  case 10:
393  switch (rate)
394  {
395  case 3000000:
396  return GetOfdmRate3MbpsBW10MHz ();
397  case 4500000:
398  return GetOfdmRate4_5MbpsBW10MHz ();
399  case 6000000:
400  return GetOfdmRate6MbpsBW10MHz ();
401  case 9000000:
402  return GetOfdmRate9MbpsBW10MHz ();
403  case 12000000:
404  return GetOfdmRate12MbpsBW10MHz ();
405  case 18000000:
406  return GetOfdmRate18MbpsBW10MHz ();
407  case 24000000:
408  return GetOfdmRate24MbpsBW10MHz ();
409  case 27000000:
410  return GetOfdmRate27MbpsBW10MHz ();
411  default:
412  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (10 MHz)");
413  return WifiMode ();
414  }
415  break;
416  case 5:
417  switch (rate)
418  {
419  case 1500000:
420  return GetOfdmRate1_5MbpsBW5MHz ();
421  case 2250000:
422  return GetOfdmRate2_25MbpsBW5MHz ();
423  case 3000000:
424  return GetOfdmRate3MbpsBW5MHz ();
425  case 4500000:
426  return GetOfdmRate4_5MbpsBW5MHz ();
427  case 6000000:
428  return GetOfdmRate6MbpsBW5MHz ();
429  case 9000000:
430  return GetOfdmRate9MbpsBW5MHz ();
431  case 12000000:
432  return GetOfdmRate12MbpsBW5MHz ();
433  case 13500000:
434  return GetOfdmRate13_5MbpsBW5MHz ();
435  default:
436  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (5 MHz)");
437  return WifiMode ();
438  }
439  break;
440  default:
441  NS_ABORT_MSG ("Inexistent bandwidth (" << +bw << " MHz) requested for 11a OFDM");
442  return WifiMode ();
443  }
444 }
445 
446 #define GET_OFDM_MODE(x, f) \
447 WifiMode \
448 OfdmPhy::Get ## x (void) \
449 { \
450  static WifiMode mode = CreateOfdmMode (#x, f); \
451  return mode; \
452 }; \
453 
454 // 20 MHz channel rates (default)
455 GET_OFDM_MODE (OfdmRate6Mbps, true)
456 GET_OFDM_MODE (OfdmRate9Mbps, false)
457 GET_OFDM_MODE (OfdmRate12Mbps, true)
458 GET_OFDM_MODE (OfdmRate18Mbps, false)
459 GET_OFDM_MODE (OfdmRate24Mbps, true)
460 GET_OFDM_MODE (OfdmRate36Mbps, false)
461 GET_OFDM_MODE (OfdmRate48Mbps, false)
462 GET_OFDM_MODE (OfdmRate54Mbps, false)
463 // 10 MHz channel rates
464 GET_OFDM_MODE (OfdmRate3MbpsBW10MHz, true)
465 GET_OFDM_MODE (OfdmRate4_5MbpsBW10MHz, false)
466 GET_OFDM_MODE (OfdmRate6MbpsBW10MHz, true)
467 GET_OFDM_MODE (OfdmRate9MbpsBW10MHz, false)
468 GET_OFDM_MODE (OfdmRate12MbpsBW10MHz, true)
469 GET_OFDM_MODE (OfdmRate18MbpsBW10MHz, false)
470 GET_OFDM_MODE (OfdmRate24MbpsBW10MHz, false)
471 GET_OFDM_MODE (OfdmRate27MbpsBW10MHz, false)
472 // 5 MHz channel rates
473 GET_OFDM_MODE (OfdmRate1_5MbpsBW5MHz, true)
474 GET_OFDM_MODE (OfdmRate2_25MbpsBW5MHz, false)
475 GET_OFDM_MODE (OfdmRate3MbpsBW5MHz, true)
476 GET_OFDM_MODE (OfdmRate4_5MbpsBW5MHz, false)
477 GET_OFDM_MODE (OfdmRate6MbpsBW5MHz, true)
478 GET_OFDM_MODE (OfdmRate9MbpsBW5MHz, false)
479 GET_OFDM_MODE (OfdmRate12MbpsBW5MHz, false)
480 GET_OFDM_MODE (OfdmRate13_5MbpsBW5MHz, false)
481 #undef GET_OFDM_MODE
482 
483 WifiMode
484 OfdmPhy::CreateOfdmMode (std::string uniqueName, bool isMandatory)
485 {
486  // Check whether uniqueName is in lookup table
487  const auto it = m_ofdmModulationLookupTable.find (uniqueName);
488  NS_ASSERT_MSG (it != m_ofdmModulationLookupTable.end (), "OFDM mode cannot be created because it is not in the lookup table!");
489 
490  return WifiModeFactory::CreateWifiMode (uniqueName,
492  isMandatory,
493  MakeBoundCallback (&GetCodeRate, uniqueName),
495  MakeBoundCallback (&GetPhyRate, uniqueName),
497  MakeBoundCallback (&GetDataRate, uniqueName),
500 }
501 
503 OfdmPhy::GetCodeRate (const std::string& name)
504 {
505  return m_ofdmModulationLookupTable.at (name).first;
506 }
507 
508 uint16_t
509 OfdmPhy::GetConstellationSize (const std::string& name)
510 {
511  return m_ofdmModulationLookupTable.at (name).second;
512 }
513 
514 uint64_t
515 OfdmPhy::GetPhyRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
516 {
517  WifiCodeRate codeRate = GetCodeRate (name);
518  uint64_t dataRate = GetDataRate (name, channelWidth, guardInterval, nss);
519  return CalculatePhyRate (codeRate, dataRate);
520 }
521 
522 uint64_t
523 OfdmPhy::CalculatePhyRate (WifiCodeRate codeRate, uint64_t dataRate)
524 {
525  return (dataRate / GetCodeRatio (codeRate));
526 }
527 
528 uint64_t
529 OfdmPhy::GetPhyRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
530 {
531  return GetPhyRate (txVector.GetMode ().GetUniqueName (),
532  txVector.GetChannelWidth (),
533  txVector.GetGuardInterval (),
534  txVector.GetNss ());
535 }
536 
537 double
539 {
540  switch (codeRate)
541  {
542  case WIFI_CODE_RATE_3_4:
543  return (3.0 / 4.0);
544  case WIFI_CODE_RATE_2_3:
545  return (2.0 / 3.0);
546  case WIFI_CODE_RATE_1_2:
547  return (1.0 / 2.0);
549  default:
550  NS_FATAL_ERROR ("trying to get code ratio for undefined coding rate");
551  return 0;
552  }
553 }
554 
555 uint64_t
556 OfdmPhy::GetDataRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
557 {
558  return GetDataRate (txVector.GetMode ().GetUniqueName (),
559  txVector.GetChannelWidth (),
560  txVector.GetGuardInterval (),
561  txVector.GetNss ());
562 }
563 
564 uint64_t
565 OfdmPhy::GetDataRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
566 {
567  WifiCodeRate codeRate = GetCodeRate (name);
568  uint16_t constellationSize = GetConstellationSize (name);
569  return CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
570 }
571 
572 uint64_t
573 OfdmPhy::CalculateDataRate (WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth, uint16_t /* guardInterval */, uint8_t /* nss */)
574 {
575  double symbolDuration = 3.2; //in us
576  uint16_t guardInterval = 800; //in ns
577  if (channelWidth == 10)
578  {
579  symbolDuration = 6.4;
580  guardInterval = 1600;
581  }
582  else if (channelWidth == 5)
583  {
584  symbolDuration = 12.8;
585  guardInterval = 3200;
586  }
587  return CalculateDataRate (symbolDuration, guardInterval,
588  48, static_cast<uint16_t> (log2 (constellationSize)),
589  GetCodeRatio (codeRate));
590 }
591 
592 uint64_t
593 OfdmPhy::CalculateDataRate (double symbolDuration, uint16_t guardInterval,
594  uint16_t usableSubCarriers, uint16_t numberOfBitsPerSubcarrier,
595  double codingRate)
596 {
597  double symbolRate = (1 / (symbolDuration + (static_cast<double> (guardInterval) / 1000))) * 1e6;
598  return lrint (ceil (symbolRate * usableSubCarriers * numberOfBitsPerSubcarrier * codingRate));
599 }
600 
601 bool
602 OfdmPhy::IsModeAllowed (uint16_t /* channelWidth */, uint8_t /* nss */)
603 {
604  return true;
605 }
606 
607 uint32_t
609 {
610  return 4095;
611 }
612 
613 } //namespace ns3
614 
615 namespace {
616 
620 static class ConstructorOfdm
621 {
622 public:
624  {
626  ns3::WifiPhy::AddStaticPhyEntity (ns3::WIFI_MOD_CLASS_OFDM, ns3::Create<ns3::OfdmPhy> ()); //default variant will do
627  }
629 
630 }
double snr
SNR in linear scale.
Definition: phy-entity.h:138
static class anonymous_namespace{ofdm-phy.cc}::ConstructorOfdm g_constructor_ofdm
the constructor for OFDM modes
virtual PhyFieldRxStatus DoEndReceiveField(WifiPpduField field, Ptr< Event > event)
End receiving a given field, perform amendment-specific actions, and provide the status of the recept...
Definition: phy-entity.cc:350
Declaration of ns3::OfdmPhy class and ns3::OfdmPhyVariant enum.
Constructor class for OFDM modes.
Definition: ofdm-phy.cc:620
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
static WifiMode GetOfdmRate24MbpsBW10MHz(void)
Return a WifiMode for OFDM at 24 Mbps with 10 MHz channel spacing.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static double GetCodeRatio(WifiCodeRate codeRate)
Convert WifiCodeRate to a ratio, e.g., code ratio of WIFI_CODE_RATE_1_2 is 0.5.
Definition: ofdm-phy.cc:538
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
PhyFieldRxStatus EndReceiveHeader(Ptr< Event > event)
End receiving the header, perform OFDM-specific actions, and provide the status of the reception...
Definition: ofdm-phy.cc:293
PhyRxFailureAction actionIfFailure
action to perform in case of failure
Definition: phy-entity.h:115
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
static bool IsModeAllowed(uint16_t channelWidth, uint8_t nss)
Check whether the combination of <WifiMode, channel width, NSS> is allowed.
Definition: ofdm-phy.cc:602
static const PpduFormats m_ofdmPpduFormats
OFDM PPDU formats.
Definition: ofdm-phy.h:436
static WifiMode GetOfdmRate1_5MbpsBW5MHz(void)
Return a WifiMode for OFDM at 1.5 Mbps with 5 MHz channel spacing.
uint8_t GetNumberServiceBits(void) const
Definition: ofdm-phy.cc:262
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1124
static WifiMode CreateOfdmMode(std::string uniqueName, bool isMandatory)
Create an OFDM mode from a unique name, the unique name must already be contained inside ModulationLo...
Definition: ofdm-phy.cc:484
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
WifiPhyRxfailureReason reason
failure reason
Definition: phy-entity.h:114
static WifiMode GetOfdmRate36Mbps(void)
Return a WifiMode for OFDM at 36 Mbps.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
static WifiMode GetOfdmRate18MbpsBW10MHz(void)
Return a WifiMode for OFDM at 18 Mbps with 10 MHz channel spacing.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
uint16_t GetGuardInterval(void) const
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
static WifiMode GetOfdmRate48Mbps(void)
Return a WifiMode for OFDM at 48 Mbps.
static WifiMode GetOfdmRate3MbpsBW10MHz(void)
Return a WifiMode for OFDM at 3 Mbps with 10 MHz channel spacing.
static WifiMode GetOfdmRate(uint64_t rate, uint16_t bw=20)
Return a WifiMode for OFDM corresponding to the provided rate and the channel bandwidth (20...
Definition: ofdm-phy.cc:364
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
Declaration of ns3::OfdmPpdu class.
virtual Time GetHeaderDuration(const WifiTxVector &txVector) const
Definition: ofdm-phy.cc:219
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition: phy-entity.h:487
static uint64_t CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
Calculate the PHY rate in bps from code rate and data rate.
Definition: ofdm-phy.cc:523
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
static WifiMode GetOfdmRate6MbpsBW5MHz(void)
Return a WifiMode for OFDM at 6 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate9MbpsBW5MHz(void)
Return a WifiMode for OFDM at 9 Mbps with 5 MHz channel spacing.
MpduType
The type of an MPDU.
static WifiMode GetOfdmRate3MbpsBW5MHz(void)
Return a WifiMode for OFDM at 3 Mbps with 5 MHz channel spacing.
virtual bool IsChannelWidthSupported(Ptr< const WifiPpdu > ppdu) const
Checks if the PPDU&#39;s bandwidth is supported by the PHY.
Definition: ofdm-phy.cc:317
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode...
uint16_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1233
SYNC + SFD fields for DSSS or ERP, shortSYNC + shortSFD fields for HR/DSSS or ERP, HT-GF-STF + HT-GF-LTF1 fields for HT-GF, L-STF + L-LTF fields otherwise.
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
Definition: ofdm-phy.cc:529
WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const override
Get the WifiMode for the SIG field specified by the PPDU field.
Definition: ofdm-phy.cc:146
std::tuple< double, double, double > GetTxMaskRejectionParams(void) const
Definition: phy-entity.cc:1067
SnrPer GetPhyHeaderSnrPer(WifiPpduField field, Ptr< Event > event) const
Obtain the SNR and PER of the PPDU field from the WifiPhy&#39;s InterferenceHelper class.
Definition: phy-entity.cc:250
Status of the reception of the PPDU field.
Definition: phy-entity.h:110
static WifiMode GetOfdmRate4_5MbpsBW10MHz(void)
Return a WifiMode for OFDM at 4.5 Mbps with 10 MHz channel spacing.
virtual bool IsConfigSupported(Ptr< const WifiPpdu > ppdu) const
Checks if the signaled configuration (excluding bandwidth) is supported by the PHY.
Definition: phy-entity.cc:901
static WifiCodeRate GetCodeRate(const std::string &name)
Return the WifiCodeRate from the OFDM mode&#39;s unique name using ModulationLookupTable.
Definition: ofdm-phy.cc:503
static void InitializeModes(void)
Initialize all OFDM modes (for all variants).
Definition: ofdm-phy.cc:352
Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype, bool incFlag, uint32_t &totalAmpduSize, double &totalAmpduNumSymbols, uint16_t staId) const override
Definition: ofdm-phy.cc:242
virtual bool IsAllConfigSupported(WifiPpduField field, Ptr< const WifiPpdu > ppdu) const
Checks if the signaled configuration (including bandwidth) is supported by the PHY.
Definition: ofdm-phy.cc:329
PhyFieldRxStatus DoEndReceiveField(WifiPpduField field, Ptr< Event > event) override
End receiving a given field, perform amendment-specific actions, and provide the status of the recept...
Definition: ofdm-phy.cc:282
OfdmPhyVariant
The OFDM (11a) PHY variants.
Definition: ofdm-phy.h:43
WifiPpduField
The type of PPDU field (grouped for convenience)
OfdmPhy(OfdmPhyVariant variant=OFDM_PHY_DEFAULT, bool buildModeList=true)
Constructor for OFDM PHY.
Definition: ofdm-phy.cc:100
Time GetSignalExtension(WifiPhyBand band) const
Definition: ofdm-phy.cc:268
const std::map< uint16_t, std::array< uint64_t, 8 > > s_ofdmRatesBpsList
OFDM rates in bits per second for each bandwidth (MHz)
Definition: ofdm-phy.cc:76
Ptr< SpectrumValue > GetTxPowerSpectralDensity(double txPowerW, Ptr< const WifiPpdu > ppdu) const override
Definition: ofdm-phy.cc:339
static WifiMode GetOfdmRate54Mbps(void)
Return a WifiMode for OFDM at 54 Mbps.
virtual Time GetDuration(WifiPpduField field, const WifiTxVector &txVector) const
Get the duration of the PPDU field (or group of fields) used by this entity for the given transmissio...
Definition: phy-entity.cc:176
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
Definition: phy-entity.cc:1021
uint16_t GetCenterFrequencyForChannelWidth(const WifiTxVector &txVector) const
Get the center frequency of the channel corresponding the current TxVector rather than that of the su...
Definition: phy-entity.cc:1028
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Calculates data rate from the supplied parameters.
Definition: ofdm-phy.cc:573
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
std::string GetUniqueName(void) const
Definition: wifi-mode.cc:122
bool isSuccess
outcome (true if success) of the reception
Definition: phy-entity.h:113
A struct for both SNR and PER.
Definition: phy-entity.h:136
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
static WifiMode GetOfdmRate9Mbps(void)
Return a WifiMode for OFDM at 9 Mbps.
uint32_t GetMaxPsduSize(void) const override
Get the maximum PSDU size in bytes.
Definition: ofdm-phy.cc:608
const std::map< uint16_t, std::array< uint64_t, 8 > > & GetOfdmRatesBpsList(void)
Get the array of possible OFDM rates for each bandwidth (MHz).
Definition: ofdm-phy.cc:94
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, PhyRateFromTxVectorCallback phyRateFromTxVectorCallback, DataRateCallback dataRateCallback, DataRateFromTxVectorCallback dataRateFromTxVectorCallback, ModeAllowedCallback isModeAllowedCallback)
Definition: wifi-mode.cc:242
abort reception of PPDU
Definition: phy-entity.h:103
static const ModulationLookupTable m_ofdmModulationLookupTable
lookup table to retrieve code rate and constellation size corresponding to a unique name of modulatio...
Definition: ofdm-phy.h:438
static WifiMode GetOfdmRate9MbpsBW10MHz(void)
Return a WifiMode for OFDM at 9 Mbps with 10 MHz channel spacing.
virtual WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const
Get the WifiMode for the SIG field specified by the PPDU field.
Definition: phy-entity.cc:141
static WifiMode GetOfdmRate12MbpsBW10MHz(void)
Return a WifiMode for OFDM at 12 Mbps with 10 MHz channel spacing.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
static void AddStaticPhyEntity(WifiModulationClass modulation, Ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of implemented PHY entities for the given modulation class...
Definition: wifi-phy.cc:886
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
const PpduFormats & GetPpduFormats(void) const override
Return the PPDU formats of the PHY.
Definition: ofdm-phy.cc:178
drop PPDU and set CCA_BUSY
Definition: phy-entity.h:102
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth, double minInnerBandDbr=-20, double minOuterbandDbr=-28, double lowestPointDbr=-40)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
static WifiMode GetOfdmRate2_25MbpsBW5MHz(void)
Return a WifiMode for OFDM at 2.25 Mbps with 5 MHz channel spacing.
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:53
static uint64_t GetPhyRate(const std::string &name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the PHY rate from the OFDM mode&#39;s unique name and the supplied parameters. ...
Definition: ofdm-phy.cc:515
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
Definition: ofdm-phy.cc:556
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
static uint16_t GetConstellationSize(const std::string &name)
Return the constellation size from the OFDM mode&#39;s unique name using ModulationLookupTable.
Definition: ofdm-phy.cc:509
static WifiMode GetOfdmRate6MbpsBW10MHz(void)
Return a WifiMode for OFDM at 6 Mbps with 10 MHz channel spacing.
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:32
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
Definition: ofdm-phy.cc:274
static WifiMode GetOfdmRate4_5MbpsBW5MHz(void)
Return a WifiMode for OFDM at 4.5 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate27MbpsBW10MHz(void)
Return a WifiMode for OFDM at 27 Mbps with 10 MHz channel spacing.
static uint64_t GetDataRate(const std::string &name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the data rate from the OFDM mode&#39;s unique name and the supplied parameters.
Definition: ofdm-phy.cc:565
static WifiMode GetOfdmRate6Mbps(void)
Return a WifiMode for OFDM at 6 Mbps.
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
Definition: phy-entity.h:477
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
const uint16_t WIFI_CODE_RATE_UNDEFINED
undefined coding rate
static WifiMode GetOfdmRate13_5MbpsBW5MHz(void)
Return a WifiMode for OFDM at 13.5 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate24Mbps(void)
Return a WifiMode for OFDM at 24 Mbps.
double GetRandomValue(void) const
Obtain a random value from the WifiPhy&#39;s generator.
Definition: phy-entity.cc:991
#define GET_OFDM_MODE(x, f)
Definition: ofdm-phy.cc:446
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
virtual WifiMode GetHeaderMode(const WifiTxVector &txVector) const
Definition: ofdm-phy.cc:159
uint16_t GetChannelWidth(void) const
Time GetDuration(WifiPpduField field, const WifiTxVector &txVector) const override
Get the duration of the PPDU field (or group of fields) used by this entity for the given transmissio...
Definition: ofdm-phy.cc:184
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1329
virtual ~OfdmPhy()
Destructor for OFDM PHY.
Definition: ofdm-phy.cc:140
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:400
PHY header field for DSSS or ERP, short PHY header field for HR/DSSS or ERP, field not present for HT...
static WifiMode GetOfdmRate12MbpsBW5MHz(void)
Return a WifiMode for OFDM at 12 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate12Mbps(void)
Return a WifiMode for OFDM at 12Mbps.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
virtual Time GetPreambleDuration(const WifiTxVector &txVector) const
Definition: ofdm-phy.cc:198
static WifiMode GetOfdmRate18Mbps(void)
Return a WifiMode for OFDM at 18 Mbps.
std::list< WifiMode > m_modeList
the list of supported modes
Definition: phy-entity.h:786
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:783
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const
Definition: phy-entity.cc:1061