A Discrete-Event Network Simulator
API
ht-phy.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Orange Labs
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Rediet <getachew.redieteab@orange.com>
18 * Sébastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
19 */
20
21#include "ht-phy.h"
22
23#include "ht-ppdu.h"
24
25#include "ns3/assert.h"
26#include "ns3/interference-helper.h"
27#include "ns3/log.h"
28#include "ns3/wifi-phy.h"
29#include "ns3/wifi-psdu.h"
30#include "ns3/wifi-utils.h"
31
32namespace ns3
33{
34
36
37/*******************************************************
38 * HT PHY (IEEE 802.11-2016, clause 19)
39 *******************************************************/
40
41// clang-format off
42
46 WIFI_PPDU_FIELD_HT_SIG, // HT-SIG
47 WIFI_PPDU_FIELD_TRAINING, // HT-STF + HT-LTFs
49};
50
51// clang-format on
52
53HtPhy::HtPhy(uint8_t maxNss /* = 1 */, bool buildModeList /* = true */)
54 : OfdmPhy(OFDM_PHY_DEFAULT, false) // don't add OFDM modes to list
55{
56 NS_LOG_FUNCTION(this << +maxNss << buildModeList);
57 m_maxSupportedNss = maxNss;
61 if (buildModeList)
62 {
63 NS_ABORT_MSG_IF(maxNss == 0 || maxNss > 4,
64 "Unsupported max Nss " << +maxNss << " for HT PHY");
66 }
67}
68
70{
71 NS_LOG_FUNCTION(this);
72}
73
74void
76{
77 NS_LOG_FUNCTION(this);
78 NS_ASSERT(m_modeList.empty());
80
81 uint8_t index = 0;
82 for (uint8_t nss = 1; nss <= m_maxSupportedNss; ++nss)
83 {
84 for (uint8_t i = 0; i <= m_maxSupportedMcsIndexPerSs; ++i)
85 {
86 NS_LOG_LOGIC("Add HtMcs" << +index << " to list");
87 m_modeList.emplace_back(CreateHtMcs(index));
88 ++index;
89 }
90 index = 8 * nss;
91 }
92}
93
95HtPhy::GetMcs(uint8_t index) const
96{
97 for (const auto& mcs : m_modeList)
98 {
99 if (mcs.GetMcsValue() == index)
100 {
101 return mcs;
102 }
103 }
104
105 // Should have returned if MCS found
106 NS_ABORT_MSG("Unsupported MCS index " << +index << " for this PHY entity");
107 return WifiMode();
108}
109
110bool
111HtPhy::IsMcsSupported(uint8_t index) const
112{
113 for (const auto& mcs : m_modeList)
114 {
115 if (mcs.GetMcsValue() == index)
116 {
117 return true;
118 }
119 }
120 return false;
121}
122
123bool
125{
126 return true;
127}
128
131{
132 return m_htPpduFormats;
133}
134
136HtPhy::GetSigMode(WifiPpduField field, const WifiTxVector& txVector) const
137{
138 switch (field)
139 {
140 case WIFI_PPDU_FIELD_PREAMBLE: // consider non-HT header mode for preamble (useful for
141 // InterferenceHelper)
143 return GetLSigMode();
144 case WIFI_PPDU_FIELD_TRAINING: // consider HT-SIG mode for training (useful for
145 // InterferenceHelper)
147 return GetHtSigMode();
148 default:
149 return PhyEntity::GetSigMode(field, txVector);
150 }
151}
152
155{
156 return GetOfdmRate6Mbps();
157}
158
161{
162 return GetLSigMode(); // same number of data tones as OFDM (i.e. 48)
163}
164
165uint8_t
167{
169}
170
171void
173{
174 NS_LOG_FUNCTION(this << +maxIndex);
176 "Provided max MCS index " << +maxIndex
177 << " per SS greater than max standard-defined value "
179 if (maxIndex != m_maxSupportedMcsIndexPerSs)
180 {
181 NS_LOG_LOGIC("Rebuild mode list since max MCS index per spatial stream has changed");
183 m_modeList.clear();
185 }
186}
187
188uint8_t
190{
192}
193
194void
196{
197 NS_LOG_FUNCTION(this << +maxNss);
199 NS_ABORT_MSG_IF(maxNss == 0 || maxNss > 4, "Unsupported max Nss " << +maxNss << " for HT PHY");
200 if (maxNss != m_maxSupportedNss)
201 {
202 NS_LOG_LOGIC("Rebuild mode list since max number of spatial streams has changed");
203 m_maxSupportedNss = maxNss;
204 m_modeList.clear();
206 }
207}
208
209Time
210HtPhy::GetDuration(WifiPpduField field, const WifiTxVector& txVector) const
211{
212 switch (field)
213 {
215 return MicroSeconds(16); // L-STF + L-LTF or HT-GF-STF + HT-LTF1
217 return GetLSigDuration(txVector.GetPreambleType());
219 // We suppose here that STBC = 0.
220 // If STBC > 0, we need a different mapping between Nss and Nltf
221 // (see IEEE 802.11-2016 , section 19.3.9.4.6 "HT-LTF definition").
222 uint8_t nDataLtf = 8;
223 uint8_t nss = txVector.GetNssMax(); // so as to cover also HE MU case (see
224 // section 27.3.10.10 of IEEE P802.11ax/D4.0)
225 if (nss < 3)
226 {
227 nDataLtf = nss;
228 }
229 else if (nss < 5)
230 {
231 nDataLtf = 4;
232 }
233 else if (nss < 7)
234 {
235 nDataLtf = 6;
236 }
237
238 uint8_t nExtensionLtf = (txVector.GetNess() < 3) ? txVector.GetNess() : 4;
239
240 return GetTrainingDuration(txVector, nDataLtf, nExtensionLtf);
241 }
243 return GetHtSigDuration();
244 default:
245 return PhyEntity::GetDuration(field, txVector);
246 }
247}
248
249Time
251{
252 return MicroSeconds(4);
253}
254
255Time
257 uint8_t nDataLtf,
258 uint8_t nExtensionLtf /* = 0 */) const
259{
260 NS_ABORT_MSG_IF(nDataLtf == 0 || nDataLtf > 4 || nExtensionLtf > 4 ||
261 (nDataLtf + nExtensionLtf) > 5,
262 "Unsupported combination of data ("
263 << +nDataLtf << ") and extension (" << +nExtensionLtf
264 << ") LTFs numbers for HT"); // see IEEE 802.11-2016, section 19.3.9.4.6
265 // "HT-LTF definition"
266 Time duration = MicroSeconds(4) * (nDataLtf + nExtensionLtf);
267 return MicroSeconds(4) * (1 /* HT-STF */ + nDataLtf + nExtensionLtf);
268}
269
270Time
272{
273 return MicroSeconds(8); // HT-SIG
274}
275
276Time
278 const WifiTxVector& txVector,
279 WifiPhyBand band,
280 MpduType mpdutype,
281 bool incFlag,
282 uint32_t& totalAmpduSize,
283 double& totalAmpduNumSymbols,
284 uint16_t staId) const
285{
286 WifiMode payloadMode = txVector.GetMode(staId);
287 uint8_t stbc = txVector.IsStbc() ? 2 : 1; // corresponding to m_STBC in Nsym computation (see
288 // IEEE 802.11-2016, equations (19-32) and (21-62))
289 uint8_t nes = GetNumberBccEncoders(txVector);
290 // TODO: Update station managers to consider GI capabilities
291 Time symbolDuration = GetSymbolDuration(txVector);
292
293 double numDataBitsPerSymbol =
294 payloadMode.GetDataRate(txVector, staId) * symbolDuration.GetNanoSeconds() / 1e9;
295 uint8_t service = GetNumberServiceBits();
296
297 double numSymbols = 0;
298 switch (mpdutype)
299 {
301 // First packet in an A-MPDU
302 numSymbols = (stbc * (service + size * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol));
303 if (incFlag == 1)
304 {
305 totalAmpduSize += size;
306 totalAmpduNumSymbols += numSymbols;
307 }
308 break;
309 }
311 // consecutive packets in an A-MPDU
312 numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
313 if (incFlag == 1)
314 {
315 totalAmpduSize += size;
316 totalAmpduNumSymbols += numSymbols;
317 }
318 break;
319 }
321 // last packet in an A-MPDU
322 uint32_t totalSize = totalAmpduSize + size;
323 numSymbols = lrint(
324 stbc * ceil((service + totalSize * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol)));
325 NS_ASSERT(totalAmpduNumSymbols <= numSymbols);
326 numSymbols -= totalAmpduNumSymbols;
327 if (incFlag == 1)
328 {
329 totalAmpduSize = 0;
330 totalAmpduNumSymbols = 0;
331 }
332 break;
333 }
334 case NORMAL_MPDU:
335 case SINGLE_MPDU: {
336 // Not an A-MPDU or single MPDU (i.e. the current payload contains both service and padding)
337 // The number of OFDM symbols in the data field when BCC encoding
338 // is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
339 numSymbols =
340 lrint(stbc * ceil((service + size * 8.0 + 6.0 * nes) / (stbc * numDataBitsPerSymbol)));
341 break;
342 }
343 default:
344 NS_FATAL_ERROR("Unknown MPDU type");
345 }
346
347 Time payloadDuration =
348 FemtoSeconds(static_cast<uint64_t>(numSymbols * symbolDuration.GetFemtoSeconds()));
349 if (mpdutype == NORMAL_MPDU || mpdutype == SINGLE_MPDU || mpdutype == LAST_MPDU_IN_AGGREGATE)
350 {
351 payloadDuration += GetSignalExtension(band);
352 }
353 return payloadDuration;
354}
355
356uint8_t
358{
366 double maxRatePerCoder = (txVector.GetGuardInterval() == 800) ? 320e6 : 350e6;
367 return ceil(txVector.GetMode().GetDataRate(txVector) / maxRatePerCoder);
368}
369
370Time
372{
373 uint16_t gi = txVector.GetGuardInterval();
374 NS_ASSERT(gi == 400 || gi == 800);
375 return NanoSeconds(3200 + gi);
376}
377
379HtPhy::BuildPpdu(const WifiConstPsduMap& psdus, const WifiTxVector& txVector, Time ppduDuration)
380{
381 NS_LOG_FUNCTION(this << psdus << txVector << ppduDuration);
382 return Create<HtPpdu>(psdus.begin()->second,
383 txVector,
385 txVector.GetChannelWidth()),
386 ppduDuration,
388 ObtainNextUid(txVector));
389}
390
393{
394 NS_LOG_FUNCTION(this << field << *event);
395 switch (field)
396 {
398 return EndReceiveHtSig(event);
400 return PhyFieldRxStatus(true); // always consider that training has been correctly received
402 // no break so as to go to OfdmPhy for processing
403 default:
404 return OfdmPhy::DoEndReceiveField(field, event);
405 }
406}
407
410{
411 NS_LOG_FUNCTION(this << *event);
412 NS_ASSERT(event->GetTxVector().GetPreambleType() == WIFI_PREAMBLE_HT_MF);
414 NS_LOG_DEBUG("HT-SIG: SNR(dB)=" << RatioToDb(snrPer.snr) << ", PER=" << snrPer.per);
415 PhyFieldRxStatus status(GetRandomValue() > snrPer.per);
416 if (status.isSuccess)
417 {
418 NS_LOG_DEBUG("Received HT-SIG");
419 if (!IsAllConfigSupported(WIFI_PPDU_FIELD_HT_SIG, event->GetPpdu()))
420 {
422 }
423 }
424 else
425 {
426 NS_LOG_DEBUG("Drop packet because HT-SIG reception failed");
427 status.reason = HT_SIG_FAILURE;
428 status.actionIfFailure = DROP;
429 }
430 return status;
431}
432
433bool
435{
437 {
438 return true; // wait till reception of HT-SIG (or SIG-A) to make decision
439 }
440 return OfdmPhy::IsAllConfigSupported(field, ppdu);
441}
442
443bool
445{
446 const WifiTxVector& txVector = ppdu->GetTxVector();
448 {
449 NS_LOG_DEBUG("Packet reception could not be started because not enough RX antennas");
450 return false;
451 }
452 if (!IsModeSupported(txVector.GetMode()))
453 {
454 NS_LOG_DEBUG("Drop packet because it was sent using an unsupported mode ("
455 << txVector.GetMode() << ")");
456 return false;
457 }
458 return true;
459}
460
463{
464 const auto& txVector = ppdu->GetTxVector();
465 uint16_t centerFrequency = GetCenterFrequencyForChannelWidth(txVector);
466 uint16_t channelWidth = txVector.GetChannelWidth();
467 NS_LOG_FUNCTION(this << centerFrequency << channelWidth << txPowerW);
468 const auto& txMaskRejectionParams = GetTxMaskRejectionParams();
470 centerFrequency,
471 channelWidth,
472 txPowerW,
473 GetGuardBandwidth(channelWidth),
474 std::get<0>(txMaskRejectionParams),
475 std::get<1>(txMaskRejectionParams),
476 std::get<2>(txMaskRejectionParams));
477 return v;
478}
479
480void
482{
483 for (uint8_t i = 0; i < 32; ++i)
484 {
485 GetHtMcs(i);
486 }
487}
488
490HtPhy::GetHtMcs(uint8_t index)
491{
492#define CASE(x) \
493 case x: \
494 return GetHtMcs##x();
495
496 switch (index)
497 {
498 CASE(0)
499 CASE(1)
500 CASE(2)
501 CASE(3)
502 CASE(4)
503 CASE(5)
504 CASE(6)
505 CASE(7)
506 CASE(8)
507 CASE(9)
508 CASE(10)
509 CASE(11)
510 CASE(12)
511 CASE(13)
512 CASE(14)
513 CASE(15)
514 CASE(16)
515 CASE(17)
516 CASE(18)
517 CASE(19)
518 CASE(20)
519 CASE(21)
520 CASE(22)
521 CASE(23)
522 CASE(24)
523 CASE(25)
524 CASE(26)
525 CASE(27)
526 CASE(28)
527 CASE(29)
528 CASE(30)
529 CASE(31)
530 default:
531 NS_ABORT_MSG("Inexistent (or not supported) index (" << +index << ") requested for HT");
532 return WifiMode();
533 }
534#undef CASE
535}
536
537#define GET_HT_MCS(x) \
538 WifiMode HtPhy::GetHtMcs##x() \
539 { \
540 static WifiMode mcs = CreateHtMcs(x); \
541 return mcs; \
542 };
543
544GET_HT_MCS(0)
545GET_HT_MCS(1)
546GET_HT_MCS(2)
547GET_HT_MCS(3)
548GET_HT_MCS(4)
549GET_HT_MCS(5)
550GET_HT_MCS(6)
551GET_HT_MCS(7)
552GET_HT_MCS(8)
553GET_HT_MCS(9)
554GET_HT_MCS(10)
555GET_HT_MCS(11)
556GET_HT_MCS(12)
557GET_HT_MCS(13)
558GET_HT_MCS(14)
559GET_HT_MCS(15)
560GET_HT_MCS(16)
561GET_HT_MCS(17)
562GET_HT_MCS(18)
563GET_HT_MCS(19)
564GET_HT_MCS(20)
565GET_HT_MCS(21)
566GET_HT_MCS(22)
567GET_HT_MCS(23)
568GET_HT_MCS(24)
569GET_HT_MCS(25)
570GET_HT_MCS(26)
571GET_HT_MCS(27)
572GET_HT_MCS(28)
573GET_HT_MCS(29)
574GET_HT_MCS(30)
575GET_HT_MCS(31)
576#undef GET_HT_MCS
577
578WifiMode
579HtPhy::CreateHtMcs(uint8_t index)
580{
581 NS_ASSERT_MSG(index <= 31, "HtMcs index must be <= 31!");
582 return WifiModeFactory::CreateWifiMcs("HtMcs" + std::to_string(index),
583 index,
585 false,
592}
593
595HtPhy::GetHtCodeRate(uint8_t mcsValue)
596{
597 return GetCodeRate(mcsValue % 8);
598}
599
601HtPhy::GetCodeRate(uint8_t mcsValue)
602{
603 switch (mcsValue)
604 {
605 case 0:
606 case 1:
607 case 3:
608 return WIFI_CODE_RATE_1_2;
609 case 2:
610 case 4:
611 case 6:
612 return WIFI_CODE_RATE_3_4;
613 case 5:
614 return WIFI_CODE_RATE_2_3;
615 case 7:
616 return WIFI_CODE_RATE_5_6;
617 default:
619 }
620}
621
622uint16_t
624{
625 return GetConstellationSize(mcsValue % 8);
626}
627
628uint16_t
630{
631 switch (mcsValue)
632 {
633 case 0:
634 return 2;
635 case 1:
636 case 2:
637 return 4;
638 case 3:
639 case 4:
640 return 16;
641 case 5:
642 case 6:
643 case 7:
644 return 64;
645 default:
646 return 0;
647 }
648}
649
650uint64_t
651HtPhy::GetPhyRate(uint8_t mcsValue, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
652{
653 WifiCodeRate codeRate = GetHtCodeRate(mcsValue);
654 uint64_t dataRate = GetDataRate(mcsValue, channelWidth, guardInterval, nss);
655 return CalculatePhyRate(codeRate, dataRate);
656}
657
658uint64_t
659HtPhy::CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
660{
661 return (dataRate / GetCodeRatio(codeRate));
662}
663
664uint64_t
665HtPhy::GetPhyRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
666{
667 return GetPhyRate(txVector.GetMode().GetMcsValue(),
668 txVector.GetChannelWidth(),
669 txVector.GetGuardInterval(),
670 txVector.GetNss());
671}
672
673double
675{
676 switch (codeRate)
677 {
679 return (5.0 / 6.0);
680 default:
681 return OfdmPhy::GetCodeRatio(codeRate);
682 }
683}
684
685uint64_t
686HtPhy::GetDataRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
687{
688 return GetDataRate(txVector.GetMode().GetMcsValue(),
689 txVector.GetChannelWidth(),
690 txVector.GetGuardInterval(),
691 txVector.GetNss());
692}
693
694uint64_t
695HtPhy::GetDataRate(uint8_t mcsValue, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
696{
697 NS_ASSERT(guardInterval == 800 || guardInterval == 400);
698 NS_ASSERT(nss <= 4);
699 return CalculateDataRate(GetSymbolDuration(NanoSeconds(guardInterval)),
700 GetUsableSubcarriers(channelWidth),
701 static_cast<uint16_t>(log2(GetHtConstellationSize(mcsValue))),
702 GetCodeRatio(GetHtCodeRate(mcsValue)),
703 nss);
704}
705
706uint64_t
708 uint16_t usableSubCarriers,
709 uint16_t numberOfBitsPerSubcarrier,
710 double codingRate,
711 uint8_t nss)
712{
713 return nss * OfdmPhy::CalculateDataRate(symbolDuration,
714 usableSubCarriers,
715 numberOfBitsPerSubcarrier,
716 codingRate);
717}
718
719uint16_t
720HtPhy::GetUsableSubcarriers(uint16_t channelWidth)
721{
722 return (channelWidth == 40) ? 108 : 52;
723}
724
725Time
727{
728 return NanoSeconds(3200) + guardInterval;
729}
730
731uint64_t
733{
734 WifiCodeRate codeRate = GetHtCodeRate(mcsValue);
735 uint16_t constellationSize = GetHtConstellationSize(mcsValue);
736 return CalculateNonHtReferenceRate(codeRate, constellationSize);
737}
738
739uint64_t
740HtPhy::CalculateNonHtReferenceRate(WifiCodeRate codeRate, uint16_t constellationSize)
741{
742 uint64_t dataRate;
743 switch (constellationSize)
744 {
745 case 2:
746 if (codeRate == WIFI_CODE_RATE_1_2)
747 {
748 dataRate = 6000000;
749 }
750 else if (codeRate == WIFI_CODE_RATE_3_4)
751 {
752 dataRate = 9000000;
753 }
754 else
755 {
756 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
757 "coding rate and modulation");
758 }
759 break;
760 case 4:
761 if (codeRate == WIFI_CODE_RATE_1_2)
762 {
763 dataRate = 12000000;
764 }
765 else if (codeRate == WIFI_CODE_RATE_3_4)
766 {
767 dataRate = 18000000;
768 }
769 else
770 {
771 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
772 "coding rate and modulation");
773 }
774 break;
775 case 16:
776 if (codeRate == WIFI_CODE_RATE_1_2)
777 {
778 dataRate = 24000000;
779 }
780 else if (codeRate == WIFI_CODE_RATE_3_4)
781 {
782 dataRate = 36000000;
783 }
784 else
785 {
786 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
787 "coding rate and modulation");
788 }
789 break;
790 case 64:
791 if (codeRate == WIFI_CODE_RATE_1_2 || codeRate == WIFI_CODE_RATE_2_3)
792 {
793 dataRate = 48000000;
794 }
795 else if (codeRate == WIFI_CODE_RATE_3_4 || codeRate == WIFI_CODE_RATE_5_6)
796 {
797 dataRate = 54000000;
798 }
799 else
800 {
801 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
802 "coding rate and modulation");
803 }
804 break;
805 default:
806 NS_FATAL_ERROR("Wrong constellation size");
807 }
808 return dataRate;
809}
810
811bool
812HtPhy::IsAllowed(const WifiTxVector& /*txVector*/)
813{
814 return true;
815}
816
819{
820 return 65535;
821}
822
825{
826 NS_LOG_FUNCTION(this);
827 if (m_wifiPhy->GetChannelWidth() < 40)
828 {
829 return PhyEntity::GetCcaIndication(ppdu);
830 }
831 double ccaThresholdDbm = GetCcaThreshold(ppdu, WIFI_CHANLIST_PRIMARY);
832 Time delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThresholdDbm, GetPrimaryBand(20));
833 if (delayUntilCcaEnd.IsStrictlyPositive())
834 {
835 return std::make_pair(
836 delayUntilCcaEnd,
837 WIFI_CHANLIST_PRIMARY); // if Primary is busy, ignore CCA for Secondary
838 }
839 if (ppdu)
840 {
841 const uint16_t primaryWidth = 20;
842 uint16_t p20MinFreq =
844 (primaryWidth / 2);
845 uint16_t p20MaxFreq =
847 (primaryWidth / 2);
848 if (ppdu->DoesOverlapChannel(p20MinFreq, p20MaxFreq))
849 {
850 /*
851 * PPDU occupies primary 20 MHz channel, hence we skip CCA sensitivity rules
852 * for signals not occupying the primary 20 MHz channel.
853 */
854 return std::nullopt;
855 }
856 }
857
858 const uint16_t secondaryWidth = 20;
859 uint16_t s20MinFreq =
861 (secondaryWidth / 2);
862 uint16_t s20MaxFreq =
864 (secondaryWidth / 2);
865 if (!ppdu || ppdu->DoesOverlapChannel(s20MinFreq, s20MaxFreq))
866 {
867 ccaThresholdDbm = GetCcaThreshold(ppdu, WIFI_CHANLIST_SECONDARY);
868 delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThresholdDbm, GetSecondaryBand(20));
869 if (delayUntilCcaEnd.IsStrictlyPositive())
870 {
871 return std::make_pair(delayUntilCcaEnd, WIFI_CHANLIST_SECONDARY);
872 }
873 }
874
875 return std::nullopt;
876}
877
878} // namespace ns3
879
880namespace
881{
882
887{
888 public:
890 {
893 ns3::Create<ns3::HtPhy>()); // dummy Nss
894 }
896
897} // namespace
Constructor class for HT modes.
Definition: ht-phy.cc:887
static uint64_t CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
Return the PHY rate corresponding to the supplied code rate and data rate.
Definition: ht-phy.cc:659
CcaIndication GetCcaIndication(const Ptr< const WifiPpdu > ppdu) override
Get CCA end time and its corresponding channel list type when a new signal has been received by the P...
Definition: ht-phy.cc:824
static uint16_t GetConstellationSize(uint8_t mcsValue)
Return the constellation size corresponding to the supplied HT MCS index between 0 and 7,...
Definition: ht-phy.cc:629
uint8_t m_bssMembershipSelector
the BSS membership selector
Definition: ht-phy.h:558
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: ht-phy.cc:392
~HtPhy() override
Destructor for HT PHY.
Definition: ht-phy.cc:69
static WifiMode GetLSigMode()
Definition: ht-phy.cc:154
static uint16_t GetHtConstellationSize(uint8_t mcsValue)
Return the constellation size corresponding to the supplied HT MCS index.
Definition: ht-phy.cc:623
uint8_t m_maxMcsIndexPerSs
the maximum MCS index per spatial stream as defined by the standard
Definition: ht-phy.h:556
bool IsAllConfigSupported(WifiPpduField field, Ptr< const WifiPpdu > ppdu) const override
Checks if the signaled configuration (including bandwidth) is supported by the PHY.
Definition: ht-phy.cc:434
HtPhy(uint8_t maxNss=1, bool buildModeList=true)
Constructor for HT PHY.
Definition: ht-phy.cc:53
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
Definition: ht-phy.cc:686
static uint64_t GetDataRate(uint8_t mcsValue, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the data rate corresponding to the supplied HT MCS index, channel width, guard interval,...
Definition: ht-phy.cc:695
static void InitializeModes()
Initialize all HT modes.
Definition: ht-phy.cc:481
static WifiCodeRate GetHtCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index.
Definition: ht-phy.cc:595
static uint64_t CalculateNonHtReferenceRate(WifiCodeRate codeRate, uint16_t constellationSize)
Return the rate (in bps) of the non-HT Reference Rate which corresponds to the supplied code rate and...
Definition: ht-phy.cc:740
virtual Time GetTrainingDuration(const WifiTxVector &txVector, uint8_t nDataLtf, uint8_t nExtensionLtf=0) const
Definition: ht-phy.cc:256
bool IsMcsSupported(uint8_t index) const override
Check if the WifiMode corresponding to the given MCS index is supported.
Definition: ht-phy.cc:111
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: ht-phy.cc:210
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: ht-phy.cc:277
uint8_t GetBssMembershipSelector() const
Definition: ht-phy.cc:166
static bool IsAllowed(const WifiTxVector &txVector)
Check whether the combination in TXVECTOR is allowed.
Definition: ht-phy.cc:812
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
Definition: ht-phy.cc:665
WifiMode GetMcs(uint8_t index) const override
Get the WifiMode corresponding to the given MCS index.
Definition: ht-phy.cc:95
virtual uint8_t GetNumberBccEncoders(const WifiTxVector &txVector) const
Definition: ht-phy.cc:357
static uint64_t GetNonHtReferenceRate(uint8_t mcsValue)
Calculate the rate in bps of the non-HT Reference Rate corresponding to the supplied HT MCS index.
Definition: ht-phy.cc:732
virtual Time GetLSigDuration(WifiPreamble preamble) const
Definition: ht-phy.cc:250
static uint64_t GetPhyRate(uint8_t mcsValue, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the PHY rate corresponding to the supplied HT MCS index, channel width, guard interval,...
Definition: ht-phy.cc:651
void SetMaxSupportedMcsIndexPerSs(uint8_t maxIndex)
Set the maximum supported MCS index per spatial stream.
Definition: ht-phy.cc:172
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition: ht-phy.cc:490
static WifiMode CreateHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition: ht-phy.cc:579
uint32_t GetMaxPsduSize() const override
Get the maximum PSDU size in bytes.
Definition: ht-phy.cc:818
static WifiCodeRate GetCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index between 0 and 7,...
Definition: ht-phy.cc:601
virtual WifiMode GetHtSigMode() const
Definition: ht-phy.cc:160
WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const override
Get the WifiMode for the SIG field specified by the PPDU field.
Definition: ht-phy.cc:136
static uint64_t CalculateDataRate(Time symbolDuration, uint16_t usableSubCarriers, uint16_t numberOfBitsPerSubcarrier, double codingRate, uint8_t nss)
Calculates data rate from the supplied parameters.
Definition: ht-phy.cc:707
uint8_t GetMaxSupportedMcsIndexPerSs() const
Set the maximum supported MCS index per spatial stream.
Definition: ht-phy.cc:189
Ptr< SpectrumValue > GetTxPowerSpectralDensity(double txPowerW, Ptr< const WifiPpdu > ppdu) const override
Definition: ht-phy.cc:462
bool IsConfigSupported(Ptr< const WifiPpdu > ppdu) const override
Checks if the signaled configuration (excluding bandwidth) is supported by the PHY.
Definition: ht-phy.cc:444
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
Definition: ht-phy.cc:379
uint8_t m_maxSupportedNss
Maximum supported number of spatial streams (used to build HT MCS indices)
Definition: ht-phy.h:580
virtual void BuildModeList()
Build mode list.
Definition: ht-phy.cc:75
static double GetCodeRatio(WifiCodeRate codeRate)
Convert WifiCodeRate to a ratio, e.g., code ratio of WIFI_CODE_RATE_1_2 is 0.5.
Definition: ht-phy.cc:674
bool HandlesMcsModes() const override
Check if the WifiModes handled by this PHY are MCSs.
Definition: ht-phy.cc:124
static const PpduFormats m_htPpduFormats
HT PPDU formats.
Definition: ht-phy.h:583
void SetMaxSupportedNss(uint8_t maxNss)
Configure the maximum number of spatial streams supported by this HT PHY.
Definition: ht-phy.cc:195
PhyFieldRxStatus EndReceiveHtSig(Ptr< Event > event)
End receiving the HT-SIG, perform HT-specific actions, and provide the status of the reception.
Definition: ht-phy.cc:409
virtual Time GetHtSigDuration() const
Definition: ht-phy.cc:271
uint8_t m_maxSupportedMcsIndexPerSs
the maximum supported MCS index per spatial stream
Definition: ht-phy.h:557
const PpduFormats & GetPpduFormats() const override
Return the PPDU formats of the PHY.
Definition: ht-phy.cc:130
virtual Time GetSymbolDuration(const WifiTxVector &txVector) const
Definition: ht-phy.cc:371
PHY entity for OFDM (11a)
Definition: ofdm-phy.h:61
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6 Mbps.
uint8_t GetNumberServiceBits() const
Definition: ofdm-phy.cc:281
double GetCcaThreshold(const Ptr< const WifiPpdu > ppdu, WifiChannelListType channelType) const override
Return the CCA threshold in dBm for a given channel type.
Definition: ofdm-phy.cc:677
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth)
Calculates data rate from the supplied parameters.
Definition: ofdm-phy.cc:614
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:357
static uint16_t GetUsableSubcarriers()
Definition: ofdm-phy.cc:633
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:309
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:582
Time GetSignalExtension(WifiPhyBand band) const
Definition: ofdm-phy.cc:287
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:190
std::tuple< double, double, double > GetTxMaskRejectionParams() const
Definition: phy-entity.cc:1324
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
Definition: phy-entity.cc:1260
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:963
WifiSpectrumBand GetSecondaryBand(uint16_t bandWidth) const
If the channel bonding is used, return the start band index and the stop band index for the secondary...
Definition: phy-entity.cc:1185
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
Definition: phy-entity.h:556
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:150
Time GetDelayUntilCcaEnd(double thresholdDbm, WifiSpectrumBand band)
Return the delay until CCA busy is ended for a given sensitivity threshold (in dBm) and a given band.
Definition: phy-entity.cc:1206
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const
Definition: phy-entity.cc:1318
virtual bool IsModeSupported(WifiMode mode) const
Check if the WifiMode is supported.
Definition: phy-entity.cc:97
std::optional< std::pair< Time, WifiChannelListType > > CcaIndication
CCA end time and its corresponding channel list type (can be std::nullopt if IDLE)
Definition: phy-entity.h:951
virtual CcaIndication GetCcaIndication(const Ptr< const WifiPpdu > ppdu)
Get CCA end time and its corresponding channel list type when a new signal has been received by the P...
Definition: phy-entity.cc:1235
std::list< WifiMode > m_modeList
the list of supported modes
Definition: phy-entity.h:967
double GetRandomValue() const
Obtain a random value from the WifiPhy's generator.
Definition: phy-entity.cc:1156
SnrPer GetPhyHeaderSnrPer(WifiPpduField field, Ptr< Event > event) const
Obtain the SNR and PER of the PPDU field from the WifiPhy's InterferenceHelper class.
Definition: phy-entity.cc:270
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:1267
WifiSpectrumBand GetPrimaryBand(uint16_t bandWidth) const
If the operating channel width is a multiple of 20 MHz, return the start band index and the stop band...
Definition: phy-entity.cc:1174
@ DROP
drop PPDU and set CCA_BUSY
Definition: phy-entity.h:104
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:427
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:350
static WifiMode CreateWifiMcs(std::string uniqueName, uint8_t mcsValue, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, NonHtReferenceRateCallback nonHtReferenceRateCallback, AllowedCallback isAllowedCallback)
Definition: wifi-mode.cc:318
represent a single transmission mode
Definition: wifi-mode.h:50
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
uint8_t GetMcsValue() const
Definition: wifi-mode.cc:163
uint16_t GetChannelWidth() const
Definition: wifi-phy.cc:1026
uint8_t GetMaxSupportedRxSpatialStreams() const
Definition: wifi-phy.cc:1295
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:996
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:745
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
Definition: wifi-phy.cc:1008
uint16_t GetSecondaryChannelCenterFrequency(uint16_t secondaryChannelWidth) const
Get the center frequency of the secondary channel of the given width.
uint16_t GetPrimaryChannelCenterFrequency(uint16_t primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(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 High Throughput (HT) (802....
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint16_t GetGuardInterval() const
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.
bool IsStbc() const
Check if STBC is used or not.
WifiPreamble GetPreambleType() 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.
uint8_t GetNssMax() const
uint16_t GetChannelWidth() const
uint8_t GetNess() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:768
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1372
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1396
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
WifiPpduField
The type of PPDU field (grouped for convenience)
MpduType
The type of an MPDU.
@ UNSUPPORTED_SETTINGS
@ HT_SIG_FAILURE
@ WIFI_PREAMBLE_HT_MF
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ OFDM_PHY_DEFAULT
Definition: ofdm-phy.h:45
@ WIFI_CHANLIST_PRIMARY
@ WIFI_CHANLIST_SECONDARY
@ WIFI_PPDU_FIELD_TRAINING
STF + LTF fields (excluding those in preamble for HT-GF)
@ WIFI_PPDU_FIELD_NON_HT_HEADER
PHY header field for DSSS or ERP, short PHY header field for HR/DSSS or ERP, field not present for HT...
@ WIFI_PPDU_FIELD_HT_SIG
HT-SIG field.
@ WIFI_PPDU_FIELD_PREAMBLE
SYNC + SFD fields for DSSS or ERP, shortSYNC + shortSFD fields for HR/DSSS or ERP,...
@ WIFI_PPDU_FIELD_DATA
data field
@ LAST_MPDU_IN_AGGREGATE
The MPDU is the last aggregate in an A-MPDU with multiple MPDUs.
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
@ FIRST_MPDU_IN_AGGREGATE
The MPDU is the first aggregate in an A-MPDU with multiple MPDUs, but is not the last aggregate.
@ SINGLE_MPDU
The MPDU is a single MPDU.
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
#define CASE(x)
#define GET_HT_MCS(x)
Definition: ht-phy.cc:537
Declaration of ns3::HtPhy class.
#define HT_PHY
This defines the BSS membership value for HT PHY.
Definition: ht-phy.h:38
Declaration of ns3::HtPpdu class.
class anonymous_namespace{ht-phy.cc}::ConstructorHt g_constructor_ht
the constructor for HT modes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint16_t WIFI_CODE_RATE_UNDEFINED
undefined coding rate
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:52
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:707
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
const uint16_t WIFI_CODE_RATE_5_6
5/6 coding rate
Status of the reception of the PPDU field.
Definition: phy-entity.h:113
WifiPhyRxfailureReason reason
failure reason
Definition: phy-entity.h:115
PhyRxFailureAction actionIfFailure
action to perform in case of failure
Definition: phy-entity.h:116
bool isSuccess
outcome (true if success) of the reception
Definition: phy-entity.h:114
A struct for both SNR and PER.
Definition: phy-entity.h:148
double snr
SNR in linear scale.
Definition: phy-entity.h:149