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-model-helper.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
* Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
19
*/
20
21
#include "
energy-model-helper.h
"
22
#include "ns3/config.h"
23
#include "ns3/names.h"
24
25
namespace
ns3 {
26
27
/*
28
* EnergySourceHelper
29
*/
30
EnergySourceHelper::~EnergySourceHelper
()
31
{
32
}
33
34
EnergySourceContainer
35
EnergySourceHelper::Install
(
Ptr<Node>
node)
const
36
{
37
return
Install
(
NodeContainer
(node));
38
}
39
40
EnergySourceContainer
41
EnergySourceHelper::Install
(
NodeContainer
c)
const
42
{
43
EnergySourceContainer
container;
44
for
(
NodeContainer::Iterator
i = c.
Begin
(); i != c.
End
(); ++i)
45
{
46
Ptr<EnergySource>
src =
DoInstall
(*i);
47
container.
Add
(src);
48
/*
49
* Check if EnergySourceContainer is already aggregated to target node. If
50
* not, create a new EnergySourceContainer and aggregate it to node.
51
*/
52
Ptr<EnergySourceContainer>
EnergySourceContrainerOnNode =
53
(*i)->GetObject<
EnergySourceContainer
> ();
54
if
(EnergySourceContrainerOnNode == NULL)
55
{
56
ObjectFactory
fac;
57
fac.
SetTypeId
(
"ns3::EnergySourceContainer"
);
58
EnergySourceContrainerOnNode = fac.
Create
<
EnergySourceContainer
> ();
59
EnergySourceContrainerOnNode->Add (src);
60
(*i)->AggregateObject (EnergySourceContrainerOnNode);
61
}
62
else
63
{
64
EnergySourceContrainerOnNode->Add (src);
// append new EnergySource
65
}
66
}
67
return
container;
68
}
69
70
EnergySourceContainer
71
EnergySourceHelper::Install
(std::string nodeName)
const
72
{
73
Ptr<Node>
node = Names::Find<Node> (nodeName);
74
return
Install
(node);
75
}
76
77
EnergySourceContainer
78
EnergySourceHelper::InstallAll
(
void
)
const
79
{
80
return
Install
(
NodeContainer::GetGlobal
());
81
}
82
83
/*
84
* DeviceEnergyModelHelper
85
*/
86
DeviceEnergyModelHelper::~DeviceEnergyModelHelper
()
87
{
88
}
89
90
DeviceEnergyModelContainer
91
DeviceEnergyModelHelper::Install
(
Ptr<NetDevice>
device,
92
Ptr<EnergySource>
source)
const
93
{
94
NS_ASSERT
(device != NULL);
95
NS_ASSERT
(source != NULL);
96
// check to make sure source and net device are on the same node
97
NS_ASSERT
(device->
GetNode
() == source->
GetNode
());
98
DeviceEnergyModelContainer
container (
DoInstall
(device, source));
99
return
container;
100
}
101
102
DeviceEnergyModelContainer
103
DeviceEnergyModelHelper::Install
(
NetDeviceContainer
deviceContainer,
104
EnergySourceContainer
sourceContainer)
const
105
{
106
NS_ASSERT
(deviceContainer.
GetN
() <= sourceContainer.
GetN
());
107
DeviceEnergyModelContainer
container;
108
NetDeviceContainer::Iterator
dev = deviceContainer.
Begin
();
109
EnergySourceContainer::Iterator
src = sourceContainer.
Begin
();
110
while
(dev != deviceContainer.
End
())
111
{
112
// check to make sure source and net device are on the same node
113
NS_ASSERT
((*dev)->GetNode () == (*src)->GetNode ());
114
Ptr<DeviceEnergyModel>
model =
DoInstall
(*dev, *src);
115
container.Add (model);
116
dev++;
117
src++;
118
}
119
return
container;
120
}
121
122
}
// namespace ns3
src
energy
helper
energy-model-helper.cc
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2