A Discrete-Event Network Simulator
API
wifi-phy-state-helper.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef WIFI_PHY_STATE_HELPER_H
22 #define WIFI_PHY_STATE_HELPER_H
23 
24 #include "ns3/object.h"
25 #include "ns3/callback.h"
26 #include "ns3/traced-callback.h"
27 #include "ns3/nstime.h"
28 #include "wifi-phy-state.h"
29 #include "wifi-preamble.h"
30 #include "wifi-ppdu.h"
31 
32 namespace ns3 {
33 
34 class WifiPhyListener;
35 class WifiTxVector;
36 class WifiMode;
37 class Packet;
38 class WifiPsdu;
39 
50 typedef Callback<void, Ptr<WifiPsdu>, double, WifiTxVector, std::vector<bool>> RxOkCallback;
57 
63 class WifiPhyStateHelper : public Object
64 {
65 public:
70  static TypeId GetTypeId (void);
71 
73 
79  void SetReceiveOkCallback (RxOkCallback callback);
91  void RegisterListener (WifiPhyListener *listener);
97  void UnregisterListener (WifiPhyListener *listener);
103  WifiPhyState GetState (void) const;
109  bool IsStateCcaBusy (void) const;
115  bool IsStateIdle (void) const;
121  bool IsStateRx (void) const;
127  bool IsStateTx (void) const;
133  bool IsStateSwitching (void) const;
139  bool IsStateSleep (void) const;
145  bool IsStateOff (void) const;
151  Time GetDelayUntilIdle (void) const;
157  Time GetLastRxStartTime (void) const;
163  Time GetLastRxEndTime (void) const;
164 
173  void SwitchToTx (Time txDuration, WifiConstPsduMap psdus, double txPowerDbm, WifiTxVector txVector);
179  void SwitchToRx (Time rxDuration);
185  void SwitchToChannelSwitching (Time switchingDuration);
193  void ContinueRxNextMpdu (Ptr<WifiPsdu> psdu, double snr, WifiTxVector txVector);
203  void SwitchFromRxEndOk (Ptr<WifiPsdu> psdu, double snr, WifiTxVector txVector, uint16_t staId, std::vector<bool> statusPerMpdu);
210  void SwitchFromRxEndError (Ptr<WifiPsdu> psdu, double snr);
216  void SwitchMaybeToCcaBusy (Time duration);
220  void SwitchToSleep (void);
226  void SwitchFromSleep (Time duration);
230  void SwitchFromRxAbort (void);
234  void SwitchToOff (void);
240  void SwitchFromOff (Time duration);
241 
250  typedef void (* StateTracedCallback)(Time start, Time duration, WifiPhyState state);
251 
260  typedef void (* RxOkTracedCallback)(Ptr<const Packet> packet, double snr, WifiMode mode, WifiPreamble preamble);
261 
268  typedef void (* RxEndErrorTracedCallback)(Ptr<const Packet> packet, double snr);
269 
278  typedef void (* TxTracedCallback)(Ptr<const Packet> packet, WifiMode mode,
279  WifiPreamble preamble, uint8_t power);
280 
281 
282 private:
286  typedef std::vector<WifiPhyListener *> Listeners;
290  typedef std::vector<WifiPhyListener *>::iterator ListenersI;
291 
296 
303  void NotifyTxStart (Time duration, double txPowerDbm);
309  void NotifyRxStart (Time duration);
313  void NotifyRxEndOk (void);
317  void NotifyRxEndError (void);
323  void NotifyMaybeCcaBusyStart (Time duration);
330  void NotifySwitchingStart (Time duration);
334  void NotifySleep (void);
338  void NotifyOff (void);
342  void NotifyWakeup (void);
346  void DoSwitchFromRx (void);
350  void NotifyOn (void);
351 
356 
357  bool m_sleeping;
358  bool m_isOff;
369 
376 };
377 
378 } //namespace ns3
379 
380 #endif /* WIFI_PHY_STATE_HELPER_H */
bool IsStateIdle(void) const
Check whether the current state is IDLE.
Time GetLastRxStartTime(void) const
Return the time the last RX start.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void ContinueRxNextMpdu(Ptr< WifiPsdu > psdu, double snr, WifiTxVector txVector)
Continue RX after the reception of an MPDU in an A-MPDU was successful.
void DoSwitchFromRx(void)
Switch the state from RX.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1278
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
TracedCallback< Time, Time, WifiPhyState > m_stateLogger
The trace source fired when state is changed.
void NotifyWakeup(void)
Notify all WifiPhyListener that we woke up.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Definition: wifi-ppdu.h:33
def start()
Definition: core.py:1855
Forward calls to a chain of Callback.
void(* StateTracedCallback)(Time start, Time duration, WifiPhyState state)
TracedCallback signature for state changes.
Time m_startCcaBusy
start CCA busy
void SwitchToOff(void)
Switch to off mode.
void SwitchToChannelSwitching(Time switchingDuration)
Switch state to channel switching for the given duration.
void UnregisterListener(WifiPhyListener *listener)
Remove WifiPhyListener from this WifiPhyStateHelper.
void NotifyRxEndError(void)
Notify all WifiPhyListener that the reception was not successful.
void SwitchFromRxAbort(void)
Abort current reception.
std::vector< WifiPhyListener * >::iterator ListenersI
typedef for a list of WifiPhyListeners iterator
bool IsStateRx(void) const
Check whether the current state is RX.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
bool IsStateSwitching(void) const
Check whether the current state is SWITCHING.
void SwitchFromSleep(Time duration)
Switch from sleep mode.
Time GetDelayUntilIdle(void) const
Return the time before the state is back to IDLE.
Callback< void, Ptr< WifiPsdu >, double, WifiTxVector, std::vector< bool > > RxOkCallback
Callback if PSDU successfully received (i.e.
std::vector< WifiPhyListener * > Listeners
typedef for a list of WifiPhyListeners
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:32
void NotifySleep(void)
Notify all WifiPhyListener that we are going to sleep.
Time m_endSwitching
end switching
bool IsStateSleep(void) const
Check whether the current state is SLEEP.
void NotifyOn(void)
Notify all WifiPhyListener that we are going to switch on.
void(* RxOkTracedCallback)(Ptr< const Packet > packet, double snr, WifiMode mode, WifiPreamble preamble)
TracedCallback signature for receive end OK event.
receive notifications about PHY events.
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(* TxTracedCallback)(Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t power)
TracedCallback signature for transmit event.
TracedCallback< Ptr< const Packet >, double, WifiMode, WifiPreamble > m_rxOkTrace
receive OK trace callback
void NotifyMaybeCcaBusyStart(Time duration)
Notify all WifiPhyListener that the CCA has started for the given duration.
Time GetLastRxEndTime(void) const
Return the time the last RX end.
RxErrorCallback m_rxErrorCallback
receive error callback
bool IsStateTx(void) const
Check whether the current state is TX.
WifiPsdu stores an MPDU, S-MPDU or A-MPDU, by keeping header(s) and payload(s) separate for each cons...
Definition: wifi-psdu.h:40
void SwitchToSleep(void)
Switch to sleep mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
Time m_startSwitching
start switching
void SetReceiveOkCallback(RxOkCallback callback)
Set a callback for a successful reception.
Time m_startTx
start transmit
void NotifyTxStart(Time duration, double txPowerDbm)
Notify all WifiPhyListener that the transmission has started for the given duration.
void NotifyRxEndOk(void)
Notify all WifiPhyListener that the reception was successful.
void SwitchFromRxEndError(Ptr< WifiPsdu > psdu, double snr)
Switch from RX after the reception failed.
TracedCallback< Ptr< const Packet >, WifiMode, WifiPreamble, uint8_t > m_txTrace
transmit trace callback
static TypeId GetTypeId(void)
Get the type ID.
This objects implements the PHY state machine of the Wifi device.
WifiPhyState GetState(void) const
Return the current state of WifiPhy.
void SwitchFromOff(Time duration)
Switch from off mode.
void SwitchToTx(Time txDuration, WifiConstPsduMap psdus, double txPowerDbm, WifiTxVector txVector)
Switch state to TX for the given duration.
Listeners m_listeners
listeners
void SwitchFromRxEndOk(Ptr< WifiPsdu > psdu, double snr, WifiTxVector txVector, uint16_t staId, std::vector< bool > statusPerMpdu)
Switch from RX after the reception was successful.
Callback< void, Ptr< WifiPsdu > > RxErrorCallback
Callback if PSDU unsuccessfully received.
bool IsStateOff(void) const
Check whether the current state is OFF.
void SetReceiveErrorCallback(RxErrorCallback callback)
Set a callback for a failed reception.
void(* RxEndErrorTracedCallback)(Ptr< const Packet > packet, double snr)
TracedCallback signature for receive end error event.
TracedCallback< Ptr< const Packet >, double > m_rxErrorTrace
receive error trace callback
A base class which provides memory management and object aggregation.
Definition: object.h:87
void SwitchToRx(Time rxDuration)
Switch state to RX for the given duration.
void LogPreviousIdleAndCcaBusyStates(void)
Log the ideal and CCA states.
void NotifyRxStart(Time duration)
Notify all WifiPhyListener that the reception has started for the given duration. ...
a unique identifier for an interface.
Definition: type-id.h:58
void RegisterListener(WifiPhyListener *listener)
Register WifiPhyListener to this WifiPhyStateHelper.
void SwitchMaybeToCcaBusy(Time duration)
Switch to CCA busy.
RxOkCallback m_rxOkCallback
receive OK callback
void NotifyOff(void)
Notify all WifiPhyListener that we are going to switch off.
bool IsStateCcaBusy(void) const
Check whether the current state is CCA busy.