A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20/* taken from src/node/ipv4.h and adapted to IPv6 */
21
22#ifndef IPV6_H
23#define IPV6_H
24
26
27#include "ns3/callback.h"
28#include "ns3/ipv6-address.h"
29#include "ns3/object.h"
30#include "ns3/socket.h"
31
32#include <stdint.h>
33
34namespace ns3
35{
36
37class Node;
38class NetDevice;
39class Packet;
40class Ipv6RoutingProtocol;
41class IpL4Protocol;
42class Ipv6Route;
43
44/**
45 * \ingroup internet
46 * \defgroup ipv6 IPv6 classes and sub-modules
47 */
48
49/**
50 * \ingroup ipv6
51 * \brief Access to the IPv6 forwarding table, interfaces, and configuration
52 *
53 * This class defines the API to manipulate the following aspects of
54 * the IPv6 implementation:
55 * -# set/get an Ipv6RoutingProtocol
56 * -# register a NetDevice for use by the IPv6 layer (basically, to
57 * create IPv6-related state such as addressing and neighbor cache that
58 * is associated with a NetDevice)
59 * -# manipulate the status of the NetDevice from the IPv6 perspective,
60 * such as marking it as Up or Down,
61 * -# adding, deleting, and getting addresses associated to the IPv6
62 * interfaces.
63 * -# exporting IPv6 configuration attributes
64 *
65 * Each NetDevice has conceptually a single IPv6 interface associated
66 * with it (the corresponding structure in the Linux IPv6 implementation
67 * is struct in_device). Each interface may have one or more IPv6
68 * addresses associated with it. Each IPv6 address may have different
69 * subnet mask, scope, etc., so all of this per-address information
70 * is stored in an Ipv6InterfaceAddress class (the corresponding
71 * structure in Linux is struct in6_ifaddr)
72 *
73 * IPv6 attributes such as whether IP forwarding is enabled and disabled
74 * are also stored in this class
75 *
76 * TO DO: Add API to allow access to the IPv6 neighbor table
77 *
78 * \see Ipv6RoutingProtocol
79 * \see Ipv6InterfaceAddress
80 */
81class Ipv6 : public Object
82{
83 public:
84 /**
85 * \brief Get the type ID.
86 * \return the object TypeId
87 */
88 static TypeId GetTypeId();
89
90 /**
91 * \brief Constructor.
92 */
93 Ipv6();
94
95 /**
96 * \brief Destructor.
97 */
98 ~Ipv6() override;
99
100 /**
101 * \brief Register a new routing protocol to be used by this IPv6 stack
102 *
103 * This call will replace any routing protocol that has been previously
104 * registered. If you want to add multiple routing protocols, you must
105 * add them to a Ipv6ListRoutingProtocol directly.
106 *
107 * \param routingProtocol smart pointer to Ipv6RoutingProtocol object
108 */
109 virtual void SetRoutingProtocol(Ptr<Ipv6RoutingProtocol> routingProtocol) = 0;
110
111 /**
112 * \brief Get the routing protocol to be used by this IPv6 stack
113 *
114 * \returns smart pointer to Ipv6RoutingProtocol object, or null pointer if none
115 */
117
118 /**
119 * \brief Add a NetDevice interface.
120 *
121 * Once a device has been added, it can never be removed: if you want
122 * to disable it, you can invoke Ipv6::SetDown which will
123 * make sure that it is never used during packet forwarding.
124 * \param device device to add to the list of IPv6 interfaces
125 * which can be used as output interfaces during packet forwarding.
126 * \returns the index of the IPv6 interface added.
127 */
129
130 /**
131 * \brief Get number of interfaces.
132 * \returns the number of interfaces added by the user.
133 */
134 virtual uint32_t GetNInterfaces() const = 0;
135
136 /**
137 * \brief Return the interface number of the interface that has been
138 * assigned the specified IP address.
139 *
140 * \param address The IP address being searched for
141 * \returns The interface number of the IPv6 interface with the given
142 * address or -1 if not found.
143 *
144 * Each IP interface has one or more IP addresses associated with it.
145 * This method searches the list of interfaces for one that holds a
146 * particular address. This call takes an IP address as a parameter and
147 * returns the interface number of the first interface that has been assigned
148 * that address, or -1 if not found. There must be an exact match.
149 */
150 virtual int32_t GetInterfaceForAddress(Ipv6Address address) const = 0;
151
152 /**
153 * \brief Return the interface number of first interface found that
154 * has an IPv6 address within the prefix specified by the input
155 * address and mask parameters
156 *
157 * \param address The IP address assigned to the interface of interest.
158 * \param mask The IP prefix to use in the mask
159 * \returns The interface number of the IPv6 interface with the given
160 * address or -1 if not found.
161 *
162 * Each IP interface has one or more IP addresses associated with it.
163 * This method searches the list of interfaces for the first one found
164 * that holds an address that is included within the prefix
165 * formed by the input address and mask parameters. The value -1 is
166 * returned if no match is found.
167 */
168 virtual int32_t GetInterfaceForPrefix(Ipv6Address address, Ipv6Prefix mask) const = 0;
169
170 /**
171 * \brief Get the NetDevice of the specified interface number.
172 * \param interface The interface number of an IPv6 interface.
173 * \returns The NetDevice associated with the IPv6 interface number.
174 */
175 virtual Ptr<NetDevice> GetNetDevice(uint32_t interface) = 0;
176
177 /**
178 * \brief Get the interface index of the specified NetDevice.
179 * \param device The NetDevice for an Ipv6Interface
180 * \returns The interface number of an IPv6 interface or -1 if not found.
181 */
183
184 /**
185 * \brief Add an address on the specified IPv6 interface.
186 * \param interface Interface number of an IPv6 interface
187 * \param address Ipv6InterfaceAddress address to associate with the underlying IPv6 interface
188 * \param addOnLinkRoute add on-link route to the network (default true)
189 * \returns true if the operation succeeded
190 */
191 virtual bool AddAddress(uint32_t interface,
192 Ipv6InterfaceAddress address,
193 bool addOnLinkRoute = true) = 0;
194
195 /**
196 * \brief Get number of addresses on specified IPv6 interface.
197 * \param interface Interface number of an IPv6 interface
198 * \returns the number of Ipv6InterfaceAddress entries for the interface.
199 */
200 virtual uint32_t GetNAddresses(uint32_t interface) const = 0;
201
202 /**
203 * \brief Get IPv6 address on specified IPv6 interface.
204 *
205 * Because addresses can be removed, the addressIndex is not guaranteed
206 * to be static across calls to this method.
207 *
208 * \param interface Interface number of an IPv6 interface
209 * \param addressIndex index of Ipv6InterfaceAddress
210 * \returns the Ipv6InterfaceAddress associated to the interface and addressIndex
211 */
212 virtual Ipv6InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const = 0;
213
214 /**
215 * \brief Remove an address on specified IPv6 interface.
216 *
217 * Remove the address at addressIndex on named interface. The addressIndex
218 * for all higher indices will decrement by one after this method is called;
219 * so, for example, to remove 5 addresses from an interface i, one could
220 * call RemoveAddress (i, 0); 5 times.
221 *
222 * \param interface Interface number of an IPv6 interface
223 * \param addressIndex index of Ipv6InterfaceAddress to remove
224 * \returns true if the operation succeeded
225 */
226 virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex) = 0;
227
228 /**
229 * \brief Remove the given address on named Ipv6 interface
230 *
231 * \param interface Interface number of an IPv6 interface
232 * \param address the address to remove
233 * \returns true if the operation succeeded
234 */
235 virtual bool RemoveAddress(uint32_t interface, Ipv6Address address) = 0;
236
237 /**
238 * \brief Set metric on specified Ipv6 interface.
239 *
240 * \param interface The interface number of an IPv6 interface
241 * \param metric routing metric (cost) associated to the underlying
242 * IPv6 interface
243 */
244 virtual void SetMetric(uint32_t interface, uint16_t metric) = 0;
245
246 /**
247 * \brief Get metric for the specified IPv6 interface.
248 *
249 * \param interface The interface number of an IPv6 interface
250 * \returns routing metric (cost) associated to the underlying
251 * IPv6 interface
252 */
253 virtual uint16_t GetMetric(uint32_t interface) const = 0;
254
255 /**
256 * \brief Get MTU for the specified IPv6 interface.
257 * \param interface Interface number of IPv6 interface
258 * \returns the Maximum Transmission Unit (in bytes) associated
259 * to the underlying IPv6 interface
260 */
261 virtual uint16_t GetMtu(uint32_t interface) const = 0;
262
263 /**
264 * \brief Set the Path MTU for the specified IPv6 destination address.
265 * \param dst Ipv6 destination address
266 * \param pmtu the Path MTU
267 */
268 virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu) = 0;
269
270 /**
271 * \brief If the specified interface index is in "up" state.
272 * \param interface Interface number of IPv6 interface
273 * \returns true if the underlying interface is in the "up" state,
274 * false otherwise.
275 */
276 virtual bool IsUp(uint32_t interface) const = 0;
277
278 /**
279 * \brief Set the interface into the "up" state.
280 *
281 * In this state, it is considered valid during IPv6 forwarding.
282 * \param interface Interface number of IPv6 interface
283 */
284 virtual void SetUp(uint32_t interface) = 0;
285
286 /**
287 * \brief Set the interface into the "down" state.
288 *
289 * In this state, it is ignored during IPv6 forwarding.
290 * \param interface Interface number of IPv6 interface
291 */
292 virtual void SetDown(uint32_t interface) = 0;
293
294 /**
295 * \brief If the specified IPv6 interface has forwarding enabled.
296 * \param interface Interface number of IPv6 interface
297 * \returns true if IPv6 forwarding enabled for input datagrams on this device
298 */
299 virtual bool IsForwarding(uint32_t interface) const = 0;
300
301 /**
302 * \brief Set forwarding on specified IPv6 interface.
303 * \param interface Interface number of IPv6 interface
304 * \param val Value to set the forwarding flag
305 *
306 * If set to true, IPv6 forwarding is enabled for input datagrams on this device
307 */
308 virtual void SetForwarding(uint32_t interface, bool val) = 0;
309
310 /**
311 * \brief Choose the source address to use with destination address.
312 * \param interface interface index
313 * \param dest IPv6 destination address
314 * \return IPv6 source address to use
315 */
317
318 /**
319 * \brief Add a L4 protocol.
320 * \param protocol L4 protocol
321 */
322 virtual void Insert(Ptr<IpL4Protocol> protocol) = 0;
323
324 /**
325 * \brief Add a L4 protocol to a specific interface.
326 *
327 * This may be called multiple times for multiple interfaces for the same
328 * protocol. To insert for all interfaces, use the separate
329 * Insert (Ptr<IpL4Protocol> protocol) method.
330 *
331 * Setting a protocol on a specific interface will overwrite the
332 * previously bound protocol.
333 *
334 * \param protocol L4 protocol.
335 * \param interfaceIndex interface index.
336 */
337 virtual void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
338
339 /**
340 * \brief Remove a L4 protocol.
341 * \param protocol L4 protocol to remove.
342 */
343 virtual void Remove(Ptr<IpL4Protocol> protocol) = 0;
344
345 /**
346 * \brief Remove a L4 protocol from a specific interface.
347 * \param protocol L4 protocol to remove.
348 * \param interfaceIndex interface index.
349 */
350 virtual void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) = 0;
351
352 /**
353 * \brief Get L4 protocol by protocol number.
354 * \param protocolNumber protocol number
355 * \return corresponding IpL4Protocol or 0 if not found
356 */
357 virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const = 0;
358
359 /**
360 * \brief Get L4 protocol by protocol number for the specified interface.
361 * \param protocolNumber protocol number
362 * \param interfaceIndex interface index, -1 means "any" interface.
363 * \return corresponding IpL4Protocol or 0 if not found
364 */
365 virtual Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const = 0;
366
367 /**
368 * \brief Higher-level layers call this method to send a packet
369 * down the stack to the MAC and PHY layers. All PMTU values are
370 * stored at this level, so packet size calculations should be
371 * done mathematically at higher levels.
372 *
373 * \param packet packet to send
374 * \param source source address of packet
375 * \param destination address of packet
376 * \param protocol number of packet
377 * \param route route to take
378 */
379 virtual void Send(Ptr<Packet> packet,
380 Ipv6Address source,
381 Ipv6Address destination,
382 uint8_t protocol,
383 Ptr<Ipv6Route> route) = 0;
384
385 /**
386 * \brief Register the IPv6 Extensions. Does nothing if the Extensions have been already
387 * registered.
388 */
389 virtual void RegisterExtensions() = 0;
390
391 /**
392 * \brief Register the IPv6 Options. Does nothing if the Options have been already
393 * registered.
394 */
395 virtual void RegisterOptions() = 0;
396
397 /**
398 * \brief Any interface magic number.
399 */
400 static const uint32_t IF_ANY = 0xffffffff;
401
402 private:
403 // Indirect the IPv6 attributes through private pure virtual methods
404 /**
405 * \brief Set IPv6 forwarding state.
406 * \param forward IPv6 forwarding enabled or not
407 */
408 virtual void SetIpForward(bool forward) = 0;
409
410 /**
411 * \brief Get IPv6 forwarding state.
412 * \return forwarding state (enabled or not)
413 */
414 virtual bool GetIpForward() const = 0;
415
416 /**
417 * \brief Set IPv6 MTU discover state.
418 * \param mtuDiscover IPv6 MTU discover enabled or not
419 */
420 virtual void SetMtuDiscover(bool mtuDiscover) = 0;
421
422 /**
423 * \brief Get IPv6 MTU discover state.
424 * \return MTU discover state (enabled or not)
425 */
426 virtual bool GetMtuDiscover() const = 0;
427
428 /**
429 * \brief Set or unset the Strong End System Model
430 *
431 * RFC1122 term for whether host rejects datagram with a dest. address on another interface
432 * \param model true for Strong End System Model
433 */
434 virtual void SetStrongEndSystemModel(bool model) = 0;
435 /**
436 * \brief Get the Strong End System Model status
437 *
438 * RFC1122 term for whether host rejects datagram with a dest. address on another interface
439 * \returns true for Strong End System Model activated
440 */
441 virtual bool GetStrongEndSystemModel() const = 0;
442};
443
444} // namespace ns3
445
446#endif /* IPV6_H */
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
virtual Ipv6InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Get IPv6 address on specified IPv6 interface.
virtual Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)=0
Choose the source address to use with destination address.
~Ipv6() override
Destructor.
Definition: ipv6.cc:65
virtual void SetIpForward(bool forward)=0
Set IPv6 forwarding state.
static const uint32_t IF_ANY
Any interface magic number.
Definition: ipv6.h:400
virtual bool RemoveAddress(uint32_t interface, Ipv6Address address)=0
Remove the given address on named Ipv6 interface.
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)=0
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers.
virtual uint16_t GetMtu(uint32_t interface) const =0
Get MTU for the specified IPv6 interface.
virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu)=0
Set the Path MTU for the specified IPv6 destination address.
virtual void SetMtuDiscover(bool mtuDiscover)=0
Set IPv6 MTU discover state.
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
static TypeId GetTypeId()
Get the type ID.
Definition: ipv6.cc:34
virtual uint32_t GetNInterfaces() const =0
Get number of interfaces.
virtual bool IsUp(uint32_t interface) const =0
If the specified interface index is in "up" state.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
virtual bool GetIpForward() const =0
Get IPv6 forwarding state.
virtual void RegisterExtensions()=0
Register the IPv6 Extensions.
virtual bool GetStrongEndSystemModel() const =0
Get the Strong End System Model status.
virtual int32_t GetInterfaceForPrefix(Ipv6Address address, Ipv6Prefix mask) const =0
Return the interface number of first interface found that has an IPv6 address within the prefix speci...
virtual uint16_t GetMetric(uint32_t interface) const =0
Get metric for the specified IPv6 interface.
virtual bool IsForwarding(uint32_t interface) const =0
If the specified IPv6 interface has forwarding enabled.
virtual Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const =0
Get the routing protocol to be used by this IPv6 stack.
virtual bool GetMtuDiscover() const =0
Get IPv6 MTU discover state.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber, int32_t interfaceIndex) const =0
Get L4 protocol by protocol number for the specified interface.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
virtual void SetForwarding(uint32_t interface, bool val)=0
Set forwarding on specified IPv6 interface.
virtual void RegisterOptions()=0
Register the IPv6 Options.
virtual int32_t GetInterfaceForAddress(Ipv6Address address) const =0
Return the interface number of the interface that has been assigned the specified IP address.
virtual void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)=0
Register a new routing protocol to be used by this IPv6 stack.
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
Set metric on specified Ipv6 interface.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const =0
Get L4 protocol by protocol number.
virtual void Insert(Ptr< IpL4Protocol > protocol, uint32_t interfaceIndex)=0
Add a L4 protocol to a specific interface.
virtual void Remove(Ptr< IpL4Protocol > protocol)=0
Remove a L4 protocol.
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)=0
Add an address on the specified IPv6 interface.
virtual uint32_t GetNAddresses(uint32_t interface) const =0
Get number of addresses on specified IPv6 interface.
virtual void Remove(Ptr< IpL4Protocol > protocol, uint32_t interfaceIndex)=0
Remove a L4 protocol from a specific interface.
virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex)=0
Remove an address on specified IPv6 interface.
virtual void SetDown(uint32_t interface)=0
Set the interface into the "down" state.
Ipv6()
Constructor.
Definition: ipv6.cc:61
virtual void SetStrongEndSystemModel(bool model)=0
Set or unset the Strong End System Model.
virtual void Insert(Ptr< IpL4Protocol > protocol)=0
Add a L4 protocol.
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
Get the NetDevice of the specified interface number.
IPv6 address associated with an interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
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
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.