A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ht-phy.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Orange Labs
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Rediet <getachew.redieteab@orange.com>
7 * Sébastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
8 */
9
10#include "ht-phy.h"
11
12#include "ht-ppdu.h"
13
14#include "ns3/assert.h"
15#include "ns3/interference-helper.h"
16#include "ns3/log.h"
17#include "ns3/wifi-phy.h"
18#include "ns3/wifi-psdu.h"
19#include "ns3/wifi-utils.h"
20
21#undef NS_LOG_APPEND_CONTEXT
22#define NS_LOG_APPEND_CONTEXT WIFI_PHY_NS_LOG_APPEND_CONTEXT(m_wifiPhy)
23
24namespace ns3
25{
26
28
29/*******************************************************
30 * HT PHY (IEEE 802.11-2016, clause 19)
31 *******************************************************/
32
33// clang-format off
34
38 WIFI_PPDU_FIELD_HT_SIG, // HT-SIG
39 WIFI_PPDU_FIELD_TRAINING, // HT-STF + HT-LTFs
41};
42
43/**
44 * \brief map a given secondary channel width to its channel list type
45 */
46const std::map<MHz_u, WifiChannelListType> htSecondaryChannels {
48};
49
50// clang-format on
51
52HtPhy::HtPhy(uint8_t maxNss /* = 1 */, bool buildModeList /* = true */)
53 : OfdmPhy(OFDM_PHY_DEFAULT, false) // don't add OFDM modes to list
54{
55 NS_LOG_FUNCTION(this << +maxNss << buildModeList);
56 m_maxSupportedNss = maxNss;
60 if (buildModeList)
61 {
62 NS_ABORT_MSG_IF(maxNss == 0 || maxNss > HT_MAX_NSS,
63 "Unsupported max Nss " << +maxNss << " for HT PHY");
65 }
66}
67
69{
70 NS_LOG_FUNCTION(this);
71}
72
73void
75{
76 NS_LOG_FUNCTION(this);
77 NS_ASSERT(m_modeList.empty());
79
80 uint8_t index = 0;
81 for (uint8_t nss = 1; nss <= m_maxSupportedNss; ++nss)
82 {
83 for (uint8_t i = 0; i <= m_maxSupportedMcsIndexPerSs; ++i)
84 {
85 NS_LOG_LOGIC("Add HtMcs" << +index << " to list");
86 m_modeList.emplace_back(CreateHtMcs(index));
87 ++index;
88 }
89 index = 8 * nss;
90 }
91}
92
94HtPhy::GetMcs(uint8_t index) const
95{
96 for (const auto& mcs : m_modeList)
97 {
98 if (mcs.GetMcsValue() == index)
99 {
100 return mcs;
101 }
102 }
103
104 // Should have returned if MCS found
105 NS_ABORT_MSG("Unsupported MCS index " << +index << " for this PHY entity");
106 return WifiMode();
107}
108
109bool
110HtPhy::IsMcsSupported(uint8_t index) const
111{
112 for (const auto& mcs : m_modeList)
113 {
114 if (mcs.GetMcsValue() == index)
115 {
116 return true;
117 }
118 }
119 return false;
120}
121
122bool
124{
125 return true;
126}
127
130{
131 return m_htPpduFormats;
132}
133
135HtPhy::GetSigMode(WifiPpduField field, const WifiTxVector& txVector) const
136{
137 switch (field)
138 {
139 case WIFI_PPDU_FIELD_PREAMBLE: // consider non-HT header mode for preamble (useful for
140 // InterferenceHelper)
142 return GetLSigMode();
143 case WIFI_PPDU_FIELD_TRAINING: // consider HT-SIG mode for training (useful for
144 // InterferenceHelper)
146 return GetHtSigMode();
147 default:
148 return OfdmPhy::GetSigMode(field, txVector);
149 }
150}
151
154{
155 return GetOfdmRate6Mbps();
156}
157
160{
161 return GetLSigMode(); // same number of data tones as OFDM (i.e. 48)
162}
163
164uint8_t
169
170void
172{
173 NS_LOG_FUNCTION(this << +maxIndex);
175 "Provided max MCS index " << +maxIndex
176 << " per SS greater than max standard-defined value "
178 if (maxIndex != m_maxSupportedMcsIndexPerSs)
179 {
180 NS_LOG_LOGIC("Rebuild mode list since max MCS index per spatial stream has changed");
182 m_modeList.clear();
184 }
185}
186
187uint8_t
192
193void
195{
196 NS_LOG_FUNCTION(this << +maxNss);
198 maxNss = std::min(HT_MAX_NSS, maxNss);
199 if (maxNss != m_maxSupportedNss)
200 {
201 NS_LOG_LOGIC("Rebuild mode list since max number of spatial streams has changed");
202 m_maxSupportedNss = maxNss;
203 m_modeList.clear();
205 }
206}
207
208Time
209HtPhy::GetDuration(WifiPpduField field, const WifiTxVector& txVector) const
210{
211 switch (field)
212 {
214 return MicroSeconds(16); // L-STF + L-LTF or HT-GF-STF + HT-LTF1
216 return GetLSigDuration(txVector.GetPreambleType());
218 // We suppose here that STBC = 0.
219 // If STBC > 0, we need a different mapping between Nss and Nltf
220 // (see IEEE 802.11-2016 , section 19.3.9.4.6 "HT-LTF definition").
221 uint8_t nDataLtf = 8;
222 uint8_t nss = txVector.GetNssMax(); // so as to cover also HE MU case (see
223 // section 27.3.10.10 of IEEE P802.11ax/D4.0)
224 if (nss < 3)
225 {
226 nDataLtf = nss;
227 }
228 else if (nss < 5)
229 {
230 nDataLtf = 4;
231 }
232 else if (nss < 7)
233 {
234 nDataLtf = 6;
235 }
236
237 uint8_t nExtensionLtf = (txVector.GetNess() < 3) ? txVector.GetNess() : 4;
238
239 return GetTrainingDuration(txVector, nDataLtf, nExtensionLtf);
240 }
242 return GetHtSigDuration();
243 default:
244 return OfdmPhy::GetDuration(field, txVector);
245 }
246}
247
248Time
250{
251 return MicroSeconds(4);
252}
253
254Time
256 uint8_t nDataLtf,
257 uint8_t nExtensionLtf /* = 0 */) const
258{
259 NS_ABORT_MSG_IF(nDataLtf == 0 || nDataLtf > 4 || nExtensionLtf > 4 ||
260 (nDataLtf + nExtensionLtf) > 5,
261 "Unsupported combination of data ("
262 << +nDataLtf << ") and extension (" << +nExtensionLtf
263 << ") LTFs numbers for HT"); // see IEEE 802.11-2016, section 19.3.9.4.6
264 // "HT-LTF definition"
265 return MicroSeconds(4) * (1 /* HT-STF */ + nDataLtf + nExtensionLtf);
266}
267
268Time
270{
271 return MicroSeconds(8); // HT-SIG
272}
273
274Time
276 const WifiTxVector& txVector,
277 WifiPhyBand band,
278 MpduType mpdutype,
279 bool incFlag,
280 uint32_t& totalAmpduSize,
281 double& totalAmpduNumSymbols,
282 uint16_t staId) const
283{
284 WifiMode payloadMode = txVector.GetMode(staId);
285 uint8_t stbc = txVector.IsStbc() ? 2 : 1; // corresponding to m_STBC in Nsym computation (see
286 // IEEE 802.11-2016, equations (19-32) and (21-62))
287 uint8_t nes = GetNumberBccEncoders(txVector);
288 // TODO: Update station managers to consider GI capabilities
289 Time symbolDuration = GetSymbolDuration(txVector);
290
291 double numDataBitsPerSymbol =
292 payloadMode.GetDataRate(txVector, staId) * symbolDuration.GetNanoSeconds() / 1e9;
293 uint8_t service = GetNumberServiceBits();
294
295 double numSymbols = 0;
296 switch (mpdutype)
297 {
299 // First packet in an A-MPDU
300 numSymbols = (stbc * (service + size * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol));
301 if (incFlag)
302 {
303 totalAmpduSize += size;
304 totalAmpduNumSymbols += numSymbols;
305 }
306 break;
307 }
309 // consecutive packets in an A-MPDU
310 numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
311 if (incFlag)
312 {
313 totalAmpduSize += size;
314 totalAmpduNumSymbols += numSymbols;
315 }
316 break;
317 }
319 // last packet in an A-MPDU
320 uint32_t totalSize = totalAmpduSize + size;
321 numSymbols =
322 stbc * ceil((service + totalSize * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol));
323 NS_ASSERT(totalAmpduNumSymbols <= numSymbols);
324 numSymbols -= totalAmpduNumSymbols;
325 if (incFlag)
326 {
327 totalAmpduSize = 0;
328 totalAmpduNumSymbols = 0;
329 }
330 break;
331 }
332 case NORMAL_MPDU:
333 case SINGLE_MPDU: {
334 // Not an A-MPDU or single MPDU (i.e. the current payload contains both service and padding)
335 // The number of OFDM symbols in the data field when BCC encoding
336 // is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
337 numSymbols =
338 stbc * ceil((service + size * 8.0 + 6.0 * nes) / (stbc * numDataBitsPerSymbol));
339 break;
340 }
341 default:
342 NS_FATAL_ERROR("Unknown MPDU type");
343 }
344
345 Time payloadDuration =
346 FemtoSeconds(static_cast<uint64_t>(numSymbols * symbolDuration.GetFemtoSeconds()));
347 if (mpdutype == NORMAL_MPDU || mpdutype == SINGLE_MPDU || mpdutype == LAST_MPDU_IN_AGGREGATE)
348 {
349 payloadDuration += GetSignalExtension(band);
350 }
351 return payloadDuration;
352}
353
354uint8_t
356{
357 /**
358 * Add an encoder when crossing maxRatePerCoder frontier.
359 *
360 * The value of 320 Mbps and 350 Mbps for normal GI and short GI (resp.)
361 * were obtained by observing the rates for which Nes was incremented in tables
362 * 19-27 to 19-41 of IEEE 802.11-2016.
363 */
364 double maxRatePerCoder = (txVector.GetGuardInterval().GetNanoSeconds() == 800) ? 320e6 : 350e6;
365 return ceil(txVector.GetMode().GetDataRate(txVector) / maxRatePerCoder);
366}
367
368Time
370{
371 const auto guardInterval = txVector.GetGuardInterval();
373 "Invalid HT guard interval " << guardInterval.As(Time::NS));
374 return GetSymbolDuration(guardInterval);
375}
376
378HtPhy::BuildPpdu(const WifiConstPsduMap& psdus, const WifiTxVector& txVector, Time ppduDuration)
379{
380 NS_LOG_FUNCTION(this << psdus << txVector << ppduDuration);
381 return Create<HtPpdu>(psdus.begin()->second,
382 txVector,
383 m_wifiPhy->GetOperatingChannel(),
384 ppduDuration,
385 ObtainNextUid(txVector));
386}
387
390{
391 NS_LOG_FUNCTION(this << field << *event);
392 switch (field)
393 {
395 return EndReceiveHtSig(event);
397 return PhyFieldRxStatus(true); // always consider that training has been correctly received
399 // no break so as to go to OfdmPhy for processing
400 default:
401 return OfdmPhy::DoEndReceiveField(field, event);
402 }
403}
404
407{
408 NS_LOG_FUNCTION(this << *event);
409 NS_ASSERT(event->GetPpdu()->GetTxVector().GetPreambleType() == WIFI_PREAMBLE_HT_MF);
411 NS_LOG_DEBUG("HT-SIG: SNR(dB)=" << RatioToDb(snrPer.snr) << ", PER=" << snrPer.per);
412 PhyFieldRxStatus status(GetRandomValue() > snrPer.per);
413 if (status.isSuccess)
414 {
415 NS_LOG_DEBUG("Received HT-SIG");
416 if (!IsAllConfigSupported(WIFI_PPDU_FIELD_HT_SIG, event->GetPpdu()))
417 {
419 }
420 }
421 else
422 {
423 NS_LOG_DEBUG("Drop packet because HT-SIG reception failed");
424 status.reason = HT_SIG_FAILURE;
425 status.actionIfFailure = DROP;
426 }
427 return status;
428}
429
430bool
432{
434 {
435 return true; // wait till reception of HT-SIG (or SIG-A) to make decision
436 }
437 return OfdmPhy::IsAllConfigSupported(field, ppdu);
438}
439
440bool
442{
443 const auto& txVector = ppdu->GetTxVector();
444 if (txVector.GetNss() > m_wifiPhy->GetMaxSupportedRxSpatialStreams())
445 {
446 NS_LOG_DEBUG("Packet reception could not be started because not enough RX antennas");
447 return false;
448 }
449 if (!IsModeSupported(txVector.GetMode()))
450 {
451 NS_LOG_DEBUG("Drop packet because it was sent using an unsupported mode ("
452 << txVector.GetMode() << ")");
453 return false;
454 }
455 return true;
456}
457
460{
461 const auto& centerFrequencies = ppdu->GetTxCenterFreqs();
462 const auto& txVector = ppdu->GetTxVector();
463 const auto channelWidth = txVector.GetChannelWidth();
464 NS_LOG_FUNCTION(this << centerFrequencies.front() << channelWidth << txPower);
465 const auto& txMaskRejectionParams = GetTxMaskRejectionParams();
467 centerFrequencies,
468 channelWidth,
469 txPower,
470 GetGuardBandwidth(channelWidth),
471 std::get<0>(txMaskRejectionParams),
472 std::get<1>(txMaskRejectionParams),
473 std::get<2>(txMaskRejectionParams));
474 return v;
475}
476
477void
479{
480 for (uint8_t i = 0; i < 32; ++i)
481 {
482 GetHtMcs(i);
483 }
484}
485
487HtPhy::GetHtMcs(uint8_t index)
488{
489#define CASE(x) \
490 case x: \
491 return GetHtMcs##x();
492
493 switch (index)
494 {
495 CASE(0)
496 CASE(1)
497 CASE(2)
498 CASE(3)
499 CASE(4)
500 CASE(5)
501 CASE(6)
502 CASE(7)
503 CASE(8)
504 CASE(9)
505 CASE(10)
506 CASE(11)
507 CASE(12)
508 CASE(13)
509 CASE(14)
510 CASE(15)
511 CASE(16)
512 CASE(17)
513 CASE(18)
514 CASE(19)
515 CASE(20)
516 CASE(21)
517 CASE(22)
518 CASE(23)
519 CASE(24)
520 CASE(25)
521 CASE(26)
522 CASE(27)
523 CASE(28)
524 CASE(29)
525 CASE(30)
526 CASE(31)
527 default:
528 NS_ABORT_MSG("Inexistent (or not supported) index (" << +index << ") requested for HT");
529 return WifiMode();
530 }
531#undef CASE
532}
533
534#define GET_HT_MCS(x) \
535 WifiMode HtPhy::GetHtMcs##x() \
536 { \
537 static WifiMode mcs = CreateHtMcs(x); \
538 return mcs; \
539 }
540
541GET_HT_MCS(0)
542GET_HT_MCS(1)
543GET_HT_MCS(2)
544GET_HT_MCS(3)
545GET_HT_MCS(4)
546GET_HT_MCS(5)
547GET_HT_MCS(6)
548GET_HT_MCS(7)
549GET_HT_MCS(8)
550GET_HT_MCS(9)
551GET_HT_MCS(10)
552GET_HT_MCS(11)
553GET_HT_MCS(12)
554GET_HT_MCS(13)
555GET_HT_MCS(14)
556GET_HT_MCS(15)
557GET_HT_MCS(16)
558GET_HT_MCS(17)
559GET_HT_MCS(18)
560GET_HT_MCS(19)
561GET_HT_MCS(20)
562GET_HT_MCS(21)
563GET_HT_MCS(22)
564GET_HT_MCS(23)
565GET_HT_MCS(24)
566GET_HT_MCS(25)
567GET_HT_MCS(26)
568GET_HT_MCS(27)
569GET_HT_MCS(28)
570GET_HT_MCS(29)
571GET_HT_MCS(30)
572GET_HT_MCS(31)
573#undef GET_HT_MCS
574
575WifiMode
576HtPhy::CreateHtMcs(uint8_t index)
577{
578 NS_ASSERT_MSG(index <= 31, "HtMcs index must be <= 31!");
579 return WifiModeFactory::CreateWifiMcs("HtMcs" + std::to_string(index),
580 index,
582 false,
589}
590
592HtPhy::GetHtCodeRate(uint8_t mcsValue)
593{
594 return GetCodeRate(mcsValue % 8);
595}
596
598HtPhy::GetCodeRate(uint8_t mcsValue)
599{
600 switch (mcsValue)
601 {
602 case 0:
603 case 1:
604 case 3:
605 return WIFI_CODE_RATE_1_2;
606 case 2:
607 case 4:
608 case 6:
609 return WIFI_CODE_RATE_3_4;
610 case 5:
611 return WIFI_CODE_RATE_2_3;
612 case 7:
613 return WIFI_CODE_RATE_5_6;
614 default:
616 }
617}
618
619uint16_t
621{
622 return GetConstellationSize(mcsValue % 8);
623}
624
625uint16_t
627{
628 switch (mcsValue)
629 {
630 case 0:
631 return 2;
632 case 1:
633 case 2:
634 return 4;
635 case 3:
636 case 4:
637 return 16;
638 case 5:
639 case 6:
640 case 7:
641 return 64;
642 default:
643 return 0;
644 }
645}
646
647uint64_t
648HtPhy::GetPhyRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
649{
650 const auto codeRate = GetHtCodeRate(mcsValue);
651 const auto dataRate = GetDataRate(mcsValue, channelWidth, guardInterval, nss);
652 return CalculatePhyRate(codeRate, dataRate);
653}
654
655uint64_t
656HtPhy::CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
657{
658 return (dataRate / GetCodeRatio(codeRate));
659}
660
661uint64_t
662HtPhy::GetPhyRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
663{
664 return GetPhyRate(txVector.GetMode().GetMcsValue(),
665 txVector.GetChannelWidth(),
666 txVector.GetGuardInterval(),
667 txVector.GetNss());
668}
669
670double
672{
673 switch (codeRate)
674 {
676 return (5.0 / 6.0);
677 default:
678 return OfdmPhy::GetCodeRatio(codeRate);
679 }
680}
681
682uint64_t
683HtPhy::GetDataRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
684{
685 return GetDataRate(txVector.GetMode().GetMcsValue(),
686 txVector.GetChannelWidth(),
687 txVector.GetGuardInterval(),
688 txVector.GetNss());
689}
690
691uint64_t
692HtPhy::GetDataRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
693{
695 "Invalid HT guard interval " << guardInterval.As(Time::NS));
696 NS_ASSERT(nss <= 4);
697 return CalculateDataRate(GetSymbolDuration(guardInterval),
698 GetUsableSubcarriers(channelWidth),
699 static_cast<uint16_t>(log2(GetHtConstellationSize(mcsValue))),
700 GetCodeRatio(GetHtCodeRate(mcsValue)),
701 nss);
702}
703
704uint64_t
706 uint16_t usableSubCarriers,
707 uint16_t numberOfBitsPerSubcarrier,
708 double codingRate,
709 uint8_t nss)
710{
711 return nss * OfdmPhy::CalculateDataRate(symbolDuration,
712 usableSubCarriers,
713 numberOfBitsPerSubcarrier,
714 codingRate);
715}
716
717uint16_t
719{
720 return (channelWidth == MHz_u{40}) ? 108 : 52;
721}
722
723Time
725{
726 return NanoSeconds(3200) + guardInterval;
727}
728
729uint64_t
731{
732 const auto codeRate = GetHtCodeRate(mcsValue);
733 const auto constellationSize = GetHtConstellationSize(mcsValue);
734 return CalculateNonHtReferenceRate(codeRate, constellationSize);
735}
736
737uint64_t
738HtPhy::CalculateNonHtReferenceRate(WifiCodeRate codeRate, uint16_t constellationSize)
739{
740 uint64_t dataRate;
741 switch (constellationSize)
742 {
743 case 2:
744 if (codeRate == WIFI_CODE_RATE_1_2)
745 {
746 dataRate = 6000000;
747 }
748 else if (codeRate == WIFI_CODE_RATE_3_4)
749 {
750 dataRate = 9000000;
751 }
752 else
753 {
754 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
755 "coding rate and modulation");
756 }
757 break;
758 case 4:
759 if (codeRate == WIFI_CODE_RATE_1_2)
760 {
761 dataRate = 12000000;
762 }
763 else if (codeRate == WIFI_CODE_RATE_3_4)
764 {
765 dataRate = 18000000;
766 }
767 else
768 {
769 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
770 "coding rate and modulation");
771 }
772 break;
773 case 16:
774 if (codeRate == WIFI_CODE_RATE_1_2)
775 {
776 dataRate = 24000000;
777 }
778 else if (codeRate == WIFI_CODE_RATE_3_4)
779 {
780 dataRate = 36000000;
781 }
782 else
783 {
784 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
785 "coding rate and modulation");
786 }
787 break;
788 case 64:
789 if (codeRate == WIFI_CODE_RATE_1_2 || codeRate == WIFI_CODE_RATE_2_3)
790 {
791 dataRate = 48000000;
792 }
793 else if (codeRate == WIFI_CODE_RATE_3_4 || codeRate == WIFI_CODE_RATE_5_6)
794 {
795 dataRate = 54000000;
796 }
797 else
798 {
799 NS_FATAL_ERROR("Trying to get reference rate for a MCS with wrong combination of "
800 "coding rate and modulation");
801 }
802 break;
803 default:
804 NS_FATAL_ERROR("Wrong constellation size");
805 }
806 return dataRate;
807}
808
809bool
810HtPhy::IsAllowed(const WifiTxVector& /*txVector*/)
811{
812 return true;
813}
814
817{
819}
820
821const std::map<MHz_u, WifiChannelListType>&
826
827std::vector<MHz_u>
829{
830 std::vector<MHz_u> secondaryWidthsToCheck{};
831 if (ppdu)
832 {
833 for (const auto& secondaryChannel : GetCcaSecondaryChannels())
834 {
835 const auto secondaryWidth = secondaryChannel.first;
836 if (secondaryWidth >= m_wifiPhy->GetChannelWidth())
837 {
838 break;
839 }
840 const MHz_u secondaryMinFreq =
841 m_wifiPhy->GetOperatingChannel().GetSecondaryChannelCenterFrequency(
842 secondaryWidth) -
843 (secondaryWidth / 2);
844 const MHz_u secondaryMaxFreq =
845 m_wifiPhy->GetOperatingChannel().GetSecondaryChannelCenterFrequency(
846 secondaryWidth) +
847 (secondaryWidth / 2);
848 if (ppdu->DoesOverlapChannel(secondaryMinFreq, secondaryMaxFreq))
849 {
850 secondaryWidthsToCheck.push_back(secondaryWidth);
851 }
852 }
853 }
854 else
855 {
856 for (MHz_u secondaryWidth = 20; secondaryWidth < m_wifiPhy->GetChannelWidth();
857 secondaryWidth *= 2)
858 {
859 secondaryWidthsToCheck.push_back(secondaryWidth);
860 }
861 }
862 return secondaryWidthsToCheck;
863}
864
867{
868 const auto& secondaryChannels = GetCcaSecondaryChannels();
869 const auto secondaryWidthsToCheck = GetCcaSecondaryWidths(ppdu);
870 for (auto secondaryWidth : secondaryWidthsToCheck)
871 {
872 const auto channelType = secondaryChannels.at(secondaryWidth);
873
874 const auto ccaThreshold = GetCcaThreshold(ppdu, channelType);
875 const auto band = GetSecondaryBand(secondaryWidth);
876 if (const auto delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThreshold, band);
877 delayUntilCcaEnd.IsStrictlyPositive())
878 {
879 return std::make_pair(delayUntilCcaEnd, channelType);
880 }
881 }
882
883 return std::nullopt;
884}
885
888{
889 if (m_wifiPhy->GetChannelWidth() < MHz_u{40})
890 {
891 return OfdmPhy::GetCcaIndication(ppdu);
892 }
893
894 auto ccaThreshold = GetCcaThreshold(ppdu, WIFI_CHANLIST_PRIMARY);
895 auto delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThreshold, GetPrimaryBand(MHz_u{20}));
896 if (delayUntilCcaEnd.IsStrictlyPositive())
897 {
898 return std::make_pair(
899 delayUntilCcaEnd,
900 WIFI_CHANLIST_PRIMARY); // if Primary is busy, ignore CCA for Secondary
901 }
902
903 if (ppdu)
904 {
905 const MHz_u primaryWidth{20};
906 const MHz_u p20MinFreq =
907 m_wifiPhy->GetOperatingChannel().GetPrimaryChannelCenterFrequency(primaryWidth) -
908 (primaryWidth / 2);
909 const MHz_u p20MaxFreq =
910 m_wifiPhy->GetOperatingChannel().GetPrimaryChannelCenterFrequency(primaryWidth) +
911 (primaryWidth / 2);
912 if (ppdu->DoesOverlapChannel(p20MinFreq, p20MaxFreq))
913 {
914 /*
915 * PPDU occupies primary 20 MHz channel, hence we skip CCA sensitivity rules
916 * for signals not occupying the primary 20 MHz channel.
917 */
918 return std::nullopt;
919 }
920 }
921
922 return GetCcaIndicationOnSecondary(ppdu);
923}
924
925} // namespace ns3
926
927namespace
928{
929
930/**
931 * Constructor class for HT modes
932 */
934{
935 public:
937 {
940 std::make_shared<ns3::HtPhy>()); // dummy Nss
941 }
942} g_constructor_ht; ///< the constructor for HT modes
943
944} // namespace
uint32_t v
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:656
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:887
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:626
uint8_t m_bssMembershipSelector
the BSS membership selector
Definition ht-phy.h:507
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:389
Ptr< SpectrumValue > GetTxPowerSpectralDensity(Watt_u txPower, Ptr< const WifiPpdu > ppdu) const override
Definition ht-phy.cc:459
~HtPhy() override
Destructor for HT PHY.
Definition ht-phy.cc:68
static WifiMode GetLSigMode()
Definition ht-phy.cc:153
static uint16_t GetHtConstellationSize(uint8_t mcsValue)
Return the constellation size corresponding to the supplied HT MCS index.
Definition ht-phy.cc:620
uint8_t m_maxMcsIndexPerSs
the maximum MCS index per spatial stream as defined by the standard
Definition ht-phy.h:505
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:431
HtPhy(uint8_t maxNss=1, bool buildModeList=true)
Constructor for HT PHY.
Definition ht-phy.cc:52
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
Definition ht-phy.cc:683
static void InitializeModes()
Initialize all HT modes.
Definition ht-phy.cc:478
static WifiCodeRate GetHtCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index.
Definition ht-phy.cc:592
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:738
virtual Time GetTrainingDuration(const WifiTxVector &txVector, uint8_t nDataLtf, uint8_t nExtensionLtf=0) const
Definition ht-phy.cc:255
bool IsMcsSupported(uint8_t index) const override
Check if the WifiMode corresponding to the given MCS index is supported.
Definition ht-phy.cc:110
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:209
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:275
uint8_t GetBssMembershipSelector() const
Definition ht-phy.cc:165
static bool IsAllowed(const WifiTxVector &txVector)
Check whether the combination in TXVECTOR is allowed.
Definition ht-phy.cc:810
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
Definition ht-phy.cc:662
WifiMode GetMcs(uint8_t index) const override
Get the WifiMode corresponding to the given MCS index.
Definition ht-phy.cc:94
std::vector< MHz_u > GetCcaSecondaryWidths(const Ptr< const WifiPpdu > ppdu) const
Get the widths of the secondary channels to inspect for CCA indication.
Definition ht-phy.cc:828
virtual uint8_t GetNumberBccEncoders(const WifiTxVector &txVector) const
Definition ht-phy.cc:355
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:730
virtual Time GetLSigDuration(WifiPreamble preamble) const
Definition ht-phy.cc:249
static uint64_t GetPhyRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
Return the PHY rate corresponding to the supplied HT MCS index, channel width, guard interval,...
Definition ht-phy.cc:648
virtual const std::map< MHz_u, WifiChannelListType > & GetCcaSecondaryChannels() const
Get the secondary channel widths and their corresponding channel list types that are supported by the...
Definition ht-phy.cc:822
void SetMaxSupportedMcsIndexPerSs(uint8_t maxIndex)
Set the maximum supported MCS index per spatial stream.
Definition ht-phy.cc:171
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition ht-phy.cc:487
static WifiMode CreateHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition ht-phy.cc:576
uint32_t GetMaxPsduSize() const override
Get the maximum PSDU size in bytes.
Definition ht-phy.cc:816
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:598
virtual WifiMode GetHtSigMode() const
Definition ht-phy.cc:159
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:135
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:705
uint8_t GetMaxSupportedMcsIndexPerSs() const
Set the maximum supported MCS index per spatial stream.
Definition ht-phy.cc:188
bool IsConfigSupported(Ptr< const WifiPpdu > ppdu) const override
Checks if the signaled configuration (excluding bandwidth) is supported by the PHY.
Definition ht-phy.cc:441
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
Definition ht-phy.cc:378
uint8_t m_maxSupportedNss
Maximum supported number of spatial streams (used to build HT MCS indices).
Definition ht-phy.h:529
virtual void BuildModeList()
Build mode list.
Definition ht-phy.cc:74
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:671
bool HandlesMcsModes() const override
Check if the WifiModes handled by this PHY are MCSs.
Definition ht-phy.cc:123
static const PpduFormats m_htPpduFormats
HT PPDU formats.
Definition ht-phy.h:532
void SetMaxSupportedNss(uint8_t maxNss)
Configure the maximum number of spatial streams supported by this HT PHY.
Definition ht-phy.cc:194
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:406
virtual Time GetHtSigDuration() const
Definition ht-phy.cc:269
uint8_t m_maxSupportedMcsIndexPerSs
the maximum supported MCS index per spatial stream
Definition ht-phy.h:506
const PpduFormats & GetPpduFormats() const override
Return the PPDU formats of the PHY.
Definition ht-phy.cc:129
virtual Time GetSymbolDuration(const WifiTxVector &txVector) const
Definition ht-phy.cc:369
virtual PhyEntity::CcaIndication GetCcaIndicationOnSecondary(const Ptr< const WifiPpdu > ppdu)
Get CCA end time and its corresponding channel list type when a new signal not occupying the primary ...
Definition ht-phy.cc:866
static uint64_t GetDataRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
Return the data rate corresponding to the supplied HT MCS index, channel width, guard interval,...
Definition ht-phy.cc:692
static WifiMode GetOfdmRate6Mbps()
dBm_u GetCcaThreshold(const Ptr< const WifiPpdu > ppdu, WifiChannelListType channelType) const override
Return the CCA threshold for a given channel type.
Definition ofdm-phy.cc:667
uint8_t GetNumberServiceBits() const
Definition ofdm-phy.cc:272
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:346
OfdmPhy(OfdmPhyVariant variant=OFDM_PHY_DEFAULT, bool buildModeList=true)
Constructor for OFDM PHY.
Definition ofdm-phy.cc:98
static uint16_t GetUsableSubcarriers()
Definition ofdm-phy.cc:623
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:183
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:298
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, MHz_u channelWidth)
Calculates data rate from the supplied parameters.
Definition ofdm-phy.cc:604
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:144
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:572
Time GetSignalExtension(WifiPhyBand band) const
Definition ofdm-phy.cc:278
MHz_u GetGuardBandwidth(MHz_u currentChannelWidth) const
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
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:887
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition phy-entity.h:902
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
Definition phy-entity.h:492
WifiSpectrumBandInfo GetPrimaryBand(MHz_u bandWidth) const
If the operating channel width is a multiple of 20 MHz, return the info corresponding to the primary ...
Time GetDelayUntilCcaEnd(dBm_u threshold, const WifiSpectrumBandInfo &band)
Return the delay until CCA busy is ended for a given sensitivity threshold and a given band.
SnrPer GetPhyHeaderSnrPer(WifiPpduField field, Ptr< Event > event) const
Obtain the SNR and PER of the PPDU field from the WifiPhy's InterferenceHelper class.
virtual bool IsModeSupported(WifiMode mode) const
Check if the WifiMode is supported.
Definition phy-entity.cc:93
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...
std::list< WifiMode > m_modeList
the list of supported modes
Definition phy-entity.h:906
double GetRandomValue() const
Obtain a random value from the WifiPhy's generator.
std::tuple< dBr_u, dBr_u, dBr_u > GetTxMaskRejectionParams() const
@ DROP
drop PPDU and set CCA_BUSY
Definition phy-entity.h:69
WifiSpectrumBandInfo GetSecondaryBand(MHz_u bandWidth) const
If the channel bonding is used, return the info corresponding to the secondary channel of the given b...
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:413
@ NS
nanosecond
Definition nstime.h:109
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:422
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:423
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:341
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:305
represent a single transmission mode
Definition wifi-mode.h:39
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
uint8_t GetMcsValue() const
Definition wifi-mode.cc:151
static void AddStaticPhyEntity(WifiModulationClass modulation, std::shared_ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of implemented PHY entities for the given modulation class.
Definition wifi-phy.cc:813
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(const std::vector< MHz_u > &centerFrequencies, MHz_u channelWidth, Watt_u txPower, MHz_u guardBandwidth, dBr_u minInnerBand=dBr_u{-20}, dBr_u minOuterband=dBr_u{-28}, dBr_u lowestPoint=dBr_u{-40})
Create a transmit power spectral density corresponding to OFDM High Throughput (HT/VHT) (802....
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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
MHz_u GetChannelWidth() const
Time GetGuardInterval() const
uint8_t GetNess() const
#define CASE(x)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:76
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:690
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:99
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:281
#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:753
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1347
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1364
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1388
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiPhyBand
Identifies the PHY band.
WifiPpduField
The type of PPDU field (grouped for convenience).
MpduType
The type of an MPDU.
Definition wifi-types.h:54
@ WIFI_STANDARD_80211n
@ UNSUPPORTED_SETTINGS
@ HT_SIG_FAILURE
@ WIFI_PREAMBLE_HT_MF
@ WIFI_MOD_CLASS_HT
HT (Clause 19).
@ OFDM_PHY_DEFAULT
Definition ofdm-phy.h:35
@ 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.
Definition wifi-types.h:66
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
Definition wifi-types.h:56
@ FIRST_MPDU_IN_AGGREGATE
The MPDU is the first aggregate in an A-MPDU with multiple MPDUs, but is not the last aggregate.
Definition wifi-types.h:61
@ SINGLE_MPDU
The MPDU is a single MPDU.
Definition wifi-types.h:58
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
Definition wifi-types.h:64
#define GET_HT_MCS(x)
Definition ht-phy.cc:534
Declaration of ns3::HtPhy class.
#define HT_PHY
This defines the BSS membership value for HT PHY.
Definition ht-phy.h:28
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.
bool IsValidGuardInterval(Time gi, WifiStandard standard)
Check whether a guard interval duration is valid for a given standard.
static constexpr uint32_t WIFI_PSDU_MAX_LENGTH_HT
The value for aPSDUMaxLength in Table 19-25 (HT PHY characteristics) of 802.11-2020.
const std::map< MHz_u, WifiChannelListType > htSecondaryChannels
map a given secondary channel width to its channel list type
Definition ht-phy.cc:46
double MHz_u
MHz weak type.
Definition wifi-units.h:31
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:39
double Watt_u
Watt weak type.
Definition wifi-units.h:25
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:45
constexpr uint8_t HT_MAX_NSS
Maximum number of supported NSS by HT PHY.
Definition ht-phy.h:31
WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
@ WIFI_CODE_RATE_2_3
2/3 coding rate
@ WIFI_CODE_RATE_1_2
1/2 coding rate
@ WIFI_CODE_RATE_3_4
3/4 coding rate
@ WIFI_CODE_RATE_UNDEFINED
undefined coding rate
@ WIFI_CODE_RATE_5_6
5/6 coding rate
Status of the reception of the PPDU field.
Definition phy-entity.h:78
WifiPhyRxfailureReason reason
failure reason
Definition phy-entity.h:80
PhyRxFailureAction actionIfFailure
action to perform in case of failure
Definition phy-entity.h:81
bool isSuccess
outcome (true if success) of the reception
Definition phy-entity.h:79
A struct for both SNR and PER.
double snr
SNR in linear scale.