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