A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
energy-source.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
19
*/
20
21
#include "
energy-source.h
"
22
#include "ns3/log.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"EnergySource"
);
25
26
namespace
ns3 {
27
28
NS_OBJECT_ENSURE_REGISTERED
(EnergySource);
29
30
TypeId
31
EnergySource::GetTypeId
(
void
)
32
{
33
static
TypeId
tid =
TypeId
(
"ns3::EnergySource"
)
34
.
SetParent
<
Object
> ()
35
;
36
return
tid;
37
}
38
39
EnergySource::EnergySource
()
40
{
41
NS_LOG_FUNCTION
(
this
);
42
}
43
44
EnergySource::~EnergySource
()
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
49
void
50
EnergySource::SetNode
(
Ptr<Node>
node)
51
{
52
NS_LOG_FUNCTION
(
this
);
53
NS_ASSERT
(node != NULL);
54
m_node
= node;
55
}
56
57
Ptr<Node>
58
EnergySource::GetNode
(
void
)
const
59
{
60
NS_LOG_FUNCTION
(
this
);
61
return
m_node
;
62
}
63
64
void
65
EnergySource::AppendDeviceEnergyModel
(
Ptr<DeviceEnergyModel>
deviceEnergyModelPtr)
66
{
67
NS_LOG_FUNCTION
(
this
<< deviceEnergyModelPtr);
68
NS_ASSERT
(deviceEnergyModelPtr != NULL);
// model must exist
69
m_models
.
Add
(deviceEnergyModelPtr);
70
}
71
72
DeviceEnergyModelContainer
73
EnergySource::FindDeviceEnergyModels
(
TypeId
tid)
74
{
75
NS_LOG_FUNCTION
(
this
<< tid);
76
DeviceEnergyModelContainer
container;
77
DeviceEnergyModelContainer::Iterator
i;
78
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
79
{
80
if
((*i)->GetInstanceTypeId () == tid)
81
{
82
container.
Add
(*i);
83
}
84
}
85
return
container;
86
}
87
88
DeviceEnergyModelContainer
89
EnergySource::FindDeviceEnergyModels
(std::string name)
90
{
91
NS_LOG_FUNCTION
(
this
<< name);
92
DeviceEnergyModelContainer
container;
93
DeviceEnergyModelContainer::Iterator
i;
94
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
95
{
96
if
((*i)->GetInstanceTypeId ().GetName ().compare (name) == 0)
97
{
98
container.
Add
(*i);
99
}
100
}
101
return
container;
102
}
103
104
void
105
EnergySource::InitializeDeviceModels
(
void
)
106
{
107
NS_LOG_FUNCTION
(
this
);
108
/*
109
* Device models are not aggregated to the node, hence we have to manually
110
* call dispose method here.
111
*/
112
DeviceEnergyModelContainer::Iterator
i;
113
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
114
{
115
(*i)->Initialize ();
116
}
117
}
118
119
void
120
EnergySource::DisposeDeviceModels
(
void
)
121
{
122
NS_LOG_FUNCTION
(
this
);
123
/*
124
* Device models are not aggregated to the node, hence we have to manually
125
* call dispose method here.
126
*/
127
DeviceEnergyModelContainer::Iterator
i;
128
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
129
{
130
(*i)->Dispose ();
131
}
132
}
133
134
/*
135
* Private function starts here.
136
*/
137
138
void
139
EnergySource::DoDispose
(
void
)
140
{
141
NS_LOG_FUNCTION
(
this
);
142
BreakDeviceEnergyModelRefCycle
();
143
}
144
145
/*
146
* Protected functions start here.
147
*/
148
149
double
150
EnergySource::CalculateTotalCurrent
(
void
)
151
{
152
NS_LOG_FUNCTION
(
this
);
153
double
totalCurrentA = 0.0;
154
DeviceEnergyModelContainer::Iterator
i;
155
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
156
{
157
totalCurrentA += (*i)->GetCurrentA ();
158
}
159
return
totalCurrentA;
160
}
161
162
void
163
EnergySource::NotifyEnergyDrained
(
void
)
164
{
165
NS_LOG_FUNCTION
(
this
);
166
// notify all device energy models installed on node
167
DeviceEnergyModelContainer::Iterator
i;
168
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
169
{
170
(*i)->HandleEnergyDepletion ();
171
}
172
}
173
174
void
175
EnergySource::BreakDeviceEnergyModelRefCycle
(
void
)
176
{
177
NS_LOG_FUNCTION
(
this
);
178
m_models
.
Clear
();
179
m_node
= NULL;
180
}
181
182
}
// namespace ns3
src
energy
model
energy-source.cc
Generated on Fri Aug 30 2013 01:42:49 for ns-3 by
1.8.1.2