27#include "ns3/wifi-phy-operating-channel.h"
28#include "ns3/wifi-phy.h"
29#include "ns3/wifi-psdu.h"
30#include "ns3/wifi-utils.h"
43 return (os <<
"PSD_NON_HE_PORTION");
45 return (os <<
"PSD_HE_PORTION");
48 return (os <<
"INVALID");
65 NS_LOG_FUNCTION(
this << psdus << txVector << channel << ppduDuration << uid << flag);
68 m_psdus.begin()->second =
nullptr;
84 m_txPsdFlag(PSD_NON_HE_PORTION)
86 NS_LOG_FUNCTION(
this << psdu << txVector << channel << ppduDuration << uid);
102 uint8_t sigExtension = 0;
108 uint8_t m =
IsDlMu() ? 1 : 2;
109 uint16_t length = ((ceil((
static_cast<double>(ppduDuration.
GetNanoSeconds() - (20 * 1000) -
110 (sigExtension * 1000)) /
140 .m_center26ToneRuIndication =
175 auto heSigHeader = std::get_if<HeSuSigHeader>(&
m_heSig);
176 NS_ASSERT(heSigHeader && (heSigHeader->m_format == 1));
185 auto heSigHeader = std::get_if<HeTbSigHeader>(&
m_heSig);
186 NS_ASSERT(heSigHeader && (heSigHeader->m_format == 0));
192 auto heSigHeader = std::get_if<HeMuSigHeader>(&
m_heSig);
201 if (heSigHeader->m_center26ToneRuIndication.has_value())
213 auto contentChannelIndex = 0;
214 for (
const auto& contentChannel : contentChannels)
217 auto ruAllocIndex = contentChannelIndex;
218 for (
const auto& userInfo : contentChannel)
231 numRusLeft = ruSpecs.size();
233 auto ruIndex = (ruSpecs.size() - numRusLeft);
234 auto ruSpec = ruSpecs.at(ruIndex);
235 auto ruType = ruSpec.GetRuType();
238 contentChannel.cbegin(),
239 contentChannel.cend(),
240 [&userInfo](
const auto& item) { return userInfo.staId == item.staId; })))
246 auto primary80 = ruAllocIndex < 4;
247 auto num20MhzSubchannelsInRu = (ruBw < 20) ? 1 : (ruBw / 20);
248 auto numRuAllocsInContentChannel = std::max(1, num20MhzSubchannelsInRu / 2);
249 auto ruIndexOffset = (ruBw < 20) ? (ruSpecs.size() * ruAllocIndex)
250 : (ruAllocIndex / num20MhzSubchannelsInRu);
258 {{ruType, ruSpec.GetIndex() + ruIndexOffset, primary80},
269 ruAllocIndex += (2 * numRuAllocsInContentChannel);
272 contentChannelIndex++;
277HePpdu::GetTxDuration()
const
281 const auto length = m_lSig.GetLength();
283 const auto preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector);
286 uint8_t m =
IsDlMu() ? 1 : 2;
288 const auto calculatedDuration =
289 MicroSeconds(((ceil(
static_cast<double>(length + 3 + m) / 3)) * 4) + 20 + sigExtension);
290 NS_ASSERT(calculatedDuration > preambleDuration);
292 floor(
static_cast<double>((calculatedDuration - preambleDuration).GetNanoSeconds() -
293 (sigExtension * 1000)) /
294 tSymbol.GetNanoSeconds());
295 return (preambleDuration + (nSymbols * tSymbol) +
MicroSeconds(sigExtension));
305HePpdu::GetType()
const
325HePpdu::IsDlMu()
const
331HePpdu::IsUlMu()
const
337HePpdu::GetPsdu(uint8_t bssColor, uint16_t staId )
const
342 return m_psdus.at(SU_STA_ID);
347 auto heSigHeader = std::get_if<HeTbSigHeader>(&m_heSig);
350 if ((bssColor == 0) || (heSigHeader->m_bssColor == 0) ||
351 (bssColor == heSigHeader->m_bssColor))
353 return m_psdus.cbegin()->second;
358 auto heSigHeader = std::get_if<HeMuSigHeader>(&m_heSig);
360 if ((bssColor == 0) || (heSigHeader->m_bssColor == 0) ||
361 (bssColor == heSigHeader->m_bssColor))
363 const auto it = m_psdus.find(staId);
364 if (it != m_psdus.cend())
374HePpdu::GetStaId()
const
377 return m_psdus.begin()->first;
381HePpdu::GetTransmissionChannelWidth()
const
384 if (txVector.
IsUlMu() && GetStaId() != SU_STA_ID)
387 uint16_t ruWidth = HeRu::GetBandwidth(txVector.
GetRu(GetStaId()).GetRuType());
388 uint16_t channelWidth = (flag == PSD_NON_HE_PORTION && ruWidth < 20) ? 20 : ruWidth;
389 NS_LOG_INFO(
"Use channelWidth=" << channelWidth <<
" MHz for HE TB from " << GetStaId()
395 return OfdmPpdu::GetTransmissionChannelWidth();
400HePpdu::GetTxPsdFlag()
const
413HePpdu::UpdateTxVectorForUlMu(
const std::optional<WifiTxVector>& trigVector)
const
415 if (trigVector.has_value())
423 if (!m_txVector.has_value())
425 m_txVector = GetTxVector();
430 const auto staId = GetStaId();
431 if (trigVector.has_value() && trigVector->IsUlMu() &&
432 (trigVector->GetHeMuUserInfoMap().count(staId) > 0))
436 m_txVector->SetGuardInterval(trigVector->GetGuardInterval());
437 m_txVector->SetHeMuUserInfo(staId, trigVector->GetHeMuUserInfo(staId));
442 m_txVector->SetHeMuUserInfo(
444 {{HeRu::GetRuType(m_txVector->GetChannelWidth()), 1,
true}, 0, 1});
448std::pair<std::size_t, std::size_t>
449HePpdu::GetNumRusPerHeSigBContentChannel(uint16_t channelWidth,
const RuAllocation& ruAllocation)
452 NS_ASSERT_MSG(!ruAllocation.empty(),
"RU allocation is not set");
454 "RU allocation is not consistent with packet bandwidth");
456 std::pair<std::size_t ,
460 switch (channelWidth)
463 chSize.second += HeRu::GetRuSpecs(ruAllocation[1]).size();
466 chSize.first += HeRu::GetRuSpecs(ruAllocation[0]).size();
469 for (
auto n = 0; n < channelWidth / 20;)
471 chSize.first += HeRu::GetRuSpecs(ruAllocation[n]).size();
472 if (ruAllocation[n] >= 208)
480 for (
auto n = 0; n < channelWidth / 20;)
482 chSize.second += HeRu::GetRuSpecs(ruAllocation[n + 1]).size();
483 if (ruAllocation[n + 1] >= 208)
497HePpdu::GetHeSigBContentChannels(
const WifiTxVector& txVector, uint8_t p20Index)
502 if (channelWidth > 20)
504 contentChannels.emplace_back();
508 for (
const auto& [ru, staId] : orderedMap)
510 auto ruType = ru.GetRuType();
511 auto ruIdx = ru.GetIndex();
515 if (ruType > HeRu::RU_242_TONE)
517 for (
auto i = 0; i < ((ruType == HeRu::RU_2x996_TONE) ? 2 : 1); ++i)
519 contentChannels[0].push_back({staId, userInfo.nss, userInfo.mcs});
520 contentChannels[1].push_back({staId, userInfo.nss, userInfo.mcs});
525 std::size_t numRus = (ruType >= HeRu::RU_242_TONE)
527 : HeRu::m_heRuSubcarrierGroups.at({20, ruType}).size();
528 if (((ruIdx - 1) / numRus) % 2 == 0)
530 contentChannels.at(0).push_back({staId, userInfo.nss, userInfo.mcs});
534 contentChannels.at(1).push_back({staId, userInfo.nss, userInfo.mcs});
539 auto numNumRusPerHeSigBContentChannel =
540 GetNumRusPerHeSigBContentChannel(channelWidth, txVector.
GetRuAllocation(p20Index));
541 std::size_t contentChannelIndex = 1;
542 for (
auto& contentChannel : contentChannels)
544 const auto totalUsersInContentChannel = (contentChannelIndex == 1)
545 ? numNumRusPerHeSigBContentChannel.first
546 : numNumRusPerHeSigBContentChannel.second;
547 NS_ASSERT(contentChannel.size() <= totalUsersInContentChannel);
548 std::size_t unallocatedRus = totalUsersInContentChannel - contentChannel.size();
549 for (std::size_t i = 0; i < unallocatedRus; i++)
551 contentChannel.push_back({NO_USER_STA_ID, 0, 0});
553 contentChannelIndex++;
556 return contentChannels;
560HePpdu::GetSigBFieldSize(uint16_t channelWidth,
const RuAllocation& ruAllocation)
565 auto commonFieldSize = 4 + 6 ;
566 if (channelWidth <= 40)
568 commonFieldSize += 8;
573 8 * (channelWidth / 40) + 1 ;
576 auto numRusPerContentChannel = GetNumRusPerHeSigBContentChannel(channelWidth, ruAllocation);
577 auto maxNumRusPerContentChannel =
578 std::max(numRusPerContentChannel.first, numRusPerContentChannel.second);
579 auto maxNumUserBlockFields = maxNumRusPerContentChannel /
581 std::size_t userSpecificFieldSize =
582 maxNumUserBlockFields * (2 * 21 + 4 + 6 );
583 if (maxNumRusPerContentChannel % 2 != 0)
585 userSpecificFieldSize += 21 + 4 + 6 ;
588 return commonFieldSize + userSpecificFieldSize;
592HePpdu::PrintPayload()
const
594 std::ostringstream ss;
598 ss <<
", " << m_txPsdFlag;
602 ss <<
"PSDU=" << m_psdus.at(SU_STA_ID) <<
" ";
608HePpdu::GetChannelWidthEncodingFromMhz(uint16_t channelWidth)
610 if (channelWidth == 160)
614 else if (channelWidth == 80)
618 else if (channelWidth == 40)
629HePpdu::GetChannelWidthMhzFromEncoding(uint8_t bandwidth)
635 else if (bandwidth == 2)
639 else if (bandwidth == 1)
650HePpdu::GetGuardIntervalAndNltfEncoding(uint16_t gi, uint8_t nltf)
652 if (gi == 800 && nltf == 1)
656 else if (gi == 800 && nltf == 2)
660 else if (gi == 1600 && nltf == 2)
671HePpdu::GetGuardIntervalFromEncoding(uint8_t giAndNltfSize)
673 if (giAndNltfSize == 3)
678 else if (giAndNltfSize == 2)
689HePpdu::GetNstsEncodingFromNss(uint8_t nss)
696HePpdu::GetNssFromNstsEncoding(uint8_t nsts)
static WifiMode GetHeMcs(uint8_t index)
Return the HE MCS corresponding to the provided index.
std::vector< std::vector< HeSigBUserSpecificField > > HeSigBContentChannels
HE SIG-B Content Channels.
HeSigHeader m_heSig
the HE-SIG PHY header
WifiTxVector DoGetTxVector() const override
Get the TXVECTOR used to send the PPDU.
virtual void SetTxVectorFromPhyHeaders(WifiTxVector &txVector) const
Fill in the TXVECTOR from PHY headers.
static uint16_t GetGuardIntervalFromEncoding(uint8_t giAndNltfSize)
Convert guard interval (in ns) from its encoding in HE-SIG-A.
static uint16_t GetChannelWidthMhzFromEncoding(uint8_t bandwidth)
Convert channel width expressed in MHz from bandwidth field encoding in HE-SIG-A.
TxPsdFlag
The transmit power spectral density flag, namely used to correctly build PSDs for pre-HE and HE porti...
@ PSD_HE_PORTION
HE portion of an HE PPDU.
@ PSD_NON_HE_PORTION
Non-HE portion of an HE PPDU.
virtual bool IsDlMu() const
Return true if the PPDU is a DL MU PPDU.
virtual bool IsUlMu() const
Return true if the PPDU is an UL MU PPDU.
void SetHeMuUserInfos(WifiTxVector &txVector, const RuAllocation &ruAllocation, const HeSigBContentChannels &contentChannels) const
Reconstruct HeMuUserInfoMap from HE-SIG-B header.
static uint8_t GetNstsEncodingFromNss(uint8_t nss)
Convert number of spatial streams to NSTS field encoding in HE-SIG-A.
void SetHeSigHeader(const WifiTxVector &txVector)
Fill in the HE-SIG header.
static uint8_t GetNssFromNstsEncoding(uint8_t nsts)
Convert number of spatial streams from NSTS field encoding in HE-SIG-A.
void SetPhyHeaders(const WifiTxVector &txVector, Time ppduDuration)
Fill in the PHY headers.
static HeSigBContentChannels GetHeSigBContentChannels(const WifiTxVector &txVector, uint8_t p20Index)
Get the HE SIG-B content channels for a given PPDU IEEE 802.11ax-2021 27.3.11.8.2 HE-SIG-B content ch...
virtual bool IsMu() const
Return true if the PPDU is a MU PPDU.
static uint8_t GetGuardIntervalAndNltfEncoding(uint16_t gi, uint8_t nltf)
Convert guard interval (in ns) and NLTF to its encoding in HE-SIG-A.
void SetLSigHeader(Time ppduDuration)
Fill in the L-SIG header.
HePpdu(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector, const WifiPhyOperatingChannel &channel, Time ppduDuration, uint64_t uid)
Create an SU HE PPDU, storing a PSDU.
static uint8_t GetChannelWidthEncodingFromMhz(uint16_t channelWidth)
Convert channel width expressed in MHz to bandwidth field encoding in HE-SIG-A.
static std::vector< RuSpec > GetRuSpecs(uint8_t ruAllocation)
Get the RU specs based on RU_ALLOCATION.
static uint16_t GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
static std::vector< HeRu::RuSpec > GetRusOfType(uint16_t bw, HeRu::RuType ruType)
Get the set of distinct RUs of the given type (number of tones) available in a HE PPDU of the given b...
LSigHeader m_lSig
the L-SIG PHY header
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static WifiMode GetVhtMcs(uint8_t index)
Return the VHT MCS corresponding to the provided index.
uint8_t GetMcsValue() const
Class that keeps track of all information about the current PHY operating channel.
bool IsSet() const
Return true if a valid channel has been set, false otherwise.
uint8_t GetPrimaryChannelIndex(uint16_t primaryChannelWidth) const
If the operating channel width is a multiple of 20 MHz, return the index of the primary channel of th...
WifiPhyBand GetPhyBand() const
Return the PHY band of the operating channel.
const WifiPhyOperatingChannel & m_operatingChannel
the operating channel of the PHY
WifiPreamble m_preamble
the PHY preamble
WifiConstPsduMap m_psdus
the PSDUs contained in this PPDU
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetCenter26ToneRuIndication(Center26ToneRuIndication center26ToneRuIndication)
Set CENTER_26_TONE_RU field.
void SetRuAllocation(const RuAllocation &ruAlloc, uint8_t p20Index)
Set RU_ALLOCATION field.
UserInfoMapOrderedByRus GetUserInfoMapOrderedByRus(uint8_t p20Index) const
Get the map of specific user info parameters ordered per increasing frequency RUs.
uint16_t GetGuardInterval() const
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
uint8_t GetBssColor() const
Get the BSS color.
const RuAllocation & GetRuAllocation(uint8_t p20Index) const
Get RU_ALLOCATION field.
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
std::optional< Center26ToneRuIndication > GetCenter26ToneRuIndication() const
Get CENTER_26_TONE_RU field This field is present if format is HE_MU and when channel width is set to...
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.
RuAllocation m_ruAllocation
RU allocations that are going to be carried in SIG-B common field per Table 27-1 IEEE.
void SetHeMuUserInfo(uint16_t staId, HeMuUserInfo userInfo)
Set the HE MU user-specific transmission information for the given STA-ID.
HeMuUserInfo GetHeMuUserInfo(uint16_t staId) const
Get the HE MU user-specific transmission information for the given STA-ID.
void SetAggregation(bool aggregation)
Sets if PSDU contains A-MPDU.
HeRu::RuSpec GetRu(uint16_t staId) const
Get the RU specification for the STA-ID.
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.
void SetLength(uint16_t length)
Set the LENGTH field of the L-SIG.
void SetSigBMode(const WifiMode &mode)
Set the MCS used for SIG-B.
void SetBssColor(uint8_t color)
Set the BSS color.
bool IsAllocated(uint16_t staId) const
Check if STA ID is allocated.
uint16_t GetChannelWidth() const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
WifiMode GetSigBMode() const
Get MCS used for SIG-B.
void SetNss(uint8_t nss)
Sets the number of Nss.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
WifiPpduType
The type of PPDU (SU, DL MU, or UL MU)
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
Declaration of ns3::HePhy class and ns3::HeSigAParameters struct.
Declaration of ns3::HePpdu class.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
std::ostream & operator<<(std::ostream &os, const Angles &a)
bool IsMu(WifiPreamble preamble)
Return true if a preamble corresponds to a multi-user transmission.
static constexpr uint16_t NO_USER_STA_ID
STA_ID for a RU that is intended for no user (Section 26.11.1 802.11ax-2021)
std::vector< uint8_t > RuAllocation
8 bit RU_ALLOCATION per 20 MHz
bool IsDlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a downlink multi-user transmission.
bool IsUlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a uplink multi-user transmission.