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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
7 */
8
10
11#include "ns3/config.h"
12#include "ns3/names.h"
13
14namespace ns3
15{
16
17/*
18 * EnergySourceHelper
19 */
23
26{
27 return Install(NodeContainer(node));
28}
29
32{
34 for (auto i = c.Begin(); i != c.End(); ++i)
35 {
37 container.Add(src);
38 /*
39 * Check if EnergySourceContainer is already aggregated to target node. If
40 * not, create a new EnergySourceContainer and aggregate it to node.
41 */
42 Ptr<energy::EnergySourceContainer> EnergySourceContainerOnNode =
43 (*i)->GetObject<energy::EnergySourceContainer>();
44 if (!EnergySourceContainerOnNode)
45 {
46 ObjectFactory fac;
47 fac.SetTypeId("ns3::energy::EnergySourceContainer");
48 EnergySourceContainerOnNode = fac.Create<energy::EnergySourceContainer>();
49 EnergySourceContainerOnNode->Add(src);
50 (*i)->AggregateObject(EnergySourceContainerOnNode);
51 }
52 else
53 {
54 EnergySourceContainerOnNode->Add(src); // append new EnergySource
55 }
56 }
57 return container;
58}
59
61EnergySourceHelper::Install(std::string nodeName) const
62{
63 Ptr<Node> node = Names::Find<Node>(nodeName);
64 return Install(node);
65}
66
72
73/*
74 * DeviceEnergyModelHelper
75 */
79
82{
83 NS_ASSERT(device);
84 NS_ASSERT(source);
85 // check to make sure source and net device are on the same node
86 NS_ASSERT(device->GetNode() == source->GetNode());
87 energy::DeviceEnergyModelContainer container(DoInstall(device, source));
88 return container;
89}
90
93 energy::EnergySourceContainer sourceContainer) const
94{
95 NS_ASSERT(deviceContainer.GetN() <= sourceContainer.GetN());
97 auto dev = deviceContainer.Begin();
98 auto src = sourceContainer.Begin();
99 while (dev != deviceContainer.End())
100 {
101 // check to make sure source and net device are on the same node
102 NS_ASSERT((*dev)->GetNode() == (*src)->GetNode());
103 Ptr<energy::DeviceEnergyModel> model = DoInstall(*dev, *src);
104 container.Add(model);
105 dev++;
106 src++;
107 }
108 return container;
109}
110
111} // namespace ns3
energy::DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const
virtual Ptr< energy::DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const =0
energy::EnergySourceContainer InstallAll() const
This function installs an EnergySource on all nodes in simulation.
energy::EnergySourceContainer Install(Ptr< Node > node) const
virtual Ptr< energy::EnergySource > DoInstall(Ptr< Node > node) const =0
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
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.
Holds a vector of ns3::DeviceEnergyModel pointers.
Holds a vector of ns3::EnergySource pointers.
Iterator Begin() const
Get an iterator which refers to the first EnergySource pointer in the container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.