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>, He Wu <mdzz@u.washington.edu>
19  */
20 
21 #ifndef WIFI_RADIO_ENERGY_MODEL_H
22 #define WIFI_RADIO_ENERGY_MODEL_H
23 
24 #include "ns3/device-energy-model.h"
25 #include "ns3/nstime.h"
26 #include "ns3/event-id.h"
27 #include "ns3/traced-value.h"
28 #include "ns3/wifi-phy.h"
29 
30 namespace ns3 {
31 
32 class WifiTxCurrentModel;
33 
41 {
42 public:
47 
50 
57 
63  void SetUpdateTxCurrentCallback (UpdateTxCurrentCallback callback);
64 
72  virtual void NotifyRxStart (Time duration);
73 
82  virtual void NotifyRxEndOk (void);
83 
92  virtual void NotifyRxEndError (void);
93 
103  virtual void NotifyTxStart (Time duration, double txPowerDbm);
104 
110  virtual void NotifyMaybeCcaBusyStart (Time duration);
111 
117  virtual void NotifySwitchingStart (Time duration);
118 
122  virtual void NotifySleep (void);
123 
127  virtual void NotifyWakeup (void);
128 
129 private:
133  void SwitchToIdle (void);
134 
135 private:
141 
146  UpdateTxCurrentCallback m_updateTxCurrentCallback;
147 
149 };
150 
151 // -------------------------------------------------------------------------- //
152 
203 {
204 public:
209 
214 
215 public:
216  static TypeId GetTypeId (void);
218  virtual ~WifiRadioEnergyModel ();
219 
227  virtual void SetEnergySource (Ptr<EnergySource> source);
228 
234  virtual double GetTotalEnergyConsumption (void) const;
235 
236  // Setter & getters for state power consumption.
237  double GetIdleCurrentA (void) const;
238  void SetIdleCurrentA (double idleCurrentA);
239  double GetCcaBusyCurrentA (void) const;
240  void SetCcaBusyCurrentA (double ccaBusyCurrentA);
241  double GetTxCurrentA (void) const;
242  void SetTxCurrentA (double txCurrentA);
243  double GetRxCurrentA (void) const;
244  void SetRxCurrentA (double rxCurrentA);
245  double GetSwitchingCurrentA (void) const;
246  void SetSwitchingCurrentA (double switchingCurrentA);
247  double GetSleepCurrentA (void) const;
248  void SetSleepCurrentA (double sleepCurrentA);
249 
253  WifiPhy::State GetCurrentState (void) const;
254 
260  void SetEnergyDepletionCallback (WifiRadioEnergyDepletionCallback callback);
261 
267  void SetEnergyRechargedCallback (WifiRadioEnergyRechargedCallback callback);
268 
273 
280  void SetTxCurrentFromModel (double txPowerDbm);
281 
289  virtual void ChangeState (int newState);
290 
296  virtual void HandleEnergyDepletion (void);
297 
303  virtual void HandleEnergyRecharged (void);
304 
309 
310 
311 private:
312  void DoDispose (void);
313 
319  virtual double DoGetCurrentA (void) const;
320 
327  void SetWifiRadioState (const WifiPhy::State state);
328 
329 private:
331 
332  // Member variables for current draw in different radio modes.
333  double m_txCurrentA;
334  double m_rxCurrentA;
340 
341  // This variable keeps track of the total energy consumed by this model.
343 
344  // State variables.
345  WifiPhy::State m_currentState; // current state the radio is in
346  Time m_lastUpdateTime; // time stamp of previous energy update
347 
350 
351  // Energy depletion callback
352  WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
353 
354  // Energy recharged callback
355  WifiRadioEnergyRechargedCallback m_energyRechargedCallback;
356 
357  // WifiPhy listener
359 };
360 
361 } // namespace ns3
362 
363 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
void SetWifiRadioState(const WifiPhy::State state)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void HandleEnergyRecharged(void)
Handles energy recharged.
TracedValue< double > m_totalEnergyConsumption
Base class for device energy models.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in WifiRadioEnergyModel based on the nominal tx power u...
virtual void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
WifiRadioEnergyModelPhyListener * m_listener
void SetSleepCurrentA(double sleepCurrentA)
virtual 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)
virtual 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)
double GetCcaBusyCurrentA(void) const
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
Ptr< WifiTxCurrentModel > m_txCurrentModel
virtual void NotifySwitchingStart(Time duration)
receive notifications about phy events.
Definition: wifi-phy.h:81
virtual void NotifyMaybeCcaBusyStart(Time duration)
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)
virtual void NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
WifiPhy::State GetCurrentState(void) const
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
virtual void NotifyTxStart(Time duration, double txPowerDbm)
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
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.
virtual void NotifyWakeup(void)
Defined in ns3::WifiPhyListener.
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
void SetTxCurrentA(double txCurrentA)
virtual void NotifySleep(void)
Defined in ns3::WifiPhyListener.
A WiFi radio energy model.
virtual void NotifyRxStart(Time duration)
Switches the WifiRadioEnergyModel to RX state.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
An identifier for simulation events.
Definition: event-id.h:53
void DoDispose(void)
Destructor implementation.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
void SetSwitchingCurrentA(double switchingCurrentA)
virtual double DoGetCurrentA(void) const
State
The state of the PHY layer.
Definition: wifi-phy.h:168
a unique identifier for an interface.
Definition: type-id.h:58
void SetIdleCurrentA(double idleCurrentA)
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
double GetSwitchingCurrentA(void) const
virtual void HandleEnergyDepletion(void)
Handles energy depletion.
void SetTxCurrentModel(Ptr< WifiTxCurrentModel > model)