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