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 "wifi-phy.h"
25 #include "ns3/object.h"
26 
27 namespace ns3 {
28 
34 class WifiPhyStateHelper : public Object
35 {
36 public:
41  static TypeId GetTypeId (void);
42 
44 
62  void RegisterListener (WifiPhyListener *listener);
68  void UnregisterListener (WifiPhyListener *listener);
74  WifiPhy::State GetState (void) const;
80  bool IsStateCcaBusy (void) const;
86  bool IsStateIdle (void) const;
92  bool IsStateBusy (void) const;
98  bool IsStateRx (void) const;
104  bool IsStateTx (void) const;
110  bool IsStateSwitching (void) const;
116  bool IsStateSleep (void) const;
122  Time GetStateDuration (void) const;
128  Time GetDelayUntilIdle (void) const;
134  Time GetLastRxStartTime (void) const;
135 
144  void SwitchToTx (Time txDuration, Ptr<const Packet> packet, double txPowerDbm, WifiTxVector txVector);
150  void SwitchToRx (Time rxDuration);
156  void SwitchToChannelSwitching (Time switchingDuration);
164  void SwitchFromRxEndOk (Ptr<Packet> packet, double snr, WifiTxVector txVector);
171  void SwitchFromRxEndError (Ptr<Packet> packet, double snr);
177  void SwitchMaybeToCcaBusy (Time duration);
181  void SwitchToSleep (void);
187  void SwitchFromSleep (Time duration);
191  void SwitchFromRxAbort (void);
192 
201  typedef void (* StateTracedCallback)(Time start, Time duration, WifiPhy::State state);
202 
211  typedef void (* RxOkTracedCallback)(Ptr<const Packet> packet, double snr, WifiMode mode, WifiPreamble preamble);
212 
219  typedef void (* RxEndErrorTracedCallback)(Ptr<const Packet> packet, double snr);
220 
229  typedef void (* TxTracedCallback)(Ptr<const Packet> packet, WifiMode mode,
230  WifiPreamble preamble, uint8_t power);
231 
232 
233 private:
237  typedef std::vector<WifiPhyListener *> Listeners;
241  typedef std::vector<WifiPhyListener *>::iterator ListenersI;
242 
247 
254  void NotifyTxStart (Time duration, double txPowerDbm);
260  void NotifyRxStart (Time duration);
264  void NotifyRxEndOk (void);
268  void NotifyRxEndError (void);
274  void NotifyMaybeCcaBusyStart (Time duration);
281  void NotifySwitchingStart (Time duration);
285  void NotifySleep (void);
289  void NotifyWakeup (void);
293  void DoSwitchFromRx (void);
294 
299 
300  bool m_rxing;
301  bool m_sleeping;
312 
313  Listeners m_listeners;
319 };
320 
321 } //namespace ns3
322 
323 #endif /* WIFI_PHY_STATE_HELPER_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void DoSwitchFromRx(void)
Switch the state from RX.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
TracedCallback< Time, Time, WifiPhy::State > m_stateLogger
The trace source fired when state is changed.
void NotifyWakeup(void)
Notify all WifiPhyListener that we woke up.
void(* StateTracedCallback)(Time start, Time duration, WifiPhy::State state)
TracedCallback signature for state changes.
Time m_endCcaBusy
endn CCA busy
def start()
Definition: core.py:1790
Forward calls to a chain of Callback.
Time m_startCcaBusy
start CCA busy
bool IsStateIdle(void) const
Check whether the current state is IDLE.
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
void SetReceiveOkCallback(WifiPhy::RxOkCallback callback)
Set a callback for a successful reception.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
void SwitchFromSleep(Time duration)
Switch from sleep mode.
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:30
void NotifySleep(void)
Notify all WifiPhyListener that we are going to sleep.
Time m_endSwitching
end switching
void(* RxOkTracedCallback)(Ptr< const Packet > packet, double snr, WifiMode mode, WifiPreamble preamble)
TracedCallback signature for receive end ok event.
receive notifications about phy events.
Definition: wifi-phy.h:83
void NotifySwitchingStart(Time duration)
Notify all WifiPhyListener that we are switching channel with the given channel switching delay...
Time GetStateDuration(void) const
Return the elapsed time of the current state.
bool IsStateSleep(void) const
Check whether the current state is SLEEP.
void SwitchFromRxEndError(Ptr< Packet > packet, double snr)
Switch from RX after the reception failed.
Time m_previousStateChangeTime
previous state change time
void SetReceiveErrorCallback(WifiPhy::RxErrorCallback callback)
Set a callback for a failed reception.
void(* TxTracedCallback)(Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t power)
TracedCallback signature for transmit event.
bool IsStateBusy(void) const
Check whether the current state is not IDLE.
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.
WifiPhy::RxErrorCallback m_rxErrorCallback
receive error callback
void SwitchToTx(Time txDuration, Ptr< const Packet > packet, double txPowerDbm, WifiTxVector txVector)
Switch state to TX for the given duration.
void SwitchToSleep(void)
Switch to sleep mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsStateTx(void) const
Check whether the current state is TX.
Time m_startSwitching
start switching
bool IsStateSwitching(void) const
Check whether the current state is SWITCHING.
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.
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.
bool IsStateRx(void) const
Check whether the current state is RX.
void SwitchFromRxEndOk(Ptr< Packet > packet, double snr, WifiTxVector txVector)
Switch from RX after the reception was successful.
WifiPhy::State GetState(void) const
Return the current state of WifiPhy.
Listeners m_listeners
listeners
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.
Time GetLastRxStartTime(void) const
Return the time the last RX start.
bool IsStateCcaBusy(void) const
Check whether the current state is CCA busy.
State
The state of the PHY layer.
Definition: wifi-phy.h:171
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.
Time GetDelayUntilIdle(void) const
Return the time before the state is back to IDLE.
void SwitchMaybeToCcaBusy(Time duration)
Switch to CCA busy.
WifiPhy::RxOkCallback m_rxOkCallback
receive OK callback