A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ripng.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#ifndef RIPNG_H
10#define RIPNG_H
11
12#include "ipv6-interface.h"
13#include "ipv6-l3-protocol.h"
16#include "ripng-header.h"
17
18#include "ns3/inet6-socket-address.h"
19#include "ns3/random-variable-stream.h"
20
21#include <list>
22
23namespace ns3
24{
25
26/**
27 * \ingroup ipv6Routing
28 * \defgroup ripng RIPng
29 *
30 * The RIPng protocol (\RFC{2080}) is a unicast-only IPv6 IGP (Interior Gateway Protocol).
31 * Its convergence time is rather long. As a consequence, it is suggested to
32 * carefully check the network topology and the route status before sending
33 * data flows.
34 *
35 * RIPng implements the Bellman-Ford algorithm (although the RFC does not state it).
36 * Bellman-Ford algorithm convergence time is O(|V|*|E|) where |V| and |E| are the
37 * number of vertices (routers) and edges (links) respectively. Since unsolicited
38 * updates are exchanged every 30 seconds, the convergence might require a long time.
39 *
40 * For the RIPng protocol, the exact convergence time is shorter, thanks to the
41 * use of triggered updates, which are sent when a route changes.
42 * Even with triggered updates, the convergence is in the order of magnitude of
43 * O(|V|*|E|) * 5 seconds, which is still quite long for complex topologies.
44 *
45 * \todo: Add routing table compression (CIDR). The most evident result: without
46 * it a router will announce to be the default router *and* more RTEs, which is silly.
47 */
48
49/**
50 * \ingroup ripng
51 * \brief RipNg Routing Table Entry
52 */
54{
55 public:
56 /**
57 * Route status
58 */
64
66
67 /**
68 * \brief Constructor
69 * \param network network address
70 * \param networkPrefix network prefix
71 * \param nextHop next hop address to route the packet
72 * \param interface interface index
73 * \param prefixToUse prefix that should be used for source address for this destination
74 */
76 Ipv6Prefix networkPrefix,
77 Ipv6Address nextHop,
78 uint32_t interface,
79 Ipv6Address prefixToUse);
80
81 /**
82 * \brief Constructor
83 * \param network network address
84 * \param networkPrefix network prefix
85 * \param interface interface index
86 */
87 RipNgRoutingTableEntry(Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
88
89 ~RipNgRoutingTableEntry() override;
90
91 /**
92 * \brief Set the route tag
93 * \param routeTag the route tag
94 */
95 void SetRouteTag(uint16_t routeTag);
96
97 /**
98 * \brief Get the route tag
99 * \returns the route tag
100 */
101 uint16_t GetRouteTag() const;
102
103 /**
104 * \brief Set the route metric
105 * \param routeMetric the route metric
106 */
107 void SetRouteMetric(uint8_t routeMetric);
108
109 /**
110 * \brief Get the route metric
111 * \returns the route metric
112 */
113 uint8_t GetRouteMetric() const;
114
115 /**
116 * \brief Set the route status
117 * \param status the route status
118 */
119 void SetRouteStatus(Status_e status);
120
121 /**
122 * \brief Get the route status
123 * \returns the route status
124 */
125 Status_e GetRouteStatus() const;
126
127 /**
128 * \brief Set the route as changed
129 *
130 * The changed routes are scheduled for a Triggered Update.
131 * After a Triggered Update, all the changed flags are cleared
132 * from the routing table.
133 *
134 * \param changed true if route is changed
135 */
136 void SetRouteChanged(bool changed);
137
138 /**
139 * \brief Get the route changed status
140 *
141 * \returns true if route is changed
142 */
143 bool IsRouteChanged() const;
144
145 private:
146 uint16_t m_tag; //!< route tag
147 uint8_t m_metric; //!< route metric
148 Status_e m_status; //!< route status
149 bool m_changed; //!< route has been updated
150};
151
152/**
153 * \brief Stream insertion operator.
154 *
155 * \param os the reference to the output stream
156 * \param route the Ipv6 routing table entry
157 * \returns the reference to the output stream
158 */
159std::ostream& operator<<(std::ostream& os, const RipNgRoutingTableEntry& route);
160
161/**
162 * \ingroup ripng
163 *
164 * \brief RIPng Routing Protocol, defined in \RFC{2080}.
165 */
167{
168 public:
169 // /< C-tor
170 RipNg();
171 ~RipNg() override;
172
173 /**
174 * \brief Get the type ID
175 * \return type ID
176 */
177 static TypeId GetTypeId();
178
179 // From Ipv6RoutingProtocol
181 const Ipv6Header& header,
182 Ptr<NetDevice> oif,
183 Socket::SocketErrno& sockerr) override;
185 const Ipv6Header& header,
187 const UnicastForwardCallback& ucb,
188 const MulticastForwardCallback& mcb,
189 const LocalDeliverCallback& lcb,
190 const ErrorCallback& ecb) override;
191 void NotifyInterfaceUp(uint32_t interface) override;
192 void NotifyInterfaceDown(uint32_t interface) override;
193 void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
194 void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
196 Ipv6Prefix mask,
197 Ipv6Address nextHop,
198 uint32_t interface,
199 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
201 Ipv6Prefix mask,
202 Ipv6Address nextHop,
203 uint32_t interface,
204 Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
205 void SetIpv6(Ptr<Ipv6> ipv6) override;
207 Time::Unit unit = Time::S) const override;
208
209 /**
210 * Split Horizon strategy type. See \RFC{2080}.
211 */
213 {
214 NO_SPLIT_HORIZON, //!< No Split Horizon
215 SPLIT_HORIZON, //!< Split Horizon
216 POISON_REVERSE, //!< Poison Reverse Split Horizon
217 };
218
219 /**
220 * Assign a fixed random variable stream number to the random variables
221 * used by this model. Return the number of streams (possibly zero) that
222 * have been assigned.
223 *
224 * \param stream first stream index to use
225 * \return the number of stream indices assigned by this model
226 */
227 int64_t AssignStreams(int64_t stream);
228
229 /**
230 * \brief Get the set of interface excluded from the protocol
231 * \return the set of excluded interfaces
232 */
233 std::set<uint32_t> GetInterfaceExclusions() const;
234
235 /**
236 * \brief Set the set of interface excluded from the protocol
237 * \param exceptions the set of excluded interfaces
238 */
239 void SetInterfaceExclusions(std::set<uint32_t> exceptions);
240
241 /**
242 * \brief Get the metric for an interface
243 * \param interface the interface
244 * \returns the interface metric
245 */
246 uint8_t GetInterfaceMetric(uint32_t interface) const;
247
248 /**
249 * \brief Set the metric for an interface
250 * \param interface the interface
251 * \param metric the interface metric
252 */
253 void SetInterfaceMetric(uint32_t interface, uint8_t metric);
254
255 /**
256 * \brief Add a default route to the router through the nextHop located on interface.
257 *
258 * The default route is usually installed manually, or it is the result of
259 * some "other" routing protocol (e.g., BGP).
260 *
261 * \param nextHop the next hop
262 * \param interface the interface
263 */
264 void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface);
265
266 protected:
267 /**
268 * \brief Dispose this object.
269 */
270 void DoDispose() override;
271
272 /**
273 * Start protocol operation
274 */
275 void DoInitialize() override;
276
277 private:
278 /// Container for the network routes - pair RipNgRoutingTableEntry *, EventId (update event)
279 typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>> Routes;
280
281 /// Const Iterator for container for the network routes
282 typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>>::const_iterator RoutesCI;
283
284 /// Iterator for container for the network routes
285 typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>>::iterator RoutesI;
286
287 /**
288 * \brief Receive RIPng packets.
289 *
290 * \param socket the socket the packet was received to.
291 */
292 void Receive(Ptr<Socket> socket);
293
294 /**
295 * \brief Handle RIPng requests.
296 *
297 * \param hdr message header (including RTEs)
298 * \param senderAddress sender address
299 * \param senderPort sender port
300 * \param incomingInterface incoming interface
301 * \param hopLimit packet's hop limit
302 */
304 Ipv6Address senderAddress,
305 uint16_t senderPort,
306 uint32_t incomingInterface,
307 uint8_t hopLimit);
308
309 /**
310 * \brief Handle RIPng responses.
311 *
312 * \param hdr message header (including RTEs)
313 * \param senderAddress sender address
314 * \param incomingInterface incoming interface
315 * \param hopLimit packet's hop limit
316 */
318 Ipv6Address senderAddress,
319 uint32_t incomingInterface,
320 uint8_t hopLimit);
321
322 /**
323 * \brief Lookup in the forwarding table for destination.
324 * \param dest destination address
325 * \param setSource set source address in the route
326 * \param interface output interface if any (put 0 otherwise)
327 * \return Ipv6Route to route the packet to reach dest address
328 */
329 Ptr<Ipv6Route> Lookup(Ipv6Address dest, bool setSource, Ptr<NetDevice> = nullptr);
330
331 /**
332 * Receive and process unicast packet
333 * \param socket socket where packet is arrived
334 */
336 /**
337 * Receive and process multicast packet
338 * \param socket socket where packet is arrived
339 */
341
342 /**
343 * \brief Add route to network.
344 * \param network network address
345 * \param networkPrefix network prefix
346 * \param nextHop next hop address to route the packet.
347 * \param interface interface index
348 * \param prefixToUse prefix that should be used for source address for this destination
349 */
350 void AddNetworkRouteTo(Ipv6Address network,
351 Ipv6Prefix networkPrefix,
352 Ipv6Address nextHop,
353 uint32_t interface,
354 Ipv6Address prefixToUse);
355
356 /**
357 * \brief Add route to network.
358 * \param network network address
359 * \param networkPrefix network prefix
360 * \param interface interface index
361 */
362 void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
363
364 /**
365 * \brief Send Routing Updates on all interfaces.
366 * \param periodic true for periodic update, else triggered.
367 */
368 void DoSendRouteUpdate(bool periodic);
369
370 /**
371 * \brief Send Routing Request on all interfaces.
372 */
373 void SendRouteRequest();
374
375 /**
376 * \brief Send Triggered Routing Updates on all interfaces.
377 */
379
380 /**
381 * \brief Send Unsolicited Routing Updates on all interfaces.
382 */
384
385 /**
386 * \brief Invalidate a route.
387 * \param route the route to be removed
388 */
390
391 /**
392 * \brief Delete a route.
393 * \param route the route to be removed
394 */
396
397 Routes m_routes; //!< the forwarding table for network.
398 Ptr<Ipv6> m_ipv6; //!< IPv6 reference
399 Time m_startupDelay; //!< Random delay before protocol startup.
400 Time m_minTriggeredUpdateDelay; //!< Min cooldown delay after a Triggered Update.
401 Time m_maxTriggeredUpdateDelay; //!< Max cooldown delay after a Triggered Update.
402 Time m_unsolicitedUpdate; //!< time between two Unsolicited Routing Updates
403 Time m_timeoutDelay; //!< Delay before invalidating a route
404 Time m_garbageCollectionDelay; //!< Delay before deleting an INVALID route
405
406 // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
407 // it is dependent on the interface initialization (i.e., if the loopback is already up).
408 /// Socket list type
409 typedef std::map<Ptr<Socket>, uint32_t> SocketList;
410 /// Socket list type iterator
411 typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
412 /// Socket list type const iterator
413 typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
414
416 m_unicastSocketList; //!< list of sockets for unicast messages (socket, interface index)
417 Ptr<Socket> m_multicastRecvSocket; //!< multicast receive socket
418
419 EventId m_nextUnsolicitedUpdate; //!< Next Unsolicited Update event
420 EventId m_nextTriggeredUpdate; //!< Next Triggered Update event
421
423
424 std::set<uint32_t> m_interfaceExclusions; //!< Set of excluded interfaces
425 std::map<uint32_t, uint8_t> m_interfaceMetrics; //!< Map of interface metrics
426
427 SplitHorizonType_e m_splitHorizonStrategy; //!< Split Horizon strategy
428
429 bool m_initialized; //!< flag to allow socket's late-creation.
430 uint8_t m_linkDown; //!< Link down value.
431};
432
433} // namespace ns3
434#endif /* RIPNG_H */
An identifier for simulation events.
Definition event-id.h:45
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.
Describes an IPv6 prefix.
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Smart pointer class similar to boost::intrusive_ptr.
RipNgHeader - see RFC 2080
RIPng Routing Protocol, defined in RFC 2080 .
Definition ripng.h:167
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition ripng.h:417
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
Definition ripng.cc:283
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition ripng.cc:393
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
Definition ripng.cc:455
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition ripng.cc:1180
Time m_startupDelay
Random delay before protocol startup.
Definition ripng.h:399
void DoDispose() override
Dispose this object.
Definition ripng.cc:564
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition ripng.h:282
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition ripng.h:427
SplitHorizonType_e
Split Horizon strategy type.
Definition ripng.h:213
@ SPLIT_HORIZON
Split Horizon.
Definition ripng.h:215
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition ripng.h:216
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition ripng.h:214
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition ripng.h:420
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition ripng.h:285
~RipNg() override
Definition ripng.cc:46
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition ripng.cc:419
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition ripng.h:400
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition ripng.cc:1319
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.
Definition ripng.cc:189
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition ripng.h:419
uint8_t m_linkDown
Link down value.
Definition ripng.h:430
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition ripng.h:401
void DoInitialize() override
Start protocol operation.
Definition ripng.cc:116
bool m_initialized
flag to allow socket's late-creation.
Definition ripng.h:429
void RecvUnicastRipng(Ptr< Socket > socket)
Receive and process unicast packet.
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition ripng.h:416
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition ripng.h:411
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition ripng.cc:1327
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)
Definition ripng.cc:223
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition ripng.h:402
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition ripng.h:424
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition ripng.cc:1340
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition ripng.cc:107
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition ripng.cc:745
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition ripng.cc:685
void RecvMulticastRipng(Ptr< Socket > socket)
Receive and process multicast packet.
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition ripng.h:404
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition ripng.h:425
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition ripng.cc:1351
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
Definition ripng.cc:361
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition ripng.h:409
std::list< std::pair< RipNgRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipNgRoutingTableEntry *, EventId (update event)
Definition ripng.h:279
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition ripng.h:398
Routes m_routes
the forwarding table for network.
Definition ripng.h:397
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition ripng.cc:1313
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition ripng.cc:1264
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition ripng.cc:816
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition ripng.h:422
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition ripng.cc:994
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
Definition ripng.cc:466
static TypeId GetTypeId()
Get the type ID.
Definition ripng.cc:51
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition ripng.cc:721
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition ripng.h:413
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition ripng.cc:477
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition ripng.cc:762
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition ripng.cc:1385
Time m_timeoutDelay
Delay before invalidating a route.
Definition ripng.h:403
void SendUnsolicitedRouteUpdate()
Send Unsolicited Routing Updates on all interfaces.
Definition ripng.cc:1296
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Definition ripng.cc:499
Ptr< Ipv6Route > Lookup(Ipv6Address dest, bool setSource, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
Definition ripng.cc:594
RipNg Routing Table Entry.
Definition ripng.h:54
bool IsRouteChanged() const
Get the route changed status.
Definition ripng.cc:1496
RipNgRoutingTableEntry()
Definition ripng.cc:1400
uint16_t GetRouteTag() const
Get the route tag.
Definition ripng.cc:1452
bool m_changed
route has been updated
Definition ripng.h:149
uint16_t m_tag
route tag
Definition ripng.h:146
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition ripng.cc:1442
uint8_t GetRouteMetric() const
Get the route metric.
Definition ripng.cc:1468
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition ripng.cc:1458
uint8_t m_metric
route metric
Definition ripng.h:147
Status_e m_status
route status
Definition ripng.h:148
Status_e GetRouteStatus() const
Get the route status.
Definition ripng.cc:1484
void SetRouteChanged(bool changed)
Set the route as changed.
Definition ripng.cc:1490
~RipNgRoutingTableEntry() override
Definition ripng.cc:1437
Status_e
Route status.
Definition ripng.h:60
@ RIPNG_INVALID
Definition ripng.h:62
@ RIPNG_VALID
Definition ripng.h:61
void SetRouteStatus(Status_e status)
Set the route status.
Definition ripng.cc:1474
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148