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