28#include "ns3/packet.h"
29#include "ns3/simulator.h"
45 TypeId(
"ns3::WifiPhyStateHelper")
49 .AddTraceSource(
"State",
50 "The state of the PHY layer",
52 "ns3::WifiPhyStateHelper::StateTracedCallback")
53 .AddTraceSource(
"RxOk",
54 "A packet has been received successfully.",
56 "ns3::WifiPhyStateHelper::RxOkTracedCallback")
57 .AddTraceSource(
"RxError",
58 "A packet has been received unsuccessfuly.",
60 "ns3::WifiPhyStateHelper::RxEndErrorTracedCallback")
62 "Packet transmission is starting.",
64 "ns3::WifiPhyStateHelper::TxTracedCallback");
80 m_previousStateChangeTime(
Seconds(0))
116 return (
GetState() == WifiPhyState::IDLE);
122 return (
GetState() == WifiPhyState::CCA_BUSY);
128 return (
GetState() == WifiPhyState::RX);
134 return (
GetState() == WifiPhyState::TX);
140 return (
GetState() == WifiPhyState::SWITCHING);
146 return (
GetState() == WifiPhyState::SLEEP);
152 return (
GetState() == WifiPhyState::OFF);
162 case WifiPhyState::RX:
165 case WifiPhyState::TX:
168 case WifiPhyState::CCA_BUSY:
171 case WifiPhyState::SWITCHING:
174 case WifiPhyState::IDLE:
175 case WifiPhyState::SLEEP:
176 case WifiPhyState::OFF:
205 return WifiPhyState::OFF;
209 return WifiPhyState::SLEEP;
213 return WifiPhyState::TX;
217 return WifiPhyState::RX;
221 return WifiPhyState::SWITCHING;
225 return WifiPhyState::CCA_BUSY;
229 return WifiPhyState::IDLE;
239 listener->NotifyTxStart(duration, txPowerDbm);
249 listener->NotifyRxStart(duration);
259 listener->NotifyRxEndOk();
269 listener->NotifyRxEndError();
276 const std::vector<Time>& per20MhzDurations)
281 listener->NotifyCcaBusyStart(duration, channelType, per20MhzDurations);
291 listener->NotifySwitchingStart(duration);
301 listener->NotifySleep();
311 listener->NotifyOff();
321 listener->NotifyWakeup();
331 listener->NotifyOn();
341 if (state == WifiPhyState::CCA_BUSY)
344 m_stateLogger(ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY);
346 else if (state == WifiPhyState::IDLE)
353 Time ccaBusyDuration = idleStart - ccaBusyStart;
354 if (ccaBusyDuration.IsStrictlyPositive())
356 m_stateLogger(ccaBusyStart, ccaBusyDuration, WifiPhyState::CCA_BUSY);
359 Time idleDuration = now - idleStart;
373 NS_LOG_FUNCTION(
this << txDuration << psdus << txPowerDbm << txVector);
376 for (
const auto& psdu : psdus)
387 case WifiPhyState::RX:
394 case WifiPhyState::CCA_BUSY:
396 case WifiPhyState::IDLE:
418 case WifiPhyState::IDLE:
420 case WifiPhyState::CCA_BUSY:
441 case WifiPhyState::RX:
448 case WifiPhyState::CCA_BUSY:
450 case WifiPhyState::IDLE:
459 m_stateLogger(now, switchingDuration, WifiPhyState::SWITCHING);
484 const std::vector<bool>& statusPerMpdu)
486 NS_LOG_FUNCTION(
this << *psdu << rxSignalInfo << txVector << staId << statusPerMpdu.size()
487 << std::all_of(statusPerMpdu.begin(), statusPerMpdu.end(), [](
bool v) {
550 const std::vector<Time>& per20MhzDurations)
564 if (
GetState() == WifiPhyState::IDLE)
568 if (
GetState() != WifiPhyState::CCA_BUSY)
582 case WifiPhyState::IDLE:
584 case WifiPhyState::CCA_BUSY:
619 std::vector<Time> per20MhzDurations;
620 if (operatingWidth >= 40)
622 std::fill_n(std::back_inserter(per20MhzDurations), (operatingWidth / 20),
Seconds(0));
635 case WifiPhyState::RX:
642 case WifiPhyState::TX:
649 case WifiPhyState::IDLE:
651 case WifiPhyState::CCA_BUSY:
bool IsNull() const
Check for null implementation.
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
bool IsZero() const
Exactly equivalent to t == 0.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
receive notifications about PHY events.
This objects implements the PHY state machine of the Wifi device.
void NotifyRxEndOk()
Notify all WifiPhyListener that the reception was successful.
bool IsStateSwitching() const
Check whether the current state is SWITCHING.
void SwitchToRx(Time rxDuration)
Switch state to RX for the given duration.
void NotifyOn()
Notify all WifiPhyListener that we are going to switch on.
bool IsStateCcaBusy() const
Check whether the current state is CCA busy.
Time m_startSleep
start sleep
Time GetDelayUntilIdle() const
Return the time before the state is back to IDLE.
bool IsStateIdle() const
Check whether the current state is IDLE.
Time GetLastRxStartTime() const
Return the time the last RX start.
Time m_endCcaBusy
end CCA busy
Time m_startRx
start receive
void DoSwitchFromRx()
Switch the state from RX.
void NotifyRxEndError()
Notify all WifiPhyListener that the reception was not successful.
void NotifySwitchingStart(Time duration)
Notify all WifiPhyListener that we are switching channel with the given channel switching delay.
void SwitchFromRxEndOk()
Switch from RX after the reception was successful.
Time m_previousStateChangeTime
previous state change time
void NotifyRxStart(Time duration)
Notify all WifiPhyListener that the reception has started for the given duration.
void SwitchToChannelSwitching(Time switchingDuration)
Switch state to channel switching for the given duration.
void SwitchToOff()
Switch to off mode.
void NotifyRxMpdu(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector)
Notify the reception of an MPDU included in an A-MPDU.
TracedCallback< Ptr< const Packet >, WifiMode, WifiPreamble, uint8_t > m_txTrace
transmit trace callback
Time m_endSwitching
end switching
void SwitchToTx(Time txDuration, WifiConstPsduMap psdus, double txPowerDbm, const WifiTxVector &txVector)
Switch state to TX for the given duration.
Time m_startSwitching
start switching
TracedCallback< Time, Time, WifiPhyState > m_stateLogger
The trace source fired when state is changed.
void LogPreviousIdleAndCcaBusyStates()
Log the idle and CCA busy states.
void NotifySleep()
Notify all WifiPhyListener that we are going to sleep.
void RegisterListener(WifiPhyListener *listener)
Register WifiPhyListener to this WifiPhyStateHelper.
void NotifyCcaBusyStart(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations)
Notify all WifiPhyListener that the CCA has started for the given duration.
static TypeId GetTypeId()
Get the type ID.
RxOkCallback m_rxOkCallback
receive OK callback
TracedCallback< Ptr< const Packet >, double, WifiMode, WifiPreamble > m_rxOkTrace
receive OK trace callback
void NotifyRxPsduFailed(Ptr< const WifiPsdu > psdu, double snr)
Handle the unsuccessful reception of a PSDU.
Time m_startTx
start transmit
bool IsStateOff() const
Check whether the current state is OFF.
void SwitchFromRxAbort(uint16_t operatingWidth)
Abort current reception following a CCA reset request.
WifiPhyState GetState() const
Return the current state of WifiPhy.
RxErrorCallback m_rxErrorCallback
receive error callback
void SwitchToSleep()
Switch to sleep mode.
void SwitchMaybeToCcaBusy(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations)
Switch to CCA busy.
TracedCallback< Ptr< const Packet >, double > m_rxErrorTrace
receive error trace callback
void NotifyOff()
Notify all WifiPhyListener that we are going to switch off.
bool IsStateTx() const
Check whether the current state is TX.
void SwitchFromOff()
Switch from off mode.
Time m_startCcaBusy
start CCA busy
void NotifyWakeup()
Notify all WifiPhyListener that we woke up.
void NotifyTxStart(Time duration, double txPowerDbm)
Notify all WifiPhyListener that the transmission has started for the given duration.
Listeners m_listeners
listeners
Time GetLastRxEndTime() const
Return the time the last RX end.
void SwitchFromRxEndError()
Switch from RX after the reception failed.
void SetReceiveOkCallback(RxOkCallback callback)
Set a callback for a successful reception.
void SwitchFromSleep()
Switch from sleep mode.
bool IsStateSleep() const
Check whether the current state is SLEEP.
bool IsStateRx() const
Check whether the current state is RX.
void SetReceiveErrorCallback(RxErrorCallback callback)
Set a callback for a failed reception.
void UnregisterListener(WifiPhyListener *listener)
Remove WifiPhyListener from this WifiPhyStateHelper.
void NotifyRxPsduSucceeded(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, uint16_t staId, const std::vector< bool > &statusPerMpdu)
Handle the successful reception of a PSDU.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
WifiPreamble GetPreambleType() const
uint8_t GetTxPowerLevel() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
RxSignalInfo structure containing info on the received signal.
double snr
SNR in linear scale.
WifiPhyState
The state of the PHY layer.