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 NotifyWakeup (void);
127 
128 
129 private:
133  void SwitchToIdle (void);
134 
140 
145  UpdateTxCurrentCallback m_updateTxCurrentCallback;
146 
148 };
149 
150 
201 {
202 public:
207 
212 
217  static TypeId GetTypeId (void);
219  virtual ~WifiRadioEnergyModel ();
220 
228  void SetEnergySource (const Ptr<EnergySource> source);
229 
235  double GetTotalEnergyConsumption (void) const;
236 
237  // Setter & getters for state power consumption.
243  double GetIdleCurrentA (void) const;
249  void SetIdleCurrentA (double idleCurrentA);
255  double GetCcaBusyCurrentA (void) const;
261  void SetCcaBusyCurrentA (double ccaBusyCurrentA);
267  double GetTxCurrentA (void) const;
273  void SetTxCurrentA (double txCurrentA);
279  double GetRxCurrentA (void) const;
285  void SetRxCurrentA (double rxCurrentA);
291  double GetSwitchingCurrentA (void) const;
297  void SetSwitchingCurrentA (double switchingCurrentA);
303  double GetSleepCurrentA (void) const;
309  void SetSleepCurrentA (double sleepCurrentA);
310 
314  WifiPhy::State GetCurrentState (void) const;
315 
321  void SetEnergyDepletionCallback (WifiRadioEnergyDepletionCallback callback);
322 
328  void SetEnergyRechargedCallback (WifiRadioEnergyRechargedCallback callback);
329 
333  void SetTxCurrentModel (const Ptr<WifiTxCurrentModel> model);
334 
341  void SetTxCurrentFromModel (double txPowerDbm);
342 
350  void ChangeState (int newState);
351 
357  void HandleEnergyDepletion (void);
358 
364  void HandleEnergyRecharged (void);
365 
370 
371 
372 private:
373  void DoDispose (void);
374 
380  double DoGetCurrentA (void) const;
381 
388  void SetWifiRadioState (const WifiPhy::State state);
389 
391 
392  // Member variables for current draw in different radio modes.
393  double m_txCurrentA;
394  double m_rxCurrentA;
395  double m_idleCurrentA;
400 
403 
404  // State variables.
407 
410 
412  WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
413 
415  WifiRadioEnergyRechargedCallback m_energyRechargedCallback;
416 
419 };
420 
421 } // namespace ns3
422 
423 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
void SetWifiRadioState(const WifiPhy::State state)
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
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.
WifiPhy::State m_currentState
current state the radio is in
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double m_sleepCurrentA
sleep current
Ptr< EnergySource > m_source
energy source
receive notifications about phy events.
Definition: wifi-phy.h:83
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 NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
Time m_lastUpdateTime
time stamp of previous energy update
WifiPhy::State GetCurrentState(void) const
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
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.
void NotifyWakeup(void)
Defined in ns3::WifiPhyListener.
double GetTxCurrentA(void) const
Gets transmit current.
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.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
An identifier for simulation events.
Definition: event-id.h:53
void DoDispose(void)
Destructor implementation.
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
bool m_isSupersededChangeState
superseded change state
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
State
The state of the PHY layer.
Definition: wifi-phy.h:171
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