A Discrete-Event Network Simulator
API
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  */
31 {
32 }
33 
36 {
37  return Install (NodeContainer (node));
38 }
39 
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> EnergySourceContainerOnNode =
53  (*i)->GetObject<EnergySourceContainer> ();
54  if (EnergySourceContainerOnNode == NULL)
55  {
56  ObjectFactory fac;
57  fac.SetTypeId ("ns3::EnergySourceContainer");
58  EnergySourceContainerOnNode = fac.Create<EnergySourceContainer> ();
59  EnergySourceContainerOnNode->Add (src);
60  (*i)->AggregateObject (EnergySourceContainerOnNode);
61  }
62  else
63  {
64  EnergySourceContainerOnNode->Add (src); // append new EnergySource
65  }
66  }
67  return container;
68 }
69 
71 EnergySourceHelper::Install (std::string nodeName) const
72 {
73  Ptr<Node> node = Names::Find<Node> (nodeName);
74  return Install (node);
75 }
76 
79 {
81 }
82 
83 /*
84  * DeviceEnergyModelHelper
85  */
87 {
88 }
89 
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 
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
Holds a vector of ns3::EnergySource pointers.
void Add(EnergySourceContainer container)
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
std::vector< Ptr< EnergySource > >::const_iterator Iterator
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
virtual Ptr< EnergySource > DoInstall(Ptr< Node > node) const =0
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Holds a vector of ns3::DeviceEnergyModel pointers.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
uint32_t GetN(void) const
Get the number of Ptr<EnergySource> stored in this container.
holds a vector of ns3::NetDevice pointers
Iterator Begin(void) const
Get an iterator which refers to the first EnergySource pointer in the container.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
EnergySourceContainer InstallAll(void) const
This function installs an EnergySource on all nodes in simulation.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Instantiate subclasses of ns3::Object.
EnergySourceContainer Install(Ptr< Node > node) const
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
virtual Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const =0
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const