28 #include "ns3/simulator.h"
29 #include "ns3/packet.h"
30 #include "ns3/assert.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
35 #include "ns3/pointer.h"
36 #include "ns3/net-device.h"
37 #include "ns3/trace-source-accessor.h"
38 #include "ns3/boolean.h"
52 .AddConstructor<YansWifiPhy> ()
53 .AddAttribute (
"EnergyDetectionThreshold",
54 "The energy of a received signal should be higher than "
55 "this threshold (dbm) to allow the PHY layer to detect the signal.",
59 MakeDoubleChecker<double> ())
60 .AddAttribute (
"CcaMode1Threshold",
61 "The energy of a received signal should be higher than "
62 "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state",
66 MakeDoubleChecker<double> ())
67 .AddAttribute (
"TxGain",
68 "Transmission gain (dB).",
72 MakeDoubleChecker<double> ())
73 .AddAttribute (
"RxGain",
74 "Reception gain (dB).",
78 MakeDoubleChecker<double> ())
79 .AddAttribute (
"TxPowerLevels",
80 "Number of transmission power levels available between "
81 "TxPowerStart and TxPowerEnd included.",
84 MakeUintegerChecker<uint32_t> ())
85 .AddAttribute (
"TxPowerEnd",
86 "Maximum available transmission level (dbm).",
90 MakeDoubleChecker<double> ())
91 .AddAttribute (
"TxPowerStart",
92 "Minimum available transmission level (dbm).",
96 MakeDoubleChecker<double> ())
97 .AddAttribute (
"RxNoiseFigure",
98 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
99 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
100 "\"the difference in decibels (dB) between"
101 " the noise output of the actual receiver to the noise output of an "
102 " ideal receiver with the same overall gain and bandwidth when the receivers "
103 " are connected to sources at the standard noise temperature T0 (usually 290 K)\"."
108 MakeDoubleChecker<double> ())
109 .AddAttribute (
"State",
"The state of the PHY layer",
112 MakePointerChecker<WifiPhyStateHelper> ())
113 .AddAttribute (
"ChannelSwitchDelay",
114 "Delay between two short frames transmitted on different frequencies.",
118 .AddAttribute (
"ChannelNumber",
119 "Channel center frequency = Channel starting frequency + 5 MHz * nch",
123 MakeUintegerChecker<uint16_t> ())
124 .AddAttribute (
"Frequency",
"The operating frequency.",
128 MakeUintegerChecker<uint32_t> ())
129 .AddAttribute (
"Transmitters",
"The number of transmitters.",
133 MakeUintegerChecker<uint32_t> ())
134 .AddAttribute (
"Recievers",
"The number of recievers.",
138 MakeUintegerChecker<uint32_t> ())
139 .AddAttribute (
"ShortGuardEnabled",
"Whether or not short guard interval is enabled.",
143 MakeBooleanChecker ())
144 .AddAttribute (
"LdpcEnabled",
"Whether or not LDPC is enabled.",
148 MakeBooleanChecker ())
149 .AddAttribute (
"STBCEnabled",
"Whether or not STBC is enabled.",
153 MakeBooleanChecker ())
154 .AddAttribute (
"GreenfieldEnabled",
"Whether or not STBC is enabled.",
158 MakeBooleanChecker ())
159 .AddAttribute (
"ChannelBonding",
"Whether 20MHz or 40MHz.",
163 MakeBooleanChecker ())
171 : m_channelNumber (1),
173 m_channelStartingFrequency (0)
176 m_random = CreateObject<UniformRandomVariable> ();
177 m_state = CreateObject<WifiPhyStateHelper> ();
388 NS_LOG_DEBUG (
"drop packet because of channel switching while reception");
393 NS_LOG_DEBUG (
"channel switching postponed until end of current transmission");
437 m_state->SetReceiveOkCallback (callback);
442 m_state->SetReceiveErrorCallback (callback);
452 double rxPowerW =
DbmToW (rxPowerDbm);
468 NS_LOG_DEBUG (
"drop packet because of channel switching");
486 NS_LOG_DEBUG (
"drop packet because already in Rx (power=" <<
497 NS_LOG_DEBUG (
"drop packet because already in Tx (power=" <<
511 NS_LOG_DEBUG (
"sync to signal (power=" << rxPowerW <<
"W)");
513 m_state->SwitchToRx (rxDuration);
523 NS_LOG_DEBUG (
"drop packet because signal power too Small (" <<
540 if (!delayUntilCcaEnd.
IsZero ())
542 m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
684 m_state->RegisterListener (listener);
690 return m_state->IsStateCcaBusy ();
696 return m_state->IsStateIdle ();
701 return m_state->IsStateBusy ();
716 return m_state->IsStateSwitching ();
722 return m_state->GetStateDuration ();
727 return m_state->GetDelayUntilIdle ();
733 return m_state->GetLastRxStartTime ();
739 double ratio = std::pow (10.0, dB / 10.0);
746 double mW = std::pow (10.0, dBm / 10.0);
753 return 10.0 * std::log10 (w * 1000.0);
759 return 10.0 * std::log10 (ratio);
797 NS_LOG_DEBUG (
"mode=" << (event->GetPayloadMode ().GetDataRate ()) <<
798 ", snr=" << snrPer.snr <<
", per=" << snrPer.per <<
", size=" << packet->
GetSize ());
802 uint32_t dataRate500KbpsUnits =
event->GetPayloadMode ().GetDataRate () *
event->GetTxVector().GetNss()/ 500000;
804 double signalDbm =
RatioToDb (event->GetRxPowerW ()) + 30;
807 m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetPayloadMode (),
event->GetPreambleType ());
813 m_state->SwitchFromRxEndError (packet, snrPer.snr);
928 for (uint8_t i=0; i <8; i++)
961 return supportedmodes;
static WifiMode GetOfdmRate9MbpsBW5MHz()
static WifiMode GetErpOfdmRate24Mbps()
static WifiMode GetDsssRate11Mbps()
virtual bool IsStateBusy(void)
keep track of time values and allow control of global simulation resolution
static WifiMode GetErpOfdmRate36Mbps()
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void Configure80211b(void)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
virtual uint32_t GetFrequency(void) const
static WifiMode GetOfdmRate26MbpsBW20MHz()
virtual WifiModeList GetMembershipSelectorModes(uint32_t selector)
Ptr< ErrorRateModel > GetErrorRateModel(void) const
double DbmToW(double dbm) const
static WifiMode GetOfdmRate9Mbps()
double DbToRatio(double db) const
static WifiMode GetOfdmRate7_2MbpsBW20MHz()
static WifiMode GetOfdmRate18MbpsBW10MHz()
static WifiMode GetOfdmRate27MbpsBW10MHz()
void SetErrorRateModel(Ptr< ErrorRateModel > rate)
virtual bool IsStateSwitching(void)
virtual bool IsStateTx(void)
static WifiMode GetOfdmRate3MbpsBW5MHz()
static WifiMode GetDsssRate1Mbps()
void NotifyMonitorSniffTx(Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, uint8_t txPower)
void Configure80211n(void)
Ptr< YansWifiChannel > m_channel
static WifiMode GetOfdmRate81MbpsBW40MHz()
void SetTxGain(double gain)
static WifiMode GetErpOfdmRate18Mbps()
static WifiMode GetOfdmRate12Mbps()
#define NS_ASSERT(condition)
static WifiMode GetOfdmRate43_3MbpsBW20MHz()
Time GetEnergyDuration(double energyW)
virtual void RegisterListener(WifiPhyListener *listener)
static WifiMode GetOfdmRate60MbpsBW40MHz()
static WifiMode GetOfdmRate1_5MbpsBW5MHz()
uint32_t GetSize(void) const
static WifiMode GetOfdmRate4_5MbpsBW10MHz()
static WifiMode GetOfdmRate54Mbps()
uint16_t GetChannelNumber() const
Return current channel number, see SetChannelNumber()
void SetChannelNumber(uint16_t id)
Set channel number.
virtual void SendPacket(Ptr< const Packet > packet, WifiMode mode, enum WifiPreamble preamble, WifiTxVector txvector)
static WifiMode GetOfdmRate108MbpsBW40MHz()
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
static WifiMode GetOfdmRate21_7MbpsBW20MHz()
void NotifyTxBegin(Ptr< const Packet > packet)
Ptr< Object > GetDevice(void) const
void Configure80211_5Mhz()
virtual Time GetDelayUntilIdle(void)
void Configure80211a(void)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
void Configure80211g(void)
static WifiMode GetOfdmRate135MbpsBW40MHz()
static WifiMode GetOfdmRate36Mbps()
static WifiMode GetOfdmRate6MbpsBW5MHz()
virtual Time GetStateDuration(void)
virtual uint32_t GetNBssMembershipSelectors(void) const
uint8_t GetTxPowerLevel(void) const
double GetTxGain(void) const
virtual bool GetChannelBonding(void) const
std::vector< uint32_t > m_bssMembershipSelectorSet
static WifiMode GetErpOfdmRate54Mbps()
virtual void SetReceiveErrorCallback(WifiPhy::RxErrorCallback callback)
void NotifyRxDrop(Ptr< const Packet > packet)
void SetErrorRateModel(Ptr< ErrorRateModel > rate)
virtual uint32_t GetNModes(void) const
static WifiMode GetOfdmRate6_5MbpsBW20MHz()
virtual bool IsStateRx(void)
virtual uint8_t GetNMcs(void) const
virtual double GetTxPowerStart(void) const
virtual WifiMode GetMode(uint32_t mode) const
double m_channelStartingFrequency
Standard-dependent center frequency of 0-th channel, MHz.
void SetEdThreshold(double threshold)
static WifiMode GetOfdmRate135MbpsBW40MHzShGi()
virtual uint8_t GetMcs(uint8_t mcs) const
hold objects of type ns3::Time
virtual void SetGuardInterval(bool GuardInterval)
receive notifications about phy events.
virtual bool GetStbc(void) const
Hold an unsigned integer type.
WifiModeList m_deviceRateSet
static WifiMode GetErpOfdmRate48Mbps()
double m_ccaMode1ThresholdW
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual void DoDispose(void)
virtual void SetStbc(bool stbc)
static WifiMode GetOfdmRate12MbpsBW10MHz()
virtual uint32_t GetBssMembershipSelector(uint32_t selector) const
std::string GetUniqueName(void) const
double GetRxGain(void) const
Ptr< InterferenceHelper::Event > Add(uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble, Time duration, double rxPower, WifiTxVector txvector)
void NotifyRxBegin(Ptr< const Packet > packet)
static WifiMode GetOfdmRate19_5MbpsBW20MHz()
static WifiMode GetOfdmRate18Mbps()
double GetChannelFrequencyMhz() const
Return current center channel frequency in MHz, see SetChannelNumber()
static WifiMode GetOfdmRate9MbpsBW10MHz()
static WifiMode GetOfdmRate12MbpsBW5MHz()
static WifiMode GetOfdmRate52MbpsBW20MHz()
double WToDbm(double w) const
static WifiMode GetOfdmRate40_5MbpsBW40MHz()
void SetChannel(Ptr< YansWifiChannel > channel)
void SetNTxPower(uint32_t n)
virtual bool IsStateCcaBusy(void)
static WifiMode GetOfdmRate72_2MbpsBW20MHz()
static WifiMode GetOfdmRate65MbpsBW20MHzShGi()
void SetDevice(Ptr< Object > device)
struct InterferenceHelper::SnrPer CalculateSnrPer(Ptr< InterferenceHelper::Event > event)
static WifiMode GetOfdmRate48Mbps()
void NotifyMonitorSniffRx(Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm)
virtual void SetReceiveOkCallback(WifiPhy::RxOkCallback callback)
int64_t AssignStreams(int64_t stream)
double GetCcaMode1Threshold(void) const
static WifiMode GetOfdmRate57_8MbpsBW20MHz()
static WifiMode GetOfdmRate24Mbps()
double GetEdThreshold(void) const
static TypeId GetTypeId(void)
static WifiMode GetOfdmRate13MbpsBW20MHz()
virtual uint32_t GetNumberOfTransmitAntennas(void) const
virtual uint32_t WifiModeToMcs(WifiMode mode)
static WifiMode GetOfdmRate65MbpsBW20MHz()
virtual uint32_t GetNumberOfReceiveAntennas(void) const
static WifiMode GetOfdmRate58_5MbpsBW20MHz()
void SetRxGain(double gain)
static WifiMode GetDsssRate5_5Mbps()
static WifiMode GetOfdmRate2_25MbpsBW5MHz()
std::vector< WifiMode > WifiModeList
static WifiMode GetErpOfdmRate9Mbps()
virtual WifiMode McsToWifiMode(uint8_t mcs)
void SetTxPowerStart(double start)
double RatioToDb(double ratio) const
virtual void SetNumberOfTransmitAntennas(uint32_t tx)
static WifiMode GetOfdmRate15MbpsBW40MHz()
static WifiMode GetOfdmRate121_5MbpsBW40MHz()
#define NS_ASSERT_MSG(condition, message)
static WifiMode GetOfdmRate28_9MbpsBW20MHz()
virtual bool IsStateIdle(void)
void StartReceivePacket(Ptr< Packet > packet, double rxPowerDbm, WifiTxVector txVector, WifiPreamble preamble)
virtual Time GetLastRxStartTime(void) const
virtual double CalculateSnr(WifiMode txMode, double ber) const
virtual bool GetGreenfield(void) const
static WifiMode GetErpOfdmRate6Mbps()
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
static Time CalculateTxDuration(uint32_t size, WifiTxVector txvector, enum WifiPreamble preamble)
uint8_t GetNss(void) const
InterferenceHelper m_interference
static WifiMode GetErpOfdmRate12Mbps()
virtual bool GetGuardInterval(void) const
void NotifyRxEnd(Ptr< const Packet > packet)
void SetMobility(Ptr< Object > mobility)
void SetNoiseFigure(double value)
Time m_channelSwitchDelay
virtual void ConfigureStandard(enum WifiPhyStandard standard)
static WifiMode GetOfdmRate13_5MbpsBW40MHz()
static WifiMode GetOfdmRate30MbpsBW40MHz()
#define NS_LOG_DEBUG(msg)
static WifiMode GetOfdmRate54MbpsBW40MHz()
virtual bool GetLdpc(void) const
std::vector< uint8_t > m_deviceMcsSet
double GetPowerDbm(uint8_t power) const
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range. Both limits are inclusive.
void EndReceive(Ptr< Packet > packet, Ptr< InterferenceHelper::Event > event)
static WifiMode GetOfdmRate90MbpsBW40MHz()
virtual void SetNumberOfReceiveAntennas(uint32_t rx)
static WifiMode GetOfdmRate45MbpsBW40MHz()
uint32_t m_numberOfTransmitters
static WifiMode GetOfdmRate120MbpsBW40MHz()
double GetEdThresholdW(void) const
static WifiMode GetOfdmRate39MbpsBW20MHz()
virtual Ptr< WifiChannel > GetChannel(void) const
static WifiMode GetDsssRate2Mbps()
void SetCcaMode1Threshold(double threshold)
static WifiMode GetOfdmRate6MbpsBW10MHz()
WifiMode GetMode(void) const
void ConfigureHolland(void)
double GetNoiseFigure(void) const
virtual void SetLdpc(bool Ldpc)
void SetTxPowerEnd(double end)
Hold an floating point type.
double GetRxNoiseFigure(void) const
static WifiMode GetOfdmRate24MbpsBW10MHz()
static WifiMode GetOfdmRate13_5MbpsBW5MHz()
virtual double GetTxPowerEnd(void) const
bool IsExpired(void) const
a unique identifier for an interface.
uint32_t m_numberOfReceivers
uint64_t GetDataRate(void) const
virtual void SetChannelBonding(bool channelbonding)
TypeId SetParent(TypeId tid)
static WifiMode GetOfdmRate6Mbps()
static WifiMode GetOfdmRate27MbpsBW40MHz()
virtual void SetFrequency(uint32_t freq)
static WifiMode GetOfdmRate4_5MbpsBW5MHz()
static WifiMode GetOfdmRate14_4MbpsBW20MHz()
void Configure80211_10Mhz(void)
virtual uint32_t GetNTxPower(void) const
void SetRxNoiseFigure(double noiseFigureDb)
static WifiMode GetOfdmRate3MbpsBW10MHz()
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Ptr< Object > GetMobility(void)
Ptr< WifiPhyStateHelper > m_state
NS_LOG_COMPONENT_DEFINE("YansWifiPhy")
static WifiMode GetOfdmRate150MbpsBW40MHz()
virtual void SetGreenfield(bool greenfield)