|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " << rxPowerPerBandW);
310 totalRxPowerW += rxPowerPerBandW;
311 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
312 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
315 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
317 for (uint8_t i = 0; i < (channelWidth / bw); i++)
322 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for " << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW);
324 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
325 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
330 for (uint8_t i = 0; i < (channelWidth / 20); i++)
334 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW);
336 totalRxPowerW += rxPowerPerBandW;
337 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
338 NS_LOG_DEBUG (
"Signal power received after antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
344 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
347 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 <<
"): " << rxPowerPerBandW);
349 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)");
350 rxPowerW.insert ({bandRuPair.first, rxPowerPerBandW});
354 NS_LOG_DEBUG (
"Total signal power received after antenna gain: " << totalRxPowerW <<
" W (" <<
WToDbm (totalRxPowerW) <<
" dBm)");
359 m_signalCb (wifiRxParams ?
true :
false, senderNodeId,
WToDbm (totalRxPowerW), rxDuration);
361 if (wifiRxParams == 0)
370 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
378 uint16_t txWidth = wifiRxParams->ppdu->GetTransmissionChannelWidth ();
381 NS_LOG_INFO (
"Received signal too weak to process: " <<
WToDbm (totalRxPowerW) <<
" dBm");
382 m_interference.
Add (wifiRxParams->ppdu, wifiRxParams->ppdu->GetTxVector (), rxDuration,
390 if (wifiRxParams->txPhy != 0)
396 uint16_t txChannelWidth = wifiRxParams->ppdu->GetTxVector ().GetChannelWidth ();
401 uint16_t p20MinFreq =
403 uint16_t p20MaxFreq =
406 if (!wifiRxParams->ppdu->CanBeReceived (txCenterFreq, p20MinFreq, p20MaxFreq))
408 NS_LOG_INFO (
"Cannot receive the PPDU, consider it as interference");
410 rxDuration, rxPowerW);
466 uint32_t bandBandwidth = 0;
475 bandBandwidth = 312500;
481 bandBandwidth = 78125;
486 bandBandwidth = 156250;
491 bandBandwidth = 78125;
497 return bandBandwidth;
503 uint16_t guardBandwidth = 0;
504 if (currentChannelWidth == 22)
517 guardBandwidth = currentChannelWidth;
519 return guardBandwidth;
527 size_t numBandsInChannel =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
528 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 / bandBandwidth);
529 if (numBandsInBand % 2 == 0)
531 numBandsInChannel += 1;
534 NS_ASSERT_MSG ((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
"Should have odd number of bands");
535 NS_ASSERT_MSG ((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
537 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
538 if (band.first >= totalNumBands / 2)
543 band.second = band.first + numBandsInBand - 1;
552 uint32_t nGuardBands =
static_cast<uint32_t
> (((2 * guardBandwidth * 1e6) /
GetBandBandwidth ()) + 0.5);
553 uint32_t centerFrequencyIndex = 0;
557 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
560 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
563 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
566 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
573 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 /
GetBandBandwidth ());
574 centerFrequencyIndex += numBandsInBand * bandIndex;
576 convertedSubcarriers.first = centerFrequencyIndex + range.first;
577 convertedSubcarriers.second = centerFrequencyIndex + range.second;
578 return convertedSubcarriers;
581 std::tuple<double, double, double>
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< Channel > GetChannel(void) const override
Return the Channel this WifiPhy is connected to.
double Integral(const SpectrumValue &arg)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
AttributeValue implementation for Boolean.
std::pair< uint32_t, uint32_t > WifiSpectrumBand
typedef for a pair of start and stop sub-band indexes
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
void Transmit(Ptr< WifiSpectrumSignalParameters > txParams)
This function is sending the signal to the Spectrum channel after finishing the configuration of the ...
Ptr< WifiPhy > GetPhy(void) const
void SetChannelNumber(uint8_t id) override
Set channel number.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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::vector< SubcarrierRange > SubcarrierGroup
a vector of subcarrier ranges defining a subcarrier group
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.
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.
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
uint16_t GetFrequency(void) const
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
double WToDbm(double w)
Convert from Watts to dBm.
void DoInitialize(void) override
Initialize() implementation.
void AddForeignSignal(Time duration, RxPowerWattPerChannelBand &rxPower)
Add a non-Wifi signal to interference helper.
void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band) override
Configure the PHY-level parameters for different Wi-Fi standard.
void ResetSpectrumModel(void)
Perform run-time spectrum model change.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
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.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
std::size_t GetPhyIndex(void) const
Get the RU PHY index.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
InterferenceHelper m_interference
the class handling interference computations
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
double m_txMaskInnerBandMinimumRejection
The minimum rejection (in dBr) for the inner band of the transmit spectrum mask.
@ WIFI_PHY_STANDARD_80211ax
HE PHY (clause 26)
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...
@ WIFI_PHY_STANDARD_80211p
OFDM PHY (Clause 17 - amendment for 10 MHz and 5 MHz channels)
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...
Ptr< AntennaModel > m_antenna
antenna model
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...
WifiPhyStandard GetPhyStandard(void) const
Get the configured Wi-Fi standard.
double m_txMaskOuterBandMaximumRejection
The maximum rejection (in dBr) for the outer band of the transmit spectrum mask.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Abstract base class for Spectrum-aware PHY layers.
RuType
The different HE Resource Unit (RU) types.
@ WIFI_PHY_STANDARD_80211a
OFDM PHY (Clause 17)
std::tuple< double, double, double > GetTxMaskRejectionParams(void) const override
Ptr< const AttributeChecker > MakeBooleanChecker(void)
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...
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
@ WIFI_PHY_STANDARD_80211b
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
Simulation virtual time values and global simulation resolution.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual void DoInitialize(void)
Initialize() implementation.
void StartTx(Ptr< WifiPpdu > ppdu) override
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...
TracedCallback< bool, uint32_t, double, Time > m_signalCb
Signal callback.
void SetAntenna(const Ptr< AntennaModel > antenna)
size_t GetNumBands() const
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override
@ WIFI_PHY_STANDARD_80211n
HT PHY (clause 20)
@ WIFI_PHY_STANDARD_80211ac
VHT PHY (clause 22)
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand &rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
void SwitchMaybeToCcaBusy(uint16_t channelWidth)
Check if PHY state should move to CCA busy state based on current state of interference tracker.
void SetPhyIndex(uint16_t bw, uint8_t p20Index)
Set the RU PHY index.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
static TypeId GetTypeId(void)
Get the type ID.
double DbmToW(double dBm)
Convert from dBm to Watts.
void AddBand(WifiSpectrumBand band)
Add a frequency band.
uint16_t GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const
Return the channel width used to measure the RSSI.
double GetRxGain(void) const
Return the reception gain (dB).
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
double GetRxSensitivity(void) const
Return the receive sensitivity threshold (dBm).
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band)
Configure the PHY-level parameters for different Wi-Fi standard.
void DoDispose(void) override
Destructor implementation.
void UpdateInterferenceHelperBands(void)
This function is called to update the bands handled by the InterferenceHelper.
virtual void DoDispose(void)
Destructor implementation.
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.
uint16_t GetChannelWidth(void) const
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void RemoveBands(void)
Remove the frequency bands.
double DbToRatio(double dB)
Convert from dB to ratio.
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...
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...
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
uint32_t GetBandBandwidth(void) const
Ptr< const SpectrumModel > GetRxSpectrumModel()
WifiSpectrumBand ConvertHeRuSubcarriers(uint16_t bandWidth, uint16_t guardBandwidth, HeRu::SubcarrierRange range, uint8_t bandIndex=0) const override
WifiPhyBand
Identifies the PHY band.
std::pair< int16_t, int16_t > SubcarrierRange
(lowest index, highest index) pair defining a subcarrier range
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
Spectrum PHY interface.
virtual void SetChannelNumber(uint8_t id)
Set channel number.
virtual ~SpectrumWifiPhy()
static double GetBandPowerW(Ptr< SpectrumValue > psd, const WifiSpectrumBand &band)
Calculate the power of the specified band composed of uniformly-sized sub-bands.
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...
uint16_t GetPrimaryChannelCenterFrequency(uint16_t primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
@ WIFI_PHY_STANDARD_80211g
ERP-OFDM PHY (Clause 19, Section 19.5)
make Callback use a separate empty type
bool m_disableWifiReception
forces this PHY to fail to sync on any signal
bool IsInitialized(void) const
Check if the object has been initialized.