A Discrete-Event Network Simulator
API
wifi-radio-energy-model.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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  * Authors: Sidharth Nabar <snabar@uw.edu>
19  * He Wu <mdzz@u.washington.edu>
20  */
21 
22 #ifndef WIFI_RADIO_ENERGY_MODEL_H
23 #define WIFI_RADIO_ENERGY_MODEL_H
24 
25 #include "ns3/device-energy-model.h"
26 #include "ns3/traced-value.h"
27 #include "wifi-phy.h"
28 
29 namespace ns3 {
30 
31 class WifiTxCurrentModel;
32 
40 {
41 public:
46 
49 
56 
62  void SetUpdateTxCurrentCallback (UpdateTxCurrentCallback callback);
63 
71  void NotifyRxStart (Time duration);
72 
81  void NotifyRxEndOk (void);
82 
91  void NotifyRxEndError (void);
92 
102  void NotifyTxStart (Time duration, double txPowerDbm);
103 
109  void NotifyMaybeCcaBusyStart (Time duration);
110 
116  void NotifySwitchingStart (Time duration);
117 
121  void NotifySleep (void);
122 
126  void NotifyOff (void);
127 
131  void NotifyWakeup (void);
132 
136  void NotifyOn (void);
137 
138 
139 private:
143  void SwitchToIdle (void);
144 
150 
155  UpdateTxCurrentCallback m_updateTxCurrentCallback;
156 
158 };
159 
160 
211 {
212 public:
217 
222 
227  static TypeId GetTypeId (void);
229  virtual ~WifiRadioEnergyModel ();
230 
238  void SetEnergySource (const Ptr<EnergySource> source);
239 
245  double GetTotalEnergyConsumption (void) const;
246 
247  // Setter & getters for state power consumption.
253  double GetIdleCurrentA (void) const;
259  void SetIdleCurrentA (double idleCurrentA);
265  double GetCcaBusyCurrentA (void) const;
271  void SetCcaBusyCurrentA (double ccaBusyCurrentA);
277  double GetTxCurrentA (void) const;
283  void SetTxCurrentA (double txCurrentA);
289  double GetRxCurrentA (void) const;
295  void SetRxCurrentA (double rxCurrentA);
301  double GetSwitchingCurrentA (void) const;
307  void SetSwitchingCurrentA (double switchingCurrentA);
313  double GetSleepCurrentA (void) const;
319  void SetSleepCurrentA (double sleepCurrentA);
320 
324  WifiPhyState GetCurrentState (void) const;
325 
331  void SetEnergyDepletionCallback (WifiRadioEnergyDepletionCallback callback);
332 
338  void SetEnergyRechargedCallback (WifiRadioEnergyRechargedCallback callback);
339 
343  void SetTxCurrentModel (const Ptr<WifiTxCurrentModel> model);
344 
351  void SetTxCurrentFromModel (double txPowerDbm);
352 
360  void ChangeState (int newState);
361 
367  Time GetMaximumTimeInState (int state) const;
368 
374  void HandleEnergyDepletion (void);
375 
381  void HandleEnergyRecharged (void);
382 
388  void HandleEnergyChanged (void);
389 
394 
395 
396 private:
397  void DoDispose (void);
398 
404  double DoGetCurrentA (void) const;
405 
412  void SetWifiRadioState (const WifiPhyState state);
413 
415 
416  // Member variables for current draw in different radio modes.
417  double m_txCurrentA;
418  double m_rxCurrentA;
419  double m_idleCurrentA;
424 
427 
428  // State variables.
431 
433 
435  WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
436 
438  WifiRadioEnergyRechargedCallback m_energyRechargedCallback;
439 
442 
444 };
445 
446 } // namespace ns3
447 
448 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
void NotifyOn(void)
Defined in ns3::WifiPhyListener.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
static TypeId GetTypeId(void)
Get the type ID.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void HandleEnergyRecharged(void)
Handles energy recharged.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model.
Base class for device energy models.
double m_rxCurrentA
receive current
void SetWifiRadioState(const WifiPhyState state)
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in WifiRadioEnergyModel based on the nominal tx power u...
double m_ccaBusyCurrentA
CCA busy current.
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
WifiRadioEnergyModelPhyListener * m_listener
WifiPhy listener.
double GetSleepCurrentA(void) const
Gets sleep current.
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current.
double GetTotalEnergyConsumption(void) const
WifiRadioEnergyModelPhyListener * GetPhyListener(void)
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update tx current callback.
void SwitchToIdle(void)
A helper function that makes scheduling m_changeStateCallback possible.
void SetRxCurrentA(double rxCurrentA)
Sets receive current.
void NotifyRxEndOk(void)
Switches the WifiRadioEnergyModel back to IDLE state.
Callback< void > WifiRadioEnergyRechargedCallback
Callback type for energy recharged handling.
Callback< void > WifiRadioEnergyDepletionCallback
Callback type for energy depletion handling.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
Sets CCA busy current.
double GetCcaBusyCurrentA(void) const
Gets CCA busy current.
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double m_sleepCurrentA
sleep current
Ptr< EnergySource > m_source
energy source
receive notifications about phy events.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the tx current model to compute the tx current based on such model...
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
void NotifyOff(void)
Defined in ns3::WifiPhyListener.
void NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
Time m_lastUpdateTime
time stamp of previous energy update
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
EventId m_switchToOffEvent
switch to off event
EventId m_switchToIdleEvent
switch to idle event
void NotifyTxStart(Time duration, double txPowerDbm)
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
Callback< void, double > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal tx power.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
void NotifyWakeup(void)
Defined in ns3::WifiPhyListener.
double GetTxCurrentA(void) const
Gets transmit current.
WifiPhyState m_currentState
current state the radio is in
double GetRxCurrentA(void) const
Gets receive current.
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
void NotifySleep(void)
Defined in ns3::WifiPhyListener.
A WiFi radio energy model.
void NotifyRxStart(Time duration)
Switches the WifiRadioEnergyModel to RX state.
WifiPhyState GetCurrentState(void) const
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
An identifier for simulation events.
Definition: event-id.h:53
void DoDispose(void)
Destructor implementation.
void HandleEnergyChanged(void)
Handles energy changed.
uint8_t m_nPendingChangeState
pending state change
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
double GetIdleCurrentA(void) const
Gets idle current.
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current.
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
double m_switchingCurrentA
switching current
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
Time GetMaximumTimeInState(int state) const
a unique identifier for an interface.
Definition: type-id.h:58
void SetIdleCurrentA(double idleCurrentA)
Sets idle current.
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double GetSwitchingCurrentA(void) const
Gets switching current.
void HandleEnergyDepletion(void)
Handles energy depletion.
double m_txCurrentA
transmit current