A Discrete-Event Network Simulator
API
ripng.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Universita' di Firenze, Italy
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18  */
19 
20 #ifndef RIPNG_H
21 #define RIPNG_H
22 
23 #include "ns3/inet6-socket-address.h"
24 #include "ns3/ipv6-interface.h"
25 #include "ns3/ipv6-l3-protocol.h"
26 #include "ns3/ipv6-routing-protocol.h"
27 #include "ns3/ipv6-routing-table-entry.h"
28 #include "ns3/random-variable-stream.h"
29 #include "ns3/ripng-header.h"
30 
31 #include <list>
32 
33 namespace ns3
34 {
35 
64 {
65  public:
69  enum Status_e
70  {
73  };
74 
76 
86  Ipv6Prefix networkPrefix,
87  Ipv6Address nextHop,
88  uint32_t interface,
89  Ipv6Address prefixToUse);
90 
97  RipNgRoutingTableEntry(Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
98 
99  ~RipNgRoutingTableEntry() override;
100 
105  void SetRouteTag(uint16_t routeTag);
106 
111  uint16_t GetRouteTag() const;
112 
117  void SetRouteMetric(uint8_t routeMetric);
118 
123  uint8_t GetRouteMetric() const;
124 
129  void SetRouteStatus(Status_e status);
130 
135  Status_e GetRouteStatus() const;
136 
146  void SetRouteChanged(bool changed);
147 
153  bool IsRouteChanged() const;
154 
155  private:
156  uint16_t m_tag;
157  uint8_t m_metric;
159  bool m_changed;
160 };
161 
169 std::ostream& operator<<(std::ostream& os, const RipNgRoutingTableEntry& route);
170 
177 {
178  public:
179  // /< C-tor
180  RipNg();
181  ~RipNg() override;
182 
187  static TypeId GetTypeId();
188 
189  // From Ipv6RoutingProtocol
191  const Ipv6Header& header,
192  Ptr<NetDevice> oif,
193  Socket::SocketErrno& sockerr) override;
195  const Ipv6Header& header,
200  ErrorCallback ecb) override;
201  void NotifyInterfaceUp(uint32_t interface) override;
202  void NotifyInterfaceDown(uint32_t interface) override;
203  void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
204  void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
205  void NotifyAddRoute(Ipv6Address dst,
206  Ipv6Prefix mask,
207  Ipv6Address nextHop,
208  uint32_t interface,
209  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
211  Ipv6Prefix mask,
212  Ipv6Address nextHop,
213  uint32_t interface,
214  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
215  void SetIpv6(Ptr<Ipv6> ipv6) override;
217  Time::Unit unit = Time::S) const override;
218 
223  {
227  };
228 
237  int64_t AssignStreams(int64_t stream);
238 
243  std::set<uint32_t> GetInterfaceExclusions() const;
244 
249  void SetInterfaceExclusions(std::set<uint32_t> exceptions);
250 
256  uint8_t GetInterfaceMetric(uint32_t interface) const;
257 
263  void SetInterfaceMetric(uint32_t interface, uint8_t metric);
264 
274  void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface);
275 
276  protected:
280  void DoDispose() override;
281 
285  void DoInitialize() override;
286 
287  private:
289  typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>> Routes;
290 
292  typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>>::const_iterator RoutesCI;
293 
295  typedef std::list<std::pair<RipNgRoutingTableEntry*, EventId>>::iterator RoutesI;
296 
302  void Receive(Ptr<Socket> socket);
303 
313  void HandleRequests(RipNgHeader hdr,
314  Ipv6Address senderAddress,
315  uint16_t senderPort,
316  uint32_t incomingInterface,
317  uint8_t hopLimit);
318 
327  void HandleResponses(RipNgHeader hdr,
328  Ipv6Address senderAddress,
329  uint32_t incomingInterface,
330  uint8_t hopLimit);
331 
339  Ptr<Ipv6Route> Lookup(Ipv6Address dest, bool setSource, Ptr<NetDevice> = nullptr);
340 
351 
360  void AddNetworkRouteTo(Ipv6Address network,
361  Ipv6Prefix networkPrefix,
362  Ipv6Address nextHop,
363  uint32_t interface,
364  Ipv6Address prefixToUse);
365 
372  void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
373 
378  void DoSendRouteUpdate(bool periodic);
379 
383  void SendRouteRequest();
384 
389 
394 
400 
405  void DeleteRoute(RipNgRoutingTableEntry* route);
406 
415 
416  // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
417  // it is dependent on the interface initialization (i.e., if the loopback is already up).
419  typedef std::map<Ptr<Socket>, uint32_t> SocketList;
421  typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
423  typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
424 
425  SocketList
428 
431 
433 
434  std::set<uint32_t> m_interfaceExclusions;
435  std::map<uint32_t, uint8_t> m_interfaceMetrics;
436 
438 
440  uint8_t m_linkDown;
441 };
442 
443 } // namespace ns3
444 #endif /* RIPNG_H */
Callback template class.
Definition: callback.h:443
An identifier for simulation events.
Definition: event-id.h:55
Describes an IPv6 address.
Definition: ipv6-address.h:50
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Packet header for IPv6.
Definition: ipv6-header.h:36
IPv6 address associated with an interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
RipNgHeader - see RFC 2080
Definition: ripng-header.h:146
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:177
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: ripng.h:427
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
Definition: ripng.cc:293
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition: ripng.cc:403
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
Definition: ripng.cc:465
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: ripng.cc:1193
Time m_startupDelay
Random delay before protocol startup.
Definition: ripng.h:409
void DoDispose() override
Dispose this object.
Definition: ripng.cc:574
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: ripng.h:292
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: ripng.h:437
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:223
@ SPLIT_HORIZON
Split Horizon.
Definition: ripng.h:225
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: ripng.h:226
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: ripng.h:224
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) override
Route an input packet (to be forwarded or locally delivered)
Definition: ripng.cc:233
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: ripng.h:430
~RipNg() override
Definition: ripng.cc:56
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition: ripng.cc:429
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: ripng.h:410
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: ripng.cc:1335
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
Definition: ripng.cc:199
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: ripng.h:421
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: ripng.h:429
uint8_t m_linkDown
Link down value.
Definition: ripng.h:440
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: ripng.h:411
void DoInitialize() override
Start protocol operation.
Definition: ripng.cc:126
bool m_initialized
flag to allow socket's late-creation.
Definition: ripng.h:439
void RecvUnicastRipng(Ptr< Socket > socket)
Receive and process unicast packet.
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: ripng.h:423
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition: ripng.h:426
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: ripng.cc:1343
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: ripng.h:412
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: ripng.h:434
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: ripng.cc:1356
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: ripng.cc:117
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition: ripng.cc:754
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition: ripng.cc:694
void RecvMulticastRipng(Ptr< Socket > socket)
Receive and process multicast packet.
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: ripng.h:414
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: ripng.h:435
RipNg()
Definition: ripng.cc:48
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: ripng.cc:1367
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
Definition: ripng.cc:371
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: ripng.h:419
std::list< std::pair< RipNgRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipNgRoutingTableEntry *, EventId (update event)
Definition: ripng.h:289
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition: ripng.h:408
Routes m_routes
the forwarding table for network.
Definition: ripng.h:407
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: ripng.cc:1329
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: ripng.cc:1280
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition: ripng.cc:825
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: ripng.h:432
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition: ripng.cc:1005
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
Definition: ripng.cc:476
static TypeId GetTypeId()
Get the type ID.
Definition: ripng.cc:61
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition: ripng.cc:730
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: ripng.h:295
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition: ripng.cc:487
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition: ripng.cc:771
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: ripng.cc:1401
Time m_timeoutDelay
Delay before invalidating a route.
Definition: ripng.h:413
void SendUnsolicitedRouteUpdate()
Send Unsolicited Routing Updates on all interfaces.
Definition: ripng.cc:1312
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Definition: ripng.cc:509
Ptr< Ipv6Route > Lookup(Ipv6Address dest, bool setSource, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
Definition: ripng.cc:604
RipNg Routing Table Entry.
Definition: ripng.h:64
bool IsRouteChanged() const
Get the route changed status.
Definition: ripng.cc:1512
RipNgRoutingTableEntry()
Definition: ripng.cc:1416
uint16_t GetRouteTag() const
Get the route tag.
Definition: ripng.cc:1468
bool m_changed
route has been updated
Definition: ripng.h:159
uint16_t m_tag
route tag
Definition: ripng.h:156
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: ripng.cc:1458
uint8_t GetRouteMetric() const
Get the route metric.
Definition: ripng.cc:1484
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: ripng.cc:1474
uint8_t m_metric
route metric
Definition: ripng.h:157
Status_e m_status
route status
Definition: ripng.h:158
Status_e GetRouteStatus() const
Get the route status.
Definition: ripng.cc:1500
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: ripng.cc:1506
~RipNgRoutingTableEntry() override
Definition: ripng.cc:1453
Status_e
Route status.
Definition: ripng.h:70
@ RIPNG_INVALID
Definition: ripng.h:72
@ RIPNG_VALID
Definition: ripng.h:71
void SetRouteStatus(Status_e status)
Set the route status.
Definition: ripng.cc:1490
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
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:129