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
65{
66 public:
71 {
74 };
75
77
86 Ipv4Mask networkPrefix,
87 Ipv4Address nextHop,
88 uint32_t interface);
89
96 RipRoutingTableEntry(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
97
98 virtual ~RipRoutingTableEntry();
99
104 void SetRouteTag(uint16_t routeTag);
105
110 uint16_t GetRouteTag() const;
111
116 void SetRouteMetric(uint8_t routeMetric);
117
122 uint8_t GetRouteMetric() const;
123
128 void SetRouteStatus(Status_e status);
129
134 Status_e GetRouteStatus() const;
135
145 void SetRouteChanged(bool changed);
146
152 bool IsRouteChanged() const;
153
154 private:
155 uint16_t m_tag;
156 uint8_t m_metric;
159};
160
168std::ostream& operator<<(std::ostream& os, const RipRoutingTableEntry& route);
169
176{
177 public:
178 // /< C-tor
179 Rip();
180 ~Rip() override;
181
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
212 {
216 };
217
226 int64_t AssignStreams(int64_t stream);
227
232 std::set<uint32_t> GetInterfaceExclusions() const;
233
238 void SetInterfaceExclusions(std::set<uint32_t> exceptions);
239
245 uint8_t GetInterfaceMetric(uint32_t interface) const;
246
252 void SetInterfaceMetric(uint32_t interface, uint8_t metric);
253
263 void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface);
264
265 protected:
269 void DoDispose() override;
270
274 void DoInitialize() override;
275
276 private:
278 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>> Routes;
279
281 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::const_iterator RoutesCI;
282
284 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::iterator RoutesI;
285
291 void Receive(Ptr<Socket> socket);
292
302 void HandleRequests(RipHeader hdr,
303 Ipv4Address senderAddress,
304 uint16_t senderPort,
305 uint32_t incomingInterface,
306 uint8_t hopLimit);
307
316 void HandleResponses(RipHeader hdr,
317 Ipv4Address senderAddress,
318 uint32_t incomingInterface,
319 uint8_t hopLimit);
320
328 Ptr<Ipv4Route> Lookup(Ipv4Address dest, bool setSource, Ptr<NetDevice> = nullptr);
329
340
348 void AddNetworkRouteTo(Ipv4Address network,
349 Ipv4Mask networkPrefix,
350 Ipv4Address nextHop,
351 uint32_t interface);
352
359 void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
360
365 void DoSendRouteUpdate(bool periodic);
366
370 void SendRouteRequest();
371
376
381
387
393
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).
406 typedef std::map<Ptr<Socket>, uint32_t> SocketList;
408 typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
410 typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
411
415
418
420
421 std::set<uint32_t> m_interfaceExclusions;
422 std::map<uint32_t, uint8_t> m_interfaceMetrics;
423
425
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