15#include "ns3/interference-helper.h"
17#include "ns3/simulator.h"
18#include "ns3/wifi-phy.h"
19#include "ns3/wifi-psdu.h"
20#include "ns3/wifi-utils.h"
24#undef NS_LOG_APPEND_CONTEXT
25#define NS_LOG_APPEND_CONTEXT WIFI_PHY_NS_LOG_APPEND_CONTEXT(m_wifiPhy)
75 { 6000000, 9000000, 12000000, 18000000,
76 24000000, 36000000, 48000000, 54000000 }},
78 { 3000000, 4500000, 6000000, 9000000,
79 12000000, 18000000, 24000000, 27000000 }},
81 { 1500000, 2250000, 3000000, 4500000,
82 6000000, 9000000, 12000000, 13500000 }},
92const std::map<MHz_u, std::array<uint64_t, 8>>&
109 for (
const auto& rate : bwRatesMap.at(20))
117 for (
const auto& rate : bwRatesMap.at(10))
125 for (
const auto& rate : bwRatesMap.at(5))
258 double numDataBitsPerSymbol =
266 Time payloadDuration =
269 return payloadDuration;
291 psdus.begin()->second,
326 NS_LOG_DEBUG(
"Abort reception because non-HT PHY header reception failed");
336 const auto channelWidth = ppdu->GetTxVector().GetChannelWidth();
339 NS_LOG_DEBUG(
"Packet reception could not be started because not enough channel width ("
359 const auto& centerFrequencies = ppdu->GetTxCenterFreqs();
360 const auto& txVector = ppdu->GetTxVector();
361 const auto channelWidth = txVector.GetChannelWidth();
362 NS_LOG_FUNCTION(
this << centerFrequencies.front() << channelWidth << txPower);
365 if (txVector.IsNonHtDuplicate())
372 std::get<0>(txMaskRejectionParams),
373 std::get<1>(txMaskRejectionParams),
374 std::get<2>(txMaskRejectionParams));
378 NS_ASSERT(centerFrequencies.size() == 1);
380 centerFrequencies.front(),
384 std::get<0>(txMaskRejectionParams),
385 std::get<1>(txMaskRejectionParams),
386 std::get<2>(txMaskRejectionParams));
396 for (
const auto& rate : ratesPerBw.second)
406 switch (
static_cast<uint16_t
>(bw))
428 NS_ABORT_MSG(
"Inexistent rate (" << rate <<
" bps) requested for 11a OFDM (default)");
452 NS_ABORT_MSG(
"Inexistent rate (" << rate <<
" bps) requested for 11a OFDM (10 MHz)");
476 NS_ABORT_MSG(
"Inexistent rate (" << rate <<
" bps) requested for 11a OFDM (5 MHz)");
481 NS_ABORT_MSG(
"Inexistent bandwidth (" << +bw <<
" MHz) requested for 11a OFDM");
486#define GET_OFDM_MODE(x, f) \
487 WifiMode OfdmPhy::Get##x() \
489 static WifiMode mode = CreateOfdmMode(#x, f); \
528 "OFDM mode cannot be created because it is not in the lookup table!");
556 uint64_t dataRate =
GetDataRate(name, channelWidth);
585 NS_FATAL_ERROR(
"trying to get code ratio for undefined coding rate");
609 static_cast<uint16_t
>(log2(constellationSize)),
615 uint16_t usableSubCarriers,
616 uint16_t numberOfBitsPerSubcarrier,
619 double symbolRate = (1e9 /
static_cast<double>(symbolDuration.
GetNanoSeconds()));
620 return lrint(ceil(symbolRate * usableSubCarriers * numberOfBitsPerSubcarrier * codingRate));
633 uint8_t bwFactor = 1;
634 if (channelWidth == 10)
638 else if (channelWidth == 5)
642 return bwFactor * symbolDuration;
670 if (ppdu && ppdu->GetTxVector().GetChannelWidth() < 20)
675 return WToDbm(thresholdW);
683 const auto txWidth = ppdu->GetTxChannelWidth();
684 const auto& txVector = ppdu->GetTxVector();
690 auto rxPpdu = ppdu->Copy();
691 auto updatedTxVector = txVector;
693 rxPpdu->UpdateTxVector(updatedTxVector);
Constructor class for OFDM modes.
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6 Mbps.
uint32_t GetMaxPsduSize() const override
Get the maximum PSDU size in bytes.
~OfdmPhy() override
Destructor for OFDM PHY.
static WifiMode GetOfdmRate(uint64_t rate, MHz_u bw=20)
Return a WifiMode for OFDM corresponding to the provided rate and the channel bandwidth (20,...
static WifiMode GetOfdmRate13_5MbpsBW5MHz()
Return a WifiMode for OFDM at 13.5 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate48Mbps()
Return a WifiMode for OFDM at 48 Mbps.
dBm_u GetCcaThreshold(const Ptr< const WifiPpdu > ppdu, WifiChannelListType channelType) const override
Return the CCA threshold for a given channel type.
static const PpduFormats m_ofdmPpduFormats
OFDM PPDU formats.
static uint16_t GetConstellationSize(const std::string &name)
Return the constellation size from the OFDM mode's unique name using ModulationLookupTable.
static WifiMode GetOfdmRate54Mbps()
Return a WifiMode for OFDM at 54 Mbps.
uint8_t GetNumberServiceBits() const
static WifiCodeRate GetCodeRate(const std::string &name)
Return the WifiCodeRate from the OFDM mode's unique name using ModulationLookupTable.
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
static WifiMode GetOfdmRate36Mbps()
Return a WifiMode for OFDM at 36 Mbps.
static WifiMode GetOfdmRate3MbpsBW10MHz()
Return a WifiMode for OFDM at 3 Mbps with 10 MHz channel spacing.
static void InitializeModes()
Initialize all OFDM modes (for all variants).
virtual bool IsAllConfigSupported(WifiPpduField field, Ptr< const WifiPpdu > ppdu) const
Checks if the signaled configuration (including bandwidth) is supported by the PHY.
PhyFieldRxStatus EndReceiveHeader(Ptr< Event > event)
End receiving the header, perform OFDM-specific actions, and provide the status of the reception.
static WifiMode GetOfdmRate2_25MbpsBW5MHz()
Return a WifiMode for OFDM at 2.25 Mbps with 5 MHz channel spacing.
const PpduFormats & GetPpduFormats() const override
Return the PPDU formats of the PHY.
static uint64_t GetDataRate(const std::string &name, MHz_u channelWidth)
Return the data rate from the OFDM mode's unique name and the supplied parameters.
static bool IsAllowed(const WifiTxVector &txVector)
Check whether the combination in TXVECTOR is allowed.
static WifiMode GetOfdmRate6MbpsBW5MHz()
Return a WifiMode for OFDM at 6 Mbps with 5 MHz channel spacing.
OfdmPhy(OfdmPhyVariant variant=OFDM_PHY_DEFAULT, bool buildModeList=true)
Constructor for OFDM PHY.
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
static WifiMode GetOfdmRate1_5MbpsBW5MHz()
Return a WifiMode for OFDM at 1.5 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate18MbpsBW10MHz()
Return a WifiMode for OFDM at 18 Mbps with 10 MHz channel spacing.
static Time GetSymbolDuration(MHz_u channelWidth)
static WifiMode GetOfdmRate12MbpsBW10MHz()
Return a WifiMode for OFDM at 12 Mbps with 10 MHz channel spacing.
static uint16_t GetUsableSubcarriers()
static WifiMode GetOfdmRate9MbpsBW10MHz()
Return a WifiMode for OFDM at 9 Mbps with 10 MHz channel spacing.
static WifiMode GetOfdmRate4_5MbpsBW5MHz()
Return a WifiMode for OFDM at 4.5 Mbps with 5 MHz channel spacing.
static WifiMode GetOfdmRate3MbpsBW5MHz()
Return a WifiMode for OFDM at 3 Mbps with 5 MHz channel spacing.
virtual Time GetPreambleDuration(const WifiTxVector &txVector) const
Ptr< const WifiPpdu > GetRxPpduFromTxPpdu(Ptr< const WifiPpdu > ppdu) override
The WifiPpdu from the TX PHY is received by each RX PHY attached to the same channel.
static WifiMode GetOfdmRate27MbpsBW10MHz()
Return a WifiMode for OFDM at 27 Mbps with 10 MHz channel spacing.
Ptr< SpectrumValue > GetTxPowerSpectralDensity(Watt_u txPower, Ptr< const WifiPpdu > ppdu) const override
static WifiMode GetOfdmRate9MbpsBW5MHz()
Return a WifiMode for OFDM at 9 Mbps with 5 MHz channel spacing.
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
static WifiMode GetOfdmRate12Mbps()
Return a WifiMode for OFDM at 12Mbps.
static WifiMode CreateOfdmMode(std::string uniqueName, bool isMandatory)
Create an OFDM mode from a unique name, the unique name must already be contained inside ModulationLo...
static WifiMode GetOfdmRate24MbpsBW10MHz()
Return a WifiMode for OFDM at 24 Mbps with 10 MHz channel spacing.
static WifiMode GetOfdmRate18Mbps()
Return a WifiMode for OFDM at 18 Mbps.
static uint64_t CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
Calculate the PHY rate in bps from code rate and data rate.
static WifiMode GetOfdmRate6MbpsBW10MHz()
Return a WifiMode for OFDM at 6 Mbps with 10 MHz channel spacing.
MHz_u GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const override
Return the channel width used to measure the RSSI.
static WifiMode GetOfdmRate24Mbps()
Return a WifiMode for OFDM at 24 Mbps.
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.
virtual Time GetHeaderDuration(const WifiTxVector &txVector) const
virtual WifiMode GetHeaderMode(const WifiTxVector &txVector) const
WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const override
Get the WifiMode for the SIG field specified by the PPDU field.
static WifiMode GetOfdmRate12MbpsBW5MHz()
Return a WifiMode for OFDM at 12 Mbps with 5 MHz channel spacing.
static uint64_t GetPhyRate(const std::string &name, MHz_u channelWidth)
Return the PHY rate from the OFDM mode's unique name and the supplied parameters.
static const ModulationLookupTable m_ofdmModulationLookupTable
lookup table to retrieve code rate and constellation size corresponding to a unique name of modulatio...
static WifiMode GetOfdmRate4_5MbpsBW10MHz()
Return a WifiMode for OFDM at 4.5 Mbps with 10 MHz channel spacing.
static WifiMode GetOfdmRate9Mbps()
Return a WifiMode for OFDM at 9 Mbps.
virtual bool IsChannelWidthSupported(Ptr< const WifiPpdu > ppdu) const
Checks if the PPDU's bandwidth is supported by the PHY.
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
Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype, bool incFlag, uint32_t &totalAmpduSize, double &totalAmpduNumSymbols, uint16_t staId) const override
MHz_u GetGuardBandwidth(MHz_u currentChannelWidth) const
virtual Time GetDuration(WifiPpduField field, const WifiTxVector &txVector) const
Get the duration of the PPDU field (or group of fields) used by this entity for the given transmissio...
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
virtual MHz_u GetRxChannelWidth(const WifiTxVector &txVector) const
Return the channel width used in the reception spectrum model.
std::map< WifiPreamble, std::vector< WifiPpduField > > PpduFormats
A map of PPDU field elements per preamble type.
virtual WifiMode GetSigMode(WifiPpduField field, const WifiTxVector &txVector) const
Get the WifiMode for the SIG field specified by the PPDU field.
virtual dBm_u GetCcaThreshold(const Ptr< const WifiPpdu > ppdu, WifiChannelListType channelType) const
Return the CCA threshold for a given channel type.
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.
virtual Ptr< const WifiPpdu > GetRxPpduFromTxPpdu(Ptr< const WifiPpdu > ppdu)
The WifiPpdu from the TX PHY is received by each RX PHY attached to the same channel.
std::tuple< dBr_u, dBr_u, dBr_u > GetTxMaskRejectionParams() const
virtual bool IsConfigSupported(Ptr< const WifiPpdu > ppdu) const
Checks if the signaled configuration (excluding bandwidth) is supported by the PHY.
@ DROP
drop PPDU and set CCA_BUSY
@ ABORT
abort reception of PPDU
virtual PhyFieldRxStatus DoEndReceiveField(WifiPpduField field, Ptr< Event > event)
End receiving a given field, perform amendment-specific actions, and provide the status of the recept...
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 CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, AllowedCallback isAllowedCallback)
represent a single transmission mode
const std::string & GetUniqueName() const
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) 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.
Ptr< PhyEntity > GetLatestPhyEntity() const
Get the latest PHY entity supported by this PHY instance.
dBm_u GetCcaSensitivityThreshold() const
Return the CCA sensitivity threshold.
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(MHz_u centerFrequency, 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 (802.11a/g).
static Ptr< SpectrumValue > CreateDuplicated20MhzTxPowerSpectralDensity(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, const std::vector< bool > &puncturedSubchannels={})
Create a transmit power spectral density corresponding to OFDM duplicated over multiple 20 MHz subcha...
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.
MHz_u GetChannelWidth() 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_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 FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
WifiPhyBand
Identifies the PHY band.
OfdmPhyVariant
The OFDM (11a) PHY variants.
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
WifiPpduField
The type of PPDU field (grouped for convenience)
MpduType
The type of an MPDU.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ 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_PREAMBLE
SYNC + SFD fields for DSSS or ERP, shortSYNC + shortSFD fields for HR/DSSS or ERP,...
@ WIFI_PPDU_FIELD_DATA
data field
class anonymous_namespace{ofdm-phy.cc}::ConstructorOfdm g_constructor_ofdm
the constructor for OFDM 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.
const std::map< MHz_u, std::array< uint64_t, 8 > > & GetOfdmRatesBpsList()
Get the array of possible OFDM rates for each bandwidth.
dBm_u WToDbm(Watt_u val)
Convert from Watts to dBm.
double MHz_u
MHz weak type.
double dBm_u
dBm weak type
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
const std::map< MHz_u, std::array< uint64_t, 8 > > s_ofdmRatesBpsList
OFDM rates in bits per second for each bandwidth.
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
#define GET_OFDM_MODE(x, f)
Declaration of ns3::OfdmPhy class and ns3::OfdmPhyVariant enum.
Declaration of ns3::OfdmPpdu class.
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.