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 
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::Ipv4Header
Packet header for IPv4.
Definition: ipv4-header.h:34
ns3::Rip::m_startupDelay
Time m_startupDelay
Random delay before protocol startup.
Definition: rip.h:377
ns3::Rip::DoInitialize
void DoInitialize()
Start protocol operation.
Definition: rip.cc:110
ns3::Rip::m_linkDown
uint32_t m_linkDown
Link down value.
Definition: rip.h:407
ns3::Rip::m_routes
Routes m_routes
the forwarding table for network.
Definition: rip.h:375
ns3::RipRoutingTableEntry::IsRouteChanged
bool IsRouteChanged(void) const
Get the route changed status.
Definition: rip.cc:1376
ns3::Rip::GetInterfaceMetric
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: rip.cc:1240
ns3::RipRoutingTableEntry::~RipRoutingTableEntry
virtual ~RipRoutingTableEntry()
Definition: rip.cc:1324
ns3::RipRoutingTableEntry::Status_e
Status_e
Route status.
Definition: rip.h:70
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::Socket::SocketErrno
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
ns3::Callback
Callback template class.
Definition: callback.h:1279
ns3::Rip::SendTriggeredRouteUpdate
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: rip.cc:1183
ns3::Rip::RouteOutput
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:190
ns3::Rip::SetIpv4
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
Definition: rip.cc:470
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RipRoutingTableEntry::RIP_VALID
@ RIP_VALID
Definition: rip.h:71
ns3::Rip::DeleteRoute
void DeleteRoute(RipRoutingTableEntry *route)
Delete a route.
Definition: rip.cc:708
ns3::Rip::RecvMulticastRip
void RecvMulticastRip(Ptr< Socket > socket)
Receive and process multicast packet.
ns3::RipRoutingTableEntry::RipRoutingTableEntry
RipRoutingTableEntry(void)
Definition: rip.cc:1307
ns3::Rip::DoDispose
virtual void DoDispose()
Dispose this object.
Definition: rip.cc:556
ns3::Rip::SocketList
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: rip.h:387
ns3::Rip::m_timeoutDelay
Time m_timeoutDelay
Delay before invalidating a route.
Definition: rip.h:381
ns3::Rip::m_rng
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: rip.h:399
ns3::Rip::m_initialized
bool m_initialized
flag to allow socket's late-creation.
Definition: rip.h:406
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::RipRoutingTableEntry::GetRouteStatus
Status_e GetRouteStatus(void) const
Get the route status.
Definition: rip.cc:1366
ns3::Rip::m_interfaceMetrics
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: rip.h:402
ns3::RipRoutingTableEntry::GetRouteMetric
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: rip.cc:1352
ns3::Rip::NotifyRemoveAddress
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:433
ns3::Ipv4RoutingTableEntry
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Definition: ipv4-routing-table-entry.h:37
ns3::Rip::Receive
void Receive(Ptr< Socket > socket)
Receive RIP packets.
Definition: rip.cc:725
ns3::Rip::RouteInput
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:220
ns3::Rip::NO_SPLIT_HORIZON
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: rip.h:203
ns3::Rip::~Rip
virtual ~Rip()
Definition: rip.cc:53
ns3::RipRoutingTableEntry::m_tag
uint16_t m_tag
route tag
Definition: rip.h:151
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::Rip::m_interfaceExclusions
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: rip.h:401
ns3::Rip::SendUnsolicitedRouteUpdate
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: rip.cc:1213
ns3::Rip::SplitHorizonType_e
SplitHorizonType_e
Split Horizon strategy type.
Definition: rip.h:202
ns3::Rip::Lookup
Ptr< Ipv4Route > Lookup(Ipv4Address dest, bool setSource, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: rip.cc:585
ns3::RipRoutingTableEntry::GetRouteTag
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: rip.cc:1338
ns3::RipRoutingTableEntry::RIP_INVALID
@ RIP_INVALID
Definition: rip.h:72
ns3::Rip::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: rip.cc:58
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition: ipv4-interface-address.h:44
ns3::RipHeader
RipHeader - see RFC 2453
Definition: rip-header.h:158
ns3::RipRoutingTableEntry::SetRouteStatus
void SetRouteStatus(Status_e status)
Set the route status.
Definition: rip.cc:1357
ns3::Rip::SPLIT_HORIZON
@ SPLIT_HORIZON
Split Horizon.
Definition: rip.h:204
ns3::Rip::m_minTriggeredUpdateDelay
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: rip.h:378
ns3::Rip::DoSendRouteUpdate
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: rip.cc:1092
ns3::Rip::NotifyInterfaceDown
virtual void NotifyInterfaceDown(uint32_t interface)
Definition: rip.cc:377
ns3::Rip::m_ipv4
Ptr< Ipv4 > m_ipv4
IPv4 reference.
Definition: rip.h:376
ns3::Rip::AssignStreams
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: rip.cc:102
ns3::Rip::Routes
std::list< std::pair< RipRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipRoutingTableEntry *, EventId (update event)
Definition: rip.h:268
ns3::Rip::NotifyInterfaceUp
virtual void NotifyInterfaceUp(uint32_t interface)
Definition: rip.cc:294
ns3::Rip::HandleResponses
void HandleResponses(RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP responses.
Definition: rip.cc:952
ns3::Rip::SocketListCI
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: rip.h:391
first.address
address
Definition: first.py:44
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Rip::m_multicastRecvSocket
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: rip.h:394
ns3::Rip::RoutesCI
std::list< std::pair< RipRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: rip.h:271
ns3::RipRoutingTableEntry::SetRouteTag
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: rip.cc:1329
ns3::Rip::InvalidateRoute
void InvalidateRoute(RipRoutingTableEntry *route)
Invalidate a route.
Definition: rip.cc:686
ns3::Rip::m_nextTriggeredUpdate
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: rip.h:397
ns3::Rip::m_nextUnsolicitedUpdate
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: rip.h:396
ns3::Rip::m_unsolicitedUpdate
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: rip.h:380
ns3::Rip::PrintRoutingTable
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
Definition: rip.cc:491
ns3::Ipv4RoutingProtocol
Abstract base class for IPv4 routing protocols.
Definition: ipv4-routing-protocol.h:57
ns3::Rip::AddDefaultRouteTo
void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: rip.cc:1295
ns3::Rip::HandleRequests
void HandleRequests(RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP requests.
Definition: rip.cc:790
ns3::RipRoutingTableEntry::m_status
Status_e m_status
route status
Definition: rip.h:153
ns3::Rip::RecvUnicastRip
void RecvUnicastRip(Ptr< Socket > socket)
Receive and process unicast packet.
ns3::Rip::SendRouteRequest
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: rip.cc:1262
ns3::Rip::GetInterfaceExclusions
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: rip.cc:1228
ns3::Rip::m_splitHorizonStrategy
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: rip.h:404
ns3::Rip::Rip
Rip()
Definition: rip.cc:47
ns3::Rip::SetInterfaceMetric
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: rip.cc:1252
ns3::RipRoutingTableEntry
Rip Routing Table Entry.
Definition: rip.h:64
ns3::RipRoutingTableEntry::SetRouteChanged
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: rip.cc:1371
ns3::Time::S
@ S
second
Definition: nstime.h:115
ns3::Rip::SocketListI
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: rip.h:389
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::Rip::AddNetworkRouteTo
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface)
Add route to network.
Definition: rip.cc:662
ns3::Rip
RIP Routing Protocol, defined in RFC 2453.
Definition: rip.h:174
ns3::Rip::m_garbageCollectionDelay
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: rip.h:382
ns3::Rip::m_unicastSocketList
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition: rip.h:393
ns3::Rip::POISON_REVERSE
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: rip.h:205
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::RipRoutingTableEntry::m_changed
bool m_changed
route has been updated
Definition: rip.h:154
ns3::Rip::m_maxTriggeredUpdateDelay
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: rip.h:379
ns3::RipRoutingTableEntry::SetRouteMetric
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: rip.cc:1343
ns3::RipRoutingTableEntry::m_metric
uint8_t m_metric
route metric
Definition: rip.h:152
ns3::Rip::NotifyAddAddress
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:408
ns3::Rip::RoutesI
std::list< std::pair< RipRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: rip.h:274
ns3::Time::Unit
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:110
ns3::Rip::SetInterfaceExclusions
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: rip.cc:1233