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 
64 {
65 public:
66 
70  enum Status_e {
73  };
74 
76 
85  RipNgRoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse);
86 
93  RipNgRoutingTableEntry (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
94 
95  virtual ~RipNgRoutingTableEntry ();
96 
101  void SetRouteTag (uint16_t routeTag);
102 
107  uint16_t GetRouteTag (void) const;
108 
113  void SetRouteMetric (uint8_t routeMetric);
114 
119  uint8_t GetRouteMetric (void) const;
120 
125  void SetRouteStatus (Status_e status);
126 
131  Status_e GetRouteStatus (void) const;
132 
142  void SetRouteChanged (bool changed);
143 
149  bool IsRouteChanged (void) const;
150 
151 private:
152  uint16_t m_tag;
153  uint8_t m_metric;
155  bool m_changed;
156 };
157 
165 std::ostream& operator<< (std::ostream& os, RipNgRoutingTableEntry const& route);
166 
167 
168 
175 {
176 public:
177  // /< C-tor
178  RipNg ();
179  virtual ~RipNg ();
180 
185  static TypeId GetTypeId (void);
186 
187  // From Ipv6RoutingProtocol
189  Socket::SocketErrno &sockerr);
190  bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
193  virtual void NotifyInterfaceUp (uint32_t interface);
194  virtual void NotifyInterfaceDown (uint32_t interface);
195  virtual void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address);
196  virtual void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address);
197  virtual void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop,
198  uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
199  virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop,
200  uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ());
201  virtual void SetIpv6 (Ptr<Ipv6> ipv6);
202  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
203 
211  };
212 
221  int64_t AssignStreams (int64_t stream);
222 
227  std::set<uint32_t> GetInterfaceExclusions () const;
228 
233  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
234 
240  uint8_t GetInterfaceMetric (uint32_t interface) const;
241 
247  void SetInterfaceMetric (uint32_t interface, uint8_t metric);
248 
258  void AddDefaultRouteTo (Ipv6Address nextHop, uint32_t interface);
259 
260 protected:
264  virtual void DoDispose ();
265 
269  void DoInitialize ();
270 
271 private:
273  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> > Routes;
274 
276  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> >::const_iterator RoutesCI;
277 
279  typedef std::list<std::pair <RipNgRoutingTableEntry *, EventId> >::iterator RoutesI;
280 
281 
287  void Receive (Ptr<Socket> socket);
288 
298  void HandleRequests (RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit);
299 
308  void HandleResponses (RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit);
309 
317 
322  void RecvUnicastRipng (Ptr<Socket> socket);
327  void RecvMulticastRipng (Ptr<Socket> socket);
328 
337  void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse);
338 
345  void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
346 
351  void DoSendRouteUpdate (bool periodic);
352 
356  void SendRouteRequest ();
357 
361  void SendTriggeredRouteUpdate ();
362 
366  void SendUnsolicitedRouteUpdate (void);
367 
373 
378  void DeleteRoute (RipNgRoutingTableEntry *route);
379 
388 
389  // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
390  // it is dependent on the interface initialization (i.e., if the loopback is already up).
392  typedef std::map< Ptr<Socket>, uint32_t> SocketList;
394  typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
396  typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
397 
400 
403 
405 
406  std::set<uint32_t> m_interfaceExclusions;
407  std::map<uint32_t, uint8_t> m_interfaceMetrics;
408 
410 
412  uint8_t m_linkDown;
413 };
414 
415 } // namespace ns3
416 #endif /* RIPNG_H */
417 
Status_e GetRouteStatus(void) const
Get the route status.
Definition: ripng.cc:1340
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: ripng.h:409
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: ripng.h:394
bool IsRouteChanged(void) const
Get the route changed status.
Definition: ripng.cc:1350
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:343
Packet header for IPv6.
Definition: ipv6-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1176
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: ripng.cc:1303
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition: ripng.cc:634
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: ripng.cc:1207
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
Definition: ripng.cc:469
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: ripng.h:402
virtual ~RipNg()
Definition: ripng.cc:53
IPv6 address associated with an interface.
uint8_t m_metric
route metric
Definition: ripng.h:153
RipNg()
Definition: ripng.cc:47
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: ripng.cc:1226
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: ripng.cc:1187
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: ripng.h:401
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition: ripng.cc:702
virtual void DoDispose()
Dispose this object.
Definition: ripng.cc:526
uint8_t m_linkDown
Link down value.
Definition: ripng.h:412
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: ripng.cc:1269
void RecvUnicastRipng(Ptr< Socket > socket)
Receive and process unicast packet.
uint16_t m_tag
route tag
Definition: ripng.h:152
SocketList m_sendSocketList
list of sockets for sending (socket, interface index)
Definition: ripng.h:398
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition: ripng.cc:663
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:174
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: ripng.cc:1157
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: ripng.h:406
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: ripng.cc:1214
void DoInitialize()
Start protocol operation.
Definition: ripng.cc:110
Status_e
Route status.
Definition: ripng.h:70
Definition: ripng.h:72
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:436
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: ripng.cc:1317
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: ripng.cc:102
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition: ripng.h:381
Poison Reverse Split Horizon.
Definition: ripng.h:210
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:273
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
Time m_timeoutDelay
Delay before invalidating a route.
Definition: ripng.h:386
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: ripng.cc:1326
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: ripng.h:396
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: ripng.cc:1077
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: ripng.cc:1345
Split Horizon.
Definition: ripng.h:209
RipNgHeader - see RFC 2080
Definition: ripng-header.h:146
Ptr< Socket > m_recvSocket
receive socket
Definition: ripng.h:399
virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:399
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition: ripng.cc:685
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:181
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:211
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: ripng.h:385
address
Definition: first.py:37
virtual ~RipNgRoutingTableEntry()
Definition: ripng.cc:1298
virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:374
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition: ripng.cc:921
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition: ripng.cc:756
virtual void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition: ripng.cc:448
void RecvMulticastRipng(Ptr< Socket > socket)
Receive and process multicast packet.
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: ripng.h:404
void SetRouteStatus(Status_e status)
Set the route status.
Definition: ripng.cc:1331
virtual void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
Definition: ripng.cc:267
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: ripng.cc:1202
Describes an IPv6 address.
Definition: ipv6-address.h:49
Definition: ripng.h:71
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: ripng.cc:1236
static TypeId GetTypeId(void)
Get the type ID.
Definition: ripng.cc:58
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:407
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: ripng.h:276
RipNg Routing Table Entry.
Definition: ripng.h:63
Routes m_routes
the forwarding table for network.
Definition: ripng.h:380
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: ripng.h:279
No Split Horizon.
Definition: ripng.h:208
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: ripng.h:392
Ptr< Ipv6Route > Lookup(Ipv6Address dest, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: ripng.cc:556
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
bool m_changed
route has been updated
Definition: ripng.h:155
second
Definition: nstime.h:114
bool m_initialized
flag to allow socket&#39;s late-creation.
Definition: ripng.h:411
RipNgRoutingTableEntry(void)
Definition: ripng.cc:1281
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:207
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: ripng.h:384
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: ripng.h:387
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: ripng.cc:1312
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:442
Status_e m_status
route status
Definition: ripng.h:154
a unique identifier for an interface.
Definition: type-id.h:58
Time m_startupDelay
Random delay before protocol startup.
Definition: ripng.h:382
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: ripng.h:383