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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
10
11#include <ns3/data-rate.h>
12#include <ns3/names.h>
13#include <ns3/string.h>
14
15namespace ns3
16{
17
22
23ApplicationHelper::ApplicationHelper(const std::string& typeId)
24{
25 SetTypeId(typeId);
26}
27
28void
33
34void
35ApplicationHelper::SetTypeId(const std::string& typeId)
36{
37 m_factory.SetTypeId(typeId);
38}
39
40void
41ApplicationHelper::SetAttribute(const std::string& name, const AttributeValue& value)
42{
43 m_factory.Set(name, value);
44}
45
51
53ApplicationHelper::Install(const std::string& nodeName)
54{
55 auto node = Names::Find<Node>(nodeName);
56 NS_ABORT_MSG_IF(!node, "Node " << nodeName << " does not exist");
57 return ApplicationContainer(DoInstall(node));
58}
59
62{
64 for (auto i = c.Begin(); i != c.End(); ++i)
65 {
66 apps.Add(DoInstall(*i));
67 }
68 return apps;
69}
70
73{
74 NS_ABORT_MSG_IF(!node, "Node does not exist");
75 auto app = m_factory.Create<Application>();
76 node->AddApplication(app);
77 return app;
78}
79
80int64_t
82{
83 NS_ABORT_MSG_IF(!m_factory.IsTypeIdSet(), "Type ID not set");
84 auto currentStream = stream;
85 for (auto i = c.Begin(); i != c.End(); ++i)
86 {
87 auto node = (*i);
88 for (uint32_t j = 0; j < node->GetNApplications(); ++j)
89 {
90 if (auto app = node->GetApplication(j);
91 app->GetInstanceTypeId() == m_factory.GetTypeId())
92 {
93 currentStream += app->AssignStreams(currentStream);
94 }
95 }
96 }
97 return (currentStream - stream);
98}
99
100int64_t
102{
103 auto currentStream = stream;
104 for (auto i = c.Begin(); i != c.End(); ++i)
105 {
106 auto node = (*i);
107 for (uint32_t j = 0; j < node->GetNApplications(); ++j)
108 {
109 currentStream += node->GetApplication(j)->AssignStreams(currentStream);
110 }
111 }
112 return (currentStream - stream);
113}
114
115} // 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:51
Hold a value for an Attribute.
Definition attribute.h:59
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
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.
a unique identifier for an interface.
Definition type-id.h:48
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
Every class exported by the ns3 library is enclosed in the ns3 namespace.