A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
application-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
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 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20#include "application-helper.h"
21
22#include <ns3/data-rate.h>
23#include <ns3/names.h>
24#include <ns3/string.h>
25
26namespace ns3
27{
28
30{
31 SetTypeId(typeId);
32}
33
34ApplicationHelper::ApplicationHelper(const std::string& typeId)
35{
36 SetTypeId(typeId);
37}
38
39void
41{
42 m_factory.SetTypeId(typeId);
43}
44
45void
46ApplicationHelper::SetTypeId(const std::string& typeId)
47{
48 m_factory.SetTypeId(typeId);
49}
50
51void
52ApplicationHelper::SetAttribute(const std::string& name, const AttributeValue& value)
53{
54 m_factory.Set(name, value);
55}
56
59{
60 return ApplicationContainer(DoInstall(node));
61}
62
64ApplicationHelper::Install(const std::string& nodeName)
65{
66 auto node = Names::Find<Node>(nodeName);
67 NS_ABORT_MSG_IF(!node, "Node " << nodeName << " does not exist");
68 return ApplicationContainer(DoInstall(node));
69}
70
73{
75 for (auto i = c.Begin(); i != c.End(); ++i)
76 {
77 apps.Add(DoInstall(*i));
78 }
79 return apps;
80}
81
84{
85 NS_ABORT_MSG_IF(!node, "Node does not exist");
86 auto app = m_factory.Create<Application>();
87 node->AddApplication(app);
88 return app;
89}
90
91int64_t
93{
94 NS_ABORT_MSG_IF(!m_factory.IsTypeIdSet(), "Type ID not set");
95 auto currentStream = stream;
96 for (auto i = c.Begin(); i != c.End(); ++i)
97 {
98 auto node = (*i);
99 for (uint32_t j = 0; j < node->GetNApplications(); ++j)
100 {
101 if (auto app = node->GetApplication(j);
102 app->GetInstanceTypeId() == m_factory.GetTypeId())
103 {
104 currentStream += app->AssignStreams(currentStream);
105 }
106 }
107 }
108 return (currentStream - stream);
109}
110
111int64_t
113{
114 auto currentStream = stream;
115 for (auto i = c.Begin(); i != c.End(); ++i)
116 {
117 auto node = (*i);
118 for (uint32_t j = 0; j < node->GetNApplications(); ++j)
119 {
120 currentStream += node->GetApplication(j)->AssignStreams(currentStream);
121 }
122 }
123 return (currentStream - stream);
124}
125
126} // namespace ns3
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
ObjectFactory m_factory
Object factory.
static int64_t AssignStreamsToAllApps(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by all the applications.
ApplicationHelper(TypeId typeId)
Create an application of a given type ID.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assigns a unique (monotonically increasing) stream number to all applications that match the configur...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetTypeId(TypeId typeId)
Allow the helper to be repurposed for another application type.
virtual Ptr< Application > DoInstall(Ptr< Node > node)
Install an application on the node configured with all the attributes set with SetAttribute.
The base class for all ns3 applications.
Definition: application.h:62
Hold a value for an Attribute.
Definition: attribute.h:70
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
TypeId GetTypeId() const
Get the TypeId which will be created by this ObjectFactory.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsTypeIdSet() const
Check if the ObjectFactory has been configured with a TypeId.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Every class exported by the ns3 library is enclosed in the ns3 namespace.