14#include "ns3/assert.h"
15#include "ns3/interference-helper.h"
17#include "ns3/wifi-phy.h"
18#include "ns3/wifi-psdu.h"
19#include "ns3/wifi-utils.h"
21#undef NS_LOG_APPEND_CONTEXT
22#define NS_LOG_APPEND_CONTEXT WIFI_PHY_NS_LOG_APPEND_CONTEXT(m_wifiPhy)
56 "Unsupported max Nss " << +maxNss <<
" for HT PHY");
91 if (mcs.GetMcsValue() == index)
98 NS_ABORT_MSG(
"Unsupported MCS index " << +index <<
" for this PHY entity");
107 if (mcs.GetMcsValue() == index)
168 "Provided max MCS index " << +maxIndex
169 <<
" per SS greater than max standard-defined value "
173 NS_LOG_LOGIC(
"Rebuild mode list since max MCS index per spatial stream has changed");
194 NS_LOG_LOGIC(
"Rebuild mode list since max number of spatial streams has changed");
214 uint8_t nDataLtf = 8;
230 uint8_t nExtensionLtf = (txVector.
GetNess() < 3) ? txVector.
GetNess() : 4;
250 uint8_t nExtensionLtf )
const
253 (nDataLtf + nExtensionLtf) > 5,
254 "Unsupported combination of data ("
255 << +nDataLtf <<
") and extension (" << +nExtensionLtf
256 <<
") LTFs numbers for HT");
259 return MicroSeconds(4) * (1 + nDataLtf + nExtensionLtf);
275 double& totalAmpduNumSymbols,
276 uint16_t staId)
const
279 uint8_t stbc = txVector.
IsStbc() ? 2 : 1;
285 double numDataBitsPerSymbol =
289 double numSymbols = 0;
294 numSymbols = (stbc * (service + size * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol));
297 totalAmpduSize += size;
298 totalAmpduNumSymbols += numSymbols;
304 numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
307 totalAmpduSize += size;
308 totalAmpduNumSymbols += numSymbols;
314 uint32_t totalSize = totalAmpduSize + size;
316 stbc * ceil((service + totalSize * 8.0 + 6 * nes) / (stbc * numDataBitsPerSymbol)));
317 NS_ASSERT(totalAmpduNumSymbols <= numSymbols);
318 numSymbols -= totalAmpduNumSymbols;
322 totalAmpduNumSymbols = 0;
332 lrint(stbc * ceil((service + size * 8.0 + 6.0 * nes) / (stbc * numDataBitsPerSymbol)));
339 Time payloadDuration =
345 return payloadDuration;
417 NS_LOG_DEBUG(
"Drop packet because HT-SIG reception failed");
437 const auto& txVector = ppdu->GetTxVector();
440 NS_LOG_DEBUG(
"Packet reception could not be started because not enough RX antennas");
445 NS_LOG_DEBUG(
"Drop packet because it was sent using an unsupported mode ("
446 << txVector.GetMode() <<
")");
455 const auto& centerFrequencies = ppdu->GetTxCenterFreqs();
456 NS_ASSERT(centerFrequencies.size() == 1);
457 const auto& txVector = ppdu->GetTxVector();
458 const auto channelWidth = txVector.GetChannelWidth();
459 NS_LOG_FUNCTION(
this << centerFrequencies.front() << channelWidth << txPower);
466 std::get<0>(txMaskRejectionParams),
467 std::get<1>(txMaskRejectionParams),
468 std::get<2>(txMaskRejectionParams));
475 for (uint8_t i = 0; i < 32; ++i)
486 return GetHtMcs##x();
523 NS_ABORT_MSG(
"Inexistent (or not supported) index (" << +index <<
") requested for HT");
529#define GET_HT_MCS(x) \
530 WifiMode HtPhy::GetHtMcs##x() \
532 static WifiMode mcs = CreateHtMcs(x); \
646 const auto dataRate =
GetDataRate(mcsValue, channelWidth, guardInterval, nss);
701 uint16_t usableSubCarriers,
702 uint16_t numberOfBitsPerSubcarrier,
708 numberOfBitsPerSubcarrier,
715 return (channelWidth == 40) ? 108 : 52;
736 switch (constellationSize)
749 NS_FATAL_ERROR(
"Trying to get reference rate for a MCS with wrong combination of "
750 "coding rate and modulation");
764 NS_FATAL_ERROR(
"Trying to get reference rate for a MCS with wrong combination of "
765 "coding rate and modulation");
779 NS_FATAL_ERROR(
"Trying to get reference rate for a MCS with wrong combination of "
780 "coding rate and modulation");
794 NS_FATAL_ERROR(
"Trying to get reference rate for a MCS with wrong combination of "
795 "coding rate and modulation");
825 if (delayUntilCcaEnd.IsStrictlyPositive())
827 return std::make_pair(
833 const MHz_u primaryWidth = 20;
834 const MHz_u p20MinFreq =
837 const MHz_u p20MaxFreq =
840 if (ppdu->DoesOverlapChannel(p20MinFreq, p20MaxFreq))
850 const MHz_u secondaryWidth = 20;
851 const MHz_u s20MinFreq =
853 (secondaryWidth / 2);
854 const MHz_u s20MaxFreq =
856 (secondaryWidth / 2);
857 if (!ppdu || ppdu->DoesOverlapChannel(s20MinFreq, s20MaxFreq))
861 if (delayUntilCcaEnd.IsStrictlyPositive())
Constructor class for HT modes.
static uint64_t CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
Return the PHY rate corresponding to the supplied code rate and data rate.
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...
static uint16_t GetConstellationSize(uint8_t mcsValue)
Return the constellation size corresponding to the supplied HT MCS index between 0 and 7,...
uint8_t m_bssMembershipSelector
the BSS membership selector
PhyFieldRxStatus DoEndReceiveField(WifiPpduField field, Ptr< Event > event) override
End receiving a given field, perform amendment-specific actions, and provide the status of the recept...
Ptr< SpectrumValue > GetTxPowerSpectralDensity(Watt_u txPower, Ptr< const WifiPpdu > ppdu) const override
~HtPhy() override
Destructor for HT PHY.
static WifiMode GetLSigMode()
static uint16_t GetHtConstellationSize(uint8_t mcsValue)
Return the constellation size corresponding to the supplied HT MCS index.
uint8_t m_maxMcsIndexPerSs
the maximum MCS index per spatial stream as defined by the standard
bool IsAllConfigSupported(WifiPpduField field, Ptr< const WifiPpdu > ppdu) const override
Checks if the signaled configuration (including bandwidth) is supported by the PHY.
HtPhy(uint8_t maxNss=1, bool buildModeList=true)
Constructor for HT PHY.
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
static void InitializeModes()
Initialize all HT modes.
static WifiCodeRate GetHtCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index.
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...
virtual Time GetTrainingDuration(const WifiTxVector &txVector, uint8_t nDataLtf, uint8_t nExtensionLtf=0) const
bool IsMcsSupported(uint8_t index) const override
Check if the WifiMode corresponding to the given MCS index is supported.
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...
Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype, bool incFlag, uint32_t &totalAmpduSize, double &totalAmpduNumSymbols, uint16_t staId) const override
uint8_t GetBssMembershipSelector() const
static bool IsAllowed(const WifiTxVector &txVector)
Check whether the combination in TXVECTOR is allowed.
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
WifiMode GetMcs(uint8_t index) const override
Get the WifiMode corresponding to the given MCS index.
virtual uint8_t GetNumberBccEncoders(const WifiTxVector &txVector) const
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.
virtual Time GetLSigDuration(WifiPreamble preamble) const
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,...
void SetMaxSupportedMcsIndexPerSs(uint8_t maxIndex)
Set the maximum supported MCS index per spatial stream.
static WifiMode GetHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
static WifiMode CreateHtMcs(uint8_t index)
Return the HT MCS corresponding to the provided index.
uint32_t GetMaxPsduSize() const override
Get the maximum PSDU size in bytes.
static WifiCodeRate GetCodeRate(uint8_t mcsValue)
Return the coding rate corresponding to the supplied HT MCS index between 0 and 7,...
virtual WifiMode GetHtSigMode() const
WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const override
Get the WifiMode for the SIG field specified by the PPDU field.
static uint64_t CalculateDataRate(Time symbolDuration, uint16_t usableSubCarriers, uint16_t numberOfBitsPerSubcarrier, double codingRate, uint8_t nss)
Calculates data rate from the supplied parameters.
uint8_t GetMaxSupportedMcsIndexPerSs() const
Set the maximum supported MCS index per spatial stream.
bool IsConfigSupported(Ptr< const WifiPpdu > ppdu) const override
Checks if the signaled configuration (excluding bandwidth) is supported by the PHY.
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
uint8_t m_maxSupportedNss
Maximum supported number of spatial streams (used to build HT MCS indices)
virtual void BuildModeList()
Build mode list.
static double GetCodeRatio(WifiCodeRate codeRate)
Convert WifiCodeRate to a ratio, e.g., code ratio of WIFI_CODE_RATE_1_2 is 0.5.
bool HandlesMcsModes() const override
Check if the WifiModes handled by this PHY are MCSs.
static const PpduFormats m_htPpduFormats
HT PPDU formats.
void SetMaxSupportedNss(uint8_t maxNss)
Configure the maximum number of spatial streams supported by this HT PHY.
PhyFieldRxStatus EndReceiveHtSig(Ptr< Event > event)
End receiving the HT-SIG, perform HT-specific actions, and provide the status of the reception.
virtual Time GetHtSigDuration() const
uint8_t m_maxSupportedMcsIndexPerSs
the maximum supported MCS index per spatial stream
const PpduFormats & GetPpduFormats() const override
Return the PPDU formats of the PHY.
virtual Time GetSymbolDuration(const WifiTxVector &txVector) const
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,...
PHY entity for OFDM (11a)
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.
uint8_t GetNumberServiceBits() const
virtual bool IsAllConfigSupported(WifiPpduField field, Ptr< const WifiPpdu > ppdu) const
Checks if the signaled configuration (including bandwidth) is supported by the PHY.
static uint16_t GetUsableSubcarriers()
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...
PhyFieldRxStatus DoEndReceiveField(WifiPpduField field, Ptr< Event > event) override
End receiving a given field, perform amendment-specific actions, and provide the status of the recept...
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, MHz_u channelWidth)
Calculates data rate from the supplied parameters.
WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const override
Get the WifiMode for the SIG field specified by the PPDU field.
static double GetCodeRatio(WifiCodeRate codeRate)
Convert WifiCodeRate to a ratio, e.g., code ratio of WIFI_CODE_RATE_1_2 is 0.5.
Time GetSignalExtension(WifiPhyBand band) const
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.
std::optional< std::pair< Time, WifiChannelListType > > CcaIndication
CCA end time and its corresponding channel list type (can be std::nullopt if IDLE)
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
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.
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
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
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.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetFemtoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
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)
represent a single transmission mode
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
uint8_t GetMcsValue() const
uint8_t GetMaxSupportedRxSpatialStreams() const
static void AddStaticPhyEntity(WifiModulationClass modulation, Ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of implemented PHY entities for the given modulation class.
MHz_u GetChannelWidth() const
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
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 > ¢erFrequencies, MHz_u channelWidth, Watt_u txPower, MHz_u guardBandwidth, dBr_u minInnerBand=-20, dBr_u minOuterband=-28, dBr_u lowestPoint=-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
#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_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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 FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_CHANLIST_SECONDARY
@ WIFI_PPDU_FIELD_TRAINING
STF + LTF fields (excluding those in preamble for HT-GF)
@ WIFI_PPDU_FIELD_NON_HT_HEADER
PHY header field for DSSS or ERP, short PHY header field for HR/DSSS or ERP, field not present for HT...
@ WIFI_PPDU_FIELD_HT_SIG
HT-SIG field.
@ WIFI_PPDU_FIELD_PREAMBLE
SYNC + SFD fields for DSSS or ERP, shortSYNC + shortSFD fields for HR/DSSS or ERP,...
@ WIFI_PPDU_FIELD_DATA
data field
@ LAST_MPDU_IN_AGGREGATE
The MPDU is the last aggregate in an A-MPDU with multiple MPDUs.
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
@ FIRST_MPDU_IN_AGGREGATE
The MPDU is the first aggregate in an A-MPDU with multiple MPDUs, but is not the last aggregate.
@ SINGLE_MPDU
The MPDU is a single MPDU.
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
Declaration of ns3::HtPhy class.
#define HT_PHY
This defines the BSS membership value for HT PHY.
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.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
constexpr uint8_t HT_MAX_NSS
Maximum number of supported NSS by HT PHY.
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.
WifiPhyRxfailureReason reason
failure reason
PhyRxFailureAction actionIfFailure
action to perform in case of failure
bool isSuccess
outcome (true if success) of the reception
A struct for both SNR and PER.
double snr
SNR in linear scale.