A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rip.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 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 RIP_H
10#define RIP_H
11
12#include "ipv4-interface.h"
13#include "ipv4-l3-protocol.h"
16#include "rip-header.h"
17
18#include "ns3/inet-socket-address.h"
19#include "ns3/random-variable-stream.h"
20
21#include <list>
22
23namespace ns3
24{
25
26/**
27 * \ingroup ipv4Routing
28 * \defgroup rip RIP
29 *
30 * The RIP protocol (\RFC{2453}) is a unicast-only IPv4 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 * RIP 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 RIP 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 rip
51 * \brief Rip 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 */
75 Ipv4Mask networkPrefix,
76 Ipv4Address nextHop,
77 uint32_t interface);
78
79 /**
80 * \brief Constructor
81 * \param network network address
82 * \param networkPrefix network prefix
83 * \param interface interface index
84 */
85 RipRoutingTableEntry(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
86
87 virtual ~RipRoutingTableEntry();
88
89 /**
90 * \brief Set the route tag
91 * \param routeTag the route tag
92 */
93 void SetRouteTag(uint16_t routeTag);
94
95 /**
96 * \brief Get the route tag
97 * \returns the route tag
98 */
99 uint16_t GetRouteTag() const;
100
101 /**
102 * \brief Set the route metric
103 * \param routeMetric the route metric
104 */
105 void SetRouteMetric(uint8_t routeMetric);
106
107 /**
108 * \brief Get the route metric
109 * \returns the route metric
110 */
111 uint8_t GetRouteMetric() const;
112
113 /**
114 * \brief Set the route status
115 * \param status the route status
116 */
117 void SetRouteStatus(Status_e status);
118
119 /**
120 * \brief Get the route status
121 * \returns the route status
122 */
123 Status_e GetRouteStatus() const;
124
125 /**
126 * \brief Set the route as changed
127 *
128 * The changed routes are scheduled for a Triggered Update.
129 * After a Triggered Update, all the changed flags are cleared
130 * from the routing table.
131 *
132 * \param changed true if route is changed
133 */
134 void SetRouteChanged(bool changed);
135
136 /**
137 * \brief Get the route changed status
138 *
139 * \returns true if route is changed
140 */
141 bool IsRouteChanged() const;
142
143 private:
144 uint16_t m_tag; //!< route tag
145 uint8_t m_metric; //!< route metric
146 Status_e m_status; //!< route status
147 bool m_changed; //!< route has been updated
148};
149
150/**
151 * \brief Stream insertion operator.
152 *
153 * \param os the reference to the output stream
154 * \param route the Ipv4 routing table entry
155 * \returns the reference to the output stream
156 */
157std::ostream& operator<<(std::ostream& os, const RipRoutingTableEntry& route);
158
159/**
160 * \ingroup rip
161 *
162 * \brief RIP Routing Protocol, defined in \RFC{2453}.
163 */
165{
166 public:
167 // /< C-tor
168 Rip();
169 ~Rip() override;
170
171 /**
172 * \brief Get the type ID
173 * \return type ID
174 */
175 static TypeId GetTypeId();
176
177 // From Ipv4RoutingProtocol
179 const Ipv4Header& header,
180 Ptr<NetDevice> oif,
181 Socket::SocketErrno& sockerr) override;
183 const Ipv4Header& header,
185 const UnicastForwardCallback& ucb,
186 const MulticastForwardCallback& mcb,
187 const LocalDeliverCallback& lcb,
188 const ErrorCallback& ecb) override;
189 void NotifyInterfaceUp(uint32_t interface) override;
190 void NotifyInterfaceDown(uint32_t interface) override;
191 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
192 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
193 void SetIpv4(Ptr<Ipv4> ipv4) override;
195 Time::Unit unit = Time::S) const override;
196
197 /**
198 * Split Horizon strategy type. See \RFC{2453}.
199 */
201 {
202 NO_SPLIT_HORIZON, //!< No Split Horizon
203 SPLIT_HORIZON, //!< Split Horizon
204 POISON_REVERSE, //!< Poison Reverse Split Horizon
205 };
206
207 /**
208 * Assign a fixed random variable stream number to the random variables
209 * used by this model. Return the number of streams (possibly zero) that
210 * have been assigned.
211 *
212 * \param stream first stream index to use
213 * \return the number of stream indices assigned by this model
214 */
215 int64_t AssignStreams(int64_t stream);
216
217 /**
218 * \brief Get the set of interface excluded from the protocol
219 * \return the set of excluded interfaces
220 */
221 std::set<uint32_t> GetInterfaceExclusions() const;
222
223 /**
224 * \brief Set the set of interface excluded from the protocol
225 * \param exceptions the set of excluded interfaces
226 */
227 void SetInterfaceExclusions(std::set<uint32_t> exceptions);
228
229 /**
230 * \brief Get the metric for an interface
231 * \param interface the interface
232 * \returns the interface metric
233 */
234 uint8_t GetInterfaceMetric(uint32_t interface) const;
235
236 /**
237 * \brief Set the metric for an interface
238 * \param interface the interface
239 * \param metric the interface metric
240 */
241 void SetInterfaceMetric(uint32_t interface, uint8_t metric);
242
243 /**
244 * \brief Add a default route to the router through the nextHop located on interface.
245 *
246 * The default route is usually installed manually, or it is the result of
247 * some "other" routing protocol (e.g., BGP).
248 *
249 * \param nextHop the next hop
250 * \param interface the interface
251 */
252 void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface);
253
254 protected:
255 /**
256 * \brief Dispose this object.
257 */
258 void DoDispose() override;
259
260 /**
261 * Start protocol operation
262 */
263 void DoInitialize() override;
264
265 private:
266 /// Container for the network routes - pair RipRoutingTableEntry *, EventId (update event)
267 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>> Routes;
268
269 /// Const Iterator for container for the network routes
270 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::const_iterator RoutesCI;
271
272 /// Iterator for container for the network routes
273 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::iterator RoutesI;
274
275 /**
276 * \brief Receive RIP packets.
277 *
278 * \param socket the socket the packet was received to.
279 */
280 void Receive(Ptr<Socket> socket);
281
282 /**
283 * \brief Handle RIP requests.
284 *
285 * \param hdr message header (including RTEs)
286 * \param senderAddress sender address
287 * \param senderPort sender port
288 * \param incomingInterface incoming interface
289 * \param hopLimit packet's hop limit
290 */
291 void HandleRequests(RipHeader hdr,
292 Ipv4Address senderAddress,
293 uint16_t senderPort,
294 uint32_t incomingInterface,
295 uint8_t hopLimit);
296
297 /**
298 * \brief Handle RIP responses.
299 *
300 * \param hdr message header (including RTEs)
301 * \param senderAddress sender address
302 * \param incomingInterface incoming interface
303 * \param hopLimit packet's hop limit
304 */
305 void HandleResponses(RipHeader hdr,
306 Ipv4Address senderAddress,
307 uint32_t incomingInterface,
308 uint8_t hopLimit);
309
310 /**
311 * \brief Lookup in the forwarding table for destination.
312 * \param dest destination address
313 * \param setSource set source address in the route
314 * \param interface output interface if any (put 0 otherwise)
315 * \return Ipv4Route to route the packet to reach dest address
316 */
317 Ptr<Ipv4Route> Lookup(Ipv4Address dest, bool setSource, Ptr<NetDevice> = nullptr);
318
319 /**
320 * Receive and process unicast packet
321 * \param socket socket where packet is arrived
322 */
324 /**
325 * Receive and process multicast packet
326 * \param socket socket where packet is arrived
327 */
329
330 /**
331 * \brief Add route to network.
332 * \param network network address
333 * \param networkPrefix network prefix
334 * \param nextHop next hop address to route the packet.
335 * \param interface interface index
336 */
337 void AddNetworkRouteTo(Ipv4Address network,
338 Ipv4Mask networkPrefix,
339 Ipv4Address nextHop,
340 uint32_t interface);
341
342 /**
343 * \brief Add route to network.
344 * \param network network address
345 * \param networkPrefix network prefix
346 * \param interface interface index
347 */
348 void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
349
350 /**
351 * \brief Send Routing Updates on all interfaces.
352 * \param periodic true for periodic update, else triggered.
353 */
354 void DoSendRouteUpdate(bool periodic);
355
356 /**
357 * \brief Send Routing Request on all interfaces.
358 */
359 void SendRouteRequest();
360
361 /**
362 * \brief Send Triggered Routing Updates on all interfaces.
363 */
365
366 /**
367 * \brief Send Unsolicited Routing Updates on all interfaces.
368 */
370
371 /**
372 * \brief Invalidate a route.
373 * \param route the route to be removed
374 */
376
377 /**
378 * \brief Delete a route.
379 * \param route the route to be removed
380 */
382
383 Routes m_routes; //!< the forwarding table for network.
384 Ptr<Ipv4> m_ipv4; //!< IPv4 reference
385 Time m_startupDelay; //!< Random delay before protocol startup.
386 Time m_minTriggeredUpdateDelay; //!< Min cooldown delay after a Triggered Update.
387 Time m_maxTriggeredUpdateDelay; //!< Max cooldown delay after a Triggered Update.
388 Time m_unsolicitedUpdate; //!< time between two Unsolicited Routing Updates
389 Time m_timeoutDelay; //!< Delay before invalidating a route
390 Time m_garbageCollectionDelay; //!< Delay before deleting an INVALID route
391
392 // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
393 // it is dependent on the interface initialization (i.e., if the loopback is already up).
394 /// Socket list type
395 typedef std::map<Ptr<Socket>, uint32_t> SocketList;
396 /// Socket list type iterator
397 typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
398 /// Socket list type const iterator
399 typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
400
402 m_unicastSocketList; //!< list of sockets for unicast messages (socket, interface index)
403 Ptr<Socket> m_multicastRecvSocket; //!< multicast receive socket
404
405 EventId m_nextUnsolicitedUpdate; //!< Next Unsolicited Update event
406 EventId m_nextTriggeredUpdate; //!< Next Triggered Update event
407
409
410 std::set<uint32_t> m_interfaceExclusions; //!< Set of excluded interfaces
411 std::map<uint32_t, uint8_t> m_interfaceMetrics; //!< Map of interface metrics
412
413 SplitHorizonType_e m_splitHorizonStrategy; //!< Split Horizon strategy
414
415 bool m_initialized; //!< flag to allow socket's late-creation.
416 uint32_t m_linkDown; //!< Link down value.
417};
418
419} // namespace ns3
420#endif /* RIP_H */
An identifier for simulation events.
Definition event-id.h:45
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Smart pointer class similar to boost::intrusive_ptr.
RipHeader - see RFC 2453
Definition rip-header.h:147
RIP Routing Protocol, defined in RFC 2453 .
Definition rip.h:165
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition rip.cc:1339
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition rip.cc:1168
void DoDispose() override
Dispose this object.
Definition rip.cc:580
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition rip.h:413
Ptr< Ipv4Route > Lookup(Ipv4Address dest, bool setSource, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
Definition rip.cc:610
Rip()
Definition rip.cc:38
Time m_startupDelay
Random delay before protocol startup.
Definition rip.h:385
void NotifyInterfaceDown(uint32_t interface) override
Definition rip.cc:393
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition rip.h:411
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition rip.h:410
std::list< std::pair< RipRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition rip.h:273
uint32_t m_linkDown
Link down value.
Definition rip.h:416
void HandleRequests(RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP requests.
Definition rip.cc:831
void DeleteRoute(RipRoutingTableEntry *route)
Delete a route.
Definition rip.cc:746
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &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 rip.cc:231
void InvalidateRoute(RipRoutingTableEntry *route)
Invalidate a route.
Definition rip.cc:722
void Receive(Ptr< Socket > socket)
Receive RIP packets.
Definition rip.cc:763
void NotifyInterfaceUp(uint32_t interface) override
Definition rip.cc:310
void RecvMulticastRip(Ptr< Socket > socket)
Receive and process multicast packet.
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition rip.h:405
std::list< std::pair< RipRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition rip.h:270
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Definition rip.cc:509
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition rip.cc:107
~Rip() override
Definition rip.cc:46
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition rip.h:406
Ptr< Ipv4 > m_ipv4
IPv4 reference.
Definition rip.h:384
void RecvUnicastRip(Ptr< Socket > socket)
Receive and process unicast packet.
void DoInitialize() override
Start protocol operation.
Definition rip.cc:116
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition rip.cc:1350
Time m_timeoutDelay
Delay before invalidating a route.
Definition rip.h:389
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface)
Add route to network.
Definition rip.cc:693
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition rip.h:399
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition rip.h:397
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition rip.h:403
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition rip.h:386
SplitHorizonType_e
Split Horizon strategy type.
Definition rip.h:201
@ SPLIT_HORIZON
Split Horizon.
Definition rip.h:203
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition rip.h:202
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition rip.h:204
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition rip.h:388
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition rip.h:395
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition rip.cc:1312
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
Definition rip.cc:197
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition rip.cc:1326
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
Definition rip.cc:451
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
Definition rip.cc:425
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition rip.h:402
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition rip.h:390
void SetIpv4(Ptr< Ipv4 > ipv4) override
Definition rip.cc:487
static TypeId GetTypeId()
Get the type ID.
Definition rip.cc:51
bool m_initialized
flag to allow socket's late-creation.
Definition rip.h:415
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition rip.cc:1318
void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition rip.cc:1384
Routes m_routes
the forwarding table for network.
Definition rip.h:383
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition rip.h:387
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition rip.cc:1263
void SendUnsolicitedRouteUpdate()
Send Unsolicited Routing Updates on all interfaces.
Definition rip.cc:1295
void HandleResponses(RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP responses.
Definition rip.cc:1006
std::list< std::pair< RipRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipRoutingTableEntry *, EventId (update event)
Definition rip.h:267
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition rip.h:408
Rip Routing Table Entry.
Definition rip.h:54
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition rip.cc:1449
Status_e m_status
route status
Definition rip.h:146
RipRoutingTableEntry()
Definition rip.cc:1395
bool m_changed
route has been updated
Definition rip.h:147
void SetRouteStatus(Status_e status)
Set the route status.
Definition rip.cc:1465
Status_e
Route status.
Definition rip.h:60
@ RIP_INVALID
Definition rip.h:62
@ RIP_VALID
Definition rip.h:61
bool IsRouteChanged() const
Get the route changed status.
Definition rip.cc:1487
Status_e GetRouteStatus() const
Get the route status.
Definition rip.cc:1475
uint8_t GetRouteMetric() const
Get the route metric.
Definition rip.cc:1459
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition rip.cc:1433
uint16_t GetRouteTag() const
Get the route tag.
Definition rip.cc:1443
void SetRouteChanged(bool changed)
Set the route as changed.
Definition rip.cc:1481
uint8_t m_metric
route metric
Definition rip.h:145
virtual ~RipRoutingTableEntry()
Definition rip.cc:1428
uint16_t m_tag
route tag
Definition rip.h:144
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