A Discrete-Event Network Simulator
API
wifi-radio-energy-model.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Sidharth Nabar <snabar@uw.edu>
18  * 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 "wifi-phy-listener.h"
25 #include "wifi-phy-state.h"
26 
27 #include "ns3/device-energy-model.h"
28 #include "ns3/event-id.h"
29 #include "ns3/nstime.h"
30 #include "ns3/traced-value.h"
31 
32 namespace ns3
33 {
34 
35 class WifiTxCurrentModel;
36 
44 {
45  public:
50 
53 
60 
67 
68  void NotifyRxStart(Time duration) override;
69  void NotifyRxEndOk() override;
70  void NotifyRxEndError() override;
71  void NotifyTxStart(Time duration, double txPowerDbm) override;
72  void NotifyCcaBusyStart(Time duration,
73  WifiChannelListType channelType,
74  const std::vector<Time>& per20MhzDurations) override;
75  void NotifySwitchingStart(Time duration) override;
76  void NotifySleep() override;
77  void NotifyOff() override;
78  void NotifyWakeup() override;
79  void NotifyOn() override;
80 
81  private:
85  void SwitchToIdle();
86 
92 
98 
100 };
101 
152 {
153  public:
158 
163 
168  static TypeId GetTypeId();
170  ~WifiRadioEnergyModel() override;
171 
179  void SetEnergySource(const Ptr<EnergySource> source) override;
180 
186  double GetTotalEnergyConsumption() const override;
187 
188  // Setter & getters for state power consumption.
194  double GetIdleCurrentA() const;
200  void SetIdleCurrentA(double idleCurrentA);
206  double GetCcaBusyCurrentA() const;
212  void SetCcaBusyCurrentA(double ccaBusyCurrentA);
218  double GetTxCurrentA() const;
224  void SetTxCurrentA(double txCurrentA);
230  double GetRxCurrentA() const;
236  void SetRxCurrentA(double rxCurrentA);
242  double GetSwitchingCurrentA() const;
248  void SetSwitchingCurrentA(double switchingCurrentA);
254  double GetSleepCurrentA() const;
260  void SetSleepCurrentA(double sleepCurrentA);
261 
266 
273 
280 
284  void SetTxCurrentModel(const Ptr<WifiTxCurrentModel> model);
285 
292  void SetTxCurrentFromModel(double txPowerDbm);
293 
301  void ChangeState(int newState) override;
302 
308  Time GetMaximumTimeInState(int state) const;
309 
315  void HandleEnergyDepletion() override;
316 
322  void HandleEnergyRecharged() override;
323 
329  void HandleEnergyChanged() override;
330 
334  std::shared_ptr<WifiRadioEnergyModelPhyListener> GetPhyListener();
335 
336  private:
337  void DoDispose() override;
338 
343  double GetStateA(int state) const;
344 
350  double DoGetCurrentA() const override;
351 
358  void SetWifiRadioState(const WifiPhyState state);
359 
361 
362  // Member variables for current draw in different radio modes.
363  double m_txCurrentA;
364  double m_rxCurrentA;
365  double m_idleCurrentA;
370 
373 
374  // State variables.
377 
379 
382 
385 
387  std::shared_ptr<WifiRadioEnergyModelPhyListener> m_listener;
388 
390 };
391 
392 } // namespace ns3
393 
394 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
Base class for device energy models.
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
receive notifications about PHY events.
A WiFi radio energy model.
double GetStateA(int state) const
void HandleEnergyChanged() override
Handles energy changed.
double GetCcaBusyCurrentA() const
Gets CCA busy current in Amperes.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
double m_idleCurrentA
idle current in Amperes
Callback< void > WifiRadioEnergyRechargedCallback
Callback type for energy recharged handling.
WifiPhyState GetCurrentState() const
double m_ccaBusyCurrentA
CCA busy current in Amperes.
void ChangeState(int newState) override
Changes state of the WifiRadioEnergyMode.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
Sets CCA busy current in Amperes.
Time GetMaximumTimeInState(int state) const
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double m_sleepCurrentA
sleep current in Amperes
Ptr< EnergySource > m_source
energy source
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model in watts.
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
EventId m_switchToOffEvent
switch to off event
void DoDispose() override
Destructor implementation.
void SetRxCurrentA(double rxCurrentA)
Sets receive current in Amperes.
double GetTotalEnergyConsumption() const override
double m_txCurrentA
transmit current in Amperes
void HandleEnergyRecharged() override
Handles energy recharged.
Time m_lastUpdateTime
time stamp of previous energy update
void SetTxCurrentA(double txCurrentA)
Sets transmit current in Amperes.
double GetRxCurrentA() const
Gets receive current in Amperes.
double GetTxCurrentA() const
Gets transmit current in Amperes.
std::shared_ptr< WifiRadioEnergyModelPhyListener > m_listener
WifiPhy listener.
void HandleEnergyDepletion() override
Handles energy depletion.
static TypeId GetTypeId()
Get the type ID.
double GetIdleCurrentA() const
Gets idle current in Amperes.
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current in Amperes.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
std::shared_ptr< WifiRadioEnergyModelPhyListener > GetPhyListener()
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current in Amperes.
double m_rxCurrentA
receive current in Amperes
WifiPhyState m_currentState
current state the radio is in
void SetWifiRadioState(const WifiPhyState state)
double GetSleepCurrentA() const
Gets sleep current in Amperes.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double GetSwitchingCurrentA() const
Gets switching current in Amperes.
void SetIdleCurrentA(double idleCurrentA)
Sets idle current in Amperes.
double DoGetCurrentA() const override
void SetEnergySource(const Ptr< EnergySource > source) override
Sets pointer to EnergySource installed on node.
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
double m_switchingCurrentA
switching current in Amperes
uint8_t m_nPendingChangeState
pending state change
Callback< void > WifiRadioEnergyDepletionCallback
Callback type for energy depletion handling.
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change.
Callback< void, double > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal TX power.
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
void NotifyTxStart(Time duration, double txPowerDbm) override
void NotifySleep() override
Notify listeners that we went to sleep.
void NotifyOff() override
Notify listeners that we went to switch off.
void NotifyRxStart(Time duration) override
void NotifyRxEndOk() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the TX current stored in WifiRadioEnergyModel based on the nominal TX power u...
void NotifyRxEndError() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void NotifySwitchingStart(Time duration) override
void SwitchToIdle()
A helper function that makes scheduling m_changeStateCallback possible.
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
void NotifyWakeup() override
Notify listeners that we woke up.
EventId m_switchToIdleEvent
switch to idle event
void NotifyOn() override
Notify listeners that we went to switch on.
void NotifyCcaBusyStart(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations) override
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.