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/traced-callback.h"
26 #include "ns3/object.h"
27 #include <vector>
28 
29 namespace ns3 {
30 
36 class WifiPhyStateHelper : public Object
37 {
38 public:
39  static TypeId GetTypeId (void);
40 
42 
60  void RegisterListener (WifiPhyListener *listener);
66  void UnregisterListener (WifiPhyListener *listener);
72  enum WifiPhy::State GetState (void);
78  bool IsStateCcaBusy (void);
84  bool IsStateIdle (void);
90  bool IsStateBusy (void);
96  bool IsStateRx (void);
102  bool IsStateTx (void);
108  bool IsStateSwitching (void);
114  bool IsStateSleep (void);
120  Time GetStateDuration (void);
126  Time GetDelayUntilIdle (void);
132  Time GetLastRxStartTime (void) const;
133 
143  void SwitchToTx (Time txDuration, Ptr<const Packet> packet, double txPowerDbm, WifiTxVector txVector, WifiPreamble preamble);
149  void SwitchToRx (Time rxDuration);
155  void SwitchToChannelSwitching (Time switchingDuration);
164  void SwitchFromRxEndOk (Ptr<Packet> packet, double snr, WifiTxVector txVector, enum WifiPreamble preamble);
172  void SwitchFromRxEndError (Ptr<Packet> packet, double snr, bool isEndOfFrame);
178  void SwitchMaybeToCcaBusy (Time duration);
182  void SwitchToSleep (void);
188  void SwitchFromSleep (Time duration);
189 
192 
201  typedef void (* StateTracedCallback)
202  (Time start, Time duration, WifiPhy::State state);
203 
212  typedef void (* RxOkTracedCallback)
213  (Ptr<const Packet> packet, double snr, WifiMode mode, WifiPreamble preamble);
214 
222  typedef void (* RxEndErrorTracedCallback)
223  (Ptr<const Packet> packet, double snr, bool isEndOfFrame);
224 
233  typedef void (* TxTracedCallback)
235  WifiPreamble preamble, uint8_t power);
236 
237 
238 private:
242  typedef std::vector<WifiPhyListener *> Listeners;
243  typedef std::vector<WifiPhyListener *>::iterator ListenersI;
244 
249 
256  void NotifyTxStart (Time duration, double txPowerDbm);
262  void NotifyRxStart (Time duration);
266  void NotifyRxEndOk (void);
270  void NotifyRxEndError (void);
276  void NotifyMaybeCcaBusyStart (Time duration);
283  void NotifySwitchingStart (Time duration);
287  void NotifySleep (void);
291  void NotifyWakeup (void);
295  void DoSwitchFromRx (void);
296 
297  bool m_rxing;
309 
310  Listeners m_listeners;
316 };
317 
318 } //namespace ns3
319 
320 #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.
Time GetStateDuration(void)
Return the elapsed time of the current state.
void SwitchFromRxEndOk(Ptr< Packet > packet, double snr, WifiTxVector txVector, enum WifiPreamble preamble)
Switch from RX after the reception was successful.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void NotifyWakeup(void)
Notify all WifiPhyListener that we woke up.
void(* StateTracedCallback)(Time start, Time duration, WifiPhy::State state)
TracedCallback signature for state changes.
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:99
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
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
bool IsStateSwitching(void)
Check whether the current state is 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:70
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.
void(* TxTracedCallback)(Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t power)
TracedCallback signature for transmit event.
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 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.
static TypeId GetTypeId(void)
TracedCallback< Time, Time, enum WifiPhy::State > m_stateLogger
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.
void(* RxEndErrorTracedCallback)(Ptr< const Packet > packet, double snr, bool isEndOfFrame)
TracedCallback signature for receive end error event.
bool IsStateCcaBusy(void)
Check whether the current state is CCA busy.
TracedCallback< Ptr< const Packet >, WifiMode, WifiPreamble, uint8_t > m_txTrace
TracedCallback< Ptr< const Packet >, double > m_rxErrorTrace
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:157
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 SwitchFromRxEndError(Ptr< Packet > packet, double snr, bool isEndOfFrame)
Switch from RX after the reception failed.
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