A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-static-routing.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#ifndef IPV6_STATIC_ROUTING_H
21#define IPV6_STATIC_ROUTING_H
22
23#include "ipv6-header.h"
25#include "ipv6.h"
26
27#include "ns3/ipv6-address.h"
28#include "ns3/ptr.h"
29
30#include <list>
31#include <stdint.h>
32
33namespace ns3
34{
35
36class Packet;
37class NetDevice;
38class Ipv6Interface;
39class Ipv6Route;
40class Node;
41class Ipv6RoutingTableEntry;
42class Ipv6MulticastRoutingTableEntry;
43
44/**
45 * \ingroup ipv6Routing
46 *
47 * \brief Static routing protocol for IP version 6 stacks.
48 *
49 * This class provides a basic set of methods for inserting static
50 * unicast and multicast routes into the Ipv6 routing system.
51 * This particular protocol is designed to be inserted into an
52 * Ipv6ListRouting protocol but can be used also as a standalone
53 * protocol.
54 *
55 * The Ipv6StaticRouting class inherits from the abstract base class
56 * Ipv6RoutingProtocol that defines the interface methods that a routing
57 * protocol must support.
58 *
59 * \see Ipv6RoutingProtocol
60 * \see Ipv6ListRouting
61 * \see Ipv6ListRouting::AddRoutingProtocol
62 */
64{
65 public:
66 /**
67 * \brief The interface Id associated with this class.
68 * \return type identifier
69 */
70 static TypeId GetTypeId();
71
73 ~Ipv6StaticRouting() override;
74
75 /**
76 * \brief Add route to host.
77 * \param dest destination address
78 * \param nextHop next hop address to route the packet.
79 * \param interface interface index
80 * \param prefixToUse prefix that should be used for source address for this destination
81 * \param metric metric of route in case of multiple routes to same destination
82 */
84 Ipv6Address nextHop,
85 uint32_t interface,
86 Ipv6Address prefixToUse = Ipv6Address("::"),
87 uint32_t metric = 0);
88
89 /**
90 * \brief Add route to host.
91 * \param dest destination address.
92 * \param interface interface index
93 * \param metric metric of route in case of multiple routes to same destination
94 */
95 void AddHostRouteTo(Ipv6Address dest, uint32_t interface, uint32_t metric = 0);
96
97 /**
98 * \brief Add route to network.
99 * \param network network address
100 * \param networkPrefix network prefix*
101 * \param nextHop next hop address to route the packet
102 * \param interface interface index
103 * \param metric metric of route in case of multiple routes to same destination
104 */
105 void AddNetworkRouteTo(Ipv6Address network,
106 Ipv6Prefix networkPrefix,
107 Ipv6Address nextHop,
108 uint32_t interface,
109 uint32_t metric = 0);
110
111 /**
112 * \brief Add route to network.
113 * \param network network address
114 * \param networkPrefix network prefix*
115 * \param nextHop next hop address to route the packet.
116 * \param interface interface index
117 * \param prefixToUse prefix that should be used for source address for this destination
118 * \param metric metric of route in case of multiple routes to same destination
119 */
120 void AddNetworkRouteTo(Ipv6Address network,
121 Ipv6Prefix networkPrefix,
122 Ipv6Address nextHop,
123 uint32_t interface,
124 Ipv6Address prefixToUse,
125 uint32_t metric = 0);
126
127 /**
128 * \brief Add route to network.
129 * \param network network address
130 * \param networkPrefix network prefix
131 * \param interface interface index
132 * \param metric metric of route in case of multiple routes to same destination
133 */
134 void AddNetworkRouteTo(Ipv6Address network,
135 Ipv6Prefix networkPrefix,
136 uint32_t interface,
137 uint32_t metric = 0);
138
139 /**
140 * \brief Set the default route.
141 * \param nextHop next hop address to route the packet
142 * \param interface interface index
143 * \param prefixToUse prefix to use (i.e for multihoming)
144 * \param metric metric of route in case of multiple routes to same destination
145 */
146 void SetDefaultRoute(Ipv6Address nextHop,
147 uint32_t interface,
148 Ipv6Address prefixToUse = Ipv6Address("::"),
149 uint32_t metric = 0);
150
151 /**
152 * \brief Get the number or entries in the routing table.
153 * \return number of entries
154 */
155 uint32_t GetNRoutes() const;
156
157 /**
158 * \brief Get the default route.
159 *
160 * If multiple default routes exist, the one with lowest metric is returned.
161 * \return default Ipv6Route
162 */
164
165 /**
166 * \brief Get a specified route.
167 * \param i index
168 * \return the route whose index is i
169 */
171
172 /**
173 * \brief Get a metric for route from the static unicast routing table.
174 * \param index The index (into the routing table) of the route to retrieve.
175 * \return If route is set, the metric is returned. If not, an infinity metric (0xffffffff) is
176 * returned
177 */
178 uint32_t GetMetric(uint32_t index) const;
179
180 /**
181 * \brief Remove a route from the routing table.
182 * \param i index
183 */
184 void RemoveRoute(uint32_t i);
185
186 /**
187 * \brief Remove a route from the routing table.
188 * \param network IPv6 network
189 * \param prefix IPv6 prefix
190 * \param ifIndex interface index
191 * \param prefixToUse IPv6 prefix to use with this route (multihoming)
192 */
193 void RemoveRoute(Ipv6Address network,
194 Ipv6Prefix prefix,
195 uint32_t ifIndex,
196 Ipv6Address prefixToUse);
197
198 /**
199 * \brief Add a multicast route for a given multicast source and group.
200 * \param origin IPv6 address of the source
201 * \param group the multicast group address.
202 * \param inputInterface the interface index
203 * \param outputInterfaces the list of output interface indices over which the packet
204 * should be sent (excluding the inputInterface).
205 */
206 void AddMulticastRoute(Ipv6Address origin,
207 Ipv6Address group,
208 uint32_t inputInterface,
209 std::vector<uint32_t> outputInterfaces);
210
211 /**
212 * \brief Set the default multicast route.
213 * \param outputInterface default output interface
214 */
215 void SetDefaultMulticastRoute(uint32_t outputInterface);
216
217 /**
218 * \brief Get the number of entries in the multicast routing table.
219 * \return number of entries
220 */
222
223 /**
224 * \brief Get the specified multicast route.
225 * \param i index
226 * \return the route whose index is i
227 */
229
230 /**
231 * \brief Remove a static multicast route.
232 * \param origin IPv6 address of the source
233 * \param group the multicast group address.
234 * \param inputInterface the input interface index
235 * \return true on success
236 */
237 bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface);
238
239 /**
240 * \brief Remove a multicast route.
241 * \param i index of route to remove
242 */
244
245 /**
246 * \brief If the destination is already present in network destination list.
247 * \param dest destination address
248 * \param interfaceIndex interface index
249 * \return true if dest is already in list, false otherwise
250 */
251 bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex);
252
254 const Ipv6Header& header,
255 Ptr<NetDevice> oif,
256 Socket::SocketErrno& sockerr) override;
257
259 const Ipv6Header& header,
261 const UnicastForwardCallback& ucb,
262 const MulticastForwardCallback& mcb,
263 const LocalDeliverCallback& lcb,
264 const ErrorCallback& ecb) override;
265
266 void NotifyInterfaceUp(uint32_t interface) override;
267 void NotifyInterfaceDown(uint32_t interface) override;
268 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
269 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
271 Ipv6Prefix mask,
272 Ipv6Address nextHop,
273 uint32_t interface,
274 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
276 Ipv6Prefix mask,
277 Ipv6Address nextHop,
278 uint32_t interface,
279 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
280 void SetIpv6(Ptr<Ipv6> ipv6) override;
282 Time::Unit unit = Time::S) const override;
283
284 protected:
285 /**
286 * \brief Dispose this object.
287 */
288 void DoDispose() override;
289
290 private:
291 /// Container for the network routes
292 typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>> NetworkRoutes;
293
294 /// Const Iterator for container for the network routes
295 typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>>::const_iterator NetworkRoutesCI;
296
297 /// Iterator for container for the network routes
298 typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>>::iterator NetworkRoutesI;
299
300 /// Container for the multicast routes
301 typedef std::list<Ipv6MulticastRoutingTableEntry*> MulticastRoutes;
302
303 /// Const Iterator for container for the multicast routes
304 typedef std::list<Ipv6MulticastRoutingTableEntry*>::const_iterator MulticastRoutesCI;
305
306 /// Iterator for container for the multicast routes
307 typedef std::list<Ipv6MulticastRoutingTableEntry*>::iterator MulticastRoutesI;
308
309 /**
310 * \brief Checks if a route is already present in the forwarding table.
311 * \param route route
312 * \param metric metric of route
313 * \return true if the route/metric is already in the forwarding table
314 */
315 bool LookupRoute(const Ipv6RoutingTableEntry& route, uint32_t metric);
316
317 /**
318 * \brief Lookup in the forwarding table for destination.
319 * \param dest destination address
320 * \param interface output interface if any (put 0 otherwise)
321 * \return Ipv6Route to route the packet to reach dest address
322 */
324
325 /**
326 * \brief Lookup in the multicast forwarding table for destination.
327 * \param origin source address
328 * \param group group multicast address
329 * \param ifIndex interface index
330 * \return Ipv6MulticastRoute to route the packet to reach dest address
331 */
333
334 /**
335 * \brief the forwarding table for network.
336 */
338
339 /**
340 * \brief the forwarding table for multicast.
341 */
343
344 /**
345 * \brief Ipv6 reference.
346 */
348};
349
350} /* namespace ns3 */
351
352#endif /* IPV6_STATIC_ROUTING_H */
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Packet header for IPv6.
Definition: ipv6-header.h:35
IPv6 address associated with an interface.
A record of an IPv6 multicast route.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Static routing protocol for IP version 6 stacks.
std::list< Ipv6MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Ipv6RoutingTableEntry GetRoute(uint32_t i) const
Get a specified route.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
void RemoveRoute(uint32_t i)
Remove a route from the routing table.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
static TypeId GetTypeId()
The interface Id associated with this class.
Ptr< Ipv6Route > LookupStatic(Ipv6Address dest, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex)
If the destination is already present in network destination list.
std::list< Ipv6MulticastRoutingTableEntry * > MulticastRoutes
Container for the multicast routes.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
bool LookupRoute(const Ipv6RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
std::list< Ipv6MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
void AddMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route for a given multicast source and group.
void AddHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Add route to host.
uint32_t GetNRoutes() const
Get the number or entries in the routing table.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > > NetworkRoutes
Container for the network routes.
Ipv6MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get the specified multicast route.
Ipv6RoutingTableEntry GetDefaultRoute()
Get the default route.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
uint32_t GetNMulticastRoutes() const
Get the number of entries in the multicast routing table.
bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface)
Remove a static multicast route.
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void DoDispose() override
Dispose this object.
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
NetworkRoutes m_networkRoutes
the forwarding table for network.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Set the default multicast route.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Ptr< Ipv6 > m_ipv6
Ipv6 reference.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.