A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-interface-address.cc
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
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13
14#include <iostream>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("Ipv6InterfaceAddress");
20
22 : m_address(Ipv6Address()),
23 m_prefix(Ipv6Prefix()),
24 m_state(TENTATIVE_OPTIMISTIC),
25 m_scope(HOST),
26 m_onLink(true),
27 m_nsDadUid(0)
28{
29 NS_LOG_FUNCTION(this);
30}
31
41
43{
44 NS_LOG_FUNCTION(this << address << prefix);
45 m_prefix = prefix;
46 SetAddress(address);
48 m_onLink = true;
49 m_nsDadUid = 0;
50}
51
53{
54 NS_LOG_FUNCTION(this << address << prefix << onLink);
55 m_prefix = prefix;
56 SetAddress(address);
58 m_onLink = onLink;
59 m_nsDadUid = 0;
60}
61
63 : m_address(o.m_address),
64 m_prefix(o.m_prefix),
65 m_state(o.m_state),
66 m_scope(o.m_scope),
67 m_onLink(o.m_onLink),
68 m_nsDadUid(o.m_nsDadUid)
69{
70}
71
76
79{
80 NS_LOG_FUNCTION(this);
81 return m_address;
82}
83
84void
86{
87 NS_LOG_FUNCTION(this << address);
88 m_address = address;
89
90 if (address.IsLocalhost())
91 {
92 m_scope = HOST;
93 /* localhost address is always /128 prefix */
94 m_prefix = Ipv6Prefix(128);
95 }
96 else if (address.IsLinkLocal())
97 {
99 /* link-local address is always /64 prefix */
100 m_prefix = Ipv6Prefix(64);
101 }
102 else if (address.IsLinkLocalMulticast())
103 {
105 /* link-local multicast address is always /16 prefix */
106 m_prefix = Ipv6Prefix(16);
107 }
108 else
109 {
110 m_scope = GLOBAL;
111 }
112}
113
116{
117 NS_LOG_FUNCTION(this);
118 return m_prefix;
119}
120
121void
127
130{
131 NS_LOG_FUNCTION(this);
132 return m_state;
133}
134
135void
141
144{
145 NS_LOG_FUNCTION(this);
146 return m_scope;
147}
148
149bool
151{
152 NS_LOG_FUNCTION(this);
153
154 Ipv6Address aAddr = m_address;
155 aAddr = aAddr.CombinePrefix(m_prefix);
156 Ipv6Address bAddr = b;
157 bAddr = bAddr.CombinePrefix(m_prefix);
158
159 if (aAddr == bAddr)
160 {
161 return true;
162 }
163
164 if ((bAddr.IsLinkLocalMulticast() && aAddr.IsLinkLocal()) ||
165 (aAddr.IsLinkLocalMulticast() && bAddr.IsLinkLocal()))
166 {
167 return true;
168 }
169
170 return false;
171}
172
173std::ostream&
174operator<<(std::ostream& os, const Ipv6InterfaceAddress& addr)
175{
176 os << "address: " << addr.GetAddress() << addr.GetPrefix() << "; scope: ";
177 switch (addr.GetScope())
178 {
180 os << "HOST";
181 break;
183 os << "LINK-LOCAL";
184 break;
186 os << "GLOBAL";
187 break;
188 default:
189 os << "UNKNOWN";
190 break;
191 }
192 return os;
193}
194
197{
198 NS_LOG_FUNCTION(this);
199 return m_nsDadUid;
200}
201
202void
204{
205 NS_LOG_FUNCTION(this << nsDadUid);
206 m_nsDadUid = nsDadUid;
207}
208
209bool
211{
212 NS_LOG_FUNCTION(this);
213 return m_onLink;
214}
215
216void
218{
219 NS_LOG_FUNCTION(this << onLink);
220 m_onLink = onLink;
221}
222
223#if 0
224void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
225{
226 NS_LOG_FUNCTION (this << interface);
227 m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
228 m_dadTimer.SetArguments (interface, m_address);
229 m_dadTimer.Schedule (Seconds (1));
231}
232
233void Ipv6InterfaceAddress::StopDadTimer ()
234{
235 NS_LOG_FUNCTION (this);
236 m_dadTimer.Cancel ();
237 Simulator::Cancel (m_dadId);
238}
239#endif
240
241} /* namespace ns3 */
virtual void FunctionDadTimeout(Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
IPv6 address associated with an interface.
void SetScope(Ipv6InterfaceAddress::Scope_e scope)
Set the scope.
Ipv6Address m_address
The IPv6 address.
uint32_t m_nsDadUid
Last DAD probe packet UID.
void SetAddress(Ipv6Address address)
Set IPv6 address (and scope).
Ipv6Address GetAddress() const
Get the IPv6 address.
Ipv6InterfaceAddress()
Default constructor.
uint32_t GetNsDadUid() const
Get the latest DAD probe packet UID.
void SetState(Ipv6InterfaceAddress::State_e state)
Set the state.
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
void SetNsDadUid(uint32_t uid)
Set the latest DAD probe packet UID.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
bool GetOnLink() const
Get the on-link property.
void SetOnLink(bool onLink)
Get the on-link property.
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
bool m_onLink
The address belongs to an on-link network.
State_e
State of an address associated with an interface.
@ TENTATIVE_OPTIMISTIC
Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished.
bool IsInSameSubnet(Ipv6Address b) const
Checks if the address is in the same subnet.
Scope_e m_scope
Scope of the address.
State_e m_state
State of the address.
Ipv6Prefix m_prefix
The IPv6 prefix.
@ LINKLOCAL
Link-local address (fe80::/64)
@ GLOBAL
Global address (2000::/3)
Describes an IPv6 prefix.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition simulator.cc:274
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148