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