A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-radio-energy-model-helper.cc
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>, He Wu <mdzz@u.washington.edu>
7 */
8
10
11#include "ns3/wifi-net-device.h"
12#include "ns3/wifi-phy.h"
13#include "ns3/wifi-tx-current-model.h"
14
15namespace ns3
16{
17
19{
20 m_radioEnergy.SetTypeId("ns3::WifiRadioEnergyModel");
21 m_depletionCallback.Nullify();
22 m_rechargedCallback.Nullify();
23}
24
28
29void
31{
32 m_radioEnergy.Set(name, v);
33}
34
35void
41
42void
48
49/*
50 * Private function starts here.
51 */
52
55{
56 NS_ASSERT(device);
57 NS_ASSERT(source);
58 // check if device is WifiNetDevice
59 std::string deviceName = device->GetInstanceTypeId().GetName();
60 if (deviceName != "ns3::WifiNetDevice")
61 {
62 NS_FATAL_ERROR("NetDevice type is not WifiNetDevice!");
63 }
64 Ptr<Node> node = device->GetNode();
66 NS_ASSERT(model);
67
68 // set energy depletion callback
69 // if none is specified, make a callback to WifiPhy::SetOffMode
71 Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy();
72 wifiPhy->SetWifiRadioEnergyModel(model);
73 if (m_depletionCallback.IsNull())
74 {
75 model->SetEnergyDepletionCallback(MakeCallback(&WifiPhy::SetOffMode, wifiPhy));
76 }
77 else
78 {
79 model->SetEnergyDepletionCallback(m_depletionCallback);
80 }
81 // set energy recharged callback
82 // if none is specified, make a callback to WifiPhy::ResumeFromOff
83 if (m_rechargedCallback.IsNull())
84 {
85 model->SetEnergyRechargedCallback(MakeCallback(&WifiPhy::ResumeFromOff, wifiPhy));
86 }
87 else
88 {
89 model->SetEnergyRechargedCallback(m_rechargedCallback);
90 }
91 // add model to device model list in energy source
92 source->AppendDeviceEnergyModel(model);
93 // set energy source pointer
94 model->SetEnergySource(source);
95 // create and register energy model PHY listener
96 wifiPhy->RegisterListener(model->GetPhyListener());
97 //
98 if (m_txCurrentModel.GetTypeId().GetUid())
99 {
101 model->SetTxCurrentModel(txcurrent);
102 }
103 return model;
104}
105
106} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
void SetOffMode()
Put in off mode.
Definition wifi-phy.cc:1439
void ResumeFromOff()
Resume from off mode.
Definition wifi-phy.cc:1476
~WifiRadioEnergyModelHelper() override
Destroy a RadioEnergy Helper.
void SetRechargedCallback(WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback callback)
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
Ptr< energy::DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const override
WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback m_rechargedCallback
radio energy recharged callback
WifiRadioEnergyModelHelper()
Construct a helper which is used to add a radio energy model to a node.
WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback m_depletionCallback
radio energy depletion callback
void Set(std::string name, const AttributeValue &v) override
ObjectFactory m_txCurrentModel
transmit current model
A WiFi radio energy model.
Callback< void > WifiRadioEnergyRechargedCallback
Callback type for energy recharged handling.
Callback< void > WifiRadioEnergyDepletionCallback
Callback type for energy depletion handling.
Model the transmit current as a function of the transmit power and mode.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580