A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
9
#include "
wifi-radio-energy-model-helper.h
"
10
11
#include "ns3/wifi-net-device.h"
12
#include "ns3/wifi-phy.h"
13
#include "ns3/wifi-tx-current-model.h"
14
15
namespace
ns3
16
{
17
18
WifiRadioEnergyModelHelper::WifiRadioEnergyModelHelper
()
19
{
20
m_radioEnergy
.SetTypeId(
"ns3::WifiRadioEnergyModel"
);
21
m_depletionCallback
.Nullify();
22
m_rechargedCallback
.Nullify();
23
}
24
25
WifiRadioEnergyModelHelper::~WifiRadioEnergyModelHelper
()
26
{
27
}
28
29
void
30
WifiRadioEnergyModelHelper::Set
(std::string name,
const
AttributeValue
& v)
31
{
32
m_radioEnergy
.Set(name, v);
33
}
34
35
void
36
WifiRadioEnergyModelHelper::SetDepletionCallback
(
37
WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback
callback)
38
{
39
m_depletionCallback
= callback;
40
}
41
42
void
43
WifiRadioEnergyModelHelper::SetRechargedCallback
(
44
WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback
callback)
45
{
46
m_rechargedCallback
= callback;
47
}
48
49
/*
50
* Private function starts here.
51
*/
52
53
Ptr<energy::DeviceEnergyModel>
54
WifiRadioEnergyModelHelper::DoInstall
(
Ptr<NetDevice>
device,
Ptr<energy::EnergySource>
source)
const
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();
65
Ptr<WifiRadioEnergyModel>
model =
m_radioEnergy
.Create()->GetObject<
WifiRadioEnergyModel
>();
66
NS_ASSERT
(model);
67
68
// set energy depletion callback
69
// if none is specified, make a callback to WifiPhy::SetOffMode
70
Ptr<WifiNetDevice>
wifiDevice =
DynamicCast<WifiNetDevice>
(device);
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
{
100
Ptr<WifiTxCurrentModel>
txcurrent =
m_txCurrentModel
.Create<
WifiTxCurrentModel
>();
101
model->SetTxCurrentModel(txcurrent);
102
}
103
return
model;
104
}
105
106
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::WifiPhy::SetOffMode
void SetOffMode()
Put in off mode.
Definition
wifi-phy.cc:1439
ns3::WifiPhy::ResumeFromOff
void ResumeFromOff()
Resume from off mode.
Definition
wifi-phy.cc:1476
ns3::WifiRadioEnergyModelHelper::~WifiRadioEnergyModelHelper
~WifiRadioEnergyModelHelper() override
Destroy a RadioEnergy Helper.
Definition
wifi-radio-energy-model-helper.cc:25
ns3::WifiRadioEnergyModelHelper::SetRechargedCallback
void SetRechargedCallback(WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback callback)
Definition
wifi-radio-energy-model-helper.cc:43
ns3::WifiRadioEnergyModelHelper::SetDepletionCallback
void SetDepletionCallback(WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback)
Definition
wifi-radio-energy-model-helper.cc:36
ns3::WifiRadioEnergyModelHelper::DoInstall
Ptr< energy::DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const override
Definition
wifi-radio-energy-model-helper.cc:54
ns3::WifiRadioEnergyModelHelper::m_rechargedCallback
WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback m_rechargedCallback
radio energy recharged callback
Definition
wifi-radio-energy-model-helper.h:86
ns3::WifiRadioEnergyModelHelper::WifiRadioEnergyModelHelper
WifiRadioEnergyModelHelper()
Construct a helper which is used to add a radio energy model to a node.
Definition
wifi-radio-energy-model-helper.cc:18
ns3::WifiRadioEnergyModelHelper::m_depletionCallback
WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback m_depletionCallback
radio energy depletion callback
Definition
wifi-radio-energy-model-helper.h:84
ns3::WifiRadioEnergyModelHelper::Set
void Set(std::string name, const AttributeValue &v) override
Definition
wifi-radio-energy-model-helper.cc:30
ns3::WifiRadioEnergyModelHelper::m_radioEnergy
ObjectFactory m_radioEnergy
radio energy
Definition
wifi-radio-energy-model-helper.h:82
ns3::WifiRadioEnergyModelHelper::m_txCurrentModel
ObjectFactory m_txCurrentModel
transmit current model
Definition
wifi-radio-energy-model-helper.h:87
ns3::WifiRadioEnergyModel
A WiFi radio energy model.
Definition
wifi-radio-energy-model.h:141
ns3::WifiRadioEnergyModel::WifiRadioEnergyRechargedCallback
Callback< void > WifiRadioEnergyRechargedCallback
Callback type for energy recharged handling.
Definition
wifi-radio-energy-model.h:151
ns3::WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback
Callback< void > WifiRadioEnergyDepletionCallback
Callback type for energy depletion handling.
Definition
wifi-radio-energy-model.h:146
ns3::WifiTxCurrentModel
Model the transmit current as a function of the transmit power and mode.
Definition
wifi-tx-current-model.h:26
NS_ASSERT
#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
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition
fatal-error.h:168
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeCallback
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
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:580
wifi-radio-energy-model-helper.h
src
wifi
helper
wifi-radio-energy-model-helper.cc
Generated on Wed Jun 11 2025 13:15:39 for ns-3 by
1.13.2