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