A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wifi-radio-energy-model.h
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 
39 {
40 public:
43 
50 
58  virtual void NotifyRxStart (Time duration);
59 
68  virtual void NotifyRxEndOk (void);
69 
78  virtual void NotifyRxEndError (void);
79 
88  virtual void NotifyTxStart (Time duration);
89 
95  virtual void NotifyMaybeCcaBusyStart (Time duration);
96 
102  virtual void NotifySwitchingStart (Time duration, uint16_t toChannel);
103  virtual void NotifySensingStart (Time duration);
104 
105 private:
109  void SwitchToIdle (void);
110 
111 private:
117 
118  EventId m_switchToIdleEvent;
119 };
120 
121 // -------------------------------------------------------------------------- //
122 
148 {
149 public:
154 
155 public:
156  static TypeId GetTypeId (void);
158  virtual ~WifiRadioEnergyModel ();
159 
167  virtual void SetEnergySource (Ptr<EnergySource> source);
168 
174  virtual double GetTotalEnergyConsumption (void) const;
175 
176  // Setter & getters for state power consumption.
177  double GetIdleCurrentA (void) const;
178  void SetIdleCurrentA (double idleCurrentA);
179  double GetCcaBusyCurrentA (void) const;
180  void SetCcaBusyCurrentA (double ccaBusyCurrentA);
181  double GetTxCurrentA (void) const;
182  void SetTxCurrentA (double txCurrentA);
183  double GetRxCurrentA (void) const;
184  void SetRxCurrentA (double rxCurrentA);
185  double GetSwitchingCurrentA (void) const;
186  void SetSwitchingCurrentA (double switchingCurrentA);
187 
191  WifiPhy::State GetCurrentState (void) const;
192 
199 
207  virtual void ChangeState (int newState);
208 
214  virtual void HandleEnergyDepletion (void);
215 
220 
221 
222 private:
223  void DoDispose (void);
224 
230  virtual double DoGetCurrentA (void) const;
231 
238  void SetWifiRadioState (const WifiPhy::State state);
239 
240 private:
241  Ptr<EnergySource> m_source;
242 
243  // Member variables for current draw in different radio modes.
244  double m_txCurrentA;
245  double m_rxCurrentA;
246  double m_idleCurrentA;
247  double m_ccaBusyCurrentA;
248  double m_switchingCurrentA;
249 
250  // This variable keeps track of the total energy consumed by this model.
251  TracedValue<double> m_totalEnergyConsumption;
252 
253  // State variables.
254  WifiPhy::State m_currentState; // current state the radio is in
255  Time m_lastUpdateTime; // time stamp of previous energy update
256 
257  // Energy depletion callback
258  WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
259 
260  // WifiPhy listener
262 };
263 
264 } // namespace ns3
265 
266 #endif /* WIFI_RADIO_ENERGY_MODEL_H */
virtual void NotifySwitchingStart(Time duration, uint16_t toChannel)
void SetWifiRadioState(const WifiPhy::State state)
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Base class for device energy models.
virtual void NotifySensingStart(Time duration)
virtual void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
virtual double GetTotalEnergyConsumption(void) const
virtual void NotifyTxStart(Time duration)
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
WifiRadioEnergyModelPhyListener * GetPhyListener(void)
virtual void NotifyRxEndOk(void)
Switches the WifiRadioEnergyModel back to IDLE state.
Callback< void > WifiRadioEnergyDepletionCallback
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback. Used by helper class.
receive notifications about phy events.
Definition: wifi-phy.h:44
virtual void NotifyMaybeCcaBusyStart(Time duration)
virtual void NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
WifiPhy::State GetCurrentState(void) const
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
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:46
virtual double DoGetCurrentA(void) const
a unique identifier for an interface.
Definition: type-id.h:44
virtual void HandleEnergyDepletion(void)
Handles energy depletion.