/usr/include/ns3.27/ns3/wifi-radio-energy-model.h is in libns3-dev 3.27+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Sidharth Nabar <snabar@uw.edu>
* He Wu <mdzz@u.washington.edu>
*/
#ifndef WIFI_RADIO_ENERGY_MODEL_H
#define WIFI_RADIO_ENERGY_MODEL_H
#include "ns3/device-energy-model.h"
#include "ns3/traced-value.h"
#include "wifi-phy.h"
namespace ns3 {
class WifiTxCurrentModel;
/**
* \ingroup energy
* A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio
* state change.
*
*/
class WifiRadioEnergyModelPhyListener : public WifiPhyListener
{
public:
/**
* Callback type for updating the transmit current based on the nominal tx power.
*/
typedef Callback<void, double> UpdateTxCurrentCallback;
WifiRadioEnergyModelPhyListener ();
virtual ~WifiRadioEnergyModelPhyListener ();
/**
* \brief Sets the change state callback. Used by helper class.
*
* \param callback Change state callback.
*/
void SetChangeStateCallback (DeviceEnergyModel::ChangeStateCallback callback);
/**
* \brief Sets the update tx current callback.
*
* \param callback Update tx current callback.
*/
void SetUpdateTxCurrentCallback (UpdateTxCurrentCallback callback);
/**
* \brief Switches the WifiRadioEnergyModel to RX state.
*
* \param duration the expected duration of the packet reception.
*
* Defined in ns3::WifiPhyListener
*/
void NotifyRxStart (Time duration);
/**
* \brief Switches the WifiRadioEnergyModel back to IDLE state.
*
* Defined in ns3::WifiPhyListener
*
* Note that for the WifiRadioEnergyModel, the behavior of the function is the
* same as NotifyRxEndError.
*/
void NotifyRxEndOk (void);
/**
* \brief Switches the WifiRadioEnergyModel back to IDLE state.
*
* Defined in ns3::WifiPhyListener
*
* Note that for the WifiRadioEnergyModel, the behavior of the function is the
* same as NotifyRxEndOk.
*/
void NotifyRxEndError (void);
/**
* \brief Switches the WifiRadioEnergyModel to TX state and switches back to
* IDLE after TX duration.
*
* \param duration the expected transmission duration.
* \param txPowerDbm the nominal tx power in dBm
*
* Defined in ns3::WifiPhyListener
*/
void NotifyTxStart (Time duration, double txPowerDbm);
/**
* \param duration the expected busy duration.
*
* Defined in ns3::WifiPhyListener
*/
void NotifyMaybeCcaBusyStart (Time duration);
/**
* \param duration the expected channel switching duration.
*
* Defined in ns3::WifiPhyListener
*/
void NotifySwitchingStart (Time duration);
/**
* Defined in ns3::WifiPhyListener
*/
void NotifySleep (void);
/**
* Defined in ns3::WifiPhyListener
*/
void NotifyWakeup (void);
private:
/**
* A helper function that makes scheduling m_changeStateCallback possible.
*/
void SwitchToIdle (void);
/**
* Change state callback used to notify the WifiRadioEnergyModel of a state
* change.
*/
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback;
/**
* Callback used to update the tx current stored in WifiRadioEnergyModel based on
* the nominal tx power used to transmit the current frame.
*/
UpdateTxCurrentCallback m_updateTxCurrentCallback;
EventId m_switchToIdleEvent; ///< switch to idle event
};
/**
* \ingroup energy
* \brief A WiFi radio energy model.
*
* 4 states are defined for the radio: TX, RX, IDLE, SLEEP. Default state is
* IDLE.
* The different types of transactions that are defined are:
* 1. Tx: State goes from IDLE to TX, radio is in TX state for TX_duration,
* then state goes from TX to IDLE.
* 2. Rx: State goes from IDLE to RX, radio is in RX state for RX_duration,
* then state goes from RX to IDLE.
* 3. Go_to_Sleep: State goes from IDLE to SLEEP.
* 4. End_of_Sleep: State goes from SLEEP to IDLE.
* The class keeps track of what state the radio is currently in.
*
* Energy calculation: For each transaction, this model notifies EnergySource
* object. The EnergySource object will query this model for the total current.
* Then the EnergySource object uses the total current to calculate energy.
*
* Default values for power consumption are based on measurements reported in:
*
* Daniel Halperin, Ben Greenstein, Anmol Sheth, David Wetherall,
* "Demystifying 802.11n power consumption", Proceedings of HotPower'10
*
* Power consumption in Watts (single antenna):
*
* \f$ P_{tx} = 1.14 \f$ (transmit at 0dBm)
*
* \f$ P_{rx} = 0.94 \f$
*
* \f$ P_{idle} = 0.82 \f$
*
* \f$ P_{sleep} = 0.10 \f$
*
* Hence, considering the default supply voltage of 3.0 V for the basic energy
* source, the default current values in Ampere are:
*
* \f$ I_{tx} = 0.380 \f$
*
* \f$ I_{rx} = 0.313 \f$
*
* \f$ I_{idle} = 0.273 \f$
*
* \f$ I_{sleep} = 0.033 \f$
*
* The dependence of the power consumption in transmission mode on the nominal
* transmit power can also be achieved through a wifi tx current model.
*
*/
class WifiRadioEnergyModel : public DeviceEnergyModel
{
public:
/**
* Callback type for energy depletion handling.
*/
typedef Callback<void> WifiRadioEnergyDepletionCallback;
/**
* Callback type for energy recharged handling.
*/
typedef Callback<void> WifiRadioEnergyRechargedCallback;
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);
WifiRadioEnergyModel ();
virtual ~WifiRadioEnergyModel ();
/**
* \brief Sets pointer to EnergySouce installed on node.
*
* \param source Pointer to EnergySource installed on node.
*
* Implements DeviceEnergyModel::SetEnergySource.
*/
void SetEnergySource (const Ptr<EnergySource> source);
/**
* \returns Total energy consumption of the wifi device.
*
* Implements DeviceEnergyModel::GetTotalEnergyConsumption.
*/
double GetTotalEnergyConsumption (void) const;
// Setter & getters for state power consumption.
/**
* \brief Gets idle current.
*
* \returns idle current of the wifi device.
*/
double GetIdleCurrentA (void) const;
/**
* \brief Sets idle current.
*
* \param idleCurrentA the idle current
*/
void SetIdleCurrentA (double idleCurrentA);
/**
* \brief Gets CCA busy current.
*
* \returns CCA Busy current of the wifi device.
*/
double GetCcaBusyCurrentA (void) const;
/**
* \brief Sets CCA busy current.
*
* \param ccaBusyCurrentA the CCA busy current
*/
void SetCcaBusyCurrentA (double ccaBusyCurrentA);
/**
* \brief Gets transmit current.
*
* \returns transmit current of the wifi device.
*/
double GetTxCurrentA (void) const;
/**
* \brief Sets transmit current.
*
* \param txCurrentA the transmit current
*/
void SetTxCurrentA (double txCurrentA);
/**
* \brief Gets receive current.
*
* \returns receive current of the wifi device.
*/
double GetRxCurrentA (void) const;
/**
* \brief Sets receive current.
*
* \param rxCurrentA the receive current
*/
void SetRxCurrentA (double rxCurrentA);
/**
* \brief Gets switching current.
*
* \returns switching current of the wifi device.
*/
double GetSwitchingCurrentA (void) const;
/**
* \brief Sets switching current.
*
* \param switchingCurrentA the switching current
*/
void SetSwitchingCurrentA (double switchingCurrentA);
/**
* \brief Gets sleep current.
*
* \returns sleep current of the wifi device.
*/
double GetSleepCurrentA (void) const;
/**
* \brief Sets sleep current.
*
* \param sleepCurrentA the sleep current
*/
void SetSleepCurrentA (double sleepCurrentA);
/**
* \returns Current state.
*/
WifiPhy::State GetCurrentState (void) const;
/**
* \param callback Callback function.
*
* Sets callback for energy depletion handling.
*/
void SetEnergyDepletionCallback (WifiRadioEnergyDepletionCallback callback);
/**
* \param callback Callback function.
*
* Sets callback for energy recharged handling.
*/
void SetEnergyRechargedCallback (WifiRadioEnergyRechargedCallback callback);
/**
* \param model the model used to compute the wifi tx current.
*/
void SetTxCurrentModel (const Ptr<WifiTxCurrentModel> model);
/**
* \brief Calls the CalcTxCurrent method of the tx current model to
* compute the tx current based on such model
*
* \param txPowerDbm the nominal tx power in dBm
*/
void SetTxCurrentFromModel (double txPowerDbm);
/**
* \brief Changes state of the WifiRadioEnergyMode.
*
* \param newState New state the wifi radio is in.
*
* Implements DeviceEnergyModel::ChangeState.
*/
void ChangeState (int newState);
/**
* \brief Handles energy depletion.
*
* Implements DeviceEnergyModel::HandleEnergyDepletion
*/
void HandleEnergyDepletion (void);
/**
* \brief Handles energy recharged.
*
* Implements DeviceEnergyModel::HandleEnergyRecharged
*/
void HandleEnergyRecharged (void);
/**
* \returns Pointer to the PHY listener.
*/
WifiRadioEnergyModelPhyListener * GetPhyListener (void);
private:
void DoDispose (void);
/**
* \returns Current draw of device, at current state.
*
* Implements DeviceEnergyModel::GetCurrentA.
*/
double DoGetCurrentA (void) const;
/**
* \param state New state the radio device is currently in.
*
* Sets current state. This function is private so that only the energy model
* can change its own state.
*/
void SetWifiRadioState (const WifiPhy::State state);
Ptr<EnergySource> m_source; ///< energy source
// Member variables for current draw in different radio modes.
double m_txCurrentA; ///< transmit current
double m_rxCurrentA; ///< receive current
double m_idleCurrentA; ///< idle current
double m_ccaBusyCurrentA; ///< CCA busy current
double m_switchingCurrentA; ///< switching current
double m_sleepCurrentA; ///< sleep current
Ptr<WifiTxCurrentModel> m_txCurrentModel; ///< current model
/// This variable keeps track of the total energy consumed by this model.
TracedValue<double> m_totalEnergyConsumption;
// State variables.
WifiPhy::State m_currentState; ///< current state the radio is in
Time m_lastUpdateTime; ///< time stamp of previous energy update
uint8_t m_nPendingChangeState; ///< pending state change
bool m_isSupersededChangeState; ///< superseded change state
/// Energy depletion callback
WifiRadioEnergyDepletionCallback m_energyDepletionCallback;
/// Energy recharged callback
WifiRadioEnergyRechargedCallback m_energyRechargedCallback;
/// WifiPhy listener
WifiRadioEnergyModelPhyListener *m_listener;
};
} // namespace ns3
#endif /* WIFI_RADIO_ENERGY_MODEL_H */
|