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 index = 1; index <= nRus; index++)
188 bool primary80 = (channelWidth < 160 || index <= nRus / 2);
195 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
220 NS_LOG_DEBUG (
"Run-time change of spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
276 Time rxDuration = rxParams->duration;
278 NS_LOG_DEBUG (
"Received signal with PSD " << *receivedSignalPsd <<
" and duration " << rxDuration.
As (
Time::NS));
279 uint32_t senderNodeId = 0;
282 senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
284 NS_LOG_DEBUG (
"Received signal from " << senderNodeId <<
" with unfiltered power " <<
WToDbm (
Integral (*receivedSignalPsd)) <<
" dBm");
291 double totalRxPowerW = 0;
294 if ((channelWidth == 5) || (channelWidth == 10))
298 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
299 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " <<
Integral (filteredSignal));
301 totalRxPowerW += rxPowerPerBandW;
302 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
303 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
306 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
308 for (uint8_t i = 0; i < (channelWidth / bw); i++)
313 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
314 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for" << bw <<
" MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
316 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
317 NS_LOG_DEBUG (
"Signal power received after antenna gain for" << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
322 for (uint8_t i = 0; i < (channelWidth / 20); i++)
326 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
327 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for 20 MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
329 totalRxPowerW += rxPowerPerBandW;
330 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
331 NS_LOG_DEBUG (
"Signal power received after antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
337 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
340 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
341 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for RU with type " << bandRuPair.second.ruType <<
" and index " << bandRuPair.second.index <<
" -> (" << bandRuPair.first.first <<
"; " << bandRuPair.first.second <<
"): " <<
Integral (filteredSignal));
343 NS_LOG_DEBUG (
"Signal power received after antenna gain for RU with type " << bandRuPair.second.ruType <<
" and index " << bandRuPair.second.index <<
" -> (" << bandRuPair.first.first <<
"; " << bandRuPair.first.second <<
"): " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
344 rxPowerW.insert ({bandRuPair.first, rxPowerPerBandW});
348 NS_LOG_DEBUG (
"Total signal power received after antenna gain: " << totalRxPowerW <<
" W (" <<
WToDbm (totalRxPowerW) <<
" dBm)");
353 m_signalCb (wifiRxParams ?
true :
false, senderNodeId,
WToDbm (totalRxPowerW), rxDuration);
359 NS_LOG_INFO (
"Received signal too weak to process: " <<
WToDbm (totalRxPowerW) <<
" dBm");
362 if (wifiRxParams == 0)
371 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
378 if (wifiRxParams->txPhy != 0)
384 uint16_t txChannelWidth = wifiRxParams->ppdu->GetTxVector ().GetChannelWidth ();
387 if (!
GetPhyEntity (wifiRxParams->ppdu->GetModulation ())->CanReceivePpdu (wifiRxParams->ppdu, txCenterFreq))
389 NS_LOG_INFO (
"Cannot receive the PPDU, consider it as interference");
391 rxDuration, rxPowerW);
447 uint32_t bandBandwidth = 0;
456 bandBandwidth = 312500;
462 bandBandwidth = 78125;
467 bandBandwidth = 156250;
472 bandBandwidth = 78125;
478 return bandBandwidth;
484 uint16_t guardBandwidth = 0;
485 if (currentChannelWidth == 22)
498 guardBandwidth = currentChannelWidth;
500 return guardBandwidth;
508 size_t numBandsInChannel =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
509 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 / bandBandwidth);
510 if (numBandsInBand % 2 == 0)
512 numBandsInChannel += 1;
515 NS_ASSERT_MSG ((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
"Should have odd number of bands");
516 NS_ASSERT_MSG ((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
518 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
519 if (band.first >= totalNumBands / 2)
524 band.second = band.first + numBandsInBand - 1;
533 uint32_t nGuardBands =
static_cast<uint32_t
> (((2 * guardBandwidth * 1e6) /
GetBandBandwidth ()) + 0.5);
534 uint32_t centerFrequencyIndex = 0;
538 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
541 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
544 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
547 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
554 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 /
GetBandBandwidth ());
555 centerFrequencyIndex += numBandsInBand * bandIndex;
557 convertedSubcarriers.first = centerFrequencyIndex + range.first;
558 convertedSubcarriers.second = centerFrequencyIndex + range.second;
559 return convertedSubcarriers;
562 std::tuple<double, double, double>
ERP-OFDM PHY (Clause 19, Section 19.5)
size_t GetNumBands() const
WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex=0) override
Get the start band index and the stop band index for a given band.
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...
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
virtual void DoInitialize(void)
Initialize() implementation.
Simulation virtual time values and global simulation resolution.
TracedCallback< bool, uint32_t, double, Time > m_signalCb
Signal callback.
std::vector< SubcarrierRange > SubcarrierGroup
a vector of subcarrier ranges defining a subcarrier group
Ptr< PhyEntity > GetPhyEntity(WifiModulationClass modulation) const
Get the supported PHY entity corresponding to the modulation class, for the WifiPhy instance...
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Abstract base class for Spectrum-aware PHY layers.
AttributeValue implementation for Boolean.
double GetRxGain(void) const
Return the reception gain (dB).
double Integral(const SpectrumValue &arg)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void RemoveBands(void)
Remove the frequency bands.
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
Ptr< const SpectrumModel > GetRxSpectrumModel()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band)
Configure the PHY-level parameters for different Wi-Fi standard.
virtual void DoDispose(void)
Destructor implementation.
void DoDispose(void) override
Destructor implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
bool IsInitialized(void) const
Check if the object has been initialized.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static TypeId GetTypeId(void)
Get the type ID.
bool m_disableWifiReception
forces this PHY to fail to sync on any signal
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint16_t GetPrimaryChannelCenterFrequency(uint16_t primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
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...
void StartTx(Ptr< WifiPpdu > ppdu) override
void SetAntenna(const Ptr< AntennaModel > antenna)
std::pair< int16_t, int16_t > SubcarrierRange
(lowest index, highest index) pair defining a subcarrier range
double GetRxSensitivity(void) const
Return the receive sensitivity threshold (dBm).
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
uint16_t GetChannelWidth(void) const
void SwitchMaybeToCcaBusy(uint16_t channelWidth)
Check if PHY state should move to CCA busy state based on current state of interference tracker...
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 Transmit(Ptr< WifiSpectrumSignalParameters > txParams)
This function is sending the signal to the Spectrum channel after finishing the configuration of the ...
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
make Callback use a separate empty type
double m_txMaskOuterBandMaximumRejection
The maximum rejection (in dBr) for the outer band of the transmit spectrum mask.
double m_txMaskOuterBandMinimumRejection
The minimum rejection (in dBr) for the outer band of the transmit spectrum mask.
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...
uint16_t GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const
Return the channel width used to measure the RSSI.
OFDM PHY (Clause 17 - amendment for 10 MHz and 5 MHz channels)
void DoInitialize(void) override
Initialize() implementation.
std::pair< uint32_t, uint32_t > WifiSpectrumBand
typedef for a pair of start and stop sub-band indexes
802.11 PHY layer modelThis PHY implements a spectrum-aware enhancement of the 802.11 SpectrumWifiPhy model.
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.
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
WifiPhyStandard GetPhyStandard(void) const
Get the configured Wi-Fi standard.
Ptr< WifiPhy > GetPhy(void) const
virtual uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t GetFrequency(void) const
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
RuType
The different HE Resource Unit (RU) types.
uint32_t GetBandBandwidth(void) const
virtual void SetChannelNumber(uint8_t id)
Set channel number.
static SubcarrierGroup GetSubcarrierGroup(uint16_t bw, RuType ruType, std::size_t index)
Get the subcarrier group of the RU having the given index among all the RUs of the given type (number...
double WToDbm(double w)
Convert from Watts to dBm.
double DbToRatio(double dB)
Convert from dB to ratio.
std::tuple< double, double, double > GetTxMaskRejectionParams(void) const override
Ptr< Channel > GetChannel(void) const override
Return the Channel this WifiPhy is connected to.
#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 AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void AddBand(WifiSpectrumBand band)
Add a frequency band.
WifiPhyBand
Identifies the PHY band.
void UpdateInterferenceHelperBands(void)
This function is called to update the bands handled by the InterferenceHelper.
virtual 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...
void AddForeignSignal(Time duration, RxPowerWattPerChannelBand rxPower)
Add a non-Wifi signal to interference helper.
Ptr< AntennaModel > GetRxAntenna(void) const
Get the antenna model used for reception.
InterferenceHelper m_interference
the class handling interference computations
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...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< AntennaModel > m_antenna
antenna model
virtual void SetChannelNumber(uint8_t id) override
Set channel number.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
Spectrum PHY interface.
void ResetSpectrumModel(void)
Perform run-time spectrum model change.
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
double m_txMaskInnerBandMinimumRejection
The minimum rejection (in dBr) for the inner band of the transmit spectrum mask.
virtual ~SpectrumWifiPhy()
WifiSpectrumBand ConvertHeRuSubcarriers(uint16_t bandWidth, uint16_t guardBandwidth, HeRu::SubcarrierRange range, uint8_t bandIndex=0) const override
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Set of values corresponding to a given SpectrumModel.
virtual 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...
a unique identifier for an interface.
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band) override
Configure the PHY-level parameters for different Wi-Fi standard.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...