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 #ifndef WIFI_PHY_STATE_HELPER_H
21 #define WIFI_PHY_STATE_HELPER_H
22 
23 #include "wifi-phy.h"
24 #include "ns3/traced-callback.h"
25 #include "ns3/object.h"
26 #include <vector>
27 
28 namespace ns3 {
29 
35 class WifiPhyStateHelper : public Object
36 {
37 public:
38  static TypeId GetTypeId (void);
39 
41 
59  void RegisterListener (WifiPhyListener *listener);
65  void UnregisterListener (WifiPhyListener *listener);
71  enum WifiPhy::State GetState (void);
77  bool IsStateCcaBusy (void);
83  bool IsStateIdle (void);
89  bool IsStateBusy (void);
95  bool IsStateRx (void);
101  bool IsStateTx (void);
107  bool IsStateSwitching (void);
113  bool IsStateSleep (void);
119  Time GetStateDuration (void);
125  Time GetDelayUntilIdle (void);
131  Time GetLastRxStartTime (void) const;
132 
142  void SwitchToTx (Time txDuration, Ptr<const Packet> packet, double txPowerDbm, WifiTxVector txVector, WifiPreamble preamble);
148  void SwitchToRx (Time rxDuration);
154  void SwitchToChannelSwitching (Time switchingDuration);
163  void SwitchFromRxEndOk (Ptr<Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble);
170  void SwitchFromRxEndError (Ptr<const Packet> packet, double snr);
176  void SwitchMaybeToCcaBusy (Time duration);
180  void SwitchToSleep (void);
186  void SwitchFromSleep (Time duration);
187 
190 
199  typedef void (* StateTracedCallback)
200  (const Time start, const Time duration, const WifiPhy::State state);
201 
210  typedef void (* RxOkTracedCallback)
211  (const Ptr<const Packet> packet, const double snr,
212  const WifiMode mode, const WifiPreamble preamble);
213 
220  typedef void (* RxEndErrorTracedCallback)
221  (const Ptr<const Packet> packet, const double snr);
222 
231  typedef void (* TxTracedCallback)
232  (const Ptr<const Packet> packet, const WifiMode mode,
233  const WifiPreamble preamble, const uint8_t power);
234 
235 
236 private:
240  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 
295  bool m_rxing;
307 
308  Listeners m_listeners;
314 };
315 
316 } // namespace ns3
317 
318 #endif /* WIFI_PHY_STATE_HELPER_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
void DoSwitchFromRx(void)
Switch the state from RX.
Time GetStateDuration(void)
Return the elapsed time of the current state.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
TracedCallback< Time, Time, enum WifiPhy::State > m_stateLogger
void NotifyWakeup(void)
Notify all WifiPhyListener that we woke up.
def start()
Definition: core.py:1482
Forward calls to a chain of Callback.
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.
std::vector< WifiPhyListener * >::iterator ListenersI
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:93
void(* RxOkTracedCallback)(const Ptr< const Packet > packet, const double snr, const WifiMode mode, const WifiPreamble preamble)
TracedCallback signature for receive end ok event.
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:29
bool IsStateIdle(void)
Check whether the current state is IDLE.
Time GetDelayUntilIdle(void)
Return the time before the state is back to IDLE.
void NotifySleep(void)
Notify all WifiPhyListener that we are going to sleep.
TracedCallback< Ptr< const Packet >, double, WifiMode, enum WifiPreamble > m_rxOkTrace
void(* StateTracedCallback)(const Time start, const Time duration, const WifiPhy::State state)
TracedCallback signature for state changes.
bool IsStateSwitching(void)
Check whether the current state is SWITCHING.
receive notifications about phy events.
Definition: wifi-phy.h:44
void NotifySwitchingStart(Time duration)
Notify all WifiPhyListener that we are switching channel with the given channel switching delay...
bool IsStateRx(void)
Check whether the current state is RX.
void SetReceiveErrorCallback(WifiPhy::RxErrorCallback callback)
Set a callback for a failed reception.
bool IsStateSleep(void)
Check whether the current state is SLEEP.
void NotifyMaybeCcaBusyStart(Time duration)
Notify all WifiPhyListener that the CCA has started for the given duration.
WifiPhy::RxErrorCallback m_rxErrorCallback
void SwitchToSleep(void)
Switch to sleep mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SwitchFromRxEndError(Ptr< const Packet > packet, double snr)
Switch from RX after the reception failed.
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 SwitchFromRxEndOk(Ptr< Packet > packet, double snr, WifiMode mode, enum WifiPreamble preamble)
Switch from RX after the reception was successful.
static TypeId GetTypeId(void)
enum WifiPhy::State GetState(void)
Return the current state of WifiPhy.
bool IsStateBusy(void)
Check whether the current state is not IDLE.
This objects implements the PHY state machine of the Wifi device.
bool IsStateCcaBusy(void)
Check whether the current state is CCA busy.
TracedCallback< Ptr< const Packet >, WifiMode, WifiPreamble, uint8_t > m_txTrace
void(* TxTracedCallback)(const Ptr< const Packet > packet, const WifiMode mode, const WifiPreamble preamble, const uint8_t power)
TracedCallback signature for transmit event.
TracedCallback< Ptr< const Packet >, double > m_rxErrorTrace
void(* RxEndErrorTracedCallback)(const Ptr< const Packet > packet, const double snr)
TracedCallback signature for receive end error event.
bool IsStateTx(void)
Check whether the current state is TX.
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.
State
The state of the PHY layer.
Definition: wifi-phy.h:132
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:51
void RegisterListener(WifiPhyListener *listener)
Register WifiPhyListener to this WifiPhyStateHelper.
void SwitchMaybeToCcaBusy(Time duration)
Switch to CCA busy.
void SwitchToTx(Time txDuration, Ptr< const Packet > packet, double txPowerDbm, WifiTxVector txVector, WifiPreamble preamble)
Switch state to TX for the given duration.
WifiPhy::RxOkCallback m_rxOkCallback