26 #include "ns3/simulator.h"
27 #include "ns3/packet.h"
28 #include "ns3/assert.h"
30 #include "ns3/double.h"
45 .SetGroupName (
"Wifi")
82 NS_LOG_DEBUG (
"drop packet because of channel switching while reception");
88 NS_LOG_DEBUG (
"channel switching postponed until end of current transmission");
96 NS_LOG_DEBUG (
"channel switching ignored in sleep mode");
134 NS_LOG_DEBUG (
"drop packet because of channel/frequency switching while reception");
137 goto switchFrequency;
140 NS_LOG_DEBUG (
"channel/frequency switching postponed until end of current transmission");
145 goto switchFrequency;
148 NS_LOG_DEBUG (
"frequency switching ignored in sleep mode");
192 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current transmission");
196 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current reception");
200 NS_LOG_DEBUG (
"setting sleep mode postponed until end of channel switching");
229 NS_LOG_DEBUG (
"not in sleep mode, there is nothing to resume");
236 m_state->SwitchFromSleep (delayUntilCcaEnd);
250 m_state->SetReceiveOkCallback (callback);
256 m_state->SetReceiveErrorCallback (callback);
272 double rxPowerW =
DbmToW (rxPowerDbm);
286 NS_LOG_DEBUG (
"drop packet because of channel switching");
305 NS_LOG_DEBUG (
"drop packet because already in Rx (power=" <<
316 NS_LOG_DEBUG (
"drop packet because already in Tx (power=" <<
334 NS_LOG_DEBUG (
"drop packet because no PLCP preamble/header has been received");
368 NS_LOG_DEBUG (
"sync to signal (power=" << rxPowerW <<
"W)");
370 m_state->SwitchToRx (rxDuration);
379 packet, txVector, preamble, mpdutype, event);
384 packet, preamble, mpdutype, event);
388 NS_LOG_DEBUG (
"drop packet because signal power too Small (" <<
411 if (!delayUntilCcaEnd.
IsZero ())
413 m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
443 NS_LOG_DEBUG (
"drop packet because it was sent using an unsupported mode (" << txMode <<
")");
450 NS_LOG_DEBUG (
"drop packet because plcp preamble/header reception failed");
467 << preamble << (uint32_t)txVector.
GetTxPowerLevel () << (uint32_t)mpdutype);
493 uint32_t dataRate500KbpsUnits;
508 aMpdu.
type = mpdutype;
518 m_state->RegisterListener (listener);
524 m_state->UnregisterListener (listener);
540 NS_LOG_DEBUG (
"mode=" << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) <<
541 ", snr(dB)=" <<
RatioToDb (snrPer.snr) <<
", per=" << snrPer.per <<
", size=" << packet->
GetSize ());
546 uint32_t dataRate500KbpsUnits;
549 dataRate500KbpsUnits = 128 +
event->GetPayloadMode ().GetMcsValue ();
553 dataRate500KbpsUnits =
event->GetPayloadMode ().GetDataRate (event->GetTxVector ().GetChannelWidth (),
event->GetTxVector ().IsShortGuardInterval (), 1) * event->GetTxVector ().GetNss () / 500000;
559 aMpdu.
type = mpdutype;
562 m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (),
event->GetPreambleType ());
568 m_state->SwitchFromRxEndError (packet, snrPer.snr);
573 m_state->SwitchFromRxEndError (packet, snrPer.snr);
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
double RatioToDb(double ratio) const
Convert from ratio to dB.
double GetTxGain(void) const
Return the transmission gain (dB).
double GetRxNoiseFigure(void) const
Return the RX noise figure (dBm).
virtual bool IsMcsSupported(WifiMode mcs) const
Check if the given WifiMode is supported by the PHY.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint8_t GetRemainingNbOfMpdus(void) const
virtual void SendPacket(Ptr< const Packet > packet, WifiTxVector txVector, enum WifiPreamble preamble)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< YansWifiChannel > m_channel
YansWifiChannel that this YansWifiPhy is connected to.
The PHY layer has sense the medium busy through the CCA mechanism.
enum WifiModulationClass GetModulationClass() const
#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.
virtual void RegisterListener(WifiPhyListener *listener)
bool IsShortGuardInterval(void) const
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
The PHY layer is sleeping.
void NotifyTxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyTxDrop trace.
void NotifyTxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyTxBegin trace.
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.
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.
uint8_t GetTxPowerLevel(void) const
virtual bool DoFrequencySwitch(uint32_t frequency)
The default implementation does nothing and returns true.
uint16_t m_mpdusNum
carries the number of expected mpdus that are part of an A-MPDU
virtual void SetReceiveErrorCallback(WifiPhy::RxErrorCallback callback)
void NotifyRxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyRxDrop trace.
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.
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.
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)
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
receive notifications about phy events.
virtual void DoDispose(void)
Destructor implementation.
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
The aim of the AmpduTag is to provide means for a MAC to specify that a packet includes A-MPDU since ...
void NotifyRxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyRxBegin trace.
The PHY layer is sending a packet.
virtual void SetChannelNumber(uint16_t id)
Set channel number.
The PHY layer is switching to other channel.
void SetChannel(Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
The MPDU is part of an A-MPDU, but is not the last aggregate.
virtual void SetReceiveOkCallback(WifiPhy::RxOkCallback callback)
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...
virtual void UnregisterListener(WifiPhyListener *listener)
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.
802.11 PHY layer modelThis PHY implements a model of 802.11a.
Ptr< InterferenceHelper::Event > Add(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, Time duration, double rxPower)
Add the packet-related signal to interference helper.
static TypeId GetTypeId(void)
bool IsInitialized(void) const
Check if the object has been initialized.
uint64_t GetDataRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
virtual void SetSleepMode(void)
Put in sleep mode.
static Time Now(void)
Return the current simulation virtual time.
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
void StartReceivePreambleAndHeader(Ptr< Packet > packet, double rxPowerDbm, WifiTxVector txVector, WifiPreamble preamble, enum mpduType mpdutype, Time rxDuration)
Starting receiving the plcp of a packet (i.e.
uint8_t GetNss(void) const
bool m_plcpSuccess
Flag if the PLCP of the packet or the first MPDU in an A-MPDU has been received.
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)
InterferenceHelper m_interference
Pointer to InterferenceHelper.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual void SetFrequency(uint32_t freq)
virtual Time GetChannelSwitchDelay(void) const
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
double DbmToW(double dbm) const
Convert from dBm to Watts.
virtual Ptr< WifiChannel > GetChannel(void) const
Return the WifiChannel this WifiPhy is connected to.
double GetEdThresholdW(void) const
Return the energy detection threshold.
WifiMode GetMode(void) const
virtual bool IsStateRx(void)
double GetCcaMode1Threshold(void) const
Return the CCA threshold (dBm).
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
void EndReceive(Ptr< Packet > packet, enum WifiPreamble preamble, enum mpduType mpdutype, Ptr< InterferenceHelper::Event > event)
The last bit of the packet has arrived.
a unique identifier for an interface.
virtual void ResumeFromSleep(void)
Resume from sleep mode.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
double GetRxGain(void) const
Return the reception gain (dB).
mpduType
This enumeration defines the type of an MPDU.
virtual bool DoChannelSwitch(uint16_t id)
The default implementation does nothing and returns true.
The MPDU is the last aggregate in an A-MPDU.