A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-interface-container.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@cutebugs.net>
18 */
19
20#ifndef IPV4_INTERFACE_CONTAINER_H
21#define IPV4_INTERFACE_CONTAINER_H
22
23#include "ns3/ipv4-address.h"
24#include "ns3/ipv4.h"
25
26#include <stdint.h>
27#include <vector>
28
29namespace ns3
30{
31
32/**
33 * \ingroup ipv4
34 *
35 * \brief holds a vector of std::pair of Ptr<Ipv4> and interface index.
36 *
37 * Typically ns-3 Ipv4Interfaces are installed on devices using an Ipv4 address
38 * helper. The helper's Assign() method takes a NetDeviceContainer which holds
39 * some number of Ptr<NetDevice>. For each of the NetDevices in the
40 * NetDeviceContainer the helper will find the associated Ptr<Node> and
41 * Ptr<Ipv4>. It makes sure that an interface exists on the node for the
42 * device and then adds an Ipv4Address according to the address helper settings
43 * (incrementing the Ipv4Address somehow as it goes). The helper then converts
44 * the Ptr<Ipv4> and the interface index to a std::pair and adds them to a
45 * container -- a container of this type.
46 *
47 * The point is then to be able to implicitly associate an index into the
48 * original NetDeviceContainer (that identifies a particular net device) with
49 * an identical index into the Ipv4InterfaceContainer that has a std::pair with
50 * the Ptr<Ipv4> and interface index you need to play with the interface.
51 *
52 * @see Ipv4AddressHelper
53 * @see Ipv4
54 */
56{
57 public:
58 /**
59 * \brief Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
60 */
61 typedef std::vector<std::pair<Ptr<Ipv4>, uint32_t>>::const_iterator Iterator;
62
63 /**
64 * Create an empty Ipv4InterfaceContainer.
65 */
67
68 /**
69 * Concatenate the entries in the other container with ours.
70 * \param other container
71 */
72 void Add(const Ipv4InterfaceContainer& other);
73
74 /**
75 * \brief Get an iterator which refers to the first pair in the
76 * container.
77 *
78 * Pairs can be retrieved from the container in two ways. First,
79 * directly by an index into the container, and second, using an iterator.
80 * This method is used in the iterator method and is typically used in a
81 * for-loop to run through the pairs
82 *
83 * \code
84 * Ipv4InterfaceContainer::Iterator i;
85 * for (i = container.Begin (); i != container.End (); ++i)
86 * {
87 * std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
88 * method (pair.first, pair.second); // use the pair
89 * }
90 * \endcode
91 *
92 * \returns an iterator which refers to the first pair in the container.
93 */
94 Iterator Begin() const;
95
96 /**
97 * \brief Get an iterator which indicates past-the-last Node in the
98 * container.
99 *
100 * Nodes can be retrieved from the container in two ways. First,
101 * directly by an index into the container, and second, using an iterator.
102 * This method is used in the iterator method and is typically used in a
103 * for-loop to run through the Nodes
104 *
105 * \code
106 * NodeContainer::Iterator i;
107 * for (i = container.Begin (); i != container.End (); ++i)
108 * {
109 * std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
110 * method (pair.first, pair.second); // use the pair
111 * }
112 * \endcode
113 *
114 * \returns an iterator which indicates an ending condition for a loop.
115 */
116 Iterator End() const;
117
118 /**
119 * \returns the number of Ptr<Ipv4> and interface pairs stored in this
120 * Ipv4InterfaceContainer.
121 *
122 * Pairs can be retrieved from the container in two ways. First,
123 * directly by an index into the container, and second, using an iterator.
124 * This method is used in the direct method and is typically used to
125 * define an ending condition in a for-loop that runs through the stored
126 * Nodes
127 *
128 * \code
129 * uint32_t nNodes = container.GetN ();
130 * for (uint32_t i = 0 i < nNodes; ++i)
131 * {
132 * std::pair<Ptr<Ipv4>, uint32_t> pair = container.Get (i);
133 * method (pair.first, pair.second); // use the pair
134 * }
135 * \endcode
136 *
137 * \returns the number of Ptr<Node> stored in this container.
138 */
139 uint32_t GetN() const;
140
141 /**
142 * \param i index of ipInterfacePair in container
143 * \param j interface address index (if interface has multiple addresses)
144 * \returns the IPv4 address of the j'th address of the interface
145 * corresponding to index i.
146 *
147 * If the second parameter is omitted, the zeroth indexed address of
148 * the interface is returned. Unless IP aliasing is being used on
149 * the interface, the second parameter may typically be omitted.
150 */
151 Ipv4Address GetAddress(uint32_t i, uint32_t j = 0) const;
152
153 /**
154 * \brief Set a metric for the given interface
155 * \param i Interface index
156 * \param metric the interface metric
157 */
158 void SetMetric(uint32_t i, uint16_t metric);
159
160 /**
161 * Manually add an entry to the container consisting of the individual parts
162 * of an entry std::pair.
163 *
164 * \param ipv4 pointer to Ipv4 object
165 * \param interface interface index of the Ipv4Interface to add to the container
166 */
167 void Add(Ptr<Ipv4> ipv4, uint32_t interface);
168
169 /**
170 * Manually add an entry to the container consisting of a previously composed
171 * entry std::pair.
172 *
173 * \param ipInterfacePair the pair of a pointer to Ipv4 object and interface index of the
174 * Ipv4Interface to add to the container
175 */
176 void Add(std::pair<Ptr<Ipv4>, uint32_t> ipInterfacePair);
177
178 /**
179 * Manually add an entry to the container consisting of the individual parts
180 * of an entry std::pair.
181 *
182 * \param ipv4Name std:string referring to the saved name of an Ipv4 Object that
183 * has been previously named using the Object Name Service.
184 * \param interface interface index of the Ipv4Interface to add to the container
185 */
186 void Add(std::string ipv4Name, uint32_t interface);
187
188 /**
189 * Get the std::pair of an Ptr<Ipv4> and interface stored at the location
190 * specified by the index.
191 *
192 * \param i the index of the container entry to retrieve.
193 * \return the std::pair of a Ptr<Ipv4> and an interface index
194 *
195 * \note The returned Ptr<Ipv4> cannot be used directly to fetch the
196 * Ipv4Interface using the returned index (the GetInterface () method
197 * is provided in class Ipv4L3Protocol, and not class Ipv4). An
198 * example usage is provided below.
199 *
200 * \code
201 * Ipv4InterfaceContainer c;
202 * ...
203 * std::pair<Ptr<Ipv4>, uint32_t> returnValue = c.Get (0);
204 * Ptr<Ipv4> ipv4 = returnValue.first;
205 * uint32_t index = returnValue.second;
206 * Ptr<Ipv4Interface> iface = DynamicCast<Ipv4L3Protocol> (ipv4)->GetInterface (index);
207 * \endcode
208 */
209 std::pair<Ptr<Ipv4>, uint32_t> Get(uint32_t i) const;
210
211 private:
212 /**
213 * \brief Container for pairs of Ipv4 smart pointer / Interface Index.
214 */
215 typedef std::vector<std::pair<Ptr<Ipv4>, uint32_t>> InterfaceVector;
216
217 /**
218 * \brief List of IPv4 stack and interfaces index.
219 */
221};
222
223} // namespace ns3
224
225#endif /* IPV4_INTERFACE_CONTAINER_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > > InterfaceVector
Container for pairs of Ipv4 smart pointer / Interface Index.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
void SetMetric(uint32_t i, uint16_t metric)
Set a metric for the given interface.
InterfaceVector m_interfaces
List of IPv4 stack and interfaces index.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
Ipv4InterfaceContainer()
Create an empty Ipv4InterfaceContainer.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.