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