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 "ns3/inet-socket-address.h"
24#include "ns3/ipv4-interface.h"
25#include "ns3/ipv4-l3-protocol.h"
26#include "ns3/ipv4-routing-protocol.h"
27#include "ns3/ipv4-routing-table-entry.h"
28#include "ns3/random-variable-stream.h"
29#include "ns3/rip-header.h"
30
31#include <list>
32
33namespace ns3
34{
35
64{
65 public:
70 {
73 };
74
76
85 Ipv4Mask networkPrefix,
86 Ipv4Address nextHop,
87 uint32_t interface);
88
95 RipRoutingTableEntry(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
96
97 virtual ~RipRoutingTableEntry();
98
103 void SetRouteTag(uint16_t routeTag);
104
109 uint16_t GetRouteTag() const;
110
115 void SetRouteMetric(uint8_t routeMetric);
116
121 uint8_t GetRouteMetric() const;
122
127 void SetRouteStatus(Status_e status);
128
133 Status_e GetRouteStatus() const;
134
144 void SetRouteChanged(bool changed);
145
151 bool IsRouteChanged() const;
152
153 private:
154 uint16_t m_tag;
155 uint8_t m_metric;
158};
159
167std::ostream& operator<<(std::ostream& os, const RipRoutingTableEntry& route);
168
175{
176 public:
177 // /< C-tor
178 Rip();
179 ~Rip() override;
180
185 static TypeId GetTypeId();
186
187 // From Ipv4RoutingProtocol
189 const Ipv4Header& header,
190 Ptr<NetDevice> oif,
191 Socket::SocketErrno& sockerr) override;
193 const Ipv4Header& header,
195 const UnicastForwardCallback& ucb,
196 const MulticastForwardCallback& mcb,
197 const LocalDeliverCallback& lcb,
198 const ErrorCallback& ecb) override;
199 void NotifyInterfaceUp(uint32_t interface) override;
200 void NotifyInterfaceDown(uint32_t interface) override;
201 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
202 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
203 void SetIpv4(Ptr<Ipv4> ipv4) override;
205 Time::Unit unit = Time::S) const override;
206
211 {
215 };
216
225 int64_t AssignStreams(int64_t stream);
226
231 std::set<uint32_t> GetInterfaceExclusions() const;
232
237 void SetInterfaceExclusions(std::set<uint32_t> exceptions);
238
244 uint8_t GetInterfaceMetric(uint32_t interface) const;
245
251 void SetInterfaceMetric(uint32_t interface, uint8_t metric);
252
262 void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface);
263
264 protected:
268 void DoDispose() override;
269
273 void DoInitialize() override;
274
275 private:
277 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>> Routes;
278
280 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::const_iterator RoutesCI;
281
283 typedef std::list<std::pair<RipRoutingTableEntry*, EventId>>::iterator RoutesI;
284
290 void Receive(Ptr<Socket> socket);
291
301 void HandleRequests(RipHeader hdr,
302 Ipv4Address senderAddress,
303 uint16_t senderPort,
304 uint32_t incomingInterface,
305 uint8_t hopLimit);
306
315 void HandleResponses(RipHeader hdr,
316 Ipv4Address senderAddress,
317 uint32_t incomingInterface,
318 uint8_t hopLimit);
319
327 Ptr<Ipv4Route> Lookup(Ipv4Address dest, bool setSource, Ptr<NetDevice> = nullptr);
328
339
347 void AddNetworkRouteTo(Ipv4Address network,
348 Ipv4Mask networkPrefix,
349 Ipv4Address nextHop,
350 uint32_t interface);
351
358 void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
359
364 void DoSendRouteUpdate(bool periodic);
365
369 void SendRouteRequest();
370
375
380
386
392
401
402 // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
403 // it is dependent on the interface initialization (i.e., if the loopback is already up).
405 typedef std::map<Ptr<Socket>, uint32_t> SocketList;
407 typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
409 typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
410
414
417
419
420 std::set<uint32_t> m_interfaceExclusions;
421 std::map<uint32_t, uint8_t> m_interfaceMetrics;
422
424
427};
428
429} // namespace ns3
430#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:78
RipHeader - see RFC 2453
Definition: rip-header.h:157
RIP Routing Protocol, defined in RFC 2453.
Definition: rip.h:175
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: rip.cc:1356
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: rip.cc:1182
void DoDispose() override
Dispose this object.
Definition: rip.cc:591
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: rip.h:423
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:395
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:421
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: rip.h:420
std::list< std::pair< RipRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: rip.h:283
uint32_t m_linkDown
Link down value.
Definition: rip.h:426
void HandleRequests(RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP requests.
Definition: rip.cc:843
void DeleteRoute(RipRoutingTableEntry *route)
Delete a route.
Definition: rip.cc:758
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:734
void Receive(Ptr< Socket > socket)
Receive RIP packets.
Definition: rip.cc:775
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:415
std::list< std::pair< RipRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: rip.h:280
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:416
Ptr< Ipv4 > m_ipv4
IPv4 reference.
Definition: rip.h:394
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:1367
Time m_timeoutDelay
Delay before invalidating a route.
Definition: rip.h:399
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:409
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: rip.h:407
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: rip.h:413
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: rip.h:396
SplitHorizonType_e
Split Horizon strategy type.
Definition: rip.h:211
@ SPLIT_HORIZON
Split Horizon.
Definition: rip.h:213
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: rip.h:212
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: rip.h:214
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: rip.h:398
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: rip.h:405
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: rip.cc:1329
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:1343
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:412
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: rip.h:400
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:425
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: rip.cc:1335
void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: rip.cc:1401
Routes m_routes
the forwarding table for network.
Definition: rip.h:393
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: rip.h:397
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: rip.cc:1280
void SendUnsolicitedRouteUpdate()
Send Unsolicited Routing Updates on all interfaces.
Definition: rip.cc:1312
void HandleResponses(RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP responses.
Definition: rip.cc:1019
std::list< std::pair< RipRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipRoutingTableEntry *, EventId (update event)
Definition: rip.h:277
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: rip.h:418
Rip Routing Table Entry.
Definition: rip.h:64
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: rip.cc:1466
Status_e m_status
route status
Definition: rip.h:156
RipRoutingTableEntry()
Definition: rip.cc:1412
bool m_changed
route has been updated
Definition: rip.h:157
void SetRouteStatus(Status_e status)
Set the route status.
Definition: rip.cc:1482
Status_e
Route status.
Definition: rip.h:70
@ RIP_INVALID
Definition: rip.h:72
@ RIP_VALID
Definition: rip.h:71
bool IsRouteChanged() const
Get the route changed status.
Definition: rip.cc:1504
Status_e GetRouteStatus() const
Get the route status.
Definition: rip.cc:1492
uint8_t GetRouteMetric() const
Get the route metric.
Definition: rip.cc:1476
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: rip.cc:1450
uint16_t GetRouteTag() const
Get the route tag.
Definition: rip.cc:1460
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: rip.cc:1498
uint8_t m_metric
route metric
Definition: rip.h:155
virtual ~RipRoutingTableEntry()
Definition: rip.cc:1445
uint16_t m_tag
route tag
Definition: rip.h:154
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:129