A Discrete-Event Network Simulator
API
ripng.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 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 RIPNG_H
22 #define RIPNG_H
23 
24 #include <list>
25 
26 #include "ns3/ipv6-routing-protocol.h"
27 #include "ns3/ipv6-interface.h"
28 #include "ns3/inet6-socket-address.h"
29 #include "ns3/ipv6-l3-protocol.h"
30 #include "ns3/ipv6-routing-table-entry.h"
31 #include "ns3/random-variable-stream.h"
32 #include "ns3/ripng-header.h"
33 
34 namespace ns3 {
35 
63 {
64 public:
65 
69  enum Status_e {
72  };
73 
75 
84  RipNgRoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse);
85 
92  RipNgRoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
93 
94  virtual ~RipNgRoutingTableEntry ();
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, RipNgRoutingTableEntry const& route);
165 
166 
167 
174 {
175 public:
176  // /< C-tor
177  RipNg ();
178  virtual ~RipNg ();
179 
184  static TypeId GetTypeId (void);
185 
186  // From Ipv6RoutingProtocol
188  Socket::SocketErrno &sockerr);
189  bool RouteInput (Ptr<const Packet> p, const Ipv6Header &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, Ipv6InterfaceAddress address);
195  virtual void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address);
196  virtual void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop,
197  uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
198  virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop,
199  uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
200  virtual void SetIpv6 (Ptr<Ipv6> ipv6);
201  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
202 
210  };
211 
220  int64_t AssignStreams (int64_t stream);
221 
226  std::set<uint32_t> GetInterfaceExclusions () const;
227 
232  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
233 
239  uint8_t GetInterfaceMetric (uint32_t interface) const;
240 
246  void SetInterfaceMetric (uint32_t interface, uint8_t metric);
247 
257  void AddDefaultRouteTo (Ipv6Address nextHop, uint32_t interface);
258 
259 protected:
263  virtual void DoDispose ();
264 
268  void DoInitialize ();
269 
270 private:
272  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> > Routes;
273 
275  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> >::const_iterator RoutesCI;
276 
278  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> >::iterator RoutesI;
279 
280 
286  void Receive (Ptr<Socket> socket);
287 
297  void HandleRequests (RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit);
298 
307  void HandleResponses (RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit);
308 
316 
321  void RecvUnicastRipng (Ptr<Socket> socket);
326  void RecvMulticastRipng (Ptr<Socket> socket);
327 
336  void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse);
337 
344  void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
345 
349  void DoSendRouteUpdate (bool periodic);
350 
354  void SendRouteRequest ();
355 
359  void SendTriggeredRouteUpdate ();
360 
364  void SendUnsolicitedRouteUpdate (void);
365 
371 
376  void DeleteRoute (RipNgRoutingTableEntry *route);
377 
378  Routes m_routes;
386 
387  // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
388  // it is dependent on the interface initialization (i.e., if the loopback is already up).
390  typedef std::map< Ptr<Socket>, uint32_t> SocketList;
392  typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
394  typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
395 
396  SocketList m_sendSocketList;
398 
401 
403 
404  std::set<uint32_t> m_interfaceExclusions;
405  std::map<uint32_t, uint8_t> m_interfaceMetrics;
406 
408 
410 };
411 
412 } // namespace ns3
413 #endif /* RIPNG_H */
414 
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: ripng.h:407
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: ripng.h:392
Split Horizon.
Definition: ripng.h:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
Definition: ripng.cc:358
Introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Callback template class.
Definition: callback.h:1164
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: ripng.cc:1315
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition: ripng.cc:647
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: ripng.cc:1219
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: ripng.h:400
virtual ~RipNg()
Definition: ripng.cc:51
IPv6 address associated with an interface.
uint8_t m_metric
route metric
Definition: ripng.h:152
RipNg()
Definition: ripng.cc:45
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: ripng.cc:1238
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: ripng.cc:1199
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: ripng.h:399
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition: ripng.cc:715
virtual void DoDispose()
Dispose this object.
Definition: ripng.cc:539
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: ripng.cc:1281
void RecvUnicastRipng(Ptr< Socket > socket)
Receive and process unicast packet.
uint16_t m_tag
route tag
Definition: ripng.h:151
SocketList m_sendSocketList
list of sockets for sending (socket, interface index)
Definition: ripng.h:396
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition: ripng.cc:676
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:173
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: ripng.cc:1169
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: ripng.h:404
void DoInitialize()
Start protocol operation.
Definition: ripng.cc:104
A record of an IPv6 route.
virtual void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
Definition: ripng.cc:451
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: ripng.cc:1329
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: ripng.cc:1226
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: ripng.cc:96
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition: ripng.h:379
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
std::list< std::pair< RipNgRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipNgRoutingTableEntry *, EventId (update event) ...
Definition: ripng.h:272
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:206
Time m_timeoutDelay
Delay before invalidating a route.
Definition: ripng.h:384
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: ripng.h:394
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: ripng.cc:1089
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: ripng.cc:1357
RipNgHeader - see RFC 2080
Definition: ripng-header.h:144
Ptr< Socket > m_recvSocket
receive socket
Definition: ripng.h:397
virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:414
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition: ripng.cc:698
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
Definition: ripng.cc:174
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
Definition: ripng.cc:204
Status_e GetRouteStatus(void) const
Get the route status.
Definition: ripng.cc:1352
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: ripng.h:383
virtual ~RipNgRoutingTableEntry()
Definition: ripng.cc:1310
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: ripng.cc:1338
virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:389
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition: ripng.cc:937
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition: ripng.cc:772
virtual void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition: ripng.cc:463
void RecvMulticastRipng(Ptr< Socket > socket)
Receive and process multicast packet.
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: ripng.h:402
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: ripng.cc:1214
void SetRouteStatus(Status_e status)
Set the route status.
Definition: ripng.cc:1343
virtual void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
Definition: ripng.cc:283
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: ripng.cc:1324
Describes an IPv6 address.
Definition: ipv6-address.h:47
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: ripng.cc:1248
static TypeId GetTypeId(void)
Get the type ID.
Definition: ripng.cc:56
An identifier for simulation events.
Definition: event-id.h:53
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: ripng.h:405
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
Definition: ripng.cc:484
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: ripng.h:275
No Split Horizon.
Definition: ripng.h:207
RipNg Routing Table Entry.
Definition: ripng.h:62
Routes m_routes
the forwarding table for network.
Definition: ripng.h:378
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: ripng.h:278
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: ripng.h:390
Ptr< Ipv6Route > Lookup(Ipv6Address dest, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: ripng.cc:569
Describes an IPv6 prefix.
Definition: ipv6-address.h:389
bool m_changed
route has been updated
Definition: ripng.h:154
bool m_initialized
flag to allow socket's late-creation.
Definition: ripng.h:409
RipNgRoutingTableEntry(void)
Definition: ripng.cc:1293
tuple address
Definition: first.py:37
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: ripng.h:382
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: ripng.h:385
Poison Reverse Split Horizon.
Definition: ripng.h:209
Abstract base class for Ipv6 routing protocols.
virtual void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify route removing.
Definition: ripng.cc:457
Status_e m_status
route status
Definition: ripng.h:153
a unique identifier for an interface.
Definition: type-id.h:58
Status_e
Route status.
Definition: ripng.h:69
Time m_startupDelay
Random delay before protocol startup.
Definition: ripng.h:380
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: ripng.h:381
bool IsRouteChanged(void) const
Get the route changed status.
Definition: ripng.cc:1362