27 #include "ns3/spectrum-channel.h"
28 #include "ns3/spectrum-value.h"
29 #include "ns3/wifi-spectrum-value-helper.h"
31 #include "ns3/simulator.h"
32 #include "ns3/assert.h"
34 #include "ns3/double.h"
35 #include "ns3/boolean.h"
39 #include "ns3/antenna-model.h"
53 .SetGroupName (
"Wifi")
55 .AddAttribute (
"DisableWifiReception",
"Prevent Wi-Fi frame sync from ever happening",
59 .AddTraceSource (
"SignalArrival",
62 "ns3::SpectrumWifiPhy::SignalArrivalCallback")
97 NS_FATAL_ERROR (
"SpectrumWifiPhy misses channel and WifiSpectrumPhyInterface objects at initialization time");
115 NS_LOG_DEBUG (
"drop packet because of channel switching while reception");
121 NS_LOG_DEBUG (
"channel switching postponed until end of current transmission");
129 NS_LOG_DEBUG (
"channel switching ignored in sleep mode");
168 NS_LOG_DEBUG (
"drop packet because of channel/frequency switching while reception");
171 goto switchFrequency;
174 NS_LOG_DEBUG (
"channel/frequency switching postponed until end of current transmission");
179 goto switchFrequency;
182 NS_LOG_DEBUG (
"frequency switching ignored in sleep mode");
255 std::vector<uint16_t>
258 std::vector<uint16_t> channelList;
283 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current transmission");
287 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current reception");
291 NS_LOG_DEBUG (
"setting sleep mode postponed until end of channel switching");
320 NS_LOG_DEBUG (
"not in sleep mode, there is nothing to resume");
327 m_state->SwitchFromSleep (delayUntilCcaEnd);
341 m_state->SetReceiveOkCallback (callback);
347 m_state->SetReceiveErrorCallback (callback);
360 if (!delayUntilCcaEnd.
IsZero ())
363 m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
371 Time rxDuration = rxParams->duration;
373 NS_LOG_DEBUG (
"Received signal with PSD " << *receivedSignalPsd <<
" and duration " << rxDuration.
As (
Time::NS));
374 uint32_t senderNodeId = 0;
377 senderNodeId = rxParams->txPhy->GetDevice ()->GetNode ()->GetId ();
379 NS_LOG_DEBUG (
"Received signal from " << senderNodeId <<
" with unfiltered power " <<
WToDbm (
Integral (*receivedSignalPsd)) <<
" dBm");
384 SpectrumValue filteredSignal = (*filter) * (*receivedSignalPsd);
386 NS_LOG_DEBUG (
"Signal power received (watts) before antenna gain: " <<
Integral (filteredSignal));
388 NS_LOG_DEBUG (
"Signal power received after antenna gain: " << rxPowerW <<
" W (" <<
WToDbm (rxPowerW) <<
" dBm)");
393 m_signalCb (wifiRxParams ?
true :
false, senderNodeId,
WToDbm (rxPowerW), rxDuration);
394 if (wifiRxParams == 0)
403 NS_LOG_INFO (
"Received Wi-Fi signal but blocked from syncing");
410 Ptr<Packet> packet = wifiRxParams->packet->Copy ();
415 NS_FATAL_ERROR (
"Received Wi-Fi Spectrum Signal with no WifiPhyTag");
424 NS_LOG_INFO (
"Reception ends in failure because less RX antennas than number of spatial streams");
449 NS_LOG_DEBUG (
"drop packet because of channel switching");
469 NS_LOG_DEBUG (
"drop packet because already in Rx (power=" <<
481 NS_LOG_DEBUG (
"drop packet because already in Tx (power=" <<
498 NS_LOG_DEBUG (
"drop packet because no preamble has been received");
505 NS_LOG_DEBUG (
"Drop MPDU because no plcp has been received");
535 NS_LOG_DEBUG (
"sync to signal (power=" << rxPowerW <<
"W)");
537 m_state->SwitchToRx (rxDuration);
546 packet, txVector, preamble, mpdutype, event);
551 packet, preamble, mpdutype, event);
555 NS_LOG_DEBUG (
"drop packet because signal power too Small (" <<
600 NS_LOG_DEBUG (
"drop packet because it was sent using an unsupported mode (" << txMode <<
")");
607 NS_LOG_DEBUG (
"drop packet because plcp preamble/header reception failed");
681 << preamble << (uint32_t)txVector.
GetTxPowerLevel () << (uint32_t)mpdutype);
707 uint32_t dataRate500KbpsUnits;
722 aMpdu.
type = mpdutype;
732 WifiPhyTag tag (txVector, preamble, mpdutype);
740 txParams->duration = txDuration;
741 txParams->psd = txPowerSpectrum;
745 txParams->packet = newPacket;
747 NS_LOG_DEBUG (
"Starting transmission with integrated spectrum power " <<
WToDbm (
Integral (*txPowerSpectrum)) <<
" dBm; spectrum model Uid: " << txPowerSpectrum->GetSpectrumModel ()->GetUid ());
754 m_state->RegisterListener (listener);
760 m_state->UnregisterListener (listener);
777 NS_LOG_DEBUG (
"mode=" << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) <<
778 ", snr(dB)=" <<
RatioToDb (snrPer.snr) <<
", per=" << snrPer.per <<
", size=" << packet->
GetSize ());
783 uint32_t dataRate500KbpsUnits;
786 dataRate500KbpsUnits = 128 +
event->GetPayloadMode ().GetMcsValue ();
790 dataRate500KbpsUnits =
event->GetPayloadMode ().GetDataRate (event->GetTxVector ().GetChannelWidth (),
event->GetTxVector ().IsShortGuardInterval (), 1) * event->GetTxVector ().GetNss () / 500000;
796 aMpdu.
type = mpdutype;
799 m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (),
event->GetPreambleType ());
806 m_state->SwitchFromRxEndError (packet, snrPer.snr);
816 m_state->SwitchFromRxEndError (packet, snrPer.snr);
ERP-OFDM PHY (Clause 19, Section 19.5)
Ptr< SpectrumValue > GetTxPowerSpectralDensity(uint32_t centerFrequency, uint32_t channelWidth, double txPowerW) const
uint32_t m_txMpduReferenceNumber
A-MPDU reference number to identify all transmitted subframes belonging to the same received A-MPDU...
Simulation virtual time values and global simulation resolution.
static Ptr< SpectrumModel > GetSpectrumModel(uint32_t centerFrequency, uint32_t channelWidth)
Return a SpectrumModel instance corresponding to the center frequency and channel width...
virtual bool DoChannelSwitch(uint16_t id)
The default implementation does nothing and returns true.
TracedCallback< bool, uint32_t, double, Time > m_signalCb
void AddForeignSignal(Time duration, double rxPower)
Add a non-Wifi signal to interference helper.
void NotifyMonitorSniffTx(Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu)
Public method used to fire a MonitorSniffer trace for a wifi packet being transmitted.
A struct for both SNR and PER.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
double RatioToDb(double ratio) const
Convert from ratio to dB.
Abstract base class for Spectrum-aware PHY layers.
double GetTxGain(void) const
Return the transmission gain (dB).
double GetRxNoiseFigure(void) const
Return the RX noise figure (dBm).
AttributeValue implementation for Boolean.
virtual bool IsMcsSupported(WifiMode mcs) const
Check if the given WifiMode is supported by the PHY.
HT OFDM PHY for the 5 GHz band (clause 20)
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)
uint8_t GetRemainingNbOfMpdus(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void StartReceivePacket(Ptr< Packet > packet, WifiTxVector txVector, WifiPreamble preamble, enum mpduType mpdutype, Ptr< InterferenceHelper::Event > event)
Starting receiving the payload of a packet (i.e.
virtual void SetReceiveErrorCallback(WifiPhy::RxErrorCallback callback)
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level Phy interface to this Sp...
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
The PHY layer has sense the medium busy through the CCA mechanism.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
void SetAntenna(Ptr< AntennaModel > antenna)
enum WifiModulationClass GetModulationClass() const
bool IsNull(void) const
Check for null implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Time GetEnergyDuration(double energyW)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static TypeId GetTypeId(void)
bool IsShortGuardInterval(void) const
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
bool m_disableWifiReception
forces this Phy to fail to sync on any signal
The PHY layer is sleeping.
virtual Ptr< WifiChannel > GetChannel(void) const
Return the WifiChannel this WifiPhy is connected to.
#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.
void NotifyTxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyTxDrop trace.
HT OFDM PHY for the 2.4 GHz band (clause 20)
Ptr< const SpectrumModel > GetRxSpectrumModel() const
Ptr< WifiSpectrumPhyInterface > GetSpectrumPhy(void) const
void NotifyTxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyTxBegin trace.
virtual void UnregisterListener(WifiPhyListener *listener)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
virtual bool IsModeSupported(WifiMode mode) const
Check if the given WifiMode is supported by the PHY.
static Ptr< SpectrumValue > CreateHtOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint32_t channelWidth, double txPowerW)
Create a transmit power spectral density corresponding to OFDM High Throughput (HT) (802...
void NotifyMonitorSniffRx(Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, struct signalNoiseDbm signalNoise)
Public method used to fire a MonitorSniffer trace for a wifi packet being received.
virtual void SetSleepMode(void)
Put in sleep mode.
uint8_t GetTxPowerLevel(void) const
virtual void DoInitialize(void)
Initialize() implementation.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
static Ptr< SpectrumValue > CreateDsssTxPowerSpectralDensity(uint32_t centerFrequency, double txPowerW)
Create a transmit power spectral density corresponding to DSSS.
Ptr< SpectrumChannel > m_channel
SpectrumChannel that this SpectrumWifiPhy is connected to.
uint16_t m_mpdusNum
carries the number of expected mpdus that are part of an A-MPDU
void NotifyRxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyRxDrop trace.
virtual uint32_t GetNumberOfReceiveAntennas(void) const
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
std::vector< uint16_t > GetOperationalChannelList(void) const
Return a list of channels to which it may be possible to roam By default, this method will return the...
The MPDU is not part of an A-MPDU.
virtual uint16_t GetChannelNumber(void) const
Return current channel number.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Time CalculatePlcpPreambleAndHeaderDuration(WifiTxVector txVector, enum WifiPreamble preamble)
Ptr< AntennaModel > GetRxAntenna(void) const
Get the antenna model used for reception.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
receive notifications about phy events.
uint32_t GetChannelWidth(void) const
struct InterferenceHelper::SnrPer CalculatePlcpHeaderSnrPer(Ptr< InterferenceHelper::Event > event)
Calculate the SNIR at the start of the plcp header and accumulate all SNIR changes in the snir vector...
virtual Time GetDelayUntilIdle(void)
uint8_t GetMcsValue(void) const
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, double frequency)
uint32_t m_rxMpduReferenceNumber
A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU...
The PHY layer is receiving a packet.
virtual uint32_t GetFrequency(void) const
virtual void DoDispose(void)
Destructor implementation.
void SetPacketReceivedCallback(RxCallback callback)
Set the packet received callback (invoked at the end of a frame reception), to notify whether the fra...
The aim of the AmpduTag is to provide means for a MAC to specify that a packet includes A-MPDU since ...
802.11 PHY layer modelThis PHY implements a spectrum-aware enhancement of the 802.11 SpectrumWifiPhy model.
void NotifyRxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyRxBegin trace.
The PHY layer is sending a packet.
virtual void RegisterListener(WifiPhyListener *listener)
virtual void SetChannelNumber(uint16_t id)
Set channel number.
Ptr< const SpectrumModel > m_rxSpectrumModel
static Ptr< SpectrumValue > CreateRfFilter(uint32_t centerFrequency, uint32_t channelWidth)
The PHY layer is switching to other channel.
The MPDU is part of an A-MPDU, but is not the last aggregate.
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
void AddOperationalChannel(uint16_t channelNumber)
Add a channel number to the list of operational channels.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
virtual uint32_t GetChannelWidth(void) const
struct InterferenceHelper::SnrPer CalculatePlcpPayloadSnrPer(Ptr< InterferenceHelper::Event > event)
Calculate the SNIR at the start of the plcp payload and accumulate all SNIR changes in the snir vecto...
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void NotifyRxStart()
Notify that RX has started.
void EraseEvents(void)
Erase all events.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< InterferenceHelper::Event > Add(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, Time duration, double rxPower)
Add the packet-related signal to interference helper.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
bool IsInitialized(void) const
Check if the object has been initialized.
uint64_t GetDataRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
WifiPreamble GetWifiPreamble(void) const
Getter for WifiPreamble parameter.
virtual void DoInitialize(void)
Initialize() implementation.
static Ptr< SpectrumValue > CreateOfdmTxPowerSpectralDensity(uint32_t centerFrequency, uint32_t channelWidth, double txPowerW)
Create a transmit power spectral density corresponding to OFDM (802.11a/g).
static Time Now(void)
Return the current simulation virtual time.
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
virtual void SetReceiveOkCallback(WifiPhy::RxOkCallback callback)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
WifiTxVector GetWifiTxVector(void) const
Getter for WifiTxVector parameter.
uint8_t GetNss(void) const
void EndReceive(Ptr< Packet > packet, enum WifiPreamble preamble, enum mpduType mpdutype, Ptr< InterferenceHelper::Event > event)
The last bit of the packet has arrived.
bool m_plcpSuccess
Flag if the PLCP of the packet or the first MPDU in an A-MPDU has been received.
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Ptr< WifiPhyStateHelper > m_state
Pointer to WifiPhyStateHelper.
void NotifyRxEnd(Ptr< const Packet > packet)
Public method used to fire a PhyRxEnd trace.
void NotifyRxEnd()
Notify that RX has ended.
virtual bool IsStateSwitching(void)
virtual void SendPacket(Ptr< const Packet > packet, WifiTxVector txVector, enum WifiPreamble preamble)
InterferenceHelper m_interference
Pointer to InterferenceHelper.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< AntennaModel > m_antenna
enum mpduType GetMpduType(void) const
Getter for mpduType parameter.
void ClearOperationalChannelList(void)
Clear the list of operational channels.
virtual void SetFrequency(uint32_t freq)
virtual Time GetChannelSwitchDelay(void) const
Ptr< WifiSpectrumPhyInterface > m_wifiSpectrumPhyInterface
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Tag for WifiTxVector and WifiPreamble information to be embedded in outgoing transmissions as a Packe...
std::vector< uint16_t > m_operationalChannelList
List of possible channels.
double WToDbm(double w) const
Convert from Watts to dBm.
void SwitchMaybeToCcaBusy(void)
Check if Phy state should move to CCA busy state based on current state of interference tracker...
double DbmToW(double dbm) const
Convert from dBm to Watts.
virtual ~SpectrumWifiPhy()
virtual enum WifiPhyStandard GetStandard(void) const
Get the configured Wi-Fi standard.
double GetEdThresholdW(void) const
Return the energy detection threshold.
WifiMode GetMode(void) const
virtual void ResumeFromSleep(void)
Resume from sleep mode.
virtual bool IsStateRx(void)
Set of values corresponding to a given SpectrumModel.
double GetCcaMode1Threshold(void) const
Return the CCA threshold (dBm).
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
double DbToRatio(double db) const
Convert from dB to ratio.
double GetRxGain(void) const
Return the reception gain (dB).
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...
mpduType
This enumeration defines the type of an MPDU.
virtual bool DoFrequencySwitch(uint32_t frequency)
The default implementation does nothing and returns true.
The MPDU is the last aggregate in an A-MPDU.