A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
32namespace ns3
33{
34
35class WifiTxCurrentModel;
36
37/**
38 * \ingroup energy
39 * A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio
40 * state change.
41 *
42 */
44{
45 public:
46 /**
47 * Callback type for updating the transmit current based on the nominal TX power.
48 */
50
53
54 /**
55 * \brief Sets the change state callback. Used by helper class.
56 *
57 * \param callback Change state callback.
58 */
60
61 /**
62 * \brief Sets the update TX current callback.
63 *
64 * \param callback Update TX current callback.
65 */
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:
82 /**
83 * A helper function that makes scheduling m_changeStateCallback possible.
84 */
85 void SwitchToIdle();
86
87 /**
88 * Change state callback used to notify the WifiRadioEnergyModel of a state
89 * change.
90 */
92
93 /**
94 * Callback used to update the TX current stored in WifiRadioEnergyModel based on
95 * the nominal TX power used to transmit the current frame.
96 */
98
99 EventId m_switchToIdleEvent; ///< switch to idle event
100};
101
102/**
103 * \ingroup energy
104 * \brief A WiFi radio energy model.
105 *
106 * 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is
107 * IDLE.
108 * The different types of transactions that are defined are:
109 * 1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration,
110 * then state goes from TX to IDLE.
111 * 2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration,
112 * then state goes from RX to IDLE.
113 * 3. Go_to_Sleep: State goes from IDLE to SLEEP.
114 * 4. End_of_Sleep: State goes from SLEEP to IDLE.
115 * The class keeps track of what state the radio is currently in.
116 *
117 * Energy calculation: For each transaction, this model notifies EnergySource
118 * object. The EnergySource object will query this model for the total current.
119 * Then the EnergySource object uses the total current to calculate energy.
120 *
121 * Default values for power consumption are based on measurements reported in:
122 *
123 * Daniel Halperin, Ben Greenstein, Anmol Sheth, David Wetherall,
124 * "Demystifying 802.11n power consumption", Proceedings of HotPower'10
125 *
126 * Power consumption in Watts (single antenna):
127 *
128 * \f$ P_{tx} = 1.14 \f$ (transmit at 0dBm)
129 *
130 * \f$ P_{rx} = 0.94 \f$
131 *
132 * \f$ P_{idle} = 0.82 \f$
133 *
134 * \f$ P_{sleep} = 0.10 \f$
135 *
136 * Hence, considering the default supply voltage of 3.0 V for the basic energy
137 * source, the default current values in Ampere are:
138 *
139 * \f$ I_{tx} = 0.380 \f$
140 *
141 * \f$ I_{rx} = 0.313 \f$
142 *
143 * \f$ I_{idle} = 0.273 \f$
144 *
145 * \f$ I_{sleep} = 0.033 \f$
146 *
147 * The dependence of the power consumption in transmission mode on the nominal
148 * transmit power can also be achieved through a wifi TX current model.
149 *
150 */
152{
153 public:
154 /**
155 * Callback type for energy depletion handling.
156 */
158
159 /**
160 * Callback type for energy recharged handling.
161 */
163
164 /**
165 * \brief Get the type ID.
166 * \return the object TypeId
167 */
168 static TypeId GetTypeId();
170 ~WifiRadioEnergyModel() override;
171
172 /**
173 * \brief Sets pointer to EnergySource installed on node.
174 *
175 * \param source Pointer to EnergySource installed on node.
176 *
177 * Implements DeviceEnergyModel::SetEnergySource.
178 */
179 void SetEnergySource(const Ptr<EnergySource> source) override;
180
181 /**
182 * \returns Total energy consumption of the wifi device in watts.
183 *
184 * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
185 */
186 double GetTotalEnergyConsumption() const override;
187
188 // Setter & getters for state power consumption.
189 /**
190 * \brief Gets idle current in Amperes.
191 *
192 * \returns idle current of the wifi device.
193 */
194 double GetIdleCurrentA() const;
195 /**
196 * \brief Sets idle current in Amperes.
197 *
198 * \param idleCurrentA the idle current
199 */
200 void SetIdleCurrentA(double idleCurrentA);
201 /**
202 * \brief Gets CCA busy current in Amperes.
203 *
204 * \returns CCA Busy current of the wifi device.
205 */
206 double GetCcaBusyCurrentA() const;
207 /**
208 * \brief Sets CCA busy current in Amperes.
209 *
210 * \param ccaBusyCurrentA the CCA busy current
211 */
212 void SetCcaBusyCurrentA(double ccaBusyCurrentA);
213 /**
214 * \brief Gets transmit current in Amperes.
215 *
216 * \returns transmit current of the wifi device.
217 */
218 double GetTxCurrentA() const;
219 /**
220 * \brief Sets transmit current in Amperes.
221 *
222 * \param txCurrentA the transmit current
223 */
224 void SetTxCurrentA(double txCurrentA);
225 /**
226 * \brief Gets receive current in Amperes.
227 *
228 * \returns receive current of the wifi device.
229 */
230 double GetRxCurrentA() const;
231 /**
232 * \brief Sets receive current in Amperes.
233 *
234 * \param rxCurrentA the receive current
235 */
236 void SetRxCurrentA(double rxCurrentA);
237 /**
238 * \brief Gets switching current in Amperes.
239 *
240 * \returns switching current of the wifi device.
241 */
242 double GetSwitchingCurrentA() const;
243 /**
244 * \brief Sets switching current in Amperes.
245 *
246 * \param switchingCurrentA the switching current
247 */
248 void SetSwitchingCurrentA(double switchingCurrentA);
249 /**
250 * \brief Gets sleep current in Amperes.
251 *
252 * \returns sleep current of the wifi device.
253 */
254 double GetSleepCurrentA() const;
255 /**
256 * \brief Sets sleep current in Amperes.
257 *
258 * \param sleepCurrentA the sleep current
259 */
260 void SetSleepCurrentA(double sleepCurrentA);
261
262 /**
263 * \returns Current state.
264 */
266
267 /**
268 * \param callback Callback function.
269 *
270 * Sets callback for energy depletion handling.
271 */
273
274 /**
275 * \param callback Callback function.
276 *
277 * Sets callback for energy recharged handling.
278 */
280
281 /**
282 * \param model the model used to compute the wifi TX current.
283 */
285
286 /**
287 * \brief Calls the CalcTxCurrent method of the TX current model to
288 * compute the TX current based on such model
289 *
290 * \param txPowerDbm the nominal TX power in dBm
291 */
292 void SetTxCurrentFromModel(double txPowerDbm);
293
294 /**
295 * \brief Changes state of the WifiRadioEnergyMode.
296 *
297 * \param newState New state the wifi radio is in.
298 *
299 * Implements DeviceEnergyModel::ChangeState.
300 */
301 void ChangeState(int newState) override;
302
303 /**
304 * \param state the wifi state
305 *
306 * \returns the time the radio can stay in that state based on the remaining energy.
307 */
309
310 /**
311 * \brief Handles energy depletion.
312 *
313 * Implements DeviceEnergyModel::HandleEnergyDepletion
314 */
315 void HandleEnergyDepletion() override;
316
317 /**
318 * \brief Handles energy recharged.
319 *
320 * Implements DeviceEnergyModel::HandleEnergyRecharged
321 */
322 void HandleEnergyRecharged() override;
323
324 /**
325 * \brief Handles energy changed.
326 *
327 * Implements DeviceEnergyModel::HandleEnergyChanged
328 */
329 void HandleEnergyChanged() override;
330
331 /**
332 * \returns Pointer to the PHY listener.
333 */
334 std::shared_ptr<WifiRadioEnergyModelPhyListener> GetPhyListener();
335
336 private:
337 void DoDispose() override;
338
339 /**
340 * \param state the wifi state
341 * \returns draw of device in Amperes, at given state.
342 */
343 double GetStateA(WifiPhyState state) const;
344
345 /**
346 * \returns Current draw of device in Amperes, at current state.
347 *
348 * Implements DeviceEnergyModel::GetCurrentA.
349 */
350 double DoGetCurrentA() const override;
351
352 /**
353 * \param state New state the radio device is currently in.
354 *
355 * Sets current state. This function is private so that only the energy model
356 * can change its own state.
357 */
358 void SetWifiRadioState(const WifiPhyState state);
359
360 Ptr<EnergySource> m_source; ///< energy source
361
362 // Member variables for current draw in different radio modes.
363 double m_txCurrentA; ///< transmit current in Amperes
364 double m_rxCurrentA; ///< receive current in Amperes
365 double m_idleCurrentA; ///< idle current in Amperes
366 double m_ccaBusyCurrentA; ///< CCA busy current in Amperes
367 double m_switchingCurrentA; ///< switching current in Amperes
368 double m_sleepCurrentA; ///< sleep current in Amperes
370
371 /// This variable keeps track of the total energy consumed by this model in watts.
373
374 // State variables.
375 WifiPhyState m_currentState; ///< current state the radio is in
376 Time m_lastUpdateTime; ///< time stamp of previous energy update
377
378 uint8_t m_nPendingChangeState; ///< pending state change
379
380 /// Energy depletion callback
382
383 /// Energy recharged callback
385
386 /// WifiPhy listener
387 std::shared_ptr<WifiRadioEnergyModelPhyListener> m_listener;
388
389 EventId m_switchToOffEvent; ///< switch to off event
390};
391
392} // namespace ns3
393
394#endif /* WIFI_RADIO_ENERGY_MODEL_H */
Callback template class.
Definition: callback.h:438
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
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
receive notifications about PHY events.
A WiFi radio energy model.
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
double GetStateA(WifiPhyState state) const
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.
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.
Time GetMaximumTimeInState(WifiPhyState state) const
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.