33#include "ns3/boolean.h"
34#include "ns3/double.h"
37#include "ns3/simulator.h"
38#include "ns3/wifi-net-device.h"
51 TypeId(
"ns3::SpectrumWifiPhy")
55 .AddAttribute(
"DisableWifiReception",
56 "Prevent Wi-Fi frame sync from ever happening",
61 "TxMaskInnerBandMinimumRejection",
62 "Minimum rejection (dBr) for the inner band of the transmit spectrum mask",
65 MakeDoubleChecker<double>())
67 "TxMaskOuterBandMinimumRejection",
68 "Minimum rejection (dBr) for the outer band of the transmit spectrum mask",
71 MakeDoubleChecker<double>())
73 "TxMaskOuterBandMaximumRejection",
74 "Maximum rejection (dBr) for the outer band of the transmit spectrum mask",
77 MakeDoubleChecker<double>())
78 .AddTraceSource(
"SignalArrival",
81 "ns3::SpectrumWifiPhy::SignalArrivalCallback");
119 NS_FATAL_ERROR(
"SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at "
120 "initialization time");
142 NS_LOG_DEBUG(
"Creating spectrum model from frequency/width pair of ("
161 if (channelWidth < 20)
168 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
170 for (
uint32_t i = 0; i < (channelWidth / bw); ++i)
186 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
188 for (
uint32_t i = 0; i < (channelWidth / bw); ++i)
194 for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++)
199 std::make_pair(group.front().first, group.back().second);
206 (bw == 160 && phyIndex > nRus / 2 ? phyIndex - nRus / 2 : phyIndex);
207 bool primary80IsLower80 =
210 (primary80IsLower80 && phyIndex <= nRus / 2) ||
211 (!primary80IsLower80 && phyIndex > nRus / 2));
215 m_ruBands[channelWidth].insert({band, ru});
221 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
246 NS_LOG_DEBUG(
"Run-time change of spectrum model from frequency/width pair of ("
275 NS_LOG_DEBUG(
"Received signal with PSD " << *receivedSignalPsd <<
" and duration "
282 NS_LOG_DEBUG(
"Received signal from " << senderNodeId <<
" with unfiltered power "
290 double totalRxPowerW = 0;
293 if ((channelWidth == 5) || (channelWidth == 10))
296 double rxPowerPerBandW =
298 NS_LOG_DEBUG(
"Signal power received (watts) before antenna gain: " << rxPowerPerBandW);
300 totalRxPowerW += rxPowerPerBandW;
301 rxPowerW.insert({filteredBand, rxPowerPerBandW});
302 NS_LOG_DEBUG(
"Signal power received after antenna gain for "
303 << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W ("
304 <<
WToDbm(rxPowerPerBandW) <<
" dBm)");
308 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
310 for (
uint32_t i = 0; i < (channelWidth / bw); i++)
314 double rxPowerPerBandW =
316 NS_LOG_DEBUG(
"Signal power received (watts) before antenna gain for "
317 << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW);
319 rxPowerW.insert({filteredBand, rxPowerPerBandW});
320 NS_LOG_DEBUG(
"Signal power received after antenna gain for "
321 << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W ("
322 <<
WToDbm(rxPowerPerBandW) <<
" dBm)");
326 for (
uint32_t i = 0; i < (channelWidth / 20); i++)
329 double rxPowerPerBandW =
331 NS_LOG_DEBUG(
"Signal power received (watts) before antenna gain for 20 MHz channel band "
332 << +i <<
": " << rxPowerPerBandW);
334 totalRxPowerW += rxPowerPerBandW;
335 rxPowerW.insert({filteredBand, rxPowerPerBandW});
336 NS_LOG_DEBUG(
"Signal power received after antenna gain for 20 MHz channel band "
337 << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm(rxPowerPerBandW)
344 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
346 double rxPowerPerBandW =
348 NS_LOG_DEBUG(
"Signal power received (watts) before antenna gain for RU with type "
349 << bandRuPair.second.GetRuType() <<
" and index "
350 << bandRuPair.second.GetIndex() <<
" -> (" << bandRuPair.first.first
351 <<
"; " << bandRuPair.first.second <<
"): " << rxPowerPerBandW);
353 NS_LOG_DEBUG(
"Signal power received after antenna gain for RU with type "
354 << bandRuPair.second.GetRuType() <<
" and index "
355 << bandRuPair.second.GetIndex() <<
" -> (" << bandRuPair.first.first
356 <<
"; " << bandRuPair.first.second <<
"): " << rxPowerPerBandW <<
" W ("
357 <<
WToDbm(rxPowerPerBandW) <<
" dBm)");
358 rxPowerW.insert({bandRuPair.first, rxPowerPerBandW});
362 NS_LOG_DEBUG(
"Total signal power received after antenna gain: "
363 << totalRxPowerW <<
" W (" <<
WToDbm(totalRxPowerW) <<
" dBm)");
366 DynamicCast<WifiSpectrumSignalParameters>(rxParams);
369 m_signalCb(
bool(wifiRxParams), senderNodeId,
WToDbm(totalRxPowerW), rxDuration);
380 NS_LOG_INFO(
"Received Wi-Fi signal but blocked from syncing");
388 uint16_t txWidth = wifiRxParams->ppdu->GetTransmissionChannelWidth();
391 NS_LOG_INFO(
"Received signal too weak to process: " <<
WToDbm(totalRxPowerW) <<
" dBm");
393 wifiRxParams->ppdu->GetTxVector(),
402 if (wifiRxParams->txPhy)
406 uint16_t p20MinFreq =
408 uint16_t p20MaxFreq =
411 if (!wifiRxParams->ppdu->CanBeReceived(p20MinFreq, p20MaxFreq))
413 NS_LOG_INFO(
"Cannot receive the PPDU, consider it as interference");
415 wifiRxParams->ppdu->GetTxVector(),
454 GetPhyEntity(ppdu->GetModulation())->StartTx(ppdu, txVector);
464 "SpectrumPhy() is not set; maybe forgot to call CreateWifiSpectrumPhyInterface?");
483 bandBandwidth = 312500;
489 bandBandwidth = 78125;
494 bandBandwidth = 156250;
500 bandBandwidth = 78125;
506 return bandBandwidth;
512 uint16_t guardBandwidth = 0;
513 if (currentChannelWidth == 22)
526 guardBandwidth = currentChannelWidth;
528 return guardBandwidth;
536 size_t numBandsInChannel =
static_cast<size_t>(channelWidth * 1e6 / bandBandwidth);
537 size_t numBandsInBand =
static_cast<size_t>(bandWidth * 1e6 / bandBandwidth);
538 if (numBandsInBand % 2 == 0)
540 numBandsInChannel += 1;
543 NS_ASSERT_MSG((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
544 "Should have odd number of bands");
545 NS_ASSERT_MSG((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
547 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
548 band.second = band.first + numBandsInBand - 1;
549 if (band.first >= totalNumBands / 2)
559 uint16_t guardBandwidth,
561 uint8_t bandIndex)
const
570 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
573 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
576 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
579 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
586 size_t numBandsInBand =
static_cast<size_t>(bandWidth * 1e6 /
GetBandBandwidth());
587 centerFrequencyIndex += numBandsInBand * bandIndex;
589 convertedSubcarriers.first = centerFrequencyIndex + range.first;
590 convertedSubcarriers.second = centerFrequencyIndex + range.second;
591 return convertedSubcarriers;
594std::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'.
std::size_t GetPhyIndex() const
Get the RU PHY index.
void SetPhyIndex(uint16_t bw, uint8_t p20Index)
Set 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.
virtual void DoInitialize()
Initialize() implementation.
bool IsInitialized() const
Check if the object has been initialized.
size_t GetNumBands() const
Abstract base class for Spectrum-aware PHY layers.
virtual Ptr< NetDevice > GetDevice() const =0
Get the associated NetDevice instance.
~SpectrumWifiPhy() override
TracedCallback< bool, uint32_t, double, Time > m_signalCb
Signal callback.
std::tuple< double, double, double > GetTxMaskRejectionParams() const override
void Transmit(Ptr< WifiSpectrumSignalParameters > txParams)
This function is sending the signal to the Spectrum channel after finishing the configuration of the ...
void DoInitialize() override
Initialize() implementation.
void StartTx(Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector) override
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
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...
void ResetSpectrumModel()
Perform run-time spectrum model change.
Ptr< Channel > GetChannel() const override
Return the Channel this WifiPhy is connected to.
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
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.
void DoDispose() override
Destructor implementation.
uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override
uint32_t GetBandBandwidth() const
static TypeId GetTypeId()
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
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.
Ptr< Object > GetAntenna() const
Get the antenna model used for reception.
void UpdateInterferenceHelperBands()
This function is called to update the bands handled by the InterferenceHelper.
Ptr< const SpectrumModel > m_rxSpectrumModel
receive spectrum model
void DoChannelSwitch() override
Actually switch channel based on the stored channel settings.
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...
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.
uint16_t GetChannelWidth() const
double GetRxSensitivity() const
Return the receive sensitivity threshold (dBm).
uint16_t GetFrequency() const
double GetRxGain() const
Return the reception gain (dB).
Ptr< PhyEntity > GetPhyEntity(WifiModulationClass modulation) const
Get the supported PHY entity corresponding to the modulation class.
void StartReceivePreamble(Ptr< const WifiPpdu > ppdu, RxPowerWattPerChannelBand &rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
void DoDispose() override
Destructor implementation.
virtual void DoChannelSwitch()
Actually switch channel based on the stored channel settings.
Ptr< InterferenceHelper > m_interference
Pointer to a helper responsible for interference computations.
WifiStandard GetStandard() const
Get the configured Wi-Fi standard.
void SwitchMaybeToCcaBusy(const Ptr< const WifiPpdu > ppdu)
Check if PHY state should move to CCA busy state based on current state of interference tracker.
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
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 double GetBandPowerW(Ptr< SpectrumValue > psd, const WifiSpectrumBand &band)
Calculate the power of the specified band composed of uniformly-sized sub-bands.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Empty class, used as a default parent class for SimpleRefCount.
#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 AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
#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.
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.
Time duration
The duration of the packet transmission.
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.