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 
317  void RecvUnicastRip (Ptr<Socket> socket);
322  void RecvMulticastRip (Ptr<Socket> socket);
323 
331  void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface);
332 
339  void AddNetworkRouteTo (Ipv4Address network, Ipv4Mask networkPrefix, uint32_t interface);
340 
345  void DoSendRouteUpdate (bool periodic);
346 
350  void SendRouteRequest ();
351 
355  void SendTriggeredRouteUpdate ();
356 
360  void SendUnsolicitedRouteUpdate (void);
361 
367 
372  void DeleteRoute (RipRoutingTableEntry *route);
373 
382 
383  // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
384  // it is dependent on the interface initialization (i.e., if the loopback is already up).
386  typedef std::map< Ptr<Socket>, uint32_t> SocketList;
388  typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
390  typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
391 
394 
397 
399 
400  std::set<uint32_t> m_interfaceExclusions;
401  std::map<uint32_t, uint8_t> m_interfaceMetrics;
402 
404 
406  uint32_t m_linkDown;
407 };
408 
409 } // namespace ns3
410 #endif /* RIP_H */
411 
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: rip.cc:1207
std::list< std::pair< RipRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipRoutingTableEntry *, EventId (update event) ...
Definition: rip.h:268
Ptr< Ipv4 > m_ipv4
IPv4 reference.
Definition: rip.h:375
void HandleRequests(RipHeader hdr, Ipv4Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP requests.
Definition: rip.cc:764
void HandleResponses(RipHeader hdr, Ipv4Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIP responses.
Definition: rip.cc:926
bool m_initialized
flag to allow socket&#39;s late-creation.
Definition: rip.h:405
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:186
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: rip.cc:1157
Definition: rip.h:72
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:402
Callback template class.
Definition: callback.h:1176
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: rip.h:381
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: rip.cc:1187
Ptr< Ipv4Route > Lookup(Ipv4Address dest, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: rip.cc:573
virtual ~RipRoutingTableEntry()
Definition: rip.cc:1298
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
virtual ~Rip()
Definition: rip.cc:53
Status_e
Route status.
Definition: rip.h:70
Time m_startupDelay
Random delay before protocol startup.
Definition: rip.h:376
uint32_t m_linkDown
Link down value.
Definition: rip.h:406
std::list< std::pair< RipRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: rip.h:274
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: rip.h:401
RipRoutingTableEntry(void)
Definition: rip.cc:1281
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: rip.cc:1345
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: rip.h:395
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: rip.cc:1066
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
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:216
Packet header for IPv4.
Definition: ipv4-header.h:33
Routes m_routes
the forwarding table for network.
Definition: rip.h:374
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
void InvalidateRoute(RipRoutingTableEntry *route)
Invalidate a route.
Definition: rip.cc:671
virtual void DoDispose()
Dispose this object.
Definition: rip.cc:543
void DeleteRoute(RipRoutingTableEntry *route)
Delete a route.
Definition: rip.cc:693
void RecvMulticastRip(Ptr< Socket > socket)
Receive and process multicast packet.
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: rip.cc:1214
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: rip.h:386
RIP Routing Protocol, defined in RFC 2453.
Definition: rip.h:173
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: rip.cc:1303
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
Split Horizon.
Definition: rip.h:204
std::list< std::pair< RipRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: rip.h:271
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: rip.h:400
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: rip.h:388
SplitHorizonType_e
Split Horizon strategy type.
Definition: rip.h:202
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkPrefix, Ipv4Address nextHop, uint32_t interface)
Add route to network.
Definition: rip.cc:647
bool m_changed
route has been updated
Definition: rip.h:154
RipHeader - see RFC 2453
Definition: rip-header.h:157
uint16_t m_tag
route tag
Definition: rip.h:151
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: rip.cc:1317
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetRouteStatus(Status_e status)
Set the route status.
Definition: rip.cc:1331
address
Definition: first.py:37
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
Definition: rip.cc:427
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: rip.cc:1236
void Receive(Ptr< Socket > socket)
Receive RIP packets.
Definition: rip.cc:710
Status_e m_status
route status
Definition: rip.h:153
virtual void NotifyInterfaceUp(uint32_t interface)
Definition: rip.cc:290
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: rip.cc:1202
uint8_t m_metric
route metric
Definition: rip.h:152
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: rip.h:390
void DoInitialize()
Start protocol operation.
Definition: rip.cc:110
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: rip.h:379
static TypeId GetTypeId(void)
Get the type ID.
Definition: rip.cc:58
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: rip.h:396
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
Definition: rip.cc:464
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
Definition: rip.cc:485
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: rip.cc:1312
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: rip.h:403
Poison Reverse Split Horizon.
Definition: rip.h:205
void AddDefaultRouteTo(Ipv4Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: rip.cc:1269
Status_e GetRouteStatus(void) const
Get the route status.
Definition: rip.cc:1340
void RecvUnicastRip(Ptr< Socket > socket)
Receive and process unicast packet.
a class to store IPv4 address information on an interface
Rip()
Definition: rip.cc:47
An identifier for simulation events.
Definition: event-id.h:53
Ptr< Socket > m_recvSocket
receive socket
Definition: rip.h:393
bool IsRouteChanged(void) const
Get the route changed status.
Definition: rip.cc:1350
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: rip.cc:1226
Abstract base class for IPv4 routing protocols.
second
Definition: nstime.h:114
virtual void NotifyInterfaceDown(uint32_t interface)
Definition: rip.cc:371
Rip Routing Table Entry.
Definition: rip.h:63
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: rip.h:377
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: rip.h:398
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: rip.cc:1326
Definition: rip.h:71
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: rip.h:378
SocketList m_sendSocketList
list of sockets for sending (socket, interface index)
Definition: rip.h:392
No Split Horizon.
Definition: rip.h:203
Time m_timeoutDelay
Delay before invalidating a route.
Definition: rip.h:380