A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
20#include "energy-model-helper.h"
21
22#include "ns3/config.h"
23#include "ns3/names.h"
24
25namespace ns3
26{
27
28/*
29 * EnergySourceHelper
30 */
32{
33}
34
37{
38 return Install(NodeContainer(node));
39}
40
43{
44 EnergySourceContainer container;
45 for (auto i = c.Begin(); i != c.End(); ++i)
46 {
48 container.Add(src);
49 /*
50 * Check if EnergySourceContainer is already aggregated to target node. If
51 * not, create a new EnergySourceContainer and aggregate it to node.
52 */
53 Ptr<EnergySourceContainer> EnergySourceContainerOnNode =
54 (*i)->GetObject<EnergySourceContainer>();
55 if (!EnergySourceContainerOnNode)
56 {
57 ObjectFactory fac;
58 fac.SetTypeId("ns3::EnergySourceContainer");
59 EnergySourceContainerOnNode = fac.Create<EnergySourceContainer>();
60 EnergySourceContainerOnNode->Add(src);
61 (*i)->AggregateObject(EnergySourceContainerOnNode);
62 }
63 else
64 {
65 EnergySourceContainerOnNode->Add(src); // append new EnergySource
66 }
67 }
68 return container;
69}
70
72EnergySourceHelper::Install(std::string nodeName) const
73{
74 Ptr<Node> node = Names::Find<Node>(nodeName);
75 return Install(node);
76}
77
80{
82}
83
84/*
85 * DeviceEnergyModelHelper
86 */
88{
89}
90
93{
94 NS_ASSERT(device);
95 NS_ASSERT(source);
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
104 EnergySourceContainer sourceContainer) const
105{
106 NS_ASSERT(deviceContainer.GetN() <= sourceContainer.GetN());
108 auto dev = deviceContainer.Begin();
109 auto 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
Holds a vector of ns3::DeviceEnergyModel pointers.
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
virtual Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const =0
Holds a vector of ns3::EnergySource pointers.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
EnergySourceContainer Install(Ptr< Node > node) const
virtual Ptr< EnergySource > DoInstall(Ptr< Node > node) const =0
EnergySourceContainer InstallAll() const
This function installs an EnergySource on all nodes in simulation.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.