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#include "ns3/traced-callback.h"
17
18#include <list>
19
20namespace ns3
21{
22
23class NetDevice;
24class Packet;
25class Node;
26class NdiscCache;
27class Ipv6InterfaceAddress;
28class Ipv6Address;
29class Ipv6Header;
30class TrafficControlLayer;
31
32/**
33 * @ingroup ipv6
34 *
35 * @brief The IPv6 representation of a network interface.
36 *
37 * By default IPv6 interfaces are created in the "down" state
38 * with IP "fe80::1" and a /64 prefix. Before becoming usable,
39 * the user must invoke SetUp on them once the final IPv6 address
40 * and mask has been set.
41 */
42class Ipv6Interface : public Object
43{
44 public:
45 /**
46 * @brief Get the type ID
47 * @return type ID
48 */
49 static TypeId GetTypeId();
50
51 /**
52 * @brief Constructs an Ipv6Interface.
53 */
55
56 /**
57 * @brief Destructor.
58 */
59 ~Ipv6Interface() override;
60
61 // Delete copy constructor and assignment operator to avoid misuse
62 Ipv6Interface(const Ipv6Interface&) = delete;
64
65 /**
66 * @brief Set node associated with interface.
67 * @param node node
68 */
69 void SetNode(Ptr<Node> node);
70
71 /**
72 * @brief Set the NetDevice.
73 * @param device NetDevice
74 */
75 void SetDevice(Ptr<NetDevice> device);
76
77 /**
78 * @brief Set the TrafficControlLayer.
79 * @param tc TrafficControlLayer object
80 */
82
83 /**
84 * @brief Get the NetDevice.
85 * @return the NetDevice associated with this interface
86 */
87 virtual Ptr<NetDevice> GetDevice() const;
88
89 /**
90 * @brief Set the metric.
91 * @param metric configured routing metric (cost) of this interface
92 */
93 void SetMetric(uint16_t metric);
94
95 /**
96 * @brief Get the metric
97 * @return the metric
98 */
99 uint16_t GetMetric() const;
100
101 /**
102 * @brief Is the interface UP ?
103 * @return true if interface is enabled, false otherwise.
104 */
105 bool IsUp() const;
106
107 /**
108 * @brief Is the interface DOWN ?
109 * @return true if interface is disabled, false otherwise.
110 */
111 bool IsDown() const;
112
113 /**
114 * @brief Enable this interface.
115 */
116 void SetUp();
117
118 /**
119 * @brief Disable this interface.
120 */
121 void SetDown();
122
123 /**
124 * @brief If the interface allows forwarding packets.
125 * @return true if forwarding is enabled, false otherwise
126 */
127 bool IsForwarding() const;
128
129 /**
130 * @brief Set forwarding enabled or not.
131 * @param forward forwarding state
132 */
133 void SetForwarding(bool forward);
134
135 /**
136 * @brief Set the current hop limit.
137 * @param curHopLimit the value to set
138 */
139 void SetCurHopLimit(uint8_t curHopLimit);
140
141 /**
142 * @brief Get the current hop limit value.
143 * @return current hop limit
144 */
145 uint8_t GetCurHopLimit() const;
146
147 /**
148 * @brief Set the base reachable time.
149 * @param baseReachableTime the value to set
150 */
151 void SetBaseReachableTime(uint16_t baseReachableTime);
152
153 /**
154 * @brief Get the base reachable time.
155 * @return base reachable time
156 */
157 uint16_t GetBaseReachableTime() const;
158
159 /**
160 * @brief Set the reachable time.
161 * @param reachableTime value to set
162 */
163 void SetReachableTime(uint16_t reachableTime);
164
165 /**
166 * @brief Get the reachable time.
167 * @return reachable time
168 */
169 uint16_t GetReachableTime() const;
170
171 /**
172 * @brief Set the retransmission timer.
173 * @param retransTimer value to set
174 */
175 void SetRetransTimer(uint16_t retransTimer);
176
177 /**
178 * @brief Get the retransmission timer.
179 * @return retransmission timer
180 */
181 uint16_t GetRetransTimer() const;
182
183 /**
184 * @brief Send a packet through this interface.
185 * @param p packet to send
186 * @param hdr IPv6 header
187 * @param dest next hop address of packet.
188 *
189 * @note This method will eventually call the private SendTo
190 * method which must be implemented by subclasses.
191 */
192 void Send(Ptr<Packet> p, const Ipv6Header& hdr, Ipv6Address dest);
193
194 /**
195 * @brief Add an IPv6 address.
196 * @param iface address to add
197 * @return true if address was added, false otherwise
198 */
200
201 /**
202 * @brief Get link-local address from IPv6 interface.
203 * @return link-local Ipv6InterfaceAddress, assert if not found
204 */
206
207 /**
208 * @brief Checks if the address is a Solicited Multicast address for this interface.
209 * @param address the address to check.
210 * @return true if it is a solicited multicast address.
211 */
212 bool IsSolicitedMulticastAddress(Ipv6Address address) const;
213
214 /**
215 * @brief Get an address from IPv6 interface.
216 * @param index index
217 * @return Ipv6InterfaceAddress address whose index is i
218 */
220
221 /**
222 * @brief Get an address which is in the same network prefix as destination.
223 * @param dst destination address
224 * @return Corresponding Ipv6InterfaceAddress or assert if not found
225 */
227
228 /**
229 * @brief Get number of addresses on this IPv6 interface.
230 * @return number of address
231 */
232 uint32_t GetNAddresses() const;
233
234 /**
235 * @brief Remove an address from interface.
236 * @param index index to remove
237 * @return Ipv6InterfaceAddress address whose index is index
238 */
240
241 /**
242 * @brief Remove the given Ipv6 address from the interface.
243 * @param address The Ipv6 address to remove
244 * @returns The removed Ipv6 interface address
245 * @returns The null interface address if the interface did not contain the
246 * address or if loopback address was passed as argument
247 */
249
250 /**
251 * @brief Update state of an interface address.
252 * @param address IPv6 address
253 * @param state new state
254 */
256
257 /**
258 * @brief Update NS DAD packet UID of an interface address.
259 * @param address IPv6 address
260 * @param uid packet UID
261 */
262 void SetNsDadUid(Ipv6Address address, uint32_t uid);
263
264 /**
265 * @return NDISC cache used by this interface
266 */
268
269 /**
270 * This callback is set when an address is removed from an interface with
271 * auto-generated Ndisc cache and it allow the neighbor cache helper to update
272 * neighbor's Ndisc cache
273 *
274 * @param removeAddressCallback Callback when remove an address.
275 */
277 Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress> removeAddressCallback);
278
279 /**
280 * This callback is set when an address is added from an interface with
281 * auto-generated Ndisc cache and it allow the neighbor cache helper to update
282 * neighbor's Ndisc cache
283 *
284 * @param addAddressCallback Callback when remove an address.
285 */
287 Callback<void, Ptr<Ipv6Interface>, Ipv6InterfaceAddress> addAddressCallback);
288
289 protected:
290 /**
291 * @brief Dispose this object.
292 */
293 void DoDispose() override;
294
295 private:
296 /**
297 * @brief Container for the Ipv6InterfaceAddresses.
298 */
299 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>> Ipv6InterfaceAddressList;
300
301 /**
302 * @brief Container Iterator for the Ipv6InterfaceAddresses.
303 */
304 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>>::iterator
306
307 /**
308 * @brief Const Container Iterator for the Ipv6InterfaceAddresses.
309 */
310 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address>>::const_iterator
312
313 /**
314 * @brief Initialize interface.
315 */
316 void DoSetup();
317
318 /**
319 * @brief The addresses assigned to this interface.
320 */
322
323 /**
324 * @brief The link-local addresses assigned to this interface.
325 */
327
328 /**
329 * @brief The state of this interface.
330 */
331 bool m_ifup;
332
333 /**
334 * @brief Forwarding state.
335 */
337
338 /**
339 * @brief The metric.
340 */
341 uint16_t m_metric;
342
343 /**
344 * @brief Node associated with this interface.
345 */
347
348 /**
349 * @brief NetDevice associated with this interface.
350 */
352
353 /**
354 * @brief TrafficControlLayer associated with this interface.
355 */
357
358 /**
359 * @brief Neighbor cache.
360 */
362
363 /**
364 * @brief Current hop limit.
365 */
367
368 /**
369 * @brief Base value used for computing the random reachable time value (in millisecond).
370 */
372
373 /**
374 * @brief Reachable time (in millisecond).
375 * The time a neighbor is considered reachable after receiving a reachability confirmation.
376 */
378
379 /**
380 * @brief Retransmission timer (in millisecond).
381 * Time between retransmission of NS.
382 */
384
386 m_removeAddressCallback; //!< remove address callback
387
389 m_addAddressCallback; //!< add address callback
390
391 /**
392 * The trace fired when the interface state changes.
393 * Includes state (true if interface is up) and the interface index.
394 */
396};
397
398} /* namespace ns3 */
399
400#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.
ns3::TracedCallback< bool, int32_t > m_interfaceStatus
The trace fired when the interface state changes.
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.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.