A Discrete-Event Network Simulator
API
ipv6-static-routing.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18  */
19 
20 #ifndef IPV6_STATIC_ROUTING_H
21 #define IPV6_STATIC_ROUTING_H
22 
23 #include "ns3/ipv6-address.h"
24 #include "ns3/ipv6-header.h"
25 #include "ns3/ipv6-routing-protocol.h"
26 #include "ns3/ipv6.h"
27 #include "ns3/ptr.h"
28 
29 #include <list>
30 #include <stdint.h>
31 
32 namespace ns3
33 {
34 
35 class Packet;
36 class NetDevice;
37 class Ipv6Interface;
38 class Ipv6Route;
39 class Node;
40 class Ipv6RoutingTableEntry;
41 class Ipv6MulticastRoutingTableEntry;
42 
63 {
64  public:
69  static TypeId GetTypeId();
70 
72  ~Ipv6StaticRouting() override;
73 
82  void AddHostRouteTo(Ipv6Address dest,
83  Ipv6Address nextHop,
84  uint32_t interface,
85  Ipv6Address prefixToUse = Ipv6Address("::"),
86  uint32_t metric = 0);
87 
94  void AddHostRouteTo(Ipv6Address dest, uint32_t interface, uint32_t metric = 0);
95 
104  void AddNetworkRouteTo(Ipv6Address network,
105  Ipv6Prefix networkPrefix,
106  Ipv6Address nextHop,
107  uint32_t interface,
108  uint32_t metric = 0);
109 
119  void AddNetworkRouteTo(Ipv6Address network,
120  Ipv6Prefix networkPrefix,
121  Ipv6Address nextHop,
122  uint32_t interface,
123  Ipv6Address prefixToUse,
124  uint32_t metric = 0);
125 
133  void AddNetworkRouteTo(Ipv6Address network,
134  Ipv6Prefix networkPrefix,
135  uint32_t interface,
136  uint32_t metric = 0);
137 
145  void SetDefaultRoute(Ipv6Address nextHop,
146  uint32_t interface,
147  Ipv6Address prefixToUse = Ipv6Address("::"),
148  uint32_t metric = 0);
149 
154  uint32_t GetNRoutes() const;
155 
163 
169  Ipv6RoutingTableEntry GetRoute(uint32_t i) const;
170 
177  uint32_t GetMetric(uint32_t index) const;
178 
183  void RemoveRoute(uint32_t i);
184 
192  void RemoveRoute(Ipv6Address network,
193  Ipv6Prefix prefix,
194  uint32_t ifIndex,
195  Ipv6Address prefixToUse);
196 
205  void AddMulticastRoute(Ipv6Address origin,
206  Ipv6Address group,
207  uint32_t inputInterface,
208  std::vector<uint32_t> outputInterfaces);
209 
214  void SetDefaultMulticastRoute(uint32_t outputInterface);
215 
220  uint32_t GetNMulticastRoutes() const;
221 
228 
236  bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface);
237 
242  void RemoveMulticastRoute(uint32_t i);
243 
250  bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex);
251 
253  const Ipv6Header& header,
254  Ptr<NetDevice> oif,
255  Socket::SocketErrno& sockerr) override;
256 
258  const Ipv6Header& header,
263  ErrorCallback ecb) override;
264 
265  void NotifyInterfaceUp(uint32_t interface) override;
266  void NotifyInterfaceDown(uint32_t interface) override;
267  void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
268  void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override;
269  void NotifyAddRoute(Ipv6Address dst,
270  Ipv6Prefix mask,
271  Ipv6Address nextHop,
272  uint32_t interface,
273  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
275  Ipv6Prefix mask,
276  Ipv6Address nextHop,
277  uint32_t interface,
278  Ipv6Address prefixToUse = Ipv6Address::GetZero()) override;
279  void SetIpv6(Ptr<Ipv6> ipv6) override;
281  Time::Unit unit = Time::S) const override;
282 
283  protected:
287  void DoDispose() override;
288 
289  private:
291  typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>> NetworkRoutes;
292 
294  typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>>::const_iterator NetworkRoutesCI;
295 
297  typedef std::list<std::pair<Ipv6RoutingTableEntry*, uint32_t>>::iterator NetworkRoutesI;
298 
300  typedef std::list<Ipv6MulticastRoutingTableEntry*> MulticastRoutes;
301 
303  typedef std::list<Ipv6MulticastRoutingTableEntry*>::const_iterator MulticastRoutesCI;
304 
306  typedef std::list<Ipv6MulticastRoutingTableEntry*>::iterator MulticastRoutesI;
307 
314  bool LookupRoute(const Ipv6RoutingTableEntry& route, uint32_t metric);
315 
323 
331  Ptr<Ipv6MulticastRoute> LookupStatic(Ipv6Address origin, Ipv6Address group, uint32_t ifIndex);
332 
337 
342 
347 };
348 
349 } /* namespace ns3 */
350 
351 #endif /* IPV6_STATIC_ROUTING_H */
Callback template class.
Definition: callback.h:443
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.
A record of an IPv6 multicast route.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Static routing protocol for IP version 6 stacks.
std::list< Ipv6MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
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)
Ipv6RoutingTableEntry GetRoute(uint32_t i) const
Get a specified route.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
void RemoveRoute(uint32_t i)
Remove a route from the routing table.
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.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
static TypeId GetTypeId()
The interface Id associated with this class.
Ptr< Ipv6Route > LookupStatic(Ipv6Address dest, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex)
If the destination is already present in network destination list.
std::list< Ipv6MulticastRoutingTableEntry * > MulticastRoutes
Container for the multicast routes.
bool LookupRoute(const Ipv6RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
std::list< Ipv6MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
void AddMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route for a given multicast source and group.
void AddHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Add route to host.
uint32_t GetNRoutes() const
Get the number or entries in the routing table.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > > NetworkRoutes
Container for the network routes.
Ipv6MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get the specified multicast route.
Ipv6RoutingTableEntry GetDefaultRoute()
Get the default route.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
uint32_t GetNMulticastRoutes() const
Get the number of entries in the multicast routing table.
bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface)
Remove a static multicast route.
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void DoDispose() override
Dispose this object.
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
NetworkRoutes m_networkRoutes
the forwarding table for network.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Set the default multicast route.
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
std::list< std::pair< Ipv6RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
Ptr< Ipv6 > m_ipv6
Ipv6 reference.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
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.