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