A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
net-device-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 NET_DEVICE_CONTAINER_H
9#define NET_DEVICE_CONTAINER_H
10
11#include "ns3/net-device.h"
12
13#include <stdint.h>
14#include <vector>
15
16namespace ns3
17{
18
19/**
20 * @brief holds a vector of ns3::NetDevice pointers
21 *
22 * Typically ns-3 NetDevices are installed on nodes using a net device
23 * helper. The helper Install method takes a NodeContainer which holds
24 * some number of Ptr<Node>. For each of the Nodes in the NodeContainer
25 * the helper will instantiate a net device, add a MAC address and a queue
26 * to the device and install it to the node. For each of the devices, the
27 * helper also adds the device into a Container for later use by the caller.
28 * This is that container used to hold the Ptr<NetDevice> which are
29 * instantiated by the device helper.
30 */
32{
33 public:
34 /// NetDevice container iterator
35 typedef std::vector<Ptr<NetDevice>>::const_iterator Iterator;
36
37 /**
38 * Create an empty NetDeviceContainer.
39 */
41
42 /**
43 * @param dev a device to add to the container
44 *
45 * Create a NetDeviceContainer with exactly one net device that has previously
46 * been instantiated
47 */
49
50 /**
51 * Create a NetDeviceContainer with exactly one device which has been
52 * previously instantiated and assigned a name using the Object name
53 * service. This NetDevice is specified by its assigned name.
54 *
55 * @param devName The name of the device to add to the container
56 *
57 * Create a NetDeviceContainer with exactly one device
58 */
59 NetDeviceContainer(std::string devName);
60
61 /**
62 * @param a a device container
63 * @param b another device container
64 *
65 * Create a device container which is a concatenation of the two input
66 * NetDeviceContainers.
67 *
68 * @note A frequently seen idiom that uses these constructors involves the
69 * implicit conversion by constructor of Ptr<NetDevice>. When used, two
70 * Ptr<NetDevice> will be passed to this constructor instead of NetDeviceContainer&.
71 * C++ will notice the implicit conversion path that goes through the
72 * NetDeviceContainer (Ptr<NetDevice> dev) constructor above. Using this conversion
73 * one may provide optionally provide arguments of Ptr<NetDevice> to these
74 * constructors.
75 */
77
78 /**
79 * @brief Get an iterator which refers to the first NetDevice in the
80 * container.
81 *
82 * NetDevices can be retrieved from the container in two ways. First,
83 * directly by an index into the container, and second, using an iterator.
84 * This method is used in the iterator method and is typically used in a
85 * for-loop to run through the NetDevices
86 *
87 * @code
88 * NetDeviceContainer::Iterator i;
89 * for (i = container.Begin (); i != container.End (); ++i)
90 * {
91 * (*i)->method (); // some NetDevice method
92 * }
93 * @endcode
94 *
95 * @returns an iterator which refers to the first NetDevice in the container.
96 */
97 Iterator Begin() const;
98
99 /**
100 * @brief Get an iterator which indicates past-the-last NetDevice in the
101 * container.
102 *
103 * NetDevices can be retrieved from the container in two ways. First,
104 * directly by an index into the container, and second, using an iterator.
105 * This method is used in the iterator method and is typically used in a
106 * for-loop to run through the NetDevices
107 *
108 * @code
109 * NetDeviceContainer::Iterator i;
110 * for (i = container.Begin (); i != container.End (); ++i)
111 * {
112 * (*i)->method (); // some NetDevice method
113 * }
114 * @endcode
115 *
116 * @returns an iterator which indicates an ending condition for a loop.
117 */
118 Iterator End() const;
119
120 /**
121 * @brief Get the number of Ptr<NetDevice> stored in this container.
122 *
123 * NetDevices can be retrieved from the container in two ways. First,
124 * directly by an index into the container, and second, using an iterator.
125 * This method is used in the direct method and is typically used to
126 * define an ending condition in a for-loop that runs through the stored
127 * NetDevices
128 *
129 * @code
130 * uint32_t nDevices = container.GetN ();
131 * for (uint32_t i = 0 i < nDevices; ++i)
132 * {
133 * Ptr<NetDevice> p = container.Get (i)
134 * i->method (); // some NetDevice method
135 * }
136 * @endcode
137 *
138 * @returns the number of Ptr<NetDevice> stored in this container.
139 */
140 uint32_t GetN() const;
141
142 /**
143 * @brief Get the Ptr<NetDevice> stored in this container at a given
144 * index.
145 *
146 * NetDevices can be retrieved from the container in two ways. First,
147 * directly by an index into the container, and second, using an iterator.
148 * This method is used in the direct method and is used to retrieve the
149 * indexed Ptr<NetDevice>.
150 *
151 * @code
152 * uint32_t nDevices = container.GetN ();
153 * for (uint32_t i = 0 i < nDevices; ++i)
154 * {
155 * Ptr<NetDevice> p = container.Get (i)
156 * i->method (); // some NetDevice method
157 * }
158 * @endcode
159 *
160 * @param i the index of the requested device pointer.
161 * @returns the requested device pointer.
162 */
163 Ptr<NetDevice> Get(uint32_t i) const;
164
165 /**
166 * @brief Append the contents of another NetDeviceContainer to the end of
167 * this container.
168 *
169 * @param other The NetDeviceContainer to append.
170 */
171 void Add(NetDeviceContainer other);
172
173 /**
174 * @brief Append a single Ptr<NetDevice> to this container.
175 *
176 * @param device The Ptr<NetDevice> to append.
177 */
178 void Add(Ptr<NetDevice> device);
179
180 /**
181 * @brief Append to this container the single Ptr<NetDevice> referred to
182 * via its object name service registered name.
183 *
184 * @param deviceName The name of the NetDevice Object to add to the container.
185 */
186 void Add(std::string deviceName);
187
188 private:
189 std::vector<Ptr<NetDevice>> m_devices; //!< NetDevices smart pointers
190};
191
192} // namespace ns3
193
194#endif /* NET_DEVICE_CONTAINER_H */
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
std::vector< Ptr< NetDevice > > m_devices
NetDevices smart pointers.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer()
Create an empty NetDeviceContainer.
Smart pointer class similar to boost::intrusive_ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.