A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
application-container.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef APPLICATION_CONTAINER_H
10#define APPLICATION_CONTAINER_H
11
12#include "ns3/application.h"
13#include "ns3/random-variable-stream.h"
14
15#include <stdint.h>
16#include <vector>
17
18namespace ns3
19{
20
21/**
22 * @brief holds a vector of ns3::Application pointers.
23 *
24 * Typically ns-3 Applications are installed on nodes using an Application
25 * helper. The helper Install method takes a NodeContainer which holds
26 * some number of Ptr<Node>. For each of the Nodes in the NodeContainer
27 * the helper will instantiate an application, install it in a node and
28 * add a Ptr<Application> to that application into a Container for use
29 * by the caller. This is that container used to hold the Ptr<Application>
30 * which are instantiated by the Application helper.
31 */
33{
34 public:
35 /**
36 * Create an empty ApplicationContainer.
37 */
39
40 /**
41 * Create an ApplicationContainer with exactly one application which has
42 * been previously instantiated. The single application is specified
43 * by a smart pointer.
44 *
45 * @param application The Ptr<Application> to add to the container.
46 */
48
49 /**
50 * Create an ApplicationContainer with exactly one application which has
51 * been previously instantiated and assigned a name using the Object Name
52 * Service. This Application is then specified by its assigned name.
53 *
54 * @param name The name of the Application Object to add to the container.
55 */
56 ApplicationContainer(std::string name);
57
58 /// Application container iterator
59 typedef std::vector<Ptr<Application>>::const_iterator Iterator;
60
61 /**
62 * @brief Get an iterator which refers to the first Application in the
63 * container.
64 *
65 * Applications can be retrieved from the container in two ways. First,
66 * directly by an index into the container, and second, using an iterator.
67 * This method is used in the iterator method and is typically used in a
68 * for-loop to run through the Applications
69 *
70 * @code
71 * ApplicationContainer::Iterator i;
72 * for (i = container.Begin (); i != container.End (); ++i)
73 * {
74 * (*i)->method (); // some Application method
75 * }
76 * @endcode
77 *
78 * @returns an iterator which refers to the first Application in the container.
79 */
80 Iterator Begin() const;
81
82 /**
83 * @brief Get an iterator which indicates past-the-last Application in the
84 * container.
85 *
86 * Applications can be retrieved from the container in two ways. First,
87 * directly by an index into the container, and second, using an iterator.
88 * This method is used in the iterator method and is typically used in a
89 * for-loop to run through the Applications
90 *
91 * @code
92 * ApplicationContainer::Iterator i;
93 * for (i = container.Begin (); i != container.End (); ++i)
94 * {
95 * (*i)->method (); // some Application method
96 * }
97 * @endcode
98 *
99 * @returns an iterator which indicates an ending condition for a loop.
100 */
101 Iterator End() const;
102
103 /**
104 * @brief Get the number of Ptr<Application> stored in this container.
105 *
106 * Applications can be retrieved from the container in two ways. First,
107 * directly by an index into the container, and second, using an iterator.
108 * This method is used in the direct method and is typically used to
109 * define an ending condition in a for-loop that runs through the stored
110 * Applications
111 *
112 * @code
113 * uint32_t nApplications = container.GetN ();
114 * for (uint32_t i = 0 i < nApplications; ++i)
115 * {
116 * Ptr<Application> p = container.Get (i)
117 * i->method (); // some Application method
118 * }
119 * @endcode
120 *
121 * @returns the number of Ptr<Application> stored in this container.
122 */
123 uint32_t GetN() const;
124
125 /**
126 * @brief Get the Ptr<Application> stored in this container at a given
127 * index.
128 *
129 * Applications can be retrieved from the container in two ways. First,
130 * directly by an index into the container, and second, using an iterator.
131 * This method is used in the direct method and is used to retrieve the
132 * indexed Ptr<Application>.
133 *
134 * @code
135 * uint32_t nApplications = container.GetN ();
136 * for (uint32_t i = 0 i < nApplications; ++i)
137 * {
138 * Ptr<Application> p = container.Get (i)
139 * i->method (); // some Application method
140 * }
141 * @endcode
142 *
143 * @param i the index of the requested application pointer.
144 * @returns the requested application pointer.
145 */
147
148 /**
149 * @brief Append the contents of another ApplicationContainer to the end of
150 * this container.
151 *
152 * @param other The ApplicationContainer to append.
153 */
154 void Add(ApplicationContainer other);
155
156 /**
157 * @brief Append a single Ptr<Application> to this container.
158 *
159 * @param application The Ptr<Application> to append.
160 */
161 void Add(Ptr<Application> application);
162
163 /**
164 * @brief Append to this container the single Ptr<Application> referred to
165 * via its object name service registered name.
166 *
167 * @param name The name of the Application Object to add to the container.
168 */
169 void Add(std::string name);
170
171 /**
172 * @brief Start all of the Applications in this container at the start time
173 * given as a parameter.
174 *
175 * All Applications need to be provided with a starting simulation time and
176 * a stopping simulation time. The ApplicationContainer is a convenient
177 * place for allowing all of the contained Applications to be told to wake
178 * up and start doing their thing (Start) at a common time.
179 *
180 * This method simply iterates through the contained Applications and calls
181 * their Application::SetStartTime() methods with the provided Time.
182 *
183 * @param start The Time at which each of the applications should start.
184 */
185 void Start(Time start) const;
186
187 /**
188 * @brief Start all of the Applications in this container at the start time
189 * given as a parameter, plus some jitter.
190 *
191 * This method iterates through the contained Applications and calls
192 * their Application::SetStartTime() methods with the provided start Time, plus
193 * a jitter value drawn from the provided random variable.
194 *
195 * @param start The Time at which each of the applications should start.
196 * @param rv The random variable that adds jitter (units of seconds)
197 */
198 void StartWithJitter(Time start, Ptr<RandomVariableStream> rv) const;
199
200 /**
201 * @brief Arrange for all of the Applications in this container to Stop()
202 * at the Time given as a parameter.
203 *
204 * All Applications need to be provided with a starting simulation time and
205 * a stopping simulation time. The ApplicationContainer is a convenient
206 * place for allowing all of the contained Applications to be told to shut
207 * down and stop doing their thing (Stop) at a common time.
208 *
209 * This method simply iterates through the contained Applications and calls
210 * their Application::SetStopTime() methods with the provided Time.
211 *
212 * @param stop The Time at which each of the applications should stop.
213 */
214 void Stop(Time stop) const;
215
216 private:
217 std::vector<Ptr<Application>> m_applications; //!< Applications smart pointers
218};
219
220} // namespace ns3
221
222#endif /* APPLICATION_CONTAINER_H */
holds a vector of ns3::Application pointers.
std::vector< Ptr< Application > > m_applications
Applications smart pointers.
Iterator Begin() const
Get an iterator which refers to the first Application in the container.
Iterator End() const
Get an iterator which indicates past-the-last Application in the container.
std::vector< Ptr< Application > >::const_iterator Iterator
Application container iterator.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void StartWithJitter(Time start, Ptr< RandomVariableStream > rv) const
Start all of the Applications in this container at the start time given as a parameter,...
ApplicationContainer()
Create an empty ApplicationContainer.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
uint32_t GetN() const
Get the number of Ptr<Application> stored in this container.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Every class exported by the ns3 library is enclosed in the ns3 namespace.