A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-interface.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
9#ifndef IPV6_INTERFACE_H
10#define IPV6_INTERFACE_H
11
13
14#include "ns3/object.h"
15#include "ns3/ptr.h"
16
17#include <list>
18
19namespace ns3
20{
21
22class NetDevice;
23class Packet;
24class Node;
25class NdiscCache;
26class Ipv6InterfaceAddress;
27class Ipv6Address;
28class Ipv6Header;
29class TrafficControlLayer;
30
31/**
32 * \ingroup ipv6
33 *
34 * \brief The IPv6 representation of a network interface.
35 *
36 * By default IPv6 interfaces are created in the "down" state
37 * with IP "fe80::1" and a /64 prefix. Before becoming usable,
38 * the user must invoke SetUp on them once the final IPv6 address
39 * and mask has been set.
40 */
41class Ipv6Interface : public Object
42{
43 public:
44 /**
45 * \brief Get the type ID
46 * \return type ID
47 */
48 static TypeId GetTypeId();
49
50 /**
51 * \brief Constructs an Ipv6Interface.
52 */
54
55 /**
56 * \brief Destructor.
57 */
58 ~Ipv6Interface() override;
59
60 // Delete copy constructor and assignment operator to avoid misuse
61 Ipv6Interface(const Ipv6Interface&) = delete;
63
64 /**
65 * \brief Set node associated with interface.
66 * \param node node
67 */
68 void SetNode(Ptr<Node> node);
69
70 /**
71 * \brief Set the NetDevice.
72 * \param device NetDevice
73 */
74 void SetDevice(Ptr<NetDevice> device);
75
76 /**
77 * \brief Set the TrafficControlLayer.
78 * \param tc TrafficControlLayer object
79 */
81
82 /**
83 * \brief Get the NetDevice.
84 * \return the NetDevice associated with this interface
85 */
86 virtual Ptr<NetDevice> GetDevice() const;
87
88 /**
89 * \brief Set the metric.
90 * \param metric configured routing metric (cost) of this interface
91 */
92 void SetMetric(uint16_t metric);
93
94 /**
95 * \brief Get the metric
96 * \return the metric
97 */
98 uint16_t GetMetric() const;
99
100 /**
101 * \brief Is the interface UP ?
102 * \return true if interface is enabled, false otherwise.
103 */
104 bool IsUp() const;
105
106 /**
107 * \brief Is the interface DOWN ?
108 * \return true if interface is disabled, false otherwise.
109 */
110 bool IsDown() const;
111
112 /**
113 * \brief Enable this interface.
114 */
115 void SetUp();
116
117 /**
118 * \brief Disable this interface.
119 */
120 void SetDown();
121
122 /**
123 * \brief If the interface allows forwarding packets.
124 * \return true if forwarding is enabled, false otherwise
125 */
126 bool IsForwarding() const;
127
128 /**
129 * \brief Set forwarding enabled or not.
130 * \param forward forwarding state
131 */
132 void SetForwarding(bool forward);
133
134 /**
135 * \brief Set the current hop limit.
136 * \param curHopLimit the value to set
137 */
138 void SetCurHopLimit(uint8_t curHopLimit);
139
140 /**
141 * \brief Get the current hop limit value.
142 * \return current hop limit
143 */
144 uint8_t GetCurHopLimit() const;
145
146 /**
147 * \brief Set the base reachable time.
148 * \param baseReachableTime the value to set
149 */
150 void SetBaseReachableTime(uint16_t baseReachableTime);
151
152 /**
153 * \brief Get the base reachable time.
154 * \return base reachable time
155 */
156 uint16_t GetBaseReachableTime() const;
157
158 /**
159 * \brief Set the reachable time.
160 * \param reachableTime value to set
161 */
162 void SetReachableTime(uint16_t reachableTime);
163
164 /**
165 * \brief Get the reachable time.
166 * \return reachable time
167 */
168 uint16_t GetReachableTime() const;
169
170 /**
171 * \brief Set the retransmission timer.
172 * \param retransTimer value to set
173 */
174 void SetRetransTimer(uint16_t retransTimer);
175
176 /**
177 * \brief Get the retransmission timer.
178 * \return retransmission timer
179 */
180 uint16_t GetRetransTimer() const;
181
182 /**
183 * \brief Send a packet through this interface.
184 * \param p packet to send
185 * \param hdr IPv6 header
186 * \param dest next hop address of packet.
187 *
188 * \note This method will eventually call the private SendTo
189 * method which must be implemented by subclasses.
190 */
191 void Send(Ptr<Packet> p, const Ipv6Header& hdr, Ipv6Address dest);
192
193 /**
194 * \brief Add an IPv6 address.
195 * \param iface address to add
196 * \return true if address was added, false otherwise
197 */
199
200 /**
201 * \brief Get link-local address from IPv6 interface.
202 * \return link-local Ipv6InterfaceAddress, assert if not found
203 */
205
206 /**
207 * \brief Checks if the address is a Solicited Multicast address for this interface.
208 * \param address the address to check.
209 * \return true if it is a solicited multicast address.
210 */
211 bool IsSolicitedMulticastAddress(Ipv6Address address) const;
212
213 /**
214 * \brief Get an address from IPv6 interface.
215 * \param index index
216 * \return Ipv6InterfaceAddress address whose index is i
217 */
219
220 /**
221 * \brief Get an address which is in the same network prefix as destination.
222 * \param dst destination address
223 * \return Corresponding Ipv6InterfaceAddress or assert if not found
224 */
226
227 /**
228 * \brief Get number of addresses on this IPv6 interface.
229 * \return number of address
230 */
231 uint32_t GetNAddresses() const;
232
233 /**
234 * \brief Remove an address from interface.
235 * \param index index to remove
236 * \return Ipv6InterfaceAddress address whose index is index
237 */
239
240 /**
241 * \brief Remove the given Ipv6 address from the interface.
242 * \param address The Ipv6 address to remove
243 * \returns The removed Ipv6 interface address
244 * \returns The null interface address if the interface did not contain the
245 * address or if loopback address was passed as argument
246 */
248
249 /**
250 * \brief Update state of an interface address.
251 * \param address IPv6 address
252 * \param state new state
253 */
255
256 /**
257 * \brief Update NS DAD packet UID of an interface address.
258 * \param address IPv6 address
259 * \param uid packet UID
260 */
261 void SetNsDadUid(Ipv6Address address, uint32_t uid);
262
263 /**
264 * \return NDISC cache used by this interface
265 */
267
268 /**
269 * This callback is set when an address is removed from an interface with
270 * auto-generated Ndisc cache and it allow the neighbor cache helper to update
271 * neighbor's Ndisc cache
272 *
273 * \param removeAddressCallback Callback when remove an address.
274 */
276 Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress> removeAddressCallback);
277
278 /**
279 * This callback is set when an address is added from an interface with
280 * auto-generated Ndisc cache and it allow the neighbor cache helper to update
281 * neighbor's Ndisc cache
282 *
283 * \param addAddressCallback Callback when remove an address.
284 */
286 Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress> addAddressCallback);
287
288 protected:
289 /**
290 * \brief Dispose this object.
291 */
292 void DoDispose() override;
293
294 private:
295 /**
296 * \brief Container for the Ipv6InterfaceAddresses.
297 */
298 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>> Ipv6InterfaceAddressList;
299
300 /**
301 * \brief Container Iterator for the Ipv6InterfaceAddresses.
302 */
303 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>>::iterator
305
306 /**
307 * \brief Const Container Iterator for the Ipv6InterfaceAddresses.
308 */
309 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>>::const_iterator
311
312 /**
313 * \brief Initialize interface.
314 */
315 void DoSetup();
316
317 /**
318 * \brief The addresses assigned to this interface.
319 */
321
322 /**
323 * \brief The link-local addresses assigned to this interface.
324 */
326
327 /**
328 * \brief The state of this interface.
329 */
330 bool m_ifup;
331
332 /**
333 * \brief Forwarding state.
334 */
336
337 /**
338 * \brief The metric.
339 */
340 uint16_t m_metric;
341
342 /**
343 * \brief Node associated with this interface.
344 */
346
347 /**
348 * \brief NetDevice associated with this interface.
349 */
351
352 /**
353 * \brief TrafficControlLayer associated with this interface.
354 */
356
357 /**
358 * \brief Neighbor cache.
359 */
361
362 /**
363 * \brief Current hop limit.
364 */
366
367 /**
368 * \brief Base value used for computing the random reachable time value (in millisecond).
369 */
371
372 /**
373 * \brief Reachable time (in millisecond).
374 * The time a neighbor is considered reachable after receiving a reachability confirmation.
375 */
377
378 /**
379 * \brief Retransmission timer (in millisecond).
380 * Time between retransmission of NS.
381 */
383
385 m_removeAddressCallback; //!< remove address callback
386
388 m_addAddressCallback; //!< add address callback
389};
390
391} /* namespace ns3 */
392
393#endif /* IPV6_INTERFACE_H */
Callback template class.
Definition callback.h:422
Describes an IPv6 address.
Packet header for IPv6.
Definition ipv6-header.h:24
IPv6 address associated with an interface.
State_e
State of an address associated with an interface.
The IPv6 representation of a network interface.
Ipv6InterfaceAddress RemoveAddress(uint32_t index)
Remove an address from interface.
uint16_t GetBaseReachableTime() const
Get the base reachable time.
uint8_t m_curHopLimit
Current hop limit.
Ptr< NetDevice > m_device
NetDevice associated with this interface.
bool IsDown() const
Is the interface DOWN ?
Ptr< NdiscCache > m_ndCache
Neighbor cache.
Ipv6InterfaceAddress GetLinkLocalAddress() const
Get link-local address from IPv6 interface.
bool m_ifup
The state of this interface.
uint8_t GetCurHopLimit() const
Get the current hop limit value.
static TypeId GetTypeId()
Get the type ID.
Ipv6Interface(const Ipv6Interface &)=delete
Ipv6Interface()
Constructs an Ipv6Interface.
void SetRetransTimer(uint16_t retransTimer)
Set the retransmission timer.
void DoSetup()
Initialize interface.
void SetForwarding(bool forward)
Set forwarding enabled or not.
void SetReachableTime(uint16_t reachableTime)
Set the reachable time.
Ipv6InterfaceAddress GetAddressMatchingDestination(Ipv6Address dst)
Get an address which is in the same network prefix as destination.
void SetNode(Ptr< Node > node)
Set node associated with interface.
void SetDown()
Disable this interface.
bool IsForwarding() const
If the interface allows forwarding packets.
void RemoveAddressCallback(Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > removeAddressCallback)
This callback is set when an address is removed from an interface with auto-generated Ndisc cache and...
uint16_t GetReachableTime() const
Get the reachable time.
bool IsUp() const
Is the interface UP ?
bool m_forwarding
Forwarding state.
uint16_t m_metric
The metric.
uint16_t m_reachableTime
Reachable time (in millisecond).
uint32_t GetNAddresses() const
Get number of addresses on this IPv6 interface.
void DoDispose() override
Dispose this object.
Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > m_removeAddressCallback
remove address callback
bool IsSolicitedMulticastAddress(Ipv6Address address) const
Checks if the address is a Solicited Multicast address for this interface.
void SetCurHopLimit(uint8_t curHopLimit)
Set the current hop limit.
Ipv6InterfaceAddress GetAddress(uint32_t index) const
Get an address from IPv6 interface.
std::list< std::pair< Ipv6InterfaceAddress, Ipv6Address > > Ipv6InterfaceAddressList
Container for the Ipv6InterfaceAddresses.
~Ipv6Interface() override
Destructor.
bool AddAddress(Ipv6InterfaceAddress iface)
Add an IPv6 address.
std::list< std::pair< Ipv6InterfaceAddress, Ipv6Address > >::iterator Ipv6InterfaceAddressListI
Container Iterator for the Ipv6InterfaceAddresses.
void SetUp()
Enable this interface.
void SetNsDadUid(Ipv6Address address, uint32_t uid)
Update NS DAD packet UID of an interface address.
uint16_t m_retransTimer
Retransmission timer (in millisecond).
void Send(Ptr< Packet > p, const Ipv6Header &hdr, Ipv6Address dest)
Send a packet through this interface.
Ipv6InterfaceAddressList m_addresses
The addresses assigned to this interface.
uint16_t GetRetransTimer() const
Get the retransmission timer.
uint16_t GetMetric() const
Get the metric.
void SetBaseReachableTime(uint16_t baseReachableTime)
Set the base reachable time.
Ptr< NdiscCache > GetNdiscCache() const
Ipv6InterfaceAddress m_linkLocalAddress
The link-local addresses assigned to this interface.
Ptr< Node > m_node
Node associated with this interface.
Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > m_addAddressCallback
add address callback
void SetTrafficControl(Ptr< TrafficControlLayer > tc)
Set the TrafficControlLayer.
void SetMetric(uint16_t metric)
Set the metric.
uint16_t m_baseReachableTime
Base value used for computing the random reachable time value (in millisecond).
Ptr< TrafficControlLayer > m_tc
TrafficControlLayer associated with this interface.
std::list< std::pair< Ipv6InterfaceAddress, Ipv6Address > >::const_iterator Ipv6InterfaceAddressListCI
Const Container Iterator for the Ipv6InterfaceAddresses.
void AddAddressCallback(Callback< void, Ptr< Ipv6Interface >, Ipv6InterfaceAddress > addAddressCallback)
This callback is set when an address is added from an interface with auto-generated Ndisc cache and i...
Ipv6Interface & operator=(const Ipv6Interface &)=delete
void SetDevice(Ptr< NetDevice > device)
Set the NetDevice.
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
void SetState(Ipv6Address address, Ipv6InterfaceAddress::State_e state)
Update state of an interface address.
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.