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 
75 // OFDM rates in bits per second
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 
89 const std::map<uint16_t, std::array<uint64_t, 8> >& GetOfdmRatesBpsList (void)
90 {
91  return s_ofdmRatesBpsList;
92 };
93 
94 
95 OfdmPhy::OfdmPhy (OfdmPhyVariant variant /* = OFDM_PHY_DEFAULT */, bool buildModeList /* = true */)
96 {
97  NS_LOG_FUNCTION (this << variant << buildModeList);
98 
99  if (buildModeList)
100  {
101  auto bwRatesMap = GetOfdmRatesBpsList ();
102 
103  switch (variant)
104  {
105  case OFDM_PHY_DEFAULT:
106  for (const auto & rate : bwRatesMap.at (20))
107  {
108  WifiMode mode = GetOfdmRate (rate, 20);
109  NS_LOG_LOGIC ("Add " << mode << " to list");
110  m_modeList.emplace_back (mode);
111  }
112  break;
113  case OFDM_PHY_10_MHZ:
114  for (const auto & rate : bwRatesMap.at (10))
115  {
116  WifiMode mode = GetOfdmRate (rate, 10);
117  NS_LOG_LOGIC ("Add " << mode << " to list");
118  m_modeList.emplace_back (mode);
119  }
120  break;
121  case OFDM_PHY_5_MHZ:
122  for (const auto & rate : bwRatesMap.at (5))
123  {
124  WifiMode mode = GetOfdmRate (rate, 5);
125  NS_LOG_LOGIC ("Add " << mode << " to list");
126  m_modeList.emplace_back (mode);
127  }
128  break;
129  default:
130  NS_ABORT_MSG ("Unsupported 11a OFDM variant");
131  }
132  }
133 }
134 
136 {
137  NS_LOG_FUNCTION (this);
138 }
139 
140 WifiMode
141 OfdmPhy::GetSigMode (WifiPpduField field, const WifiTxVector& txVector) const
142 {
143  switch (field)
144  {
145  case WIFI_PPDU_FIELD_PREAMBLE: //consider header mode for preamble (useful for InterferenceHelper)
147  return GetHeaderMode (txVector);
148  default:
149  return PhyEntity::GetSigMode (field, txVector);
150  }
151 }
152 
153 WifiMode
154 OfdmPhy::GetHeaderMode (const WifiTxVector& txVector) const
155 {
156  switch (txVector.GetChannelWidth ())
157  {
158  case 5:
159  return GetOfdmRate1_5MbpsBW5MHz ();
160  case 10:
161  return GetOfdmRate3MbpsBW10MHz ();
162  case 20:
163  default:
164  //Section 17.3.2 "PPDU frame format"; IEEE Std 802.11-2016.
165  //Actually this is only the first part of the PhyHeader,
166  //because the last 16 bits of the PhyHeader are using the
167  //same mode of the payload
168  return GetOfdmRate6Mbps ();
169  }
170 }
171 
174 {
175  return m_ofdmPpduFormats;
176 }
177 
178 Time
179 OfdmPhy::GetDuration (WifiPpduField field, const WifiTxVector& txVector) const
180 {
181  switch (field)
182  {
184  return GetPreambleDuration (txVector); //L-STF + L-LTF
186  return GetHeaderDuration (txVector); //L-SIG
187  default:
188  return PhyEntity::GetDuration (field, txVector);
189  }
190 }
191 
192 Time
194 {
195  switch (txVector.GetChannelWidth ())
196  {
197  case 20:
198  default:
199  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
200  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
201  return MicroSeconds (16);
202  case 10:
203  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
204  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
205  return MicroSeconds (32);
206  case 5:
207  //Section 17.3.3 "PHY preamble (SYNC)" Figure 17-4 "OFDM training structure"
208  //also Section 17.3.2.3 "Modulation-dependent parameters" Table 17-4 "Modulation-dependent parameters"; IEEE Std 802.11-2016
209  return MicroSeconds (64);
210  }
211 }
212 
213 Time
215 {
216  switch (txVector.GetChannelWidth ())
217  {
218  case 20:
219  default:
220  //Section 17.3.3 "PHY preamble (SYNC)" and Figure 17-4 "OFDM training structure"; IEEE Std 802.11-2016
221  //also Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
222  //We return the duration of the SIGNAL field only, since the
223  //SERVICE field (which strictly speaking belongs to the PHY
224  //header, see Section 17.3.2 and Figure 17-1) is sent using the
225  //payload mode.
226  return MicroSeconds (4);
227  case 10:
228  //Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
229  return MicroSeconds (8);
230  case 5:
231  //Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
232  return MicroSeconds (16);
233  }
234 }
235 
236 Time
237 OfdmPhy::GetPayloadDuration (uint32_t size, const WifiTxVector& txVector, WifiPhyBand band, MpduType /* mpdutype */,
238  bool /* incFlag */, uint32_t & /* totalAmpduSize */, double & /* totalAmpduNumSymbols */,
239  uint16_t /* staId */) const
240 {
241  //(Section 17.3.2.4 "Timing related parameters" Table 17-5 "Timing-related parameters"; IEEE Std 802.11-2016
242  //corresponds to T_{SYM} in the table)
243  Time symbolDuration = MicroSeconds (4);
244 
245  double numDataBitsPerSymbol = txVector.GetMode ().GetDataRate (txVector) * symbolDuration.GetNanoSeconds () / 1e9;
246 
247  //The number of OFDM symbols in the data field when BCC encoding
248  //is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
249  double numSymbols = lrint (ceil ((GetNumberServiceBits () + size * 8.0 + 6.0) / (numDataBitsPerSymbol)));
250 
251  Time payloadDuration = FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ()));
252  payloadDuration += GetSignalExtension (band);
253  return payloadDuration;
254 }
255 
256 uint8_t
258 {
259  return 16;
260 }
261 
262 Time
264 {
265  return (band == WIFI_PHY_BAND_2_4GHZ) ? MicroSeconds (6) : MicroSeconds (0);
266 }
267 
269 OfdmPhy::BuildPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, Time /* ppduDuration */)
270 {
271  NS_LOG_FUNCTION (this << psdus << txVector);
272  return Create<OfdmPpdu> (psdus.begin ()->second, txVector, m_wifiPhy->GetPhyBand (),
273  ObtainNextUid (txVector));
274 }
275 
278 {
279  NS_LOG_FUNCTION (this << field << *event);
280  if (field == WIFI_PPDU_FIELD_NON_HT_HEADER)
281  {
282  return EndReceiveHeader (event); //L-SIG
283  }
284  return PhyEntity::DoEndReceiveField (field, event);
285 }
286 
289 {
290  NS_LOG_FUNCTION (this << *event);
292  NS_LOG_DEBUG ("L-SIG: SNR(dB)=" << RatioToDb (snrPer.snr) << ", PER=" << snrPer.per);
293  PhyFieldRxStatus status (GetRandomValue () > snrPer.per);
294  if (status.isSuccess)
295  {
296  NS_LOG_DEBUG ("Received non-HT PHY header");
297  if (!IsAllConfigSupported (WIFI_PPDU_FIELD_NON_HT_HEADER, event->GetPpdu ()))
298  {
299  status = PhyFieldRxStatus (false, UNSUPPORTED_SETTINGS, DROP);
300  }
301  }
302  else
303  {
304  NS_LOG_DEBUG ("Abort reception because non-HT PHY header reception failed");
305  status.reason = L_SIG_FAILURE;
306  status.actionIfFailure = ABORT;
307  }
308  return status;
309 }
310 
311 bool
313 {
314  uint16_t channelWidth = ppdu->GetTxVector ().GetChannelWidth ();
315  if ((channelWidth >= 40) && (channelWidth > m_wifiPhy->GetChannelWidth ()))
316  {
317  NS_LOG_DEBUG ("Packet reception could not be started because not enough channel width (" << channelWidth << " vs " << m_wifiPhy->GetChannelWidth () << ")");
318  return false;
319  }
320  return true;
321 }
322 
323 bool
325 {
326  if (!IsChannelWidthSupported (ppdu))
327  {
328  return false;
329  }
330  return IsConfigSupported (ppdu);
331 }
332 
335 {
336  const WifiTxVector& txVector = ppdu->GetTxVector ();
337  uint16_t centerFrequency = GetCenterFrequencyForChannelWidth (txVector);
338  uint16_t channelWidth = txVector.GetChannelWidth ();
339  NS_LOG_FUNCTION (this << centerFrequency << channelWidth << txPowerW);
340  const auto & txMaskRejectionParams = GetTxMaskRejectionParams ();
341  Ptr<SpectrumValue> v = WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (centerFrequency, channelWidth, txPowerW, GetGuardBandwidth (channelWidth),
342  std::get<0> (txMaskRejectionParams), std::get<1> (txMaskRejectionParams), std::get<2> (txMaskRejectionParams));
343  return v;
344 }
345 
346 void
348 {
349  for (const auto & ratesPerBw : GetOfdmRatesBpsList ())
350  {
351  for (const auto & rate : ratesPerBw.second)
352  {
353  GetOfdmRate (rate, ratesPerBw.first);
354  }
355  }
356 }
357 
358 WifiMode
359 OfdmPhy::GetOfdmRate (uint64_t rate, uint16_t bw)
360 {
361  switch (bw)
362  {
363  case 20:
364  switch (rate)
365  {
366  case 6000000:
367  return GetOfdmRate6Mbps ();
368  case 9000000:
369  return GetOfdmRate9Mbps ();
370  case 12000000:
371  return GetOfdmRate12Mbps ();
372  case 18000000:
373  return GetOfdmRate18Mbps ();
374  case 24000000:
375  return GetOfdmRate24Mbps ();
376  case 36000000:
377  return GetOfdmRate36Mbps ();
378  case 48000000:
379  return GetOfdmRate48Mbps ();
380  case 54000000:
381  return GetOfdmRate54Mbps ();
382  default:
383  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (default)");
384  return WifiMode ();
385  }
386  break;
387  case 10:
388  switch (rate)
389  {
390  case 3000000:
391  return GetOfdmRate3MbpsBW10MHz ();
392  case 4500000:
393  return GetOfdmRate4_5MbpsBW10MHz ();
394  case 6000000:
395  return GetOfdmRate6MbpsBW10MHz ();
396  case 9000000:
397  return GetOfdmRate9MbpsBW10MHz ();
398  case 12000000:
399  return GetOfdmRate12MbpsBW10MHz ();
400  case 18000000:
401  return GetOfdmRate18MbpsBW10MHz ();
402  case 24000000:
403  return GetOfdmRate24MbpsBW10MHz ();
404  case 27000000:
405  return GetOfdmRate27MbpsBW10MHz ();
406  default:
407  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (10 MHz)");
408  return WifiMode ();
409  }
410  break;
411  case 5:
412  switch (rate)
413  {
414  case 1500000:
415  return GetOfdmRate1_5MbpsBW5MHz ();
416  case 2250000:
417  return GetOfdmRate2_25MbpsBW5MHz ();
418  case 3000000:
419  return GetOfdmRate3MbpsBW5MHz ();
420  case 4500000:
421  return GetOfdmRate4_5MbpsBW5MHz ();
422  case 6000000:
423  return GetOfdmRate6MbpsBW5MHz ();
424  case 9000000:
425  return GetOfdmRate9MbpsBW5MHz ();
426  case 12000000:
427  return GetOfdmRate12MbpsBW5MHz ();
428  case 13500000:
429  return GetOfdmRate13_5MbpsBW5MHz ();
430  default:
431  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for 11a OFDM (5 MHz)");
432  return WifiMode ();
433  }
434  break;
435  default:
436  NS_ABORT_MSG ("Inexistent bandwidth (" << +bw << " MHz) requested for 11a OFDM");
437  return WifiMode ();
438  }
439 }
440 
441 #define GET_OFDM_MODE(x, f) \
442 WifiMode \
443 OfdmPhy::Get ## x (void) \
444 { \
445  static WifiMode mode = CreateOfdmMode (#x, f); \
446  return mode; \
447 } \
448 
449 // 20 MHz channel rates (default)
450 GET_OFDM_MODE (OfdmRate6Mbps, true );
451 GET_OFDM_MODE (OfdmRate9Mbps, false);
452 GET_OFDM_MODE (OfdmRate12Mbps, true );
453 GET_OFDM_MODE (OfdmRate18Mbps, false);
454 GET_OFDM_MODE (OfdmRate24Mbps, true );
455 GET_OFDM_MODE (OfdmRate36Mbps, false);
456 GET_OFDM_MODE (OfdmRate48Mbps, false);
457 GET_OFDM_MODE (OfdmRate54Mbps, false);
458 // 10 MHz channel rates
459 GET_OFDM_MODE (OfdmRate3MbpsBW10MHz, true );
460 GET_OFDM_MODE (OfdmRate4_5MbpsBW10MHz, false);
461 GET_OFDM_MODE (OfdmRate6MbpsBW10MHz, true );
462 GET_OFDM_MODE (OfdmRate9MbpsBW10MHz, false);
463 GET_OFDM_MODE (OfdmRate12MbpsBW10MHz, true );
464 GET_OFDM_MODE (OfdmRate18MbpsBW10MHz, false);
465 GET_OFDM_MODE (OfdmRate24MbpsBW10MHz, false);
466 GET_OFDM_MODE (OfdmRate27MbpsBW10MHz, false);
467 // 5 MHz channel rates
468 GET_OFDM_MODE (OfdmRate1_5MbpsBW5MHz, true );
469 GET_OFDM_MODE (OfdmRate2_25MbpsBW5MHz, false);
470 GET_OFDM_MODE (OfdmRate3MbpsBW5MHz, true );
471 GET_OFDM_MODE (OfdmRate4_5MbpsBW5MHz, false);
472 GET_OFDM_MODE (OfdmRate6MbpsBW5MHz, true );
473 GET_OFDM_MODE (OfdmRate9MbpsBW5MHz, false);
474 GET_OFDM_MODE (OfdmRate12MbpsBW5MHz, false);
475 GET_OFDM_MODE (OfdmRate13_5MbpsBW5MHz, false);
476 #undef GET_OFDM_MODE
477 
478 WifiMode
479 OfdmPhy::CreateOfdmMode (std::string uniqueName, bool isMandatory)
480 {
481  // Check whether uniqueName is in lookup table
482  const auto it = m_ofdmModulationLookupTable.find (uniqueName);
483  NS_ASSERT_MSG (it != m_ofdmModulationLookupTable.end (), "OFDM mode cannot be created because it is not in the lookup table!");
484 
485  return WifiModeFactory::CreateWifiMode (uniqueName,
487  isMandatory,
488  MakeBoundCallback (&GetCodeRate, uniqueName),
490  MakeBoundCallback (&GetPhyRate, uniqueName),
492  MakeBoundCallback (&GetDataRate, uniqueName),
495 }
496 
498 OfdmPhy::GetCodeRate (const std::string& name)
499 {
500  return m_ofdmModulationLookupTable.at (name).first;
501 }
502 
503 uint16_t
504 OfdmPhy::GetConstellationSize (const std::string& name)
505 {
506  return m_ofdmModulationLookupTable.at (name).second;
507 }
508 
509 uint64_t
510 OfdmPhy::GetPhyRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
511 {
512  WifiCodeRate codeRate = GetCodeRate (name);
513  uint64_t dataRate = GetDataRate (name, channelWidth, guardInterval, nss);
514  return CalculatePhyRate (codeRate, dataRate);
515 }
516 
517 uint64_t
518 OfdmPhy::CalculatePhyRate (WifiCodeRate codeRate, uint64_t dataRate)
519 {
520  return (dataRate / GetCodeRatio (codeRate));
521 }
522 
523 uint64_t
524 OfdmPhy::GetPhyRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
525 {
526  return GetPhyRate (txVector.GetMode ().GetUniqueName (),
527  txVector.GetChannelWidth (),
528  txVector.GetGuardInterval (),
529  txVector.GetNss ());
530 }
531 
532 double
534 {
535  switch (codeRate)
536  {
537  case WIFI_CODE_RATE_3_4:
538  return (3.0 / 4.0);
539  case WIFI_CODE_RATE_2_3:
540  return (2.0 / 3.0);
541  case WIFI_CODE_RATE_1_2:
542  return (1.0 / 2.0);
544  default:
545  NS_FATAL_ERROR ("trying to get code ratio for undefined coding rate");
546  return 0;
547  }
548 }
549 
550 uint64_t
551 OfdmPhy::GetDataRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
552 {
553  return GetDataRate (txVector.GetMode ().GetUniqueName (),
554  txVector.GetChannelWidth (),
555  txVector.GetGuardInterval (),
556  txVector.GetNss ());
557 }
558 
559 uint64_t
560 OfdmPhy::GetDataRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
561 {
562  WifiCodeRate codeRate = GetCodeRate (name);
563  uint16_t constellationSize = GetConstellationSize (name);
564  return CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
565 }
566 
567 uint64_t
568 OfdmPhy::CalculateDataRate (WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth, uint16_t /* guardInterval */, uint8_t /* nss */)
569 {
570  double symbolDuration = 3.2; //in us
571  uint16_t guardInterval = 800; //in ns
572  if (channelWidth == 10)
573  {
574  symbolDuration = 6.4;
575  guardInterval = 1600;
576  }
577  else if (channelWidth == 5)
578  {
579  symbolDuration = 12.8;
580  guardInterval = 3200;
581  }
582  return CalculateDataRate (symbolDuration, guardInterval,
583  48, static_cast<uint16_t> (log2 (constellationSize)),
584  GetCodeRatio (codeRate));
585 }
586 
587 uint64_t
588 OfdmPhy::CalculateDataRate (double symbolDuration, uint16_t guardInterval,
589  uint16_t usableSubCarriers, uint16_t numberOfBitsPerSubcarrier,
590  double codingRate)
591 {
592  double symbolRate = (1 / (symbolDuration + (static_cast<double> (guardInterval) / 1000))) * 1e6;
593  return lrint (ceil (symbolRate * usableSubCarriers * numberOfBitsPerSubcarrier * codingRate));
594 }
595 
596 bool
597 OfdmPhy::IsModeAllowed (uint16_t /* channelWidth */, uint8_t /* nss */)
598 {
599  return true;
600 }
601 
602 uint32_t
604 {
605  return 4095;
606 }
607 
608 } //namespace ns3
609 
610 namespace {
611 
615 static class ConstructorOfdm
616 {
617 public:
619  {
621  ns3::WifiPhy::AddStaticPhyEntity (ns3::WIFI_MOD_CLASS_OFDM, ns3::Create<ns3::OfdmPhy> ()); //default variant will do
622  }
624 
625 }
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:615
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:533
#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:288
PhyRxFailureAction actionIfFailure
action to perform in case of failure
Definition: phy-entity.h:115
const uint16_t WIFI_CODE_RATE_2_3
static bool IsModeAllowed(uint16_t channelWidth, uint8_t nss)
Check whether the combination of <WifiMode, channel width, NSS> is allowed.
Definition: ofdm-phy.cc:597
static const PpduFormats m_ofdmPpduFormats
OFDM PPDU formats.
Definition: ofdm-phy.h:445
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:257
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:479
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:359
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:214
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition: phy-entity.h:509
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:518
const uint16_t WIFI_CODE_RATE_3_4
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:312
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:524
virtual 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:141
std::tuple< double, double, double > GetTxMaskRejectionParams(void) const
Definition: phy-entity.cc:1061
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:498
static void InitializeModes(void)
Initialize all OFDM modes (for all variants).
Definition: ofdm-phy.cc:347
virtual 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:237
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:324
virtual 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:277
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:95
Time GetSignalExtension(WifiPhyBand band) const
Definition: ofdm-phy.cc:263
const std::map< uint16_t, std::array< uint64_t, 8 > > s_ofdmRatesBpsList
Definition: ofdm-phy.cc:76
virtual Ptr< SpectrumValue > GetTxPowerSpectralDensity(double txPowerW, Ptr< const WifiPpdu > ppdu) const override
Definition: ofdm-phy.cc:334
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:1015
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:1022
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:568
#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.
virtual uint32_t GetMaxPsduSize(void) const override
Get the maximum PSDU size in bytes (see Table 17-21 OFDM PHY characteristics of IEEE 802...
Definition: ofdm-phy.cc:603
const std::map< uint16_t, std::array< uint64_t, 8 > > & GetOfdmRatesBpsList(void)
Definition: ofdm-phy.cc:89
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:447
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
virtual const PpduFormats & GetPpduFormats(void) const override
Return the PPDU formats of the PHY.
Definition: ofdm-phy.cc:173
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:510
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
Definition: ofdm-phy.cc:551
#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:504
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
virtual Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
Definition: ofdm-phy.cc:269
GET_OFDM_MODE(OfdmRate6Mbps, true)
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:560
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:499
#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
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
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:154
uint16_t GetChannelWidth(void) const
virtual 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:179
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:135
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:193
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:811
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:808
const uint16_t WIFI_CODE_RATE_1_2
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const
Definition: phy-entity.cc:1055