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 "ns3/event-id.h"
28 #include "ns3/nstime.h"
29 #include "wifi-phy-listener.h"
30 #include "wifi-phy-state.h"
31 
32 namespace ns3 {
33 
34 class WifiTxCurrentModel;
35 
43 {
44 public:
49 
52 
59 
66 
74  void NotifyRxStart (Time duration) override;
75 
84  void NotifyRxEndOk (void) override;
85 
94  void NotifyRxEndError (void) override;
95 
105  void NotifyTxStart (Time duration, double txPowerDbm) override;
106 
112  void NotifyMaybeCcaBusyStart (Time duration) override;
113 
119  void NotifySwitchingStart (Time duration) override;
120 
124  void NotifySleep (void) override;
125 
129  void NotifyOff (void) override;
130 
134  void NotifyWakeup (void) override;
135 
139  void NotifyOn (void) override;
140 
141 
142 private:
146  void SwitchToIdle (void);
147 
153 
159 
161 };
162 
163 
214 {
215 public:
220 
225 
230  static TypeId GetTypeId (void);
232  virtual ~WifiRadioEnergyModel ();
233 
241  void SetEnergySource (const Ptr<EnergySource> source);
242 
248  double GetTotalEnergyConsumption (void) const;
249 
250  // Setter & getters for state power consumption.
256  double GetIdleCurrentA (void) const;
262  void SetIdleCurrentA (double idleCurrentA);
268  double GetCcaBusyCurrentA (void) const;
274  void SetCcaBusyCurrentA (double ccaBusyCurrentA);
280  double GetTxCurrentA (void) const;
286  void SetTxCurrentA (double txCurrentA);
292  double GetRxCurrentA (void) const;
298  void SetRxCurrentA (double rxCurrentA);
304  double GetSwitchingCurrentA (void) const;
310  void SetSwitchingCurrentA (double switchingCurrentA);
316  double GetSleepCurrentA (void) const;
322  void SetSleepCurrentA (double sleepCurrentA);
323 
327  WifiPhyState GetCurrentState (void) const;
328 
335 
342 
346  void SetTxCurrentModel (const Ptr<WifiTxCurrentModel> model);
347 
354  void SetTxCurrentFromModel (double txPowerDbm);
355 
363  void ChangeState (int newState);
364 
370  Time GetMaximumTimeInState (int state) const;
371 
377  void HandleEnergyDepletion (void);
378 
384  void HandleEnergyRecharged (void);
385 
391  void HandleEnergyChanged (void);
392 
397 
398 
399 private:
400  void DoDispose (void);
401 
406  double GetStateA (int state) const;
407 
413  double DoGetCurrentA (void) const;
414 
421  void SetWifiRadioState (const WifiPhyState state);
422 
424 
425  // Member variables for current draw in different radio modes.
426  double m_txCurrentA;
427  double m_rxCurrentA;
428  double m_idleCurrentA;
433 
436 
437  // State variables.
440 
442 
445 
448 
451 
453 };
454 
455 } // namespace ns3
456 
457 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
double GetRxCurrentA(void) const
Gets receive current in Amperes.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
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 in watts.
Base class for device energy models.
double GetTxCurrentA(void) const
Gets transmit current in Amperes.
double m_rxCurrentA
receive current in Amperes
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 in Amperes.
void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
void NotifyOff(void) override
Defined in ns3::WifiPhyListener.
WifiRadioEnergyModelPhyListener * m_listener
WifiPhy listener.
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current in Amperes.
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 NotifyOn(void) override
Defined in ns3::WifiPhyListener.
void SetRxCurrentA(double rxCurrentA)
Sets receive current in Amperes.
void NotifySwitchingStart(Time duration) override
double m_idleCurrentA
idle current in Amperes
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 in Amperes.
Time GetMaximumTimeInState(int state) const
double GetTotalEnergyConsumption(void) const
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double m_sleepCurrentA
sleep current in Amperes
WifiPhyState GetCurrentState(void) const
Ptr< EnergySource > m_source
energy source
void NotifyMaybeCcaBusyStart(Time duration) override
receive notifications about PHY events.
void NotifyTxStart(Time duration, double txPowerDbm) override
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX 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)
Time m_lastUpdateTime
time stamp of previous energy update
double GetSwitchingCurrentA(void) const
Gets switching current in Amperes.
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
Callback< void, double > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal TX power.
void NotifyRxStart(Time duration) override
Switches the WifiRadioEnergyModel to RX state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void NotifyWakeup(void) override
Defined in ns3::WifiPhyListener.
WifiPhyState
The state of the PHY layer.
WifiPhyState m_currentState
current state the radio is in
double GetStateA(int state) const
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
void NotifyRxEndOk(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
double GetCcaBusyCurrentA(void) const
Gets CCA busy current in Amperes.
void SetTxCurrentA(double txCurrentA)
Sets transmit current in Amperes.
A WiFi radio energy model.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
void NotifySleep(void) override
Defined in ns3::WifiPhyListener.
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.
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current in Amperes.
void SetEnergySource(const Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
double m_switchingCurrentA
switching current in Amperes
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
double GetSleepCurrentA(void) const
Gets sleep current in Amperes.
a unique identifier for an interface.
Definition: type-id.h:58
void SetIdleCurrentA(double idleCurrentA)
Sets idle current in Amperes.
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double GetIdleCurrentA(void) const
Gets idle current in Amperes.
void NotifyRxEndError(void) override
Switches the WifiRadioEnergyModel back to IDLE state.
void HandleEnergyDepletion(void)
Handles energy depletion.
double m_txCurrentA
transmit current in Amperes