A Discrete-Event Network Simulator
API
rip.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 #ifndef RIP_H
22 #define RIP_H
23 
24 #include <list>
25 
26 #include "ns3/ipv4-routing-protocol.h"
27 #include "ns3/ipv4-interface.h"
28 #include "ns3/inet-socket-address.h"
29 #include "ns3/ipv4-l3-protocol.h"
30 #include "ns3/ipv4-routing-table-entry.h"
31 #include "ns3/random-variable-stream.h"
32 #include "ns3/rip-header.h"
33 
34 namespace ns3 {
35 
64 {
65 public:
66 
70  enum Status_e {
73  };
74 
75  RipRoutingTableEntry (void);
76 
84  RipRoutingTableEntry (Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface);
85 
92  RipRoutingTableEntry (Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
93 
94  virtual ~RipRoutingTableEntry ();
95 
100  void SetRouteTag (uint16_t routeTag);
101 
106  uint16_t GetRouteTag (void) const;
107 
112  void SetRouteMetric (uint8_t routeMetric);
113 
118  uint8_t GetRouteMetric (void) const;
119 
124  void SetRouteStatus (Status_e status);
125 
130  Status_e GetRouteStatus (void) const;
131 
141  void SetRouteChanged (bool changed);
142 
148  bool IsRouteChanged (void) const;
149 
150 private:
151  uint16_t m_tag;
152  uint8_t m_metric;
154  bool m_changed;
155 };
156 
164 std::ostream& operator<< (std::ostream& os, RipRoutingTableEntry const& route);
165 
166 
167 
173 class Rip : public Ipv4RoutingProtocol
174 {
175 public:
176  // /< C-tor
177  Rip ();
178  virtual ~Rip ();
179 
184  static TypeId GetTypeId (void);
185 
186  // From Ipv4RoutingProtocol
188  Socket::SocketErrno &sockerr);
189  bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
192  virtual void NotifyInterfaceUp (uint32_t interface);
193  virtual void NotifyInterfaceDown (uint32_t interface);
194  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
195  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
196  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
197  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
198 
206  };
207 
216  int64_t AssignStreams (int64_t stream);
217 
222  std::set<uint32_t> GetInterfaceExclusions () const;
223 
228  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
229 
235  uint8_t GetInterfaceMetric (uint32_t interface) const;
236 
242  void SetInterfaceMetric (uint32_t interface, uint8_t metric);
243 
253  void AddDefaultRouteTo (Ipv4Address nextHop, uint32_t interface);
254 
255 protected:
259  virtual void DoDispose ();
260 
264  void DoInitialize ();
265 
266 private:
268  typedef std::list<std::pair <RipRoutingTableEntry *, EventId> > Routes;
269 
271  typedef std::list<std::pair <RipRoutingTableEntry *, EventId> >::const_iterator RoutesCI;
272 
274  typedef std::list<std::pair <RipRoutingTableEntry *, EventId> >::iterator RoutesI;
275 
276 
282  void Receive (Ptr<Socket> socket);
283 
293  void HandleRequests (RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit);
294 
303  void HandleResponses (RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit);
304 
312  Ptr<Ipv4Route> Lookup (Ipv4Address dest, bool setSource, Ptr<NetDevice> = 0);
313 
324 
332  void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface);
333 
340  void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
341 
346  void DoSendRouteUpdate (bool periodic);
347 
351  void SendRouteRequest ();
352 
356  void SendTriggeredRouteUpdate ();
357 
361  void SendUnsolicitedRouteUpdate (void);
362 
368 
373  void DeleteRoute (RipRoutingTableEntry *route);
374 
383 
384  // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
385  // it is dependent on the interface initialization (i.e., if the loopback is already up).
387  typedef std::map< Ptr<Socket>, uint32_t> SocketList;
389  typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
391  typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
392 
395 
398 
400 
401  std::set<uint32_t> m_interfaceExclusions;
402  std::map<uint32_t, uint8_t> m_interfaceMetrics;
403 
405 
407  uint32_t m_linkDown;
408 };
409 
410 } // namespace ns3
411 #endif /* RIP_H */
412 
Callback template class.
Definition: callback.h:1279
An identifier for simulation events.
Definition: event-id.h:54
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
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:256
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:74
RipHeader - see RFC 2453
Definition: rip-header.h:158
RIP Routing Protocol, defined in RFC 2453.
Definition: rip.h:174
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: rip.h:389
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: rip.cc:1251
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: rip.cc:1091
virtual void NotifyInterfaceDown(uint32_t interface)
Definition: rip.cc:376
std::list< std::pair< RipRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: rip.h:271
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: rip.h:404
Rip()
Definition: rip.cc:46
Time m_startupDelay
Random delay before protocol startup.
Definition: rip.h:377
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: rip.h:402
virtual ~Rip()
Definition: rip.cc:52
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: rip.h:401
uint32_t m_linkDown
Link down value.
Definition: rip.h:407
void HandleRequests(RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP requests.
Definition: rip.cc:789
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
Definition: rip.cc:219
void DeleteRoute(RipRoutingTableEntry *route)
Delete a route.
Definition: rip.cc:707
void InvalidateRoute(RipRoutingTableEntry *route)
Invalidate a route.
Definition: rip.cc:685
void Receive(Ptr< Socket > socket)
Receive RIP packets.
Definition: rip.cc:724
Ptr< Ipv4Route > Lookup(Ipv4Address dest, bool setSource, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: rip.cc:584
void RecvMulticastRip(Ptr< Socket > socket)
Receive and process multicast packet.
virtual void DoDispose()
Dispose this object.
Definition: rip.cc:555
virtual void NotifyInterfaceUp(uint32_t interface)
Definition: rip.cc:293
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: rip.h:396
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
Definition: rip.cc:189
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: rip.cc:101
void DoInitialize()
Start protocol operation.
Definition: rip.cc:109
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:432
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: rip.h:397
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: rip.h:391
Ptr< Ipv4 > m_ipv4
IPv4 reference.
Definition: rip.h:376
std::list< std::pair< RipRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipRoutingTableEntry *, EventId (update event)
Definition: rip.h:268
void RecvUnicastRip(Ptr< Socket > socket)
Receive and process unicast packet.
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: rip.cc:1261
std::list< std::pair< RipRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: rip.h:274
Time m_timeoutDelay
Delay before invalidating a route.
Definition: rip.h:381
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface)
Add route to network.
Definition: rip.cc:661
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: rip.h:394
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: rip.h:378
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:407
SplitHorizonType_e
Split Horizon strategy type.
Definition: rip.h:202
@ SPLIT_HORIZON
Split Horizon.
Definition: rip.h:204
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: rip.h:203
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: rip.h:205
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: rip.h:380
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: rip.cc:1227
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
Definition: rip.cc:469
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
Definition: rip.cc:490
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: rip.cc:1239
static TypeId GetTypeId(void)
Get the type ID.
Definition: rip.cc:57
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition: rip.h:393
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: rip.h:382
bool m_initialized
flag to allow socket's late-creation.
Definition: rip.h:406
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: rip.cc:1232
void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: rip.cc:1294
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: rip.cc:1212
Routes m_routes
the forwarding table for network.
Definition: rip.h:375
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: rip.h:379
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: rip.cc:1182
void HandleResponses(RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP responses.
Definition: rip.cc:951
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: rip.h:387
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: rip.h:399
Rip Routing Table Entry.
Definition: rip.h:64
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: rip.cc:1342
Status_e m_status
route status
Definition: rip.h:153
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: rip.cc:1351
bool m_changed
route has been updated
Definition: rip.h:154
void SetRouteStatus(Status_e status)
Set the route status.
Definition: rip.cc:1356
Status_e
Route status.
Definition: rip.h:70
@ RIP_INVALID
Definition: rip.h:72
@ RIP_VALID
Definition: rip.h:71
bool IsRouteChanged(void) const
Get the route changed status.
Definition: rip.cc:1375
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: rip.cc:1328
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: rip.cc:1337
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: rip.cc:1370
Status_e GetRouteStatus(void) const
Get the route status.
Definition: rip.cc:1365
uint8_t m_metric
route metric
Definition: rip.h:152
RipRoutingTableEntry(void)
Definition: rip.cc:1306
virtual ~RipRoutingTableEntry()
Definition: rip.cc:1323
uint16_t m_tag
route tag
Definition: rip.h:151
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ S
second
Definition: nstime.h:114
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:44
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:139