23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
42 .SetGroupName (
"Wifi")
44 .AddTraceSource (
"State",
45 "The state of the PHY layer",
47 "ns3::WifiPhyStateHelper::StateTracedCallback")
48 .AddTraceSource (
"RxOk",
49 "A packet has been received successfully.",
51 "ns3::WifiPhyStateHelper::RxOkTracedCallback")
52 .AddTraceSource (
"RxError",
53 "A packet has been received unsuccessfully.",
55 "ns3::WifiPhyStateHelper::RxEndErrorTracedCallback")
56 .AddTraceSource (
"Tx",
"Packet transmission is starting.",
58 "ns3::WifiPhyStateHelper::TxTracedCallback")
75 m_previousStateChangeTime (
Seconds (0))
234 listener->NotifyTxStart (duration, txPowerDbm);
244 listener->NotifyRxStart (duration);
254 listener->NotifyRxEndOk ();
264 listener->NotifyRxEndError ();
274 listener->NotifyMaybeCcaBusyStart (duration);
284 listener->NotifySwitchingStart (duration);
294 listener->NotifySleep ();
304 listener->NotifyOff ();
314 listener->NotifyWakeup ();
324 listener->NotifyOn ();
348 Time ccaBusyDuration = idleStart - ccaBusyStart;
349 if (ccaBusyDuration.IsStrictlyPositive ())
354 Time idleDuration = now - idleStart;
365 NS_LOG_FUNCTION (
this << txDuration << psdus << txPowerDbm << txVector);
368 for (
auto const& psdu : psdus)
461 std::vector<bool> statusPerMpdu;
471 NS_LOG_FUNCTION (
this << *psdu << rxSignalInfo << txVector << staId << statusPerMpdu.size () <<
472 std::all_of(statusPerMpdu.begin(), statusPerMpdu.end(), [](
bool v) { return v; }));
bool IsNull(void) const
Check for null implementation.
A base class which provides memory management and object aggregation.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
bool IsStrictlyPositive(void) 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.
bool IsStateSleep(void) const
Check whether the current state is SLEEP.
void SwitchToRx(Time rxDuration)
Switch state to RX for the given duration.
bool IsStateCcaBusy(void) const
Check whether the current state is CCA busy.
void SwitchFromSleep(void)
Switch from sleep mode.
Time GetLastRxEndTime(void) const
Return the time the last RX end.
void SwitchFromRxEndOk(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, uint16_t staId, std::vector< bool > statusPerMpdu)
Switch from RX after the reception was successful.
Time GetDelayUntilIdle(void) const
Return the time before the state is back to IDLE.
void DoSwitchFromRx(void)
Switch the state from RX.
Time GetLastRxStartTime(void) const
Return the time the last RX start.
Time m_startSleep
start sleep
WifiPhyState GetState(void) const
Return the current state of WifiPhy.
Time m_endCcaBusy
end CCA busy
Time m_startRx
start receive
bool IsStateOff(void) const
Check whether the current state is OFF.
bool IsStateTx(void) const
Check whether the current state is TX.
void NotifyOn(void)
Notify all WifiPhyListener that we are going to switch on.
bool IsStateRx(void) const
Check whether the current state is RX.
void NotifySwitchingStart(Time duration)
Notify all WifiPhyListener that we are switching channel with the given channel switching delay.
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 NotifyRxEndOk(void)
Notify all WifiPhyListener that the reception was successful.
void SwitchFromOff(void)
Switch from off mode.
TracedCallback< Ptr< const Packet >, WifiMode, WifiPreamble, uint8_t > m_txTrace
transmit trace callback
Time m_endSwitching
end switching
Time m_startSwitching
start switching
TracedCallback< Time, Time, WifiPhyState > m_stateLogger
The trace source fired when state is changed.
void LogPreviousIdleAndCcaBusyStates(void)
Log the idle and CCA busy states.
void RegisterListener(WifiPhyListener *listener)
Register WifiPhyListener to this WifiPhyStateHelper.
void ContinueRxNextMpdu(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector)
Continue RX after the reception of an MPDU in an A-MPDU was successful.
void SwitchToTx(Time txDuration, WifiConstPsduMap psdus, double txPowerDbm, WifiTxVector txVector)
Switch state to TX for the given duration.
RxOkCallback m_rxOkCallback
receive OK callback
void SwitchFromRxAbort(void)
Abort current reception.
TracedCallback< Ptr< const Packet >, double, WifiMode, WifiPreamble > m_rxOkTrace
receive OK trace callback
Time m_startTx
start transmit
bool IsStateSwitching(void) const
Check whether the current state is SWITCHING.
RxErrorCallback m_rxErrorCallback
receive error callback
void NotifyOff(void)
Notify all WifiPhyListener that we are going to switch off.
TracedCallback< Ptr< const Packet >, double > m_rxErrorTrace
receive error trace callback
Time m_startCcaBusy
start CCA busy
void NotifyTxStart(Time duration, double txPowerDbm)
Notify all WifiPhyListener that the transmission has started for the given duration.
Listeners m_listeners
listeners
static TypeId GetTypeId(void)
Get the type ID.
void SwitchToOff(void)
Switch to off mode.
void SwitchFromRxEndError(Ptr< WifiPsdu > psdu, double snr)
Switch from RX after the reception failed.
void SetReceiveOkCallback(RxOkCallback callback)
Set a callback for a successful reception.
void SwitchMaybeToCcaBusy(Time duration)
Switch to CCA busy.
void SwitchToSleep(void)
Switch to sleep mode.
bool IsStateIdle(void) const
Check whether the current state is IDLE.
void NotifyRxEndError(void)
Notify all WifiPhyListener that the reception was not successful.
void SetReceiveErrorCallback(RxErrorCallback callback)
Set a callback for a failed reception.
void UnregisterListener(WifiPhyListener *listener)
Remove WifiPhyListener from this WifiPhyStateHelper.
void NotifySleep(void)
Notify all WifiPhyListener that we are going to sleep.
void NotifyWakeup(void)
Notify all WifiPhyListener that we woke up.
void NotifyMaybeCcaBusyStart(Time duration)
Notify all WifiPhyListener that the CCA has started for the given duration.
Ptr< const Packet > GetPacket(void) const
Get the PSDU as a single packet.
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.
uint8_t GetTxPowerLevel(void) const
WifiPreamble GetPreambleType(void) 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.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
int64x64_t Abs(const int64x64_t &value)
Absolute value.
#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 MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
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.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ SWITCHING
The PHY layer is switching to other channel.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ OFF
The PHY layer is switched off.
@ SLEEP
The PHY layer is sleeping.
@ IDLE
The PHY layer is IDLE.