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 Time duration = MicroSeconds(4) * (nDataLtf + nExtensionLtf);
266 return MicroSeconds(4) * (1 /* HT-STF */ + nDataLtf + nExtensionLtf);
267}
268
269Time
271{
272 return MicroSeconds(8); // HT-SIG
273}
274
275Time
277 const WifiTxVector& txVector,
278 WifiPhyBand band,
279 MpduType mpdutype,
280 bool incFlag,
281 uint32_t& totalAmpduSize,
282 double& totalAmpduNumSymbols,
283 uint16_t staId) const
284{
285 WifiMode payloadMode = txVector.GetMode(staId);
286 uint8_t stbc = txVector.IsStbc() ? 2 : 1; // corresponding to m_STBC in Nsym computation (see
287 // IEEE 802.11-2016, equations (19-32) and (21-62))
288 uint8_t nes = GetNumberBccEncoders(txVector);
289 // TODO: Update station managers to consider GI capabilities
290 Time symbolDuration = GetSymbolDuration(txVector);
291
292 double numDataBitsPerSymbol =
293 payloadMode.GetDataRate(txVector, staId) * symbolDuration.GetNanoSeconds() / 1e9;
294 uint8_t service = GetNumberServiceBits();
295
296 double numSymbols = 0;
297 switch (mpdutype)
298 {
300 // First packet in an A-MPDU
301 numSymbols = (stbc * (service + size * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol));
302 if (incFlag)
303 {
304 totalAmpduSize += size;
305 totalAmpduNumSymbols += numSymbols;
306 }
307 break;
308 }
310 // consecutive packets in an A-MPDU
311 numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
312 if (incFlag)
313 {
314 totalAmpduSize += size;
315 totalAmpduNumSymbols += numSymbols;
316 }
317 break;
318 }
320 // last packet in an A-MPDU
321 uint32_t totalSize = totalAmpduSize + size;
322 numSymbols = lrint(
323 stbc * ceil((service + totalSize * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol)));
324 NS_ASSERT(totalAmpduNumSymbols <= numSymbols);
325 numSymbols -= totalAmpduNumSymbols;
326 if (incFlag)
327 {
328 totalAmpduSize = 0;
329 totalAmpduNumSymbols = 0;
330 }
331 break;
332 }
333 case NORMAL_MPDU:
334 case SINGLE_MPDU: {
335 // Not an A-MPDU or single MPDU (i.e. the current payload contains both service and padding)
336 // The number of OFDM symbols in the data field when BCC encoding
337 // is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
338 numSymbols =
339 lrint(stbc * ceil((service + size * 8.0 + 6.0 * nes) / (stbc * numDataBitsPerSymbol)));
340 break;
341 }
342 default:
343 NS_FATAL_ERROR("Unknown MPDU type");
344 }
345
346 Time payloadDuration =
347 FemtoSeconds(static_cast<uint64_t>(numSymbols * symbolDuration.GetFemtoSeconds()));
348 if (mpdutype == NORMAL_MPDU || mpdutype == SINGLE_MPDU || mpdutype == LAST_MPDU_IN_AGGREGATE)
349 {
350 payloadDuration += GetSignalExtension(band);
351 }
352 return payloadDuration;
353}
354
355uint8_t
357{
358 /**
359 * Add an encoder when crossing maxRatePerCoder frontier.
360 *
361 * The value of 320 Mbps and 350 Mbps for normal GI and short GI (resp.)
362 * were obtained by observing the rates for which Nes was incremented in tables
363 * 19-27 to 19-41 of IEEE 802.11-2016.
364 */
365 double maxRatePerCoder = (txVector.GetGuardInterval().GetNanoSeconds() == 800) ? 320e6 : 350e6;
366 return ceil(txVector.GetMode().GetDataRate(txVector) / maxRatePerCoder);
367}
368
369Time
371{
372 const auto guardInterval = txVector.GetGuardInterval();
373 [[maybe_unused]] const auto gi = guardInterval.GetNanoSeconds();
374 NS_ASSERT(gi == 400 || gi == 800);
375 return GetSymbolDuration(guardInterval);
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 ppduDuration,
386 ObtainNextUid(txVector));
387}
388
391{
392 NS_LOG_FUNCTION(this << field << *event);
393 switch (field)
394 {
396 return EndReceiveHtSig(event);
398 return PhyFieldRxStatus(true); // always consider that training has been correctly received
400 // no break so as to go to OfdmPhy for processing
401 default:
402 return OfdmPhy::DoEndReceiveField(field, event);
403 }
404}
405
408{
409 NS_LOG_FUNCTION(this << *event);
410 NS_ASSERT(event->GetPpdu()->GetTxVector().GetPreambleType() == WIFI_PREAMBLE_HT_MF);
412 NS_LOG_DEBUG("HT-SIG: SNR(dB)=" << RatioToDb(snrPer.snr) << ", PER=" << snrPer.per);
413 PhyFieldRxStatus status(GetRandomValue() > snrPer.per);
414 if (status.isSuccess)
415 {
416 NS_LOG_DEBUG("Received HT-SIG");
417 if (!IsAllConfigSupported(WIFI_PPDU_FIELD_HT_SIG, event->GetPpdu()))
418 {
420 }
421 }
422 else
423 {
424 NS_LOG_DEBUG("Drop packet because HT-SIG reception failed");
425 status.reason = HT_SIG_FAILURE;
426 status.actionIfFailure = DROP;
427 }
428 return status;
429}
430
431bool
433{
435 {
436 return true; // wait till reception of HT-SIG (or SIG-A) to make decision
437 }
438 return OfdmPhy::IsAllConfigSupported(field, ppdu);
439}
440
441bool
443{
444 const auto& txVector = ppdu->GetTxVector();
445 if (txVector.GetNss() > m_wifiPhy->GetMaxSupportedRxSpatialStreams())
446 {
447 NS_LOG_DEBUG("Packet reception could not be started because not enough RX antennas");
448 return false;
449 }
450 if (!IsModeSupported(txVector.GetMode()))
451 {
452 NS_LOG_DEBUG("Drop packet because it was sent using an unsupported mode ("
453 << txVector.GetMode() << ")");
454 return false;
455 }
456 return true;
457}
458
461{
462 const auto& centerFrequencies = ppdu->GetTxCenterFreqs();
463 NS_ASSERT(centerFrequencies.size() == 1);
464 const auto& txVector = ppdu->GetTxVector();
465 const auto channelWidth = txVector.GetChannelWidth();
466 NS_LOG_FUNCTION(this << centerFrequencies.front() << channelWidth << txPower);
467 const auto& txMaskRejectionParams = GetTxMaskRejectionParams();
469 centerFrequencies,
470 channelWidth,
471 txPower,
472 GetGuardBandwidth(channelWidth),
473 std::get<0>(txMaskRejectionParams),
474 std::get<1>(txMaskRejectionParams),
475 std::get<2>(txMaskRejectionParams));
476 return v;
477}
478
479void
481{
482 for (uint8_t i = 0; i < 32; ++i)
483 {
484 GetHtMcs(i);
485 }
486}
487
489HtPhy::GetHtMcs(uint8_t index)
490{
491#define CASE(x) \
492 case x: \
493 return GetHtMcs##x();
494
495 switch (index)
496 {
497 CASE(0)
498 CASE(1)
499 CASE(2)
500 CASE(3)
501 CASE(4)
502 CASE(5)
503 CASE(6)
504 CASE(7)
505 CASE(8)
506 CASE(9)
507 CASE(10)
508 CASE(11)
509 CASE(12)
510 CASE(13)
511 CASE(14)
512 CASE(15)
513 CASE(16)
514 CASE(17)
515 CASE(18)
516 CASE(19)
517 CASE(20)
518 CASE(21)
519 CASE(22)
520 CASE(23)
521 CASE(24)
522 CASE(25)
523 CASE(26)
524 CASE(27)
525 CASE(28)
526 CASE(29)
527 CASE(30)
528 CASE(31)
529 default:
530 NS_ABORT_MSG("Inexistent (or not supported) index (" << +index << ") requested for HT");
531 return WifiMode();
532 }
533#undef CASE
534}
535
536#define GET_HT_MCS(x) \
537 WifiMode HtPhy::GetHtMcs##x() \
538 { \
539 static WifiMode mcs = CreateHtMcs(x); \
540 return mcs; \
541 }
542
543GET_HT_MCS(0)
544GET_HT_MCS(1)
545GET_HT_MCS(2)
546GET_HT_MCS(3)
547GET_HT_MCS(4)
548GET_HT_MCS(5)
549GET_HT_MCS(6)
550GET_HT_MCS(7)
551GET_HT_MCS(8)
552GET_HT_MCS(9)
553GET_HT_MCS(10)
554GET_HT_MCS(11)
555GET_HT_MCS(12)
556GET_HT_MCS(13)
557GET_HT_MCS(14)
558GET_HT_MCS(15)
559GET_HT_MCS(16)
560GET_HT_MCS(17)
561GET_HT_MCS(18)
562GET_HT_MCS(19)
563GET_HT_MCS(20)
564GET_HT_MCS(21)
565GET_HT_MCS(22)
566GET_HT_MCS(23)
567GET_HT_MCS(24)
568GET_HT_MCS(25)
569GET_HT_MCS(26)
570GET_HT_MCS(27)
571GET_HT_MCS(28)
572GET_HT_MCS(29)
573GET_HT_MCS(30)
574GET_HT_MCS(31)
575#undef GET_HT_MCS
576
577WifiMode
578HtPhy::CreateHtMcs(uint8_t index)
579{
580 NS_ASSERT_MSG(index <= 31, "HtMcs index must be <= 31!");
581 return WifiModeFactory::CreateWifiMcs("HtMcs" + std::to_string(index),
582 index,
584 false,
591}
592
594HtPhy::GetHtCodeRate(uint8_t mcsValue)
595{
596 return GetCodeRate(mcsValue % 8);
597}
598
600HtPhy::GetCodeRate(uint8_t mcsValue)
601{
602 switch (mcsValue)
603 {
604 case 0:
605 case 1:
606 case 3:
607 return WIFI_CODE_RATE_1_2;
608 case 2:
609 case 4:
610 case 6:
611 return WIFI_CODE_RATE_3_4;
612 case 5:
613 return WIFI_CODE_RATE_2_3;
614 case 7:
615 return WIFI_CODE_RATE_5_6;
616 default:
618 }
619}
620
621uint16_t
623{
624 return GetConstellationSize(mcsValue % 8);
625}
626
627uint16_t
629{
630 switch (mcsValue)
631 {
632 case 0:
633 return 2;
634 case 1:
635 case 2:
636 return 4;
637 case 3:
638 case 4:
639 return 16;
640 case 5:
641 case 6:
642 case 7:
643 return 64;
644 default:
645 return 0;
646 }
647}
648
649uint64_t
650HtPhy::GetPhyRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
651{
652 const auto codeRate = GetHtCodeRate(mcsValue);
653 const auto dataRate = GetDataRate(mcsValue, channelWidth, guardInterval, nss);
654 return CalculatePhyRate(codeRate, dataRate);
655}
656
657uint64_t
658HtPhy::CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
659{
660 return (dataRate / GetCodeRatio(codeRate));
661}
662
663uint64_t
664HtPhy::GetPhyRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
665{
666 return GetPhyRate(txVector.GetMode().GetMcsValue(),
667 txVector.GetChannelWidth(),
668 txVector.GetGuardInterval(),
669 txVector.GetNss());
670}
671
672double
674{
675 switch (codeRate)
676 {
678 return (5.0 / 6.0);
679 default:
680 return OfdmPhy::GetCodeRatio(codeRate);
681 }
682}
683
684uint64_t
685HtPhy::GetDataRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
686{
687 return GetDataRate(txVector.GetMode().GetMcsValue(),
688 txVector.GetChannelWidth(),
689 txVector.GetGuardInterval(),
690 txVector.GetNss());
691}
692
693uint64_t
694HtPhy::GetDataRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
695{
696 [[maybe_unused]] const auto gi = guardInterval.GetNanoSeconds();
697 NS_ASSERT((gi == 800) || (gi == 400));
698 NS_ASSERT(nss <= 4);
699 return CalculateDataRate(GetSymbolDuration(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
721{
722 return (channelWidth == MHz_u{40}) ? 108 : 52;
723}
724
725Time
727{
728 return NanoSeconds(3200) + guardInterval;
729}
730
731uint64_t
733{
734 const auto codeRate = GetHtCodeRate(mcsValue);
735 const auto 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
823const std::map<MHz_u, WifiChannelListType>&
828
829std::vector<MHz_u>
831{
832 std::vector<MHz_u> secondaryWidthsToCheck{};
833 if (ppdu)
834 {
835 for (const auto& secondaryChannel : GetCcaSecondaryChannels())
836 {
837 const auto secondaryWidth = secondaryChannel.first;
838 if (secondaryWidth >= m_wifiPhy->GetChannelWidth())
839 {
840 break;
841 }
842 const MHz_u secondaryMinFreq =
844 secondaryWidth) -
845 (secondaryWidth / 2);
846 const MHz_u secondaryMaxFreq =
848 secondaryWidth) +
849 (secondaryWidth / 2);
850 if (ppdu->DoesOverlapChannel(secondaryMinFreq, secondaryMaxFreq))
851 {
852 secondaryWidthsToCheck.push_back(secondaryWidth);
853 }
854 }
855 }
856 else
857 {
858 for (MHz_u secondaryWidth = 20; secondaryWidth < m_wifiPhy->GetChannelWidth();
859 secondaryWidth *= 2)
860 {
861 secondaryWidthsToCheck.push_back(secondaryWidth);
862 }
863 }
864 return secondaryWidthsToCheck;
865}
866
869{
870 const auto& secondaryChannels = GetCcaSecondaryChannels();
871 const auto secondaryWidthsToCheck = GetCcaSecondaryWidths(ppdu);
872 for (auto secondaryWidth : secondaryWidthsToCheck)
873 {
874 const auto channelType = secondaryChannels.at(secondaryWidth);
875
876 const auto ccaThreshold = GetCcaThreshold(ppdu, channelType);
877 const auto band = GetSecondaryBand(secondaryWidth);
878 if (const auto delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThreshold, band);
879 delayUntilCcaEnd.IsStrictlyPositive())
880 {
881 return std::make_pair(delayUntilCcaEnd, channelType);
882 }
883 }
884
885 return std::nullopt;
886}
887
890{
891 if (m_wifiPhy->GetChannelWidth() < MHz_u{40})
892 {
893 return OfdmPhy::GetCcaIndication(ppdu);
894 }
895
896 auto ccaThreshold = GetCcaThreshold(ppdu, WIFI_CHANLIST_PRIMARY);
897 auto delayUntilCcaEnd = GetDelayUntilCcaEnd(ccaThreshold, GetPrimaryBand(MHz_u{20}));
898 if (delayUntilCcaEnd.IsStrictlyPositive())
899 {
900 return std::make_pair(
901 delayUntilCcaEnd,
902 WIFI_CHANLIST_PRIMARY); // if Primary is busy, ignore CCA for Secondary
903 }
904
905 if (ppdu)
906 {
907 const MHz_u primaryWidth{20};
908 const MHz_u p20MinFreq =
910 (primaryWidth / 2);
911 const MHz_u p20MaxFreq =
913 (primaryWidth / 2);
914 if (ppdu->DoesOverlapChannel(p20MinFreq, p20MaxFreq))
915 {
916 /*
917 * PPDU occupies primary 20 MHz channel, hence we skip CCA sensitivity rules
918 * for signals not occupying the primary 20 MHz channel.
919 */
920 return std::nullopt;
921 }
922 }
923
924 return GetCcaIndicationOnSecondary(ppdu);
925}
926
927} // namespace ns3
928
929namespace
930{
931
932/**
933 * Constructor class for HT modes
934 */
936{
937 public:
944} g_constructor_ht; ///< the constructor for HT modes
945
946} // namespace
Constructor class for HT modes.
Definition ht-phy.cc:936
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:658
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:889
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:628
uint8_t m_bssMembershipSelector
the BSS membership selector
Definition ht-phy.h:570
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:390
Ptr< SpectrumValue > GetTxPowerSpectralDensity(Watt_u txPower, Ptr< const WifiPpdu > ppdu) const override
Definition ht-phy.cc:460
~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:622
uint8_t m_maxMcsIndexPerSs
the maximum MCS index per spatial stream as defined by the standard
Definition ht-phy.h:568
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:432
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:685
static void InitializeModes()
Initialize all HT modes.
Definition ht-phy.cc:480
static WifiCodeRate GetHtCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index.
Definition ht-phy.cc:594
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: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:276
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:812
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
Definition ht-phy.cc:664
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:830
virtual uint8_t GetNumberBccEncoders(const WifiTxVector &txVector) const
Definition ht-phy.cc:356
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: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:650
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:824
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:489
static WifiMode CreateHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
Definition ht-phy.cc:578
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:600
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:707
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:442
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:592
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:673
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:595
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:407
virtual Time GetHtSigDuration() const
Definition ht-phy.cc:270
uint8_t m_maxSupportedMcsIndexPerSs
the maximum supported MCS index per spatial stream
Definition ht-phy.h:569
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:370
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:868
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:694
PHY entity for OFDM (11a)
Definition ofdm-phy.h:50
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6 Mbps.
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:668
uint8_t GetNumberServiceBits() const
Definition ofdm-phy.cc:273
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:347
static uint16_t GetUsableSubcarriers()
Definition ofdm-phy.cc:624
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:299
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, MHz_u channelWidth)
Calculates data rate from the supplied parameters.
Definition ofdm-phy.cc:605
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:573
Time GetSignalExtension(WifiPhyBand band) const
Definition ofdm-phy.cc:279
MHz_u GetGuardBandwidth(MHz_u currentChannelWidth) const
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition phy-entity.h:941
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:926
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
Definition phy-entity.h:531
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.
virtual bool IsModeSupported(WifiMode mode) const
Check if the WifiMode is supported.
Definition phy-entity.cc:90
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:945
double GetRandomValue() const
Obtain a random value from the WifiPhy's generator.
SnrPer GetPhyHeaderSnrPer(WifiPpduField field, Ptr< Event > event) const
Obtain the SNR and PER of the PPDU field from the WifiPhy's InterferenceHelper class.
std::tuple< dBr_u, dBr_u, dBr_u > GetTxMaskRejectionParams() const
@ DROP
drop PPDU and set CCA_BUSY
Definition phy-entity.h:71
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.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:407
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:417
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:340
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:40
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
uint8_t GetMaxSupportedRxSpatialStreams() const
Definition wifi-phy.cc:1372
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:809
MHz_u GetChannelWidth() const
Definition wifi-phy.cc:1087
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
Definition wifi-phy.cc:1069
MHz_u GetSecondaryChannelCenterFrequency(MHz_u secondaryChannelWidth) const
Get the center frequency of the secondary channel of the given width.
MHz_u GetPrimaryChannelCenterFrequency(MHz_u primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
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) (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:75
#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:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:745
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1381
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1405
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:47
@ UNSUPPORTED_SETTINGS
@ HT_SIG_FAILURE
@ WIFI_PREAMBLE_HT_MF
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ OFDM_PHY_DEFAULT
Definition ofdm-phy.h:34
@ 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:59
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
Definition wifi-types.h:49
@ 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:54
@ SINGLE_MPDU
The MPDU is a single MPDU.
Definition wifi-types.h:51
@ 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:57
#define GET_HT_MCS(x)
Definition ht-phy.cc:536
Declaration of ns3::HtPhy class.
#define HT_PHY
This defines the BSS membership value for HT PHY.
Definition ht-phy.h:27
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.
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:684
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:47
const std::map< MHz_u, WifiChannelListType > htSecondaryChannels
map a given secondary channel width to its channel list type
Definition ht-phy.cc:46
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:38
constexpr uint8_t HT_MAX_NSS
Maximum number of supported NSS by HT PHY.
Definition ht-phy.h:30
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:80
WifiPhyRxfailureReason reason
failure reason
Definition phy-entity.h:82
PhyRxFailureAction actionIfFailure
action to perform in case of failure
Definition phy-entity.h:83
bool isSuccess
outcome (true if success) of the reception
Definition phy-entity.h:81
A struct for both SNR and PER.
Definition phy-entity.h:115
double snr
SNR in linear scale.
Definition phy-entity.h:116