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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
8 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
9 */
10
11#ifndef IPV6_INTERFACE_CONTAINER_H
12#define IPV6_INTERFACE_CONTAINER_H
13
14#include "ns3/ipv6-address.h"
15#include "ns3/ipv6.h"
16
17#include <stdint.h>
18#include <vector>
19
20namespace ns3
21{
22
23/**
24 * @ingroup ipv6
25 *
26 * @brief Keep track of a set of IPv6 interfaces.
27 */
29{
30 public:
31 /**
32 * @brief Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
33 */
34 typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t>>::const_iterator Iterator;
35
36 /**
37 * @brief Constructor.
38 */
40
41 /**
42 * @returns the number of Ptr<Ipv6> and interface pairs stored in this
43 * Ipv6InterfaceContainer.
44 *
45 * Pairs can be retrieved from the container in two ways. First,
46 * directly by an index into the container, and second, using an iterator.
47 * This method is used in the direct method and is typically used to
48 * define an ending condition in a for-loop that runs through the stored
49 * Nodes
50 *
51 * @code
52 * uint32_t nNodes = container.GetN ();
53 * for (uint32_t i = 0 i < nNodes; ++i)
54 * {
55 * std::pair<Ptr<Ipv6>, uint32_t> pair = container.Get (i);
56 * method (pair.first, pair.second); // use the pair
57 * }
58 * @endcode
59 */
60 uint32_t GetN() const;
61
62 /**
63 * @brief Get the interface index for the specified node index.
64 * @param i index of the node
65 * @return interface index
66 */
68
69 /**
70 * @brief Get the address for the specified index.
71 * @param i interface index
72 * @param j address index, generally index 0 is the link-local address
73 * @return IPv6 address
74 */
76
77 /**
78 * @brief Get the link-local address for the specified index.
79 * @param i index
80 * @return the link-local address, or "::" if the interface has no link local address.
81 */
83
84 /**
85 * @brief Get the link-local address for the node with the specified global address.
86 * @param address the address to find.
87 * @return the link-local address, or "::" if the interface has no link local address.
88 */
90
91 /**
92 * @brief Add a couple IPv6/interface.
93 * @param ipv6 IPv6 address
94 * @param interface interface index
95 */
96 void Add(Ptr<Ipv6> ipv6, uint32_t interface);
97
98 /**
99 * @brief Get an iterator which refers to the first pair in the
100 * container.
101 *
102 * Pairs can be retrieved from the container in two ways. First,
103 * directly by an index into the container, and second, using an iterator.
104 * This method is used in the iterator method and is typically used in a
105 * for-loop to run through the pairs
106 *
107 * @code
108 * for (auto i = container.Begin(); i != container.End(); ++i)
109 * {
110 * std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
111 * method(pair.first, pair.second); // use the pair
112 * }
113 * @endcode
114 *
115 * @returns an iterator which refers to the first pair in the container.
116 */
117 Iterator Begin() const;
118
119 /**
120 * @brief Get an iterator which indicates past-the-last Node in the
121 * container.
122 *
123 * Nodes 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 iterator method and is typically used in a
126 * for-loop to run through the Nodes
127 *
128 * @code
129 * for (auto i = container.Begin(); i != container.End(); ++i)
130 * {
131 * std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
132 * method(pair.first, pair.second); // use the pair
133 * }
134 * @endcode
135 *
136 * @returns an iterator which indicates an ending condition for a loop.
137 */
138 Iterator End() const;
139
140 /**
141 * @brief Fusion with another Ipv6InterfaceContainer.
142 * @param c container
143 */
144 void Add(const Ipv6InterfaceContainer& c);
145
146 /**
147 * @brief Add a couple of name/interface.
148 * @param ipv6Name name of a node
149 * @param interface interface index to add
150 */
151 void Add(std::string ipv6Name, uint32_t interface);
152
153 /**
154 * Get the std::pair of an Ptr<Ipv6> and interface stored at the location
155 * specified by the index.
156 *
157 * @param i the index of the container entry to retrieve.
158 * @return the std::pair of a Ptr<Ipv6> and an interface index
159 *
160 * @note The returned Ptr<Ipv6> cannot be used directly to fetch the
161 * Ipv6Interface using the returned index (the GetInterface () method
162 * is provided in class Ipv6L3Protocol, and not class Ipv6). An
163 * example usage is provided below.
164 *
165 * @code
166 * Ipv6InterfaceContainer c;
167 * ...
168 * std::pair<Ptr<Ipv6>, uint32_t> returnValue = c.Get (0);
169 * Ptr<Ipv6> ipv6 = returnValue.first;
170 * uint32_t index = returnValue.second;
171 * Ptr<Ipv6Interface> iface = DynamicCast<Ipv6L3Protocol> (ipv6)->GetInterface (index);
172 * @endcode
173 */
174 std::pair<Ptr<Ipv6>, uint32_t> Get(uint32_t i) const;
175
176 /**
177 * @brief Set the state of the stack (act as a router or as an host) for the specified index.
178 * This automatically sets all the node's interfaces to the same forwarding state.
179 * @param i index
180 * @param state true : is a router, false : is an host
181 */
182 void SetForwarding(uint32_t i, bool state);
183
184 /**
185 * @brief Set the default route for all the devices (except the router itself).
186 * @param router the default router index
187 */
189
190 /**
191 * @brief Set the default route for all the devices (except the router itself).
192 * Note that the route will be set to the link-local address of the node with the specified
193 * address.
194 * @param routerAddr the default router address
195 */
196 void SetDefaultRouteInAllNodes(Ipv6Address routerAddr);
197
198 /**
199 * @brief Set the default route for the specified index.
200 * @param i index
201 * @param router the default router
202 */
203 void SetDefaultRoute(uint32_t i, uint32_t router);
204
205 /**
206 * @brief Set the default route for the specified index.
207 * Note that the route will be set to the link-local address of the node with the specified
208 * address.
209 * @param i index
210 * @param routerAddr the default router address
211 */
212 void SetDefaultRoute(uint32_t i, Ipv6Address routerAddr);
213
214 private:
215 /**
216 * @brief Container for pairs of Ipv6 smart pointer / Interface Index.
217 */
218 typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t>> InterfaceVector;
219
220 /**
221 * @brief List of IPv6 stack and interfaces index.
222 */
224};
225
226} /* namespace ns3 */
227
228#endif /* IPV6_INTERFACE_CONTAINER_H */
Describes an IPv6 address.
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:70
Every class exported by the ns3 library is enclosed in the ns3 namespace.