27 #include "ns3/double.h"
28 #include "ns3/boolean.h"
29 #include "ns3/wifi-net-device.h"
31 #include "ns3/simulator.h"
50 .SetGroupName (
"Wifi")
52 .AddAttribute (
"DisableWifiReception",
53 "Prevent Wi-Fi frame sync from ever happening",
57 .AddAttribute (
"TxMaskInnerBandMinimumRejection",
58 "Minimum rejection (dBr) for the inner band of the transmit spectrum mask",
61 MakeDoubleChecker<double> ())
62 .AddAttribute (
"TxMaskOuterBandMinimumRejection",
63 "Minimum rejection (dBr) for the outer band of the transmit spectrum mask",
66 MakeDoubleChecker<double> ())
67 .AddAttribute (
"TxMaskOuterBandMaximumRejection",
68 "Maximum rejection (dBr) for the outer band of the transmit spectrum mask",
71 MakeDoubleChecker<double> ())
72 .AddTraceSource (
"SignalArrival",
75 "ns3::SpectrumWifiPhy::SignalArrivalCallback")
114 NS_FATAL_ERROR (
"SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at initialization time");
136 NS_LOG_DEBUG (
"Creating spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
150 if (channelWidth < 20)
157 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
159 for (uint8_t i = 0; i < (channelWidth / bw); ++i)
175 for (uint16_t bw = 160; bw >= 20; bw = bw / 2)
177 for (uint8_t i = 0; i < (channelWidth / bw); ++i)
179 for (
unsigned int type = 0; type < 7; type++)
183 for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++)
189 std::size_t index = (bw == 160 && phyIndex > nRus / 2
190 ? phyIndex - nRus / 2 : phyIndex);
193 bool primary80 = (bw < 160
195 || (primary80IsLower80 && phyIndex <= nRus / 2)
196 || (!primary80IsLower80 && phyIndex > nRus / 2));
200 m_ruBands[channelWidth].insert ({band, ru});
206 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
231 NS_LOG_DEBUG (
"Run-time change of spectrum model from frequency/width pair of (" <<
GetFrequency () <<
", " << channelWidth <<
")");
254 Time rxDuration = rxParams->duration;
256 NS_LOG_DEBUG (
"Received signal with PSD " << *receivedSignalPsd <<
" and duration " << rxDuration.
As (
Time::NS));
257 uint32_t senderNodeId = 0;
260 senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
262 NS_LOG_DEBUG (
"Received signal from " << senderNodeId <<
" with unfiltered power " <<
WToDbm (
Integral (*receivedSignalPsd)) <<
" dBm");
269 double totalRxPowerW = 0;
272 if ((channelWidth == 5) || (channelWidth == 10))
276 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " << rxPowerPerBandW);
278 totalRxPowerW += rxPowerPerBandW;
279 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
280 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << channelWidth <<
" MHz channel: " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
283 for (uint16_t bw = 160; bw > 20; bw = bw / 2)
285 for (uint8_t i = 0; i < (channelWidth / bw); i++)
290 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for " << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW);
292 rxPowerW.insert ({filteredBand, rxPowerPerBandW});
293 NS_LOG_DEBUG (
"Signal power received after antenna gain for " << bw <<
" MHz channel band " << +i <<
": " << rxPowerPerBandW <<
" W (" <<
WToDbm (rxPowerPerBandW) <<
" dBm)");
298 for (uint8_t i = 0; i < (channelWidth / 20); i++)
302 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain for 20 MHz channel band " << +i <<
": " << rxPowerPerBandW);
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)");
312 for (
const auto& bandRuPair :
m_ruBands[channelWidth])
315 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);
317 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)");
318 rxPowerW.insert ({bandRuPair.first, rxPowerPerBandW});
322 NS_LOG_DEBUG (
"Total signal power received after antenna gain: " << totalRxPowerW <<
" W (" <<
WToDbm (totalRxPowerW) <<
" dBm)");
327 m_signalCb (wifiRxParams, senderNodeId,
WToDbm (totalRxPowerW), rxDuration);
329 if (wifiRxParams == 0)
338 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
346 uint16_t txWidth = wifiRxParams->ppdu->GetTransmissionChannelWidth ();
349 NS_LOG_INFO (
"Received signal too weak to process: " <<
WToDbm (totalRxPowerW) <<
" dBm");
350 m_interference->Add (wifiRxParams->ppdu, wifiRxParams->ppdu->GetTxVector (), rxDuration,
358 if (wifiRxParams->txPhy != 0)
362 uint16_t p20MinFreq =
364 uint16_t p20MaxFreq =
367 if (!wifiRxParams->ppdu->CanBeReceived (wifiRxParams->txCenterFreq, p20MinFreq, p20MaxFreq))
369 NS_LOG_INFO (
"Cannot receive the PPDU, consider it as interference");
370 m_interference->Add (wifiRxParams->ppdu, wifiRxParams->ppdu->GetTxVector (),
371 rxDuration, rxPowerW);
427 uint32_t bandBandwidth = 0;
436 bandBandwidth = 312500;
442 bandBandwidth = 78125;
447 bandBandwidth = 156250;
452 bandBandwidth = 78125;
458 return bandBandwidth;
464 uint16_t guardBandwidth = 0;
465 if (currentChannelWidth == 22)
478 guardBandwidth = currentChannelWidth;
480 return guardBandwidth;
488 size_t numBandsInChannel =
static_cast<size_t> (channelWidth * 1e6 / bandBandwidth);
489 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 / bandBandwidth);
490 if (numBandsInBand % 2 == 0)
492 numBandsInChannel += 1;
495 NS_ASSERT_MSG ((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1),
"Should have odd number of bands");
496 NS_ASSERT_MSG ((bandIndex * bandWidth) < channelWidth,
"Band index is out of bound");
498 band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand);
499 if (band.first >= totalNumBands / 2)
504 band.second = band.first + numBandsInBand - 1;
513 uint32_t nGuardBands =
static_cast<uint32_t
> (((2 * guardBandwidth * 1e6) /
GetBandBandwidth ()) + 0.5);
514 uint32_t centerFrequencyIndex = 0;
518 centerFrequencyIndex = (nGuardBands / 2) + 6 + 122;
521 centerFrequencyIndex = (nGuardBands / 2) + 12 + 244;
524 centerFrequencyIndex = (nGuardBands / 2) + 12 + 500;
527 centerFrequencyIndex = (nGuardBands / 2) + 12 + 1012;
534 size_t numBandsInBand =
static_cast<size_t> (bandWidth * 1e6 /
GetBandBandwidth ());
535 centerFrequencyIndex += numBandsInBand * bandIndex;
537 convertedSubcarriers.first = centerFrequencyIndex + range.first;
538 convertedSubcarriers.second = centerFrequencyIndex + range.second;
539 return convertedSubcarriers;
542 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.
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.
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...
void DoChannelSwitch(void) override
Actually switch channel based on the stored channel settings.
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.
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
Ptr< Object > GetAntenna(void) const
Get the antenna model used for reception.
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.
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.
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand &rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
WifiStandard GetStandard(void) const
Get the configured Wi-Fi standard.
virtual void DoDispose(void)
Destructor implementation.
uint16_t GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const
Return the channel width used to measure the RSSI.
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).
Ptr< InterferenceHelper > m_interference
Pointer to a helper responsible for interference computations.
virtual void DoChannelSwitch(void)
Actually switch channel based on the stored channel settings.
uint16_t GetChannelWidth(void) const
uint16_t GetFrequency(void) const
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.
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.
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.