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 */
43 (*i)->GetObject<energy::EnergySourceContainer>();
45 {
47 fac.SetTypeId("ns3::energy::EnergySourceContainer");
50 (*i)->AggregateObject(EnergySourceContainerOnNode);
51 }
52 else
53 {
54 EnergySourceContainerOnNode->Add(src); // append new EnergySource
55 }
56 }
57 return container;
58}
59
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);
85 // check to make sure source and net device are on the same node
86 NS_ASSERT(device->GetNode() == source->GetNode());
88 return container;
89}
90
94{
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());
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
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Instantiate subclasses of ns3::Object.
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:66
Holds a vector of ns3::DeviceEnergyModel pointers.
Holds a vector of ns3::EnergySource pointers.
void Add(EnergySourceContainer 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
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.