27 #include "ns3/double.h"
28 #include "ns3/boolean.h"
29 #include "ns3/wifi-net-device.h"
31 #include "ns3/simulator.h"
49 .SetGroupName (
"Wifi")
51 .AddAttribute (
"DisableWifiReception",
52 "Prevent Wi-Fi frame sync from ever happening",
56 .AddAttribute (
"TxMaskInnerBandMinimumRejection",
57 "Minimum rejection (dBr) for the inner band of the transmit spectrum mask",
60 MakeDoubleChecker<double> ())
61 .AddAttribute (
"TxMaskOuterBandMinimumRejection",
62 "Minimum rejection (dBr) for the outer band of the transmit spectrum mask",
65 MakeDoubleChecker<double> ())
66 .AddAttribute (
"TxMaskOuterBandMaximumRejection",
67 "Maximum rejection (dBr) for the outer band of the transmit spectrum mask",
70 MakeDoubleChecker<double> ())
71 .AddTraceSource (
"SignalArrival",
74 "ns3::SpectrumWifiPhy::SignalArrivalCallback")
113 NS_FATAL_ERROR (
"SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at initialization time");
135 NS_LOG_DEBUG (
"Creating spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
149 if (channelWidth < 20)
156 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
158 for (uint8_t i = 0; i < (channelWidth / bw); ++i)
174 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
176 for (uint8_t i = 0; i < (channelWidth / bw); ++i)
178 for (
unsigned int type = 0; type < 7; type++)
182 for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++)
188 std::size_t index = (bw == 160 && phyIndex > nRus / 2
189 ? phyIndex - nRus / 2 : phyIndex);
192 bool primary80 = (bw < 160
194 || (primary80IsLower80 && phyIndex <= nRus / 2)
195 || (!primary80IsLower80 && phyIndex > nRus / 2));
199 m_ruBands[channelWidth].insert ({band, ru});
205 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
230 NS_LOG_DEBUG (
"Run-time change of spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
286 Time rxDuration = rxParams->duration;
288 NS_LOG_DEBUG (
"Received signal with PSD " << *receivedSignalPsd <<
" and duration " << rxDuration.
As (
Time::NS));
289 uint32_t senderNodeId = 0;
292 senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
294 NS_LOG_DEBUG (
"Received signal from " << senderNodeId <<
" with unfiltered power " <<
WToDbm (
Integral (*receivedSignalPsd)) <<
" dBm");
301 double totalRxPowerW = 0;
304 if ((channelWidth == 5) || (channelWidth == 10))
308 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
309 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " <<
Integral (filteredSignal));
311 totalRxPowerW += rxPowerPerBandW;
312 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
313 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
316 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
318 for (uint8_t i = 0; i < (channelWidth / bw); i++)
323 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
324 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for " << bw <<
" MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
326 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
327 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
332 for (uint8_t i = 0; i < (channelWidth / 20); i++)
336 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
337 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for 20 MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
339 totalRxPowerW += rxPowerPerBandW;
340 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
341 NS_LOG_DEBUG (
"Signal power received after antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
347 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
350 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
351 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for RU with type " << bandRuPair.second.GetRuType () <<
" and index " << bandRuPair.second.GetIndex () <<
" -> (" << bandRuPair.first.first <<
"; " << bandRuPair.first.second <<
"): " <<
Integral (filteredSignal));
353 NS_LOG_DEBUG (
"Signal power received after antenna gain for RU with type " << bandRuPair.second.GetRuType () <<
" and index " << bandRuPair.second.GetIndex () <<
" -> (" << bandRuPair.first.first <<
"; " << bandRuPair.first.second <<
"): " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
354 rxPowerW.insert ({bandRuPair.first, rxPowerPerBandW});
358 NS_LOG_DEBUG (
"Total signal power received after antenna gain: " << totalRxPowerW <<
" W (" <<
WToDbm (totalRxPowerW) <<
" dBm)");
363 m_signalCb (wifiRxParams ?
true :
false, senderNodeId,
WToDbm (totalRxPowerW), rxDuration);
365 if (wifiRxParams == 0)
374 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
382 uint16_t txWidth = wifiRxParams->ppdu->GetTransmissionChannelWidth ();
385 NS_LOG_INFO (
"Received signal too weak to process: " <<
WToDbm (totalRxPowerW) <<
" dBm");
391 if (wifiRxParams->txPhy != 0)
397 uint16_t txChannelWidth = wifiRxParams->ppdu->GetTxVector ().GetChannelWidth ();
402 uint16_t p20MinFreq =
404 uint16_t p20MaxFreq =
407 if (!wifiRxParams->ppdu->CanBeReceived (txCenterFreq, p20MinFreq, p20MaxFreq))
409 NS_LOG_INFO (
"Cannot receive the PPDU, consider it as interference");
411 rxDuration, rxPowerW);
467 uint32_t bandBandwidth = 0;
476 bandBandwidth = 312500;
482 bandBandwidth = 78125;
487 bandBandwidth = 156250;
492 bandBandwidth = 78125;
498 return bandBandwidth;
504 uint16_t guardBandwidth = 0;
505 if (currentChannelWidth == 22)
518 guardBandwidth = currentChannelWidth;
520 return guardBandwidth;
528 size_t numBandsInChannel =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
529 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 / bandBandwidth);
530 if (numBandsInBand % 2 == 0)
532 numBandsInChannel += 1;
535 NS_ASSERT_MSG ((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
"Should have odd number of bands");
536 NS_ASSERT_MSG ((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
538 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
539 if (band.first >= totalNumBands / 2)
544 band.second = band.first + numBandsInBand - 1;
553 uint32_t nGuardBands =
static_cast<uint32_t
> (((2 * guardBandwidth * 1e6) /
GetBandBandwidth ()) + 0.5);
554 uint32_t centerFrequencyIndex = 0;
558 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
561 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
564 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
567 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
574 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 /
GetBandBandwidth ());
575 centerFrequencyIndex += numBandsInBand * bandIndex;
577 convertedSubcarriers.first = centerFrequencyIndex + range.first;
578 convertedSubcarriers.second = centerFrequencyIndex + range.second;
579 return convertedSubcarriers;
582 std::tuple<double, double, double>
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void SetPhyIndex(uint16_t bw, uint8_t p20Index)
Set the RU PHY index.
std::size_t GetPhyIndex(void) const
Get the RU PHY index.
static SubcarrierGroup GetSubcarrierGroup(uint16_t bw, RuType ruType, std::size_t phyIndex)
Get the subcarrier group of the RU having the given PHY index among all the RUs of the given type (nu...
static std::size_t GetNRus(uint16_t bw, RuType ruType)
Get the number of distinct RUs of the given type (number of tones) available in a HE PPDU of the give...
std::vector< SubcarrierRange > SubcarrierGroup
a vector of subcarrier ranges defining a subcarrier group
std::pair< int16_t, int16_t > SubcarrierRange
(lowest index, highest index) pair defining a subcarrier range
RuType
The different HE Resource Unit (RU) types.
Ptr< Event > Add(Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector, Time duration, RxPowerWattPerChannelBand rxPower, bool isStartOfdmaRxing=false)
Add the PPDU-related signal to interference helper.
void AddForeignSignal(Time duration, RxPowerWattPerChannelBand rxPower)
Add a non-Wifi signal to interference helper.
void RemoveBands(void)
Remove the frequency bands.
void AddBand(WifiSpectrumBand band)
Add a frequency band.
bool IsInitialized(void) const
Check if the object has been initialized.
virtual void DoInitialize(void)
Initialize() implementation.
size_t GetNumBands() const
Abstract base class for Spectrum-aware PHY layers.
Set of values corresponding to a given SpectrumModel.
void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band) override
Configure the PHY-level parameters for different Wi-Fi standard.
void SetChannelWidth(uint16_t channelwidth) override
If the operating channel for this object has not been set yet, the given channel width is saved and w...
TracedCallback< bool, uint32_t, double, Time > m_signalCb
Signal callback.
void Transmit(Ptr< WifiSpectrumSignalParameters > txParams)
This function is sending the signal to the Spectrum channel after finishing the configuration of the ...
uint32_t GetBandBandwidth(void) const
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
void StartTx(Ptr< WifiPpdu > ppdu) override
Ptr< AntennaModel > m_antenna
antenna model
std::map< uint16_t, RuBand > m_ruBands
For each channel width, store all the distinct spectrum bands associated with every RU in a channel o...
std::tuple< double, double, double > GetTxMaskRejectionParams(void) const override
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
void DoDispose(void) override
Destructor implementation.
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
Spectrum PHY interface.
double m_txMaskInnerBandMinimumRejection
The minimum rejection (in dBr) for the inner band of the transmit spectrum mask.
double m_txMaskOuterBandMinimumRejection
The minimum rejection (in dBr) for the outer band of the transmit spectrum mask.
Ptr< AntennaModel > GetRxAntenna(void) const
Get the antenna model used for reception.
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override
static TypeId GetTypeId(void)
Get the type ID.
void SetAntenna(const Ptr< AntennaModel > antenna)
double m_txMaskOuterBandMaximumRejection
The maximum rejection (in dBr) for the outer band of the transmit spectrum mask.
WifiSpectrumBand ConvertHeRuSubcarriers(uint16_t bandWidth, uint16_t guardBandwidth, HeRu::SubcarrierRange range, uint8_t bandIndex=0) const override
void SetChannelNumber(uint8_t id) override
Set channel number.
bool m_disableWifiReception
forces this PHY to fail to sync on any signal
Ptr< const SpectrumModel > GetRxSpectrumModel()
WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex=0) override
Get the start band index and the stop band index for a given band.
void ResetSpectrumModel(void)
Perform run-time spectrum model change.
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
virtual ~SpectrumWifiPhy()
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
void UpdateInterferenceHelperBands(void)
This function is called to update the bands handled by the InterferenceHelper.
void SetFrequency(uint16_t freq) override
If the operating channel for this object has not been set yet, the given center frequency is saved an...
Ptr< Channel > GetChannel(void) const override
Return the Channel this WifiPhy is connected to.
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...
void DoInitialize(void) override
Initialize() implementation.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< WifiPhy > GetPhy(void) const
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
virtual void SetChannelNumber(uint8_t id)
Set channel number.
virtual void DoDispose(void)
Destructor implementation.
uint16_t GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const
Return the channel width used to measure the RSSI.
InterferenceHelper m_interference
the class handling interference computations
WifiPhyStandard GetPhyStandard(void) const
Get the configured Wi-Fi standard.
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band)
Configure the PHY-level parameters for different Wi-Fi standard.
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
virtual void SetChannelWidth(uint16_t channelWidth)
If the operating channel for this object has not been set yet, the given channel width is saved and w...
Ptr< PhyEntity > GetPhyEntity(WifiModulationClass modulation) const
Get the supported PHY entity corresponding to the modulation class, for the WifiPhy instance.
void SwitchMaybeToCcaBusy(uint16_t channelWidth)
Check if PHY state should move to CCA busy state based on current state of interference tracker.
double GetRxGain(void) const
Return the reception gain (dB).
double GetRxSensitivity(void) const
Return the receive sensitivity threshold (dBm).
uint16_t GetChannelWidth(void) const
uint16_t GetFrequency(void) const
virtual void SetFrequency(uint16_t freq)
If the operating channel for this object has not been set yet, the given center frequency is saved an...
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...
uint16_t GetPrimaryChannelCenterFrequency(uint16_t primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth)
Return a SpectrumModel instance corresponding to the center frequency and channel width.
static Ptr< SpectrumValue > CreateRfFilter(uint32_t centerFrequency, uint16_t totalChannelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth, WifiSpectrumBand band)
Create a spectral density corresponding to the RF filter.
make Callback use a separate empty 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...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#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_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.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
WifiPhyBand
Identifies the PHY band.
@ WIFI_PHY_STANDARD_80211a
OFDM PHY (Clause 17)
@ WIFI_PHY_STANDARD_80211b
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
@ WIFI_PHY_STANDARD_80211ac
VHT PHY (clause 22)
@ WIFI_PHY_STANDARD_80211ax
HE PHY (clause 26)
@ WIFI_PHY_STANDARD_80211p
OFDM PHY (Clause 17 - amendment for 10 MHz and 5 MHz channels)
@ WIFI_PHY_STANDARD_80211g
ERP-OFDM PHY (Clause 19, Section 19.5)
@ WIFI_PHY_STANDARD_80211n
HT PHY (clause 20)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double WToDbm(double w)
Convert from Watts to dBm.
std::pair< uint32_t, uint32_t > WifiSpectrumBand
typedef for a pair of start and stop sub-band indexes
double Integral(const SpectrumValue &arg)
double DbmToW(double dBm)
Convert from dBm to Watts.
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
double DbToRatio(double dB)
Convert from dB to ratio.