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
34namespace ns3 {
35
64{
65public:
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
151private:
152 uint16_t m_tag;
153 uint8_t m_metric;
156};
157
165std::ostream& operator<< (std::ostream& os, RipNgRoutingTableEntry const& route);
166
167
168
175{
176public:
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);
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
260protected:
264 virtual void DoDispose ();
265
269 void DoInitialize ();
270
271private:
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 Ptr<Ipv6Route> Lookup (Ipv6Address dest, bool setSource, Ptr<NetDevice> = 0);
318
329
338 void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse);
339
346 void AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface);
347
352 void DoSendRouteUpdate (bool periodic);
353
357 void SendRouteRequest ();
358
363
367 void SendUnsolicitedRouteUpdate (void);
368
374
380
389
390 // note: we can not trust the result of socket->GetBoundNetDevice ()->GetIfIndex ();
391 // it is dependent on the interface initialization (i.e., if the loopback is already up).
393 typedef std::map< Ptr<Socket>, uint32_t> SocketList;
395 typedef std::map<Ptr<Socket>, uint32_t>::iterator SocketListI;
397 typedef std::map<Ptr<Socket>, uint32_t>::const_iterator SocketListCI;
398
401
404
406
407 std::set<uint32_t> m_interfaceExclusions;
408 std::map<uint32_t, uint8_t> m_interfaceMetrics;
409
411
413 uint8_t m_linkDown;
414};
415
416} // namespace ns3
417#endif /* RIPNG_H */
418
Callback template class.
Definition: callback.h:1279
An identifier for simulation events.
Definition: event-id.h:54
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:74
RipNgHeader - see RFC 2080
Definition: ripng-header.h:147
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:175
virtual void DoDispose()
Dispose this object.
Definition: ripng.cc:528
virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:400
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: ripng.h:400
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: ripng.cc:1081
Time m_startupDelay
Random delay before protocol startup.
Definition: ripng.h:383
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::const_iterator RoutesCI
Const Iterator for container for the network routes.
Definition: ripng.h:276
std::list< std::pair< RipNgRoutingTableEntry *, EventId > > Routes
Container for the network routes - pair RipNgRoutingTableEntry *, EventId (update event)
Definition: ripng.h:273
virtual void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
Definition: ripng.cc:344
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: ripng.h:410
SplitHorizonType_e
Split Horizon strategy type.
Definition: ripng.h:207
@ SPLIT_HORIZON
Split Horizon.
Definition: ripng.h:209
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: ripng.h:210
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: ripng.h:208
std::map< Ptr< Socket >, uint32_t > SocketList
Socket list type.
Definition: ripng.h:393
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: ripng.h:403
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: ripng.h:279
static TypeId GetTypeId(void)
Get the type ID.
Definition: ripng.cc:57
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: ripng.h:384
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: ripng.cc:1211
virtual void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
Definition: ripng.cc:437
virtual void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
Definition: ripng.cc:267
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: ripng.h:402
uint8_t m_linkDown
Link down value.
Definition: ripng.h:413
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: ripng.h:385
virtual void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify route removing.
Definition: ripng.cc:443
bool m_initialized
flag to allow socket's late-creation.
Definition: ripng.h:412
void RecvUnicastRipng(Ptr< Socket > socket)
Receive and process unicast packet.
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition: ripng.h:399
std::map< Ptr< Socket >, uint32_t >::iterator SocketListI
Socket list type iterator.
Definition: ripng.h:395
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: ripng.cc:1218
void DoInitialize()
Start protocol operation.
Definition: ripng.cc:109
Ptr< Ipv6Route > Lookup(Ipv6Address dest, bool setSource, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
Definition: ripng.cc:557
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: ripng.h:386
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
Definition: ripng.cc:470
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: ripng.h:407
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: ripng.cc:1230
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: ripng.cc:101
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition: ripng.cc:689
virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Definition: ripng.cc:375
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition: ripng.cc:638
void RecvMulticastRipng(Ptr< Socket > socket)
Receive and process multicast packet.
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: ripng.h:388
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: ripng.h:408
RipNg()
Definition: ripng.cc:46
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: ripng.cc:1240
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition: ripng.h:382
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
virtual void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition: ripng.cc:449
Routes m_routes
the forwarding table for network.
Definition: ripng.h:381
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: ripng.cc:1206
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: ripng.cc:1161
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
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition: ripng.cc:760
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: ripng.h:405
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition: ripng.cc:925
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition: ripng.cc:667
std::map< Ptr< Socket >, uint32_t >::const_iterator SocketListCI
Socket list type const iterator.
Definition: ripng.h:397
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition: ripng.cc:706
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: ripng.cc:1273
Time m_timeoutDelay
Delay before invalidating a route.
Definition: ripng.h:387
void SendUnsolicitedRouteUpdate(void)
Send Unsolicited Routing Updates on all interfaces.
Definition: ripng.cc:1191
virtual ~RipNg()
Definition: ripng.cc:52
RipNg Routing Table Entry.
Definition: ripng.h:64
Status_e GetRouteStatus(void) const
Get the route status.
Definition: ripng.cc:1344
bool m_changed
route has been updated
Definition: ripng.h:155
uint16_t m_tag
route tag
Definition: ripng.h:152
uint8_t GetRouteMetric(void) const
Get the route metric.
Definition: ripng.cc:1330
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: ripng.cc:1307
uint16_t GetRouteTag(void) const
Get the route tag.
Definition: ripng.cc:1316
RipNgRoutingTableEntry(void)
Definition: ripng.cc:1285
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: ripng.cc:1321
uint8_t m_metric
route metric
Definition: ripng.h:153
bool IsRouteChanged(void) const
Get the route changed status.
Definition: ripng.cc:1354
Status_e m_status
route status
Definition: ripng.h:154
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: ripng.cc:1349
Status_e
Route status.
Definition: ripng.h:70
@ RIPNG_INVALID
Definition: ripng.h:72
@ RIPNG_VALID
Definition: ripng.h:71
virtual ~RipNgRoutingTableEntry()
Definition: ripng.cc:1302
void SetRouteStatus(Status_e status)
Set the route status.
Definition: ripng.cc:1335
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ S
second
Definition: nstime.h:114
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:44
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:139