A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-interface-container.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
3 * 2013 Universita' di Firenze
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
20 */
21
22#ifndef IPV6_INTERFACE_CONTAINER_H
23#define IPV6_INTERFACE_CONTAINER_H
24
25#include "ns3/ipv6-address.h"
26#include "ns3/ipv6.h"
27
28#include <stdint.h>
29#include <vector>
30
31namespace ns3
32{
33
34/**
35 * \ingroup ipv6
36 *
37 * \brief Keep track of a set of IPv6 interfaces.
38 */
40{
41 public:
42 /**
43 * \brief Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
44 */
45 typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t>>::const_iterator Iterator;
46
47 /**
48 * \brief Constructor.
49 */
51
52 /**
53 * \returns the number of Ptr<Ipv6> and interface pairs stored in this
54 * Ipv6InterfaceContainer.
55 *
56 * Pairs can be retrieved from the container in two ways. First,
57 * directly by an index into the container, and second, using an iterator.
58 * This method is used in the direct method and is typically used to
59 * define an ending condition in a for-loop that runs through the stored
60 * Nodes
61 *
62 * \code
63 * uint32_t nNodes = container.GetN ();
64 * for (uint32_t i = 0 i < nNodes; ++i)
65 * {
66 * std::pair<Ptr<Ipv6>, uint32_t> pair = container.Get (i);
67 * method (pair.first, pair.second); // use the pair
68 * }
69 * \endcode
70 */
71 uint32_t GetN() const;
72
73 /**
74 * \brief Get the interface index for the specified node index.
75 * \param i index of the node
76 * \return interface index
77 */
79
80 /**
81 * \brief Get the address for the specified index.
82 * \param i interface index
83 * \param j address index, generally index 0 is the link-local address
84 * \return IPv6 address
85 */
87
88 /**
89 * \brief Get the link-local address for the specified index.
90 * \param i index
91 * \return the link-local address, or "::" if the interface has no link local address.
92 */
94
95 /**
96 * \brief Get the link-local address for the node with the specified global address.
97 * \param address the address to find.
98 * \return the link-local address, or "::" if the interface has no link local address.
99 */
101
102 /**
103 * \brief Add a couple IPv6/interface.
104 * \param ipv6 IPv6 address
105 * \param interface interface index
106 */
107 void Add(Ptr<Ipv6> ipv6, uint32_t interface);
108
109 /**
110 * \brief Get an iterator which refers to the first pair in the
111 * container.
112 *
113 * Pairs can be retrieved from the container in two ways. First,
114 * directly by an index into the container, and second, using an iterator.
115 * This method is used in the iterator method and is typically used in a
116 * for-loop to run through the pairs
117 *
118 * \code
119 * Ipv6InterfaceContainer::Iterator i;
120 * for (i = container.Begin (); i != container.End (); ++i)
121 * {
122 * std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
123 * method (pair.first, pair.second); // use the pair
124 * }
125 * \endcode
126 *
127 * \returns an iterator which refers to the first pair in the container.
128 */
129 Iterator Begin() const;
130
131 /**
132 * \brief Get an iterator which indicates past-the-last Node in the
133 * container.
134 *
135 * Nodes can be retrieved from the container in two ways. First,
136 * directly by an index into the container, and second, using an iterator.
137 * This method is used in the iterator method and is typically used in a
138 * for-loop to run through the Nodes
139 *
140 * \code
141 * NodeContainer::Iterator i;
142 * for (i = container.Begin (); i != container.End (); ++i)
143 * {
144 * std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
145 * method (pair.first, pair.second); // use the pair
146 * }
147 * \endcode
148 *
149 * \returns an iterator which indicates an ending condition for a loop.
150 */
151 Iterator End() const;
152
153 /**
154 * \brief Fusion with another Ipv6InterfaceContainer.
155 * \param c container
156 */
157 void Add(const Ipv6InterfaceContainer& c);
158
159 /**
160 * \brief Add a couple of name/interface.
161 * \param ipv6Name name of a node
162 * \param interface interface index to add
163 */
164 void Add(std::string ipv6Name, uint32_t interface);
165
166 /**
167 * Get the std::pair of an Ptr<Ipv6> and interface stored at the location
168 * specified by the index.
169 *
170 * \param i the index of the container entry to retrieve.
171 * \return the std::pair of a Ptr<Ipv6> and an interface index
172 *
173 * \note The returned Ptr<Ipv6> cannot be used directly to fetch the
174 * Ipv6Interface using the returned index (the GetInterface () method
175 * is provided in class Ipv6L3Protocol, and not class Ipv6). An
176 * example usage is provided below.
177 *
178 * \code
179 * Ipv6InterfaceContainer c;
180 * ...
181 * std::pair<Ptr<Ipv6>, uint32_t> returnValue = c.Get (0);
182 * Ptr<Ipv6> ipv6 = returnValue.first;
183 * uint32_t index = returnValue.second;
184 * Ptr<Ipv6Interface> iface = DynamicCast<Ipv6L3Protocol> (ipv6)->GetInterface (index);
185 * \endcode
186 */
187 std::pair<Ptr<Ipv6>, uint32_t> Get(uint32_t i) const;
188
189 /**
190 * \brief Set the state of the stack (act as a router or as an host) for the specified index.
191 * This automatically sets all the node's interfaces to the same forwarding state.
192 * \param i index
193 * \param state true : is a router, false : is an host
194 */
195 void SetForwarding(uint32_t i, bool state);
196
197 /**
198 * \brief Set the default route for all the devices (except the router itself).
199 * \param router the default router index
200 */
202
203 /**
204 * \brief Set the default route for all the devices (except the router itself).
205 * Note that the route will be set to the link-local address of the node with the specified
206 * address.
207 * \param routerAddr the default router address
208 */
209 void SetDefaultRouteInAllNodes(Ipv6Address routerAddr);
210
211 /**
212 * \brief Set the default route for the specified index.
213 * \param i index
214 * \param router the default router
215 */
216 void SetDefaultRoute(uint32_t i, uint32_t router);
217
218 /**
219 * \brief Set the default route for the specified index.
220 * Note that the route will be set to the link-local address of the node with the specified
221 * address.
222 * \param i index
223 * \param routerAddr the default router address
224 */
225 void SetDefaultRoute(uint32_t i, Ipv6Address routerAddr);
226
227 private:
228 /**
229 * \brief Container for pairs of Ipv6 smart pointer / Interface Index.
230 */
231 typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t>> InterfaceVector;
232
233 /**
234 * \brief List of IPv6 stack and interfaces index.
235 */
237};
238
239} /* namespace ns3 */
240
241#endif /* IPV6_INTERFACE_CONTAINER_H */
Describes an IPv6 address.
Definition: ipv6-address.h:49
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
uint32_t GetInterfaceIndex(uint32_t i) const
Get the interface index for the specified node index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
void SetDefaultRoute(uint32_t i, uint32_t router)
Set the default route for the specified index.
InterfaceVector m_interfaces
List of IPv6 stack and interfaces index.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > > InterfaceVector
Container for pairs of Ipv6 smart pointer / Interface Index.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Ipv6Address GetLinkLocalAddress(uint32_t i)
Get the link-local address for the specified index.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
std::pair< Ptr< Ipv6 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv6> and interface stored at the location specified by the index.
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
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.