16#include "ns3/wifi-phy-operating-channel.h"
17#include "ns3/wifi-phy.h"
18#include "ns3/wifi-psdu.h"
19#include "ns3/wifi-utils.h"
34 return (os <<
"PSD_NON_HE_PORTION");
36 return (os <<
"PSD_HE_PORTION");
39 return (os <<
"INVALID");
56 NS_LOG_FUNCTION(
this << psdus << txVector << channel << ppduDuration << uid << flag);
59 m_psdus.begin()->second =
nullptr;
75 m_txPsdFlag(PSD_NON_HE_PORTION)
77 NS_LOG_FUNCTION(
this << psdu << txVector << channel << ppduDuration << uid);
93 uint8_t sigExtension = 0;
99 uint8_t m =
IsDlMu() ? 1 : 2;
100 uint16_t length = ((ceil((
static_cast<double>(ppduDuration.
GetNanoSeconds() - (20 * 1000) -
101 (sigExtension * 1000)) /
123 const uint8_t noMuMimoUsers{0};
136 .m_center26ToneRuIndication =
171 auto heSigHeader = std::get_if<HeSuSigHeader>(&
m_heSig);
172 NS_ASSERT(heSigHeader && (heSigHeader->m_format == 1));
181 auto heSigHeader = std::get_if<HeTbSigHeader>(&
m_heSig);
182 NS_ASSERT(heSigHeader && (heSigHeader->m_format == 0));
188 auto heSigHeader = std::get_if<HeMuSigHeader>(&
m_heSig);
195 heSigHeader->m_contentChannels,
196 heSigHeader->m_sigBCompression,
201 if (heSigHeader->m_center26ToneRuIndication.has_value())
205 if (heSigHeader->m_sigBCompression)
217 bool sigBcompression,
218 uint8_t numMuMimoUsers)
const
220 std::size_t contentChannelIndex = 0;
221 for (
const auto& contentChannel : contentChannels)
223 std::size_t numRusLeft = 0;
224 std::size_t numUsersLeft = 0;
225 std::size_t ruAllocIndex = contentChannelIndex;
226 for (
const auto& userInfo : contentChannel)
232 if (ruAllocIndex >= ruAllocation.size())
243 numRusLeft = ruSpecs.size();
245 if (numUsersLeft == 0)
249 numUsersLeft = numMuMimoUsers;
257 auto ruIndex = (ruSpecs.size() - numRusLeft);
258 auto ruSpec = ruSpecs.at(ruIndex);
259 auto ruType = ruSpec.GetRuType();
263 contentChannel.cbegin(),
264 contentChannel.cend(),
265 [&userInfo](
const auto& item) { return userInfo.staId == item.staId; })))
271 auto primary80 = ruAllocIndex < 4;
272 const uint8_t num20MhzSubchannelsInRu = (ruBw < 20) ? 1 : (ruBw / 20);
273 auto numRuAllocsInContentChannel = std::max(1, num20MhzSubchannelsInRu / 2);
274 auto ruIndexOffset = (ruBw < 20) ? (ruSpecs.size() * ruAllocIndex)
275 : (ruAllocIndex / num20MhzSubchannelsInRu);
283 {{ruType, ruSpec.GetIndex() + ruIndexOffset, primary80},
293 if (numRusLeft == 0 && numUsersLeft == 0)
295 ruAllocIndex += (2 * numRuAllocsInContentChannel);
298 contentChannelIndex++;
303HePpdu::GetTxDuration()
const
306 const auto& txVector = GetTxVector();
307 const auto length = m_lSig.GetLength();
308 const auto tSymbol = HePhy::GetSymbolDuration(txVector.GetGuardInterval());
309 const auto preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector);
312 uint8_t m =
IsDlMu() ? 1 : 2;
314 const auto calculatedDuration =
315 MicroSeconds(((ceil(
static_cast<double>(length + 3 + m) / 3)) * 4) + 20 + sigExtension);
316 NS_ASSERT(calculatedDuration > preambleDuration);
318 floor(
static_cast<double>((calculatedDuration - preambleDuration).GetNanoSeconds() -
319 (sigExtension * 1000)) /
320 tSymbol.GetNanoSeconds());
321 return (preambleDuration + (nSymbols * tSymbol) +
MicroSeconds(sigExtension));
331HePpdu::GetType()
const
351HePpdu::IsDlMu()
const
357HePpdu::IsUlMu()
const
363HePpdu::GetPsdu(uint8_t bssColor, uint16_t staId )
const
368 return m_psdus.at(SU_STA_ID);
373 auto heSigHeader = std::get_if<HeTbSigHeader>(&m_heSig);
376 if ((bssColor == 0) || (heSigHeader->m_bssColor == 0) ||
377 (bssColor == heSigHeader->m_bssColor))
379 return m_psdus.cbegin()->second;
384 auto heSigHeader = std::get_if<HeMuSigHeader>(&m_heSig);
386 if ((bssColor == 0) || (heSigHeader->m_bssColor == 0) ||
387 (bssColor == heSigHeader->m_bssColor))
389 const auto it = m_psdus.find(staId);
390 if (it != m_psdus.cend())
400HePpdu::GetStaId()
const
403 return m_psdus.begin()->first;
407HePpdu::GetTxChannelWidth()
const
409 if (
const auto& txVector = GetTxVector();
410 txVector.IsValid() && txVector.IsUlMu() && GetStaId() != SU_STA_ID)
413 const auto ruWidth = HeRu::GetBandwidth(txVector.GetRu(GetStaId()).GetRuType());
414 MHz_u channelWidth = (flag == PSD_NON_HE_PORTION && ruWidth < 20) ? 20 : ruWidth;
415 NS_LOG_INFO(
"Use channelWidth=" << channelWidth <<
" MHz for HE TB from " << GetStaId()
421 return OfdmPpdu::GetTxChannelWidth();
426HePpdu::GetTxPsdFlag()
const
439HePpdu::UpdateTxVectorForUlMu(
const std::optional<WifiTxVector>& trigVector)
const
441 if (trigVector.has_value())
449 if (!m_txVector.has_value())
451 m_txVector = GetTxVector();
456 const auto staId = GetStaId();
457 if (trigVector.has_value() && trigVector->IsUlMu() &&
458 (trigVector->GetHeMuUserInfoMap().contains(staId)))
462 m_txVector->SetGuardInterval(trigVector->GetGuardInterval());
463 m_txVector->SetHeMuUserInfo(staId, trigVector->GetHeMuUserInfo(staId));
468 m_txVector->SetHeMuUserInfo(
470 {{HeRu::GetRuType(m_txVector->GetChannelWidth()), 1,
true}, 0, 1});
474std::pair<std::size_t, std::size_t>
475HePpdu::GetNumRusPerHeSigBContentChannel(
MHz_u channelWidth,
477 bool sigBCompression,
478 uint8_t numMuMimoUsers)
480 std::pair<std::size_t ,
489 if (channelWidth == 20)
491 return {numMuMimoUsers, 0};
493 chSize.first = numMuMimoUsers / 2;
494 chSize.second = numMuMimoUsers / 2;
495 if (numMuMimoUsers != (chSize.first + chSize.second))
502 NS_ASSERT_MSG(!ruAllocation.empty(),
"RU allocation is not set");
503 [[maybe_unused]]
const std::size_t num20MhzSubchannels = channelWidth / 20;
505 "RU allocation is not consistent with packet bandwidth");
507 switch (
static_cast<uint16_t
>(channelWidth))
510 chSize.second += HeRu::GetRuSpecs(ruAllocation[1]).size();
513 chSize.first += HeRu::GetRuSpecs(ruAllocation[0]).size();
516 for (
auto n = 0; n < channelWidth / 20;)
518 chSize.first += HeRu::GetRuSpecs(ruAllocation[n]).size();
519 if (ruAllocation[n] >= 208)
527 for (
auto n = 0; n < channelWidth / 20;)
529 chSize.second += HeRu::GetRuSpecs(ruAllocation[n + 1]).size();
530 if (ruAllocation[n + 1] >= 208)
544HePpdu::GetHeSigBContentChannels(
const WifiTxVector& txVector, uint8_t p20Index)
549 if (channelWidth > 20)
551 contentChannels.emplace_back();
555 for (
const auto& [ru, staIds] : orderedMap)
557 const auto ruType = ru.GetRuType();
560 for (
auto i = 0; i < ((ruType == HeRu::RU_2x996_TONE) ? 2 : 1); ++i)
562 for (
auto staId : staIds)
566 contentChannels[0].push_back({staId, userInfo.nss, userInfo.mcs});
567 contentChannels[1].push_back({staId, userInfo.nss, userInfo.mcs});
573 std::size_t numRus = (ruType >= HeRu::RU_242_TONE)
575 : HeRu::m_heRuSubcarrierGroups.at({20, ruType}).size();
576 const auto ruIdx = ru.GetIndex();
577 for (
auto staId : staIds)
581 std::size_t ccIndex{0};
582 if (channelWidth < 40)
590 ccIndex = (contentChannels.at(0).size() <= contentChannels.at(1).size()) ? 0 : 1;
594 ccIndex = (((ruIdx - 1) / numRus) % 2 == 0) ? 0 : 1;
596 contentChannels.at(ccIndex).push_back({staId, userInfo.nss, userInfo.mcs});
601 if (!isSigBCompression)
604 auto numNumRusPerHeSigBContentChannel = GetNumRusPerHeSigBContentChannel(
609 std::size_t contentChannelIndex = 1;
610 for (
auto& contentChannel : contentChannels)
612 const auto totalUsersInContentChannel = (contentChannelIndex == 1)
613 ? numNumRusPerHeSigBContentChannel.first
614 : numNumRusPerHeSigBContentChannel.second;
615 NS_ASSERT(contentChannel.size() <= totalUsersInContentChannel);
616 std::size_t unallocatedRus = totalUsersInContentChannel - contentChannel.size();
617 for (std::size_t i = 0; i < unallocatedRus; i++)
619 contentChannel.push_back({NO_USER_STA_ID, 0, 0});
621 contentChannelIndex++;
625 return contentChannels;
629HePpdu::GetSigBFieldSize(
MHz_u channelWidth,
631 bool sigBCompression,
632 std::size_t numMuMimoUsers)
636 if (!sigBCompression)
638 commonFieldSize = 4 + 6 ;
639 if (channelWidth <= 40)
641 commonFieldSize += 8;
646 8 * (channelWidth / 40) + 1 ;
650 auto numRusPerContentChannel = GetNumRusPerHeSigBContentChannel(channelWidth,
654 auto maxNumRusPerContentChannel =
655 std::max(numRusPerContentChannel.first, numRusPerContentChannel.second);
656 auto maxNumUserBlockFields = maxNumRusPerContentChannel /
658 std::size_t userSpecificFieldSize =
659 maxNumUserBlockFields * (2 * 21 + 4 + 6 );
660 if (maxNumRusPerContentChannel % 2 != 0)
662 userSpecificFieldSize += 21 + 4 + 6 ;
665 return commonFieldSize + userSpecificFieldSize;
669HePpdu::PrintPayload()
const
671 std::ostringstream ss;
675 ss <<
", " << m_txPsdFlag;
679 ss <<
"PSDU=" << m_psdus.at(SU_STA_ID) <<
" ";
685HePpdu::GetChannelWidthEncodingFromMhz(
MHz_u channelWidth)
687 if (channelWidth == 160)
691 else if (channelWidth == 80)
695 else if (channelWidth == 40)
706HePpdu::GetChannelWidthMhzFromEncoding(uint8_t bandwidth)
712 else if (bandwidth == 2)
716 else if (bandwidth == 1)
727HePpdu::GetGuardIntervalAndNltfEncoding(
Time guardInterval, uint8_t nltf)
730 if ((gi == 800) && (nltf == 1))
734 else if ((gi == 800) && (nltf == 2))
738 else if ((gi == 1600) && (nltf == 2))
749HePpdu::GetGuardIntervalFromEncoding(uint8_t giAndNltfSize)
751 if (giAndNltfSize == 3)
756 else if (giAndNltfSize == 2)
767HePpdu::GetNstsEncodingFromNss(uint8_t nss)
774HePpdu::GetNssFromNstsEncoding(uint8_t nsts)
780HePpdu::GetMuMimoUsersEncoding(uint8_t nUsers)
787HePpdu::GetMuMimoUsersFromEncoding(uint8_t encoding)
789 return (encoding + 1);
static WifiMode GetHeMcs(uint8_t index)
Return the HE MCS corresponding to the provided index.
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.
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.
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.
static Time GetGuardIntervalFromEncoding(uint8_t giAndNltfSize)
Convert guard interval from its 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...
void SetHeMuUserInfos(WifiTxVector &txVector, const RuAllocation &ruAllocation, const HeSigBContentChannels &contentChannels, bool sigBCompression, uint8_t numMuMimoUsers) const
Reconstruct HeMuUserInfoMap from HE-SIG-B header.
std::vector< std::vector< HeSigBUserSpecificField > > HeSigBContentChannels
HE SIG-B Content Channels.
static uint8_t GetMuMimoUsersEncoding(uint8_t nUsers)
Convert number of MU-MIMO users to its encoding in HE-SIG-A.
static MHz_u GetChannelWidthMhzFromEncoding(uint8_t bandwidth)
Convert channel width expressed in MHz from bandwidth field encoding in HE-SIG-A.
virtual bool IsMu() const
Return true if the PPDU is a MU PPDU.
static uint8_t GetChannelWidthEncodingFromMhz(MHz_u channelWidth)
Convert channel width expressed in MHz to bandwidth field 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 GetGuardIntervalAndNltfEncoding(Time guardInterval, uint8_t nltf)
Convert guard interval and NLTF to its encoding in HE-SIG-A.
static uint8_t GetMuMimoUsersFromEncoding(uint8_t encoding)
Convert number of MU-MIMO users from its encoding in HE-SIG-A.
static std::vector< RuSpec > GetRuSpecs(uint8_t ruAllocation)
Get the RU specs based on RU_ALLOCATION.
static MHz_u GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
static std::vector< HeRu::RuSpec > GetRusOfType(MHz_u 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(MHz_u 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.
bool IsSigBCompression() const
Indicate whether the Common field is present in the HE-SIG-B field.
uint8_t GetBssColor() const
Get the BSS color.
const RuAllocation & GetRuAllocation(uint8_t p20Index) const
Get RU_ALLOCATION field.
void SetGuardInterval(Time 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.
void SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
const HeMuUserInfoMap & GetHeMuUserInfoMap() const
Get a const reference to the map HE MU user-specific transmission information indexed by 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.
MHz_u GetChannelWidth() const
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.
Time GetGuardInterval() 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.
double MHz_u
MHz weak type.
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)
bool IsDlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a downlink multi-user transmission.
std::vector< uint8_t > RuAllocation
8 bit RU_ALLOCATION per 20 MHz
bool IsUlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a uplink multi-user transmission.