27 #include "ns3/double.h" 28 #include "ns3/boolean.h" 29 #include "ns3/net-device.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")
110 NS_FATAL_ERROR (
"SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at initialization time");
132 NS_LOG_DEBUG (
"Creating spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
146 if (channelWidth < 20)
153 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
155 for (uint8_t i = 0; i < (channelWidth / bw); ++i)
163 for (
unsigned int type = 0; type < 7; type++)
166 for (std::size_t index = 1; index <=
HeRu::GetNRus (channelWidth, ruType); index++)
195 NS_LOG_DEBUG (
"Run-time change of spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
251 Time rxDuration = rxParams->duration;
253 NS_LOG_DEBUG (
"Received signal with PSD " << *receivedSignalPsd <<
" and duration " << rxDuration.
As (
Time::NS));
254 uint32_t senderNodeId = 0;
257 senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
259 NS_LOG_DEBUG (
"Received signal from " << senderNodeId <<
" with unfiltered power " <<
WToDbm (
Integral (*receivedSignalPsd)) <<
" dBm");
266 double totalRxPowerW = 0;
269 if ((channelWidth == 5) || (channelWidth == 10))
273 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
274 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " <<
Integral (filteredSignal));
276 totalRxPowerW += rxPowerPerBandW;
277 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
278 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
281 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
283 for (uint8_t i = 0; i < (channelWidth / bw); i++)
288 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
289 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for" << bw <<
" MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
291 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
292 NS_LOG_DEBUG (
"Signal power received after antenna gain for" << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
297 for (uint8_t i = 0; i < (channelWidth / 20); i++)
301 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
302 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for 20 MHz channel band " << +i <<
": " <<
Integral (filteredSignal));
304 totalRxPowerW += rxPowerPerBandW;
305 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
306 NS_LOG_DEBUG (
"Signal power received after antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
311 for (
unsigned int type = 0; type < 7; type++)
314 for (std::size_t index = 1; index <=
HeRu::GetNRus (channelWidth, ruType); index++)
320 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
321 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for RU with type " << ruType <<
" and range (" << range.first <<
"; " << range.second <<
") -> (" << band.first <<
"; " << band.second <<
"): " <<
Integral (filteredSignal));
323 NS_LOG_DEBUG (
"Signal power received after antenna gain for RU with type " << ruType <<
" and range (" << range.first <<
"; " << range.second <<
") -> (" << band.first <<
"; " << band.second <<
"): " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
324 rxPowerW.insert ({band, rxPowerPerBandW});
329 NS_LOG_DEBUG (
"Total signal power received after antenna gain: " << totalRxPowerW <<
" W (" <<
WToDbm (totalRxPowerW) <<
" dBm)");
334 m_signalCb (wifiRxParams ?
true :
false, senderNodeId,
WToDbm (totalRxPowerW), rxDuration);
340 NS_LOG_INFO (
"Received signal too weak to process: " <<
WToDbm (totalRxPowerW) <<
" dBm");
343 if (wifiRxParams == 0)
352 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
390 switch (modulationClass)
399 NS_ABORT_MSG_IF (channelWidth != 22,
"Invalid channel width for DSSS");
422 uint16_t centerFrequencyForSupportedWidth =
GetFrequency ();
425 if (currentWidth != supportedWidth)
427 uint16_t startingFrequency = centerFrequencyForSupportedWidth - (supportedWidth / 2);
428 return startingFrequency + (currentWidth / 2);
430 return centerFrequencyForSupportedWidth;
439 NS_LOG_DEBUG (
"Start transmission: signal power before antenna gain=" << txPowerDbm <<
"dBm");
440 double txPowerWatts =
DbmToW (txPowerDbm);
443 txParams->duration = ppdu->GetTxDuration ();
444 txParams->psd = txPowerSpectrum;
448 txParams->ppdu = ppdu;
457 uint32_t bandBandwidth = 0;
467 bandBandwidth = 312500;
473 bandBandwidth = 78125;
478 bandBandwidth = 156250;
483 bandBandwidth = 78125;
489 return bandBandwidth;
495 uint16_t guardBandwidth = 0;
496 if (currentChannelWidth == 22)
509 guardBandwidth = currentChannelWidth;
511 return guardBandwidth;
519 size_t numBandsInChannel =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
520 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 / bandBandwidth);
521 if (numBandsInBand % 2 == 0)
523 numBandsInChannel += 1;
526 NS_ASSERT_MSG ((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
"Should have odd number of bands");
527 NS_ASSERT_MSG ((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
529 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
530 if (band.first >= totalNumBands / 2)
535 band.second = band.first + numBandsInBand - 1;
544 uint32_t centerFrequencyIndex = 0;
545 switch (channelWidth)
548 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
551 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
554 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
557 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
560 NS_FATAL_ERROR (
"ChannelWidth " << channelWidth <<
" unsupported");
563 convertedSubcarriers.first = centerFrequencyIndex + range.first;
564 convertedSubcarriers.second = centerFrequencyIndex + range.second;
565 return convertedSubcarriers;
ERP-OFDM PHY (Clause 19, Section 19.5)
size_t GetNumBands() const
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const
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
#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).
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
double Integral(const SpectrumValue &arg)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand rxPowersW)
Start receiving the PHY preamble of a PPDU (i.e.
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()
double DbmToW(double dBm)
Convert from dBm to Watts.
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.
#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.
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth, double minInnerBandDbr=-20, double minOuterbandDbr=-28, double lowestPointDbr=-40)
Create a transmit power spectral density corresponding to OFDM High Throughput (HT) (802...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static Ptr< SpectrumValue > CreateDsssTxPowerSpectralDensity(uint32_t centerFrequency, double txPowerW, uint16_t guardBandwidth)
Create a transmit power spectral density corresponding to DSSS.
void StartTx(Ptr< WifiPpdu > ppdu)
double GetTxPowerForTransmission(WifiTxVector txVector) const
Compute the transmit power (in dBm) for the next transmission.
virtual void SetFrequency(uint16_t freq)
void SetAntenna(const Ptr< AntennaModel > antenna)
virtual void SetChannelNumber(uint8_t id)
Set channel number.
SpectrumModelUid_t GetUid() const
void DoInitialize(void)
Initialize() implementation.
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.
WifiSpectrumBand ConvertHeRuSubcarriers(uint16_t channelWidth, HeRu::SubcarrierRange range) const
uint16_t GetChannelWidth(void) const
Ptr< SpectrumValue > GetTxPowerSpectralDensity(uint16_t centerFrequency, uint16_t channelWidth, double txPowerW, WifiModulationClass modulationClass) const
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex=0)
Get the start band index and the stop band index for a given band.
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.
OFDM PHY (Clause 17 - amendment for 10 MHz and 5 MHz channels)
void DoDispose(void)
Destructor 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.
static Ptr< SpectrumValue > CreateHeOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth, double minInnerBandDbr=-20, double minOuterbandDbr=-28, double lowestPointDbr=-40)
Create a transmit power spectral density corresponding to OFDM High Efficiency (HE) (802...
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
virtual void SetFrequency(uint16_t freq)
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.
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
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)
RuType
The different HE Resource Unit (RU) types.
uint32_t GetBandBandwidth(void) const
Ptr< const SpectrumModel > GetSpectrumModel() const
virtual void SetChannelNumber(uint8_t id)
Set channel number.
static SubcarrierGroup GetSubcarrierGroup(uint8_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...
virtual void DoInitialize(void)
Initialize() implementation.
double WToDbm(double w)
Convert from Watts to dBm.
uint8_t GetChannelNumber(void) const
Return current channel number.
double DbToRatio(double dB)
Convert from dB to ratio.
virtual void SetChannelWidth(uint16_t channelwidth)
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth, double minInnerBandDbr=-20, double minOuterbandDbr=-28, double lowestPointDbr=-40)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
#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.
WifiModulationClass
This enumeration defines the modulation classes per (Table 9-4 "Modulation classes"; IEEE 802...
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
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
Pointer to InterferenceHelper.
virtual void SetChannelWidth(uint16_t channelWidth)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< AntennaModel > m_antenna
antenna model
Ptr< const AttributeChecker > MakeBooleanChecker(void)
uint16_t GetCenterFrequencyForChannelWidth(WifiTxVector txVector) const
Get the center frequency of the channel corresponding the current TxVector rather than that of the su...
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
Spectrum PHY interface.
void ResetSpectrumModel(void)
Perform run-time spectrum model change.
double GetTxGain(void) const
Return the transmission gain (dB).
static std::size_t GetNRus(uint8_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 GetChannelWidth(void) const
double m_txMaskInnerBandMinimumRejection
The minimum rejection (in dBr) for the inner band of the transmit spectrum mask.
virtual ~SpectrumWifiPhy()
Ptr< Channel > GetChannel(void) const
Return the Channel this WifiPhy is connected to.
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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
void SwitchMaybeToCcaBusy(void)
Check if PHY state should move to CCA busy state based on current state of interference tracker...
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...