A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
node-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
#ifndef NODE_CONTAINER_H
9
#define NODE_CONTAINER_H
10
11
#include "ns3/node.h"
12
13
#include <type_traits>
14
#include <vector>
15
16
namespace
ns3
17
{
18
19
/**
20
* @brief keep track of a set of node pointers.
21
*
22
* Typically ns-3 helpers operate on more than one node at a time. For example
23
* a device helper may want to install devices on a large number of similar
24
* nodes. The helper Install methods usually take a NodeContainer as a
25
* parameter. NodeContainers hold the multiple Ptr<Node> which are used
26
* to refer to the nodes.
27
*/
28
class
NodeContainer
29
{
30
public
:
31
/// Node container iterator
32
typedef
std::vector<Ptr<Node>>::const_iterator
Iterator
;
33
34
/**
35
* @brief Create a NodeContainer that contains a list of _all_ nodes
36
* created through NodeContainer::Create() and stored in the
37
* ns3::NodeList.
38
*
39
* Whenever a Node is created, a Ptr<Node> is added to a global list of all
40
* nodes in the system. It is sometimes useful to be able to get to all
41
* nodes in one place. This method creates a NodeContainer that is
42
* initialized to contain all of the simulation nodes,
43
*
44
* @returns a NodeContainer which contains a list of all Nodes.
45
*/
46
static
NodeContainer
GetGlobal
();
47
48
/**
49
* Create an empty NodeContainer.
50
*/
51
NodeContainer
();
52
53
/**
54
* Create a NodeContainer with exactly one node which has been previously
55
* instantiated. The single Node is specified by a smart pointer.
56
*
57
* @param node The Ptr<Node> to add to the container.
58
*/
59
NodeContainer
(
Ptr<Node>
node);
60
61
/**
62
* Create a NodeContainer with exactly one node which has been previously
63
* instantiated and assigned a name using the Object Name Service. This
64
* Node is then specified by its assigned name.
65
*
66
* @param nodeName The name of the Node Object to add to the container.
67
*/
68
NodeContainer
(std::string nodeName);
69
70
/**
71
* Create a NodeContainer with the requested number of Nodes.
72
*
73
* This is syntactic sugar for
74
*
75
* @code
76
* NodeContainer nodes;
77
* nodes.Create (size);
78
* // or nodes.Create (size, systemId);
79
* @endcode
80
*
81
* @param [in] n The number of nodes to create.
82
* @param [in] systemId The system id or rank associated with this node
83
*/
84
explicit
NodeContainer
(
uint32_t
n,
uint32_t
systemId = 0);
85
86
/**
87
* Create a node container which is a concatenation of multiple input
88
* NodeContainers.
89
*
90
* @tparam Ts \deduced Template type parameter pack for the multiple
91
* NodeContainers
92
* @param nc The first NodeContainer
93
* @param args The remaining NodeContainers
94
*
95
* @note A frequently seen idiom that uses these constructors involves the
96
* implicit conversion by constructor of Ptr<Node>. When used, Ptr<Node>
97
* will be passed to this constructor instead of NodeContainer&.
98
* C++ will notice the implicit conversion path that goes through the
99
* NodeContainer (Ptr<Node> node) constructor above. Using this conversion
100
* one may optionally provide arguments of Ptr<Node> to these constructors.
101
*/
102
template
<
typename
... Ts>
103
NodeContainer
(
const
NodeContainer
& nc, Ts&&... args);
104
105
/**
106
* @brief Get an iterator which refers to the first Node in the
107
* container.
108
*
109
* Nodes can be retrieved from the container in two ways. First,
110
* directly by an index into the container, and second, using an iterator.
111
* This method is used in the iterator method and is typically used in a
112
* for-loop to run through the Nodes
113
*
114
* @code
115
* for (auto i = container.Begin(); i != container.End(); ++i)
116
* {
117
* (*i)->method(); // some Node method
118
* }
119
* @endcode
120
*
121
* @returns an iterator which refers to the first Node in the container.
122
* @hidecaller
123
*/
124
Iterator
Begin
()
const
;
125
126
/**
127
* @brief Get an iterator which indicates past-the-last Node in the
128
* container.
129
*
130
* Nodes can be retrieved from the container in two ways. First,
131
* directly by an index into the container, and second, using an iterator.
132
* This method is used in the iterator method and is typically used in a
133
* for-loop to run through the Nodes
134
*
135
* @code
136
* for (auto i = container.Begin(); i != container.End(); ++i)
137
* {
138
* (*i)->method(); // some Node method
139
* }
140
* @endcode
141
*
142
* @returns an iterator which indicates an ending condition for a loop.
143
* @hidecaller
144
*/
145
Iterator
End
()
const
;
146
147
/**
148
* @brief Get the number of Ptr<Node> stored in this container.
149
*
150
* Nodes can be retrieved from the container in two ways. First,
151
* directly by an index into the container, and second, using an iterator.
152
* This method is used in the direct method and is typically used to
153
* define an ending condition in a for-loop that runs through the stored
154
* Nodes
155
*
156
* @code
157
* uint32_t nNodes = container.GetN ();
158
* for (uint32_t i = 0; i < nNodes; ++i)
159
* {
160
* Ptr<Node> p = container.Get (i);
161
* i->method (); // some Node method
162
* }
163
* @endcode
164
*
165
* @returns the number of Ptr<Node> stored in this container.
166
*/
167
uint32_t
GetN
()
const
;
168
169
/**
170
* @brief Get the Ptr<Node> stored in this container at a given
171
* index.
172
*
173
* Nodes can be retrieved from the container in two ways. First,
174
* directly by an index into the container, and second, using an iterator.
175
* This method is used in the direct method and is used to retrieve the
176
* indexed Ptr<Node>.
177
*
178
* @code
179
* uint32_t nNodes = container.GetN ();
180
* for (uint32_t i = 0; i < nNodes; ++i)
181
* {
182
* Ptr<Node> p = container.Get (i);
183
* i->method (); // some Node method
184
* }
185
* @endcode
186
*
187
* @param i the index of the requested node pointer.
188
* @returns the requested node pointer.
189
* @hidecaller
190
*/
191
Ptr<Node>
Get
(
uint32_t
i)
const
;
192
193
/**
194
* @brief Create n nodes and append pointers to them to the end of this
195
* NodeContainer.
196
*
197
* Nodes are at the heart of any ns-3 simulation. One of the first tasks that
198
* any simulation needs to do is to create a number of nodes. This method
199
* automates that task.
200
*
201
* @param n The number of Nodes to create
202
* @hidecaller
203
*/
204
void
Create
(
uint32_t
n);
205
206
/**
207
* @brief Create n nodes with specified systemId for distributed simulations
208
* and append pointers to them to the end of this NodeContainer.
209
*
210
* Nodes are at the heart of any ns-3 simulation. One of the first tasks that
211
* any simulation needs to do is to create a number of nodes. This method
212
* automates that task, and adds the ability to specify systemId for
213
* distributed simulations.
214
*
215
* @param n The number of Nodes to create
216
* @param systemId The system id or rank associated with this node
217
*/
218
void
Create
(
uint32_t
n,
uint32_t
systemId);
219
220
/**
221
* @brief Append the contents of another NodeContainer to the end of
222
* this container.
223
*
224
* @param nc The NodeContainer to append.
225
*/
226
void
Add
(
const
NodeContainer
& nc);
227
228
/**
229
* @brief Append the contents of another NodeContainer to the end of
230
* this container.
231
*
232
* @tparam Ts \deduced Template type parameter pack for the multiple
233
* NodeContainer
234
* @param nc The NodeContainer to append
235
* @param args The remaining NodeContainers to append
236
*/
237
template
<
typename
... Ts>
238
void
Add
(
const
NodeContainer
& nc, Ts&&... args);
239
240
/**
241
* @brief Append a single Ptr<Node> to this container.
242
*
243
* @param node The Ptr<Node> to append.
244
*/
245
void
Add
(
Ptr<Node>
node);
246
247
/**
248
* @brief Append to this container the single Ptr<Node> referred to
249
* via its object name service registered name.
250
*
251
* @param nodeName The name of the Node Object to add to the container.
252
*/
253
void
Add
(std::string nodeName);
254
255
/**
256
* @brief Return true if container contains a Node with index id
257
*
258
* @param id Node Id
259
* @return whether the NodeContainer contains a node with index id
260
*/
261
bool
Contains
(
uint32_t
id
)
const
;
262
263
private
:
264
std::vector<Ptr<Node>>
m_nodes
;
//!< Nodes smart pointers
265
};
266
267
}
// namespace ns3
268
269
///////////////////////////////////////////////////////////
270
// Implementation of the templates declared above
271
///////////////////////////////////////////////////////////
272
273
namespace
ns3
274
{
275
276
template
<
typename
... Ts>
277
NodeContainer::NodeContainer
(
const
NodeContainer
& nc, Ts&&... args)
278
{
279
static_assert
(std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
280
"Variable types are not convertible to NodeContainer"
);
281
282
Add
(nc, std::forward<Ts>(args)...);
283
}
284
285
template
<
typename
... Ts>
286
void
287
NodeContainer::Add
(
const
NodeContainer
& nc, Ts&&... args)
288
{
289
static_assert
(std::conjunction_v<std::is_convertible<Ts, NodeContainer>...>,
290
"Variable types are not convertible to NodeContainer"
);
291
292
Add
(nc);
293
Add
(std::forward<Ts>(args)...);
294
}
295
296
}
// namespace ns3
297
298
#endif
/* NODE_CONTAINER_H */
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition
node-container.h:32
ns3::NodeContainer::End
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Definition
node-container.cc:55
ns3::NodeContainer::m_nodes
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
Definition
node-container.h:264
ns3::NodeContainer::GetN
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
Definition
node-container.cc:61
ns3::NodeContainer::GetGlobal
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Definition
node-container.cc:17
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition
node-container.cc:73
ns3::NodeContainer::Contains
bool Contains(uint32_t id) const
Return true if container contains a Node with index id.
Definition
node-container.cc:113
ns3::NodeContainer::Add
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Definition
node-container.cc:91
ns3::NodeContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Definition
node-container.cc:49
ns3::NodeContainer::NodeContainer
NodeContainer()
Create an empty NodeContainer.
Definition
node-container.cc:27
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition
node-container.cc:67
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
helper
node-container.h
Generated on
for ns-3 by
1.15.0