A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-routing-protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7/* taken from src/node/ipv4-routing-protocol.h and adapted to IPv6 */
8
9#ifndef IPV6_ROUTING_PROTOCOL_H
10#define IPV6_ROUTING_PROTOCOL_H
11
12#include "ipv6-header.h"
14#include "ipv6.h"
15
16#include "ns3/callback.h"
17#include "ns3/nstime.h"
18#include "ns3/object.h"
19#include "ns3/output-stream-wrapper.h"
20#include "ns3/packet.h"
21#include "ns3/socket.h"
22
23namespace ns3
24{
25
26class Ipv6MulticastRoute;
27class Ipv6Route;
28class NetDevice;
29
30/**
31 * \ingroup internet
32 * \defgroup ipv6Routing IPv6 Routing Protocols.
33 *
34 * The classes in this group implement different routing protocols
35 * for IPv6. Other modules could implement further protocols.
36 */
37
38/**
39 * \ingroup ipv6Routing
40 * \brief Abstract base class for IPv6 routing protocols.
41 *
42 * Defines two virtual functions for packet routing and forwarding. The first,
43 * RouteOutput (), is used for locally originated packets, and the second,
44 * RouteInput (), is used for forwarding and/or delivering received packets.
45 * Also defines the signatures of four callbacks used in RouteInput ().
46 */
47
49{
50 public:
51 /**
52 * \brief Get the type ID.
53 * \return the object TypeId
54 */
55 static TypeId GetTypeId();
56
57 /// Callback for unicast packets to be forwarded
58 typedef Callback<void,
62 const Ipv6Header&>
64
65 /// Callback for multicast packets to be forwarded
66 typedef Callback<void,
70 const Ipv6Header&>
72
73 /// Callback for packets to be locally delivered
75
76 /// Callback for routing errors (e.g., no route found)
78
79 /**
80 * \brief Query routing cache for an existing route, for an outbound packet
81 *
82 * This lookup is used by transport protocols. It does not cause any
83 * packet to be forwarded, and is synchronous. Can be used for
84 * multicast or unicast. The Linux equivalent is ip_route_output ()
85 *
86 * \param p packet to be routed. Note that this method may modify the packet.
87 * Callers may also pass in a null pointer.
88 * \param header input parameter (used to form key to search for the route)
89 * \param oif Output interface device. May be zero, or may be bound via
90 * socket options to a particular output interface.
91 * \param sockerr Output parameter; socket errno
92 *
93 * \returns a code that indicates what happened in the lookup
94 */
96 const Ipv6Header& header,
98 Socket::SocketErrno& sockerr) = 0;
99
100 /**
101 * \brief Route an input packet (to be forwarded or locally delivered)
102 *
103 * This lookup is used in the forwarding process. The packet is
104 * handed over to the Ipv6RoutingProtocol, and will get forwarded onward
105 * by one of the callbacks. The Linux equivalent is ip_route_input ().
106 * There are four valid outcomes, and a matching callbacks to handle each.
107 *
108 * \param p received packet
109 * \param header input parameter used to form a search key for a route
110 * \param idev Pointer to ingress network device
111 * \param ucb Callback for the case in which the packet is to be forwarded
112 * as unicast
113 * \param mcb Callback for the case in which the packet is to be forwarded
114 * as multicast
115 * \param lcb Callback for the case in which the packet is to be locally
116 * delivered
117 * \param ecb Callback to call if there is an error in forwarding
118 * \returns true if the Ipv6RoutingProtocol takes responsibility for
119 * forwarding or delivering the packet, false otherwise
120 */
122 const Ipv6Header& header,
124 const UnicastForwardCallback& ucb,
125 const MulticastForwardCallback& mcb,
126 const LocalDeliverCallback& lcb,
127 const ErrorCallback& ecb) = 0;
128
129 /**
130 * \brief Notify when specified interface goes UP.
131 *
132 * Protocols are expected to implement this method to be notified of the state change of
133 * an interface in a node.
134 * \param interface the index of the interface we are being notified about
135 */
136 virtual void NotifyInterfaceUp(uint32_t interface) = 0;
137
138 /**
139 * \brief Notify when specified interface goes DOWN.
140 *
141 * Protocols are expected to implement this method to be notified of the state change of
142 * an interface in a node.
143 * \param interface the index of the interface we are being notified about
144 */
145 virtual void NotifyInterfaceDown(uint32_t interface) = 0;
146
147 /**
148 * \brief Notify when specified interface add an address.
149 *
150 * Protocols are expected to implement this method to be notified whenever
151 * a new address is added to an interface. Typically used to add a 'network route' on an
152 * interface. Can be invoked on an up or down interface.
153 * \param interface the index of the interface we are being notified about
154 * \param address a new address being added to an interface
155 */
156 virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) = 0;
157
158 /**
159 * \brief Notify when specified interface add an address.
160 *
161 * Protocols are expected to implement this method to be notified whenever
162 * a new address is removed from an interface. Typically used to remove the 'network route' of
163 * an interface. Can be invoked on an up or down interface.
164 * \param interface the index of the interface we are being notified about
165 * \param address a new address being added to an interface
166 */
167 virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) = 0;
168
169 /**
170 * \brief Notify a new route.
171 *
172 * Typically this is used to add another route from IPv6 stack (i.e. ICMPv6
173 * redirect case, ...).
174 * \param dst destination address
175 * \param mask destination mask
176 * \param nextHop nextHop for this destination
177 * \param interface output interface
178 * \param prefixToUse prefix to use as source with this route
179 */
180 virtual void NotifyAddRoute(Ipv6Address dst,
181 Ipv6Prefix mask,
182 Ipv6Address nextHop,
183 uint32_t interface,
184 Ipv6Address prefixToUse = Ipv6Address::GetZero()) = 0;
185
186 /**
187 * \brief Notify route removing.
188 * \param dst destination address
189 * \param mask destination mask
190 * \param nextHop nextHop for this destination
191 * \param interface output interface
192 * \param prefixToUse prefix to use as source with this route
193 */
195 Ipv6Prefix mask,
196 Ipv6Address nextHop,
197 uint32_t interface,
198 Ipv6Address prefixToUse = Ipv6Address::GetZero()) = 0;
199
200 /**
201 * \brief Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol
202 * \param ipv6 the ipv6 object this routing protocol is being associated with
203 */
204 virtual void SetIpv6(Ptr<Ipv6> ipv6) = 0;
205
206 /**
207 * \brief Print the Routing Table entries
208 *
209 * \param stream The ostream the Routing table is printed to
210 * \param unit The time unit to be used in the report
211 */
213 Time::Unit unit = Time::S) const = 0;
214};
215
216} // namespace ns3
217
218#endif /* IPV6_ROUTING_PROTOCOL_H */
Callback template class.
Definition callback.h:422
Describes an IPv6 address.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Packet header for IPv6.
Definition ipv6-header.h:24
IPv6 address associated with an interface.
Describes an IPv6 prefix.
Abstract base class for IPv6 routing protocols.
virtual void NotifyInterfaceUp(uint32_t interface)=0
Notify when specified interface goes UP.
virtual Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)=0
Query routing cache for an existing route, for an outbound packet.
static TypeId GetTypeId()
Get the type ID.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const =0
Print the Routing Table entries.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb)=0
Route an input packet (to be forwarded or locally delivered)
Callback< void, Ptr< const Packet >, const Ipv6Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found)
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6MulticastRoute >, Ptr< const Packet >, const Ipv6Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Notify when specified interface add an address.
Callback< void, Ptr< const Packet >, const Ipv6Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
virtual void NotifyInterfaceDown(uint32_t interface)=0
Notify when specified interface goes DOWN.
virtual void SetIpv6(Ptr< Ipv6 > ipv6)=0
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6Route >, Ptr< const Packet >, const Ipv6Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
virtual void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())=0
Notify a new route.
virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Notify when specified interface add an address.
virtual void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())=0
Notify route removing.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.