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 * 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>, He Wu <mdzz@u.washington.edu>
18 */
19
21
22#include "ns3/wifi-net-device.h"
23#include "ns3/wifi-phy.h"
24#include "ns3/wifi-tx-current-model.h"
25
26namespace ns3
27{
28
30{
31 m_radioEnergy.SetTypeId("ns3::WifiRadioEnergyModel");
34}
35
37{
38}
39
40void
42{
43 m_radioEnergy.Set(name, v);
44}
45
46void
49{
50 m_depletionCallback = callback;
51}
52
53void
56{
57 m_rechargedCallback = callback;
58}
59
60/*
61 * Private function starts here.
62 */
63
66{
67 NS_ASSERT(device);
68 NS_ASSERT(source);
69 // check if device is WifiNetDevice
70 std::string deviceName = device->GetInstanceTypeId().GetName();
71 if (deviceName != "ns3::WifiNetDevice")
72 {
73 NS_FATAL_ERROR("NetDevice type is not WifiNetDevice!");
74 }
75 Ptr<Node> node = device->GetNode();
77 NS_ASSERT(model);
78
79 // set energy depletion callback
80 // if none is specified, make a callback to WifiPhy::SetOffMode
81 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice>(device);
82 Ptr<WifiPhy> wifiPhy = wifiDevice->GetPhy();
83 wifiPhy->SetWifiRadioEnergyModel(model);
85 {
86 model->SetEnergyDepletionCallback(MakeCallback(&WifiPhy::SetOffMode, wifiPhy));
87 }
88 else
89 {
90 model->SetEnergyDepletionCallback(m_depletionCallback);
91 }
92 // set energy recharged callback
93 // if none is specified, make a callback to WifiPhy::ResumeFromOff
95 {
96 model->SetEnergyRechargedCallback(MakeCallback(&WifiPhy::ResumeFromOff, wifiPhy));
97 }
98 else
99 {
100 model->SetEnergyRechargedCallback(m_rechargedCallback);
101 }
102 // add model to device model list in energy source
103 source->AppendDeviceEnergyModel(model);
104 // set energy source pointer
105 model->SetEnergySource(source);
106 // create and register energy model PHY listener
107 wifiPhy->RegisterListener(model->GetPhyListener());
108 //
110 {
112 model->SetTxCurrentModel(txcurrent);
113 }
114 return model;
115}
116
117} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
void Nullify()
Discard the implementation, set it to null.
Definition: callback.h:577
bool IsNull() const
Check for null implementation.
Definition: callback.h:571
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
TypeId GetTypeId() const
Get the TypeId which will be created by this ObjectFactory.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:522
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
uint16_t GetUid() const
Get the internal id of this TypeId.
Definition: type-id.cc:1206
void SetOffMode()
Put in off mode.
Definition: wifi-phy.cc:1405
void ResumeFromOff()
Resume from off mode.
Definition: wifi-phy.cc:1442
~WifiRadioEnergyModelHelper() override
Destroy a RadioEnergy Helper.
void SetRechargedCallback(WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback callback)
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
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
Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const override
ObjectFactory m_txCurrentModel
transmit current model
A WiFi radio energy model.
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:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
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:706