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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Sidharth Nabar <snabar@uw.edu>
7 * He Wu <mdzz@u.washington.edu>
8 */
9
10#ifndef WIFI_RADIO_ENERGY_MODEL_H
11#define WIFI_RADIO_ENERGY_MODEL_H
12
13#include "wifi-phy-listener.h"
14#include "wifi-phy-state.h"
15
16#include "ns3/device-energy-model.h"
17#include "ns3/event-id.h"
18#include "ns3/nstime.h"
19#include "ns3/traced-value.h"
20#include "ns3/wifi-export.h"
21
22namespace ns3
23{
24
26
27/**
28 * @ingroup energy
29 * A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio
30 * state change.
31 *
32 */
34{
35 public:
36 /**
37 * Callback type for updating the transmit current based on the nominal TX power.
38 */
40
43
44 /**
45 * @brief Sets the change state callback. Used by helper class.
46 *
47 * @param callback Change state callback.
48 */
50
51 /**
52 * @brief Sets the update TX current callback.
53 *
54 * @param callback Update TX current callback.
55 */
57
58 void NotifyRxStart(Time duration) override;
59 void NotifyRxEndOk() override;
60 void NotifyRxEndError(const WifiTxVector& txVector) override;
61 void NotifyTxStart(Time duration, dBm_u txPower) override;
62 void NotifyCcaBusyStart(Time duration,
63 WifiChannelListType channelType,
64 const std::vector<Time>& per20MhzDurations) override;
65 void NotifySwitchingStart(Time duration) override;
66 void NotifySleep() override;
67 void NotifyOff() override;
68 void NotifyWakeup() override;
69 void NotifyOn() override;
70
71 private:
72 /**
73 * A helper function that makes scheduling m_changeStateCallback possible.
74 */
75 void SwitchToIdle();
76
77 /**
78 * Change state callback used to notify the WifiRadioEnergyModel of a state
79 * change.
80 */
82
83 /**
84 * Callback used to update the TX current stored in WifiRadioEnergyModel based on
85 * the nominal TX power used to transmit the current frame.
86 */
88
89 EventId m_switchToIdleEvent; ///< switch to idle event
90};
91
92/**
93 * @ingroup energy
94 * @brief A WiFi radio energy model.
95 *
96 * 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is
97 * IDLE.
98 * The different types of transactions that are defined are:
99 * 1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration,
100 * then state goes from TX to IDLE.
101 * 2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration,
102 * then state goes from RX to IDLE.
103 * 3. Go_to_Sleep: State goes from IDLE to SLEEP.
104 * 4. End_of_Sleep: State goes from SLEEP to IDLE.
105 * The class keeps track of what state the radio is currently in.
106 *
107 * Energy calculation: For each transaction, this model notifies EnergySource
108 * object. The EnergySource object will query this model for the total current.
109 * Then the EnergySource object uses the total current to calculate energy.
110 *
111 * Default values for power consumption are based on measurements reported in:
112 *
113 * Daniel Halperin, Ben Greenstein, Anmol Sheth, David Wetherall,
114 * "Demystifying 802.11n power consumption", Proceedings of HotPower'10
115 *
116 * Power consumption in Watts (single antenna):
117 *
118 * \f$ P_{tx} = 1.14 \f$ (transmit at 0dBm)
119 *
120 * \f$ P_{rx} = 0.94 \f$
121 *
122 * \f$ P_{idle} = 0.82 \f$
123 *
124 * \f$ P_{sleep} = 0.10 \f$
125 *
126 * Hence, considering the default supply voltage of 3.0 V for the basic energy
127 * source, the default current values in Ampere are:
128 *
129 * \f$ I_{tx} = 0.380 \f$
130 *
131 * \f$ I_{rx} = 0.313 \f$
132 *
133 * \f$ I_{idle} = 0.273 \f$
134 *
135 * \f$ I_{sleep} = 0.033 \f$
136 *
137 * The dependence of the power consumption in transmission mode on the nominal
138 * transmit power can also be achieved through a wifi TX current model.
139 *
140 */
142{
143 public:
144 /**
145 * Callback type for energy depletion handling.
146 */
148
149 /**
150 * Callback type for energy recharged handling.
151 */
153
154 /**
155 * @brief Get the type ID.
156 * @return the object TypeId
157 */
158 static TypeId GetTypeId();
160 ~WifiRadioEnergyModel() override;
161
162 /**
163 * @brief Sets pointer to EnergySource installed on node.
164 *
165 * @param source Pointer to EnergySource installed on node.
166 *
167 * Implements DeviceEnergyModel::SetEnergySource.
168 */
169 void SetEnergySource(const Ptr<energy::EnergySource> source) override;
170
171 /**
172 * @returns Total energy consumption of the wifi device.
173 *
174 * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
175 */
176 Watt_u GetTotalEnergyConsumption() const override;
177
178 // Setter & getters for state power consumption.
179 /**
180 * @brief Gets idle current.
181 *
182 * @returns idle current of the wifi device.
183 */
185 /**
186 * @brief Sets idle current.
187 *
188 * @param idleCurrentA the idle current
189 */
190 void SetIdleCurrentA(ampere_u idleCurrentA);
191 /**
192 * @brief Gets CCA busy current.
193 *
194 * @returns CCA Busy current of the wifi device.
195 */
197 /**
198 * @brief Sets CCA busy current.
199 *
200 * @param ccaBusyCurrentA the CCA busy current
201 */
202 void SetCcaBusyCurrentA(ampere_u ccaBusyCurrentA);
203 /**
204 * @brief Gets transmit current.
205 *
206 * @returns transmit current of the wifi device.
207 */
208 ampere_u GetTxCurrentA() const;
209 /**
210 * @brief Sets transmit current.
211 *
212 * @param txCurrentA the transmit current
213 */
214 void SetTxCurrentA(ampere_u txCurrentA);
215 /**
216 * @brief Gets receive current.
217 *
218 * @returns receive current of the wifi device.
219 */
220 ampere_u GetRxCurrentA() const;
221 /**
222 * @brief Sets receive current.
223 *
224 * @param rxCurrentA the receive current
225 */
226 void SetRxCurrentA(ampere_u rxCurrentA);
227 /**
228 * @brief Gets switching current.
229 *
230 * @returns switching current of the wifi device.
231 */
233 /**
234 * @brief Sets switching current.
235 *
236 * @param switchingCurrentA the switching current
237 */
238 void SetSwitchingCurrentA(ampere_u switchingCurrentA);
239 /**
240 * @brief Gets sleep current.
241 *
242 * @returns sleep current of the wifi device.
243 */
245 /**
246 * @brief Sets sleep current.
247 *
248 * @param sleepCurrentA the sleep current
249 */
250 void SetSleepCurrentA(ampere_u sleepCurrentA);
251
252 /**
253 * @returns Current state.
254 */
256
257 /**
258 * @param callback Callback function.
259 *
260 * Sets callback for energy depletion handling.
261 */
263
264 /**
265 * @param callback Callback function.
266 *
267 * Sets callback for energy recharged handling.
268 */
270
271 /**
272 * @param model the model used to compute the wifi TX current.
273 */
275
276 /**
277 * @brief Calls the CalcTxCurrent method of the TX current model to
278 * compute the TX current based on such model
279 *
280 * @param txPower the nominal TX power
281 */
282 void SetTxCurrentFromModel(dBm_u txPower);
283
284 /**
285 * @brief Changes state of the WifiRadioEnergyMode.
286 *
287 * @param newState New state the wifi radio is in.
288 *
289 * Implements DeviceEnergyModel::ChangeState.
290 */
291 void ChangeState(int newState) override;
292
293 /**
294 * @param state the wifi state
295 *
296 * @returns the time the radio can stay in that state based on the remaining energy.
297 */
299
300 /**
301 * @brief Handles energy depletion.
302 *
303 * Implements DeviceEnergyModel::HandleEnergyDepletion
304 */
305 void HandleEnergyDepletion() override;
306
307 /**
308 * @brief Handles energy recharged.
309 *
310 * Implements DeviceEnergyModel::HandleEnergyRecharged
311 */
312 void HandleEnergyRecharged() override;
313
314 /**
315 * @brief Handles energy changed.
316 *
317 * Implements DeviceEnergyModel::HandleEnergyChanged
318 */
319 void HandleEnergyChanged() override;
320
321 /**
322 * @returns Pointer to the PHY listener.
323 */
324 std::shared_ptr<WifiRadioEnergyModelPhyListener> GetPhyListener();
325
326 private:
327 void DoDispose() override;
328
329 /**
330 * @param state the wifi state
331 * @returns draw of device at given state.
332 */
333 ampere_u GetStateA(WifiPhyState state) const;
334
335 /**
336 * @returns Current draw of device at current state.
337 *
338 * Implements DeviceEnergyModel::GetCurrentA.
339 */
340 ampere_u DoGetCurrentA() const override;
341
342 /**
343 * @param state New state the radio device is currently in.
344 *
345 * Sets current state. This function is private so that only the energy model
346 * can change its own state.
347 */
348 void SetWifiRadioState(const WifiPhyState state);
349
351
352 // Member variables for current draw in different radio modes.
353 ampere_u m_txCurrent; ///< transmit current
354 ampere_u m_rxCurrent; ///< receive current
355 ampere_u m_idleCurrent; ///< idle current
356 ampere_u m_ccaBusyCurrent; ///< CCA busy current
357 ampere_u m_switchingCurrent; ///< switching current
358 ampere_u m_sleepCurrent; ///< sleep current
360
361 /// This variable keeps track of the total energy consumed by this model in watts.
363
364 // State variables.
365 WifiPhyState m_currentState; ///< current state the radio is in
366 Time m_lastUpdateTime; ///< time stamp of previous energy update
367
368 uint8_t m_nPendingChangeState; ///< pending state change
369
370 /// Energy depletion callback
372
373 /// Energy recharged callback
375
376 /// WifiPhy listener
377 std::shared_ptr<WifiRadioEnergyModelPhyListener> m_listener;
378
379 EventId m_switchToOffEvent; ///< switch to off event
380};
381
382} // namespace ns3
383
384#endif /* WIFI_RADIO_ENERGY_MODEL_H */
Callback template class.
Definition callback.h:428
An identifier for simulation events.
Definition event-id.h:45
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:50
receive notifications about PHY events.
void HandleEnergyChanged() override
Handles energy changed.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
void SetSleepCurrentA(ampere_u sleepCurrentA)
Sets sleep current.
Callback< void > WifiRadioEnergyRechargedCallback
Callback type for energy recharged handling.
void SetRxCurrentA(ampere_u rxCurrentA)
Sets receive current.
Ptr< energy::EnergySource > m_source
energy source
void ChangeState(int newState) override
Changes state of the WifiRadioEnergyMode.
ampere_u GetSleepCurrentA() const
Gets sleep current.
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
ampere_u GetCcaBusyCurrentA() const
Gets CCA busy current.
void SetIdleCurrentA(ampere_u idleCurrentA)
Sets idle current.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model in watts.
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
void SetTxCurrentFromModel(dBm_u txPower)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model.
EventId m_switchToOffEvent
switch to off event
void DoDispose() override
Destructor implementation.
void HandleEnergyRecharged() override
Handles energy recharged.
Time m_lastUpdateTime
time stamp of previous energy update
ampere_u GetSwitchingCurrentA() const
Gets switching current.
ampere_u m_switchingCurrent
switching current
ampere_u m_txCurrent
transmit current
ampere_u GetStateA(WifiPhyState state) const
ampere_u GetTxCurrentA() const
Gets transmit current.
std::shared_ptr< WifiRadioEnergyModelPhyListener > m_listener
WifiPhy listener.
void HandleEnergyDepletion() override
Handles energy depletion.
static TypeId GetTypeId()
Get the type ID.
ampere_u DoGetCurrentA() const override
void SetCcaBusyCurrentA(ampere_u ccaBusyCurrentA)
Sets CCA busy current.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
std::shared_ptr< WifiRadioEnergyModelPhyListener > GetPhyListener()
ampere_u m_rxCurrent
receive current
WifiPhyState m_currentState
current state the radio is in
ampere_u GetIdleCurrentA() const
Gets idle current.
void SetWifiRadioState(const WifiPhyState state)
ampere_u m_ccaBusyCurrent
CCA busy current.
Time GetMaximumTimeInState(WifiPhyState state) const
void SetTxCurrentA(ampere_u txCurrentA)
Sets transmit current.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
void SetSwitchingCurrentA(ampere_u switchingCurrentA)
Sets switching current.
ampere_u GetRxCurrentA() const
Gets receive current.
ampere_u m_sleepCurrent
sleep current
Watt_u GetTotalEnergyConsumption() const override
void SetEnergySource(const Ptr< energy::EnergySource > source) override
Sets pointer to EnergySource installed on node.
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
uint8_t m_nPendingChangeState
pending state change
Callback< void > WifiRadioEnergyDepletionCallback
Callback type for energy depletion handling.
energy::DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
void NotifySleep() override
Notify listeners that we went to sleep.
void NotifyOff() override
Notify listeners that we went to switch off.
void SetChangeStateCallback(energy::DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
void NotifyRxEndError(const WifiTxVector &txVector) 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...
Callback< void, dBm_u > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal TX power.
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void NotifyTxStart(Time duration, dBm_u txPower) override
void NotifySwitchingStart(Time duration) override
void SwitchToIdle()
A helper function that makes scheduling m_changeStateCallback possible.
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
Model the transmit current as a function of the transmit power and mode.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Base class for device energy models.
Callback< void, int > ChangeStateCallback
Callback type for ChangeState function.
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.
double ampere_u
ampere weak type
Definition wifi-units.h:33
double dBm_u
dBm weak type
Definition wifi-units.h:27
double Watt_u
Watt weak type.
Definition wifi-units.h:25