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 * 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
21
22#include "ns3/assert.h"
23#include "ns3/log.h"
24
25#include <iostream>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("Ipv6InterfaceAddress");
31
33 : m_address(Ipv6Address()),
34 m_prefix(Ipv6Prefix()),
35 m_state(TENTATIVE_OPTIMISTIC),
36 m_scope(HOST),
37 m_onLink(true),
38 m_nsDadUid(0)
39{
40 NS_LOG_FUNCTION(this);
41}
42
44{
45 NS_LOG_FUNCTION(this << address);
46 m_prefix = Ipv6Prefix(64);
47 SetAddress(address);
49 m_onLink = true;
50 m_nsDadUid = 0;
51}
52
54{
55 NS_LOG_FUNCTION(this << address << prefix);
56 m_prefix = prefix;
57 SetAddress(address);
59 m_onLink = true;
60 m_nsDadUid = 0;
61}
62
64{
65 NS_LOG_FUNCTION(this << address << prefix << onLink);
66 m_prefix = prefix;
67 SetAddress(address);
69 m_onLink = onLink;
70 m_nsDadUid = 0;
71}
72
74 : m_address(o.m_address),
75 m_prefix(o.m_prefix),
76 m_state(o.m_state),
77 m_scope(o.m_scope),
78 m_onLink(o.m_onLink),
79 m_nsDadUid(o.m_nsDadUid)
80{
81}
82
84{
85 NS_LOG_FUNCTION(this);
86}
87
90{
91 NS_LOG_FUNCTION(this);
92 return m_address;
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << address);
99 m_address = address;
100
101 if (address.IsLocalhost())
102 {
103 m_scope = HOST;
104 /* localhost address is always /128 prefix */
105 m_prefix = Ipv6Prefix(128);
106 }
107 else if (address.IsLinkLocal())
108 {
110 /* link-local address is always /64 prefix */
111 m_prefix = Ipv6Prefix(64);
112 }
113 else if (address.IsLinkLocalMulticast())
114 {
116 /* link-local multicast address is always /16 prefix */
117 m_prefix = Ipv6Prefix(16);
118 }
119 else
120 {
121 m_scope = GLOBAL;
122 }
123}
124
127{
128 NS_LOG_FUNCTION(this);
129 return m_prefix;
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << state);
136 m_state = state;
137}
138
141{
142 NS_LOG_FUNCTION(this);
143 return m_state;
144}
145
146void
148{
149 NS_LOG_FUNCTION(this << scope);
150 m_scope = scope;
151}
152
155{
156 NS_LOG_FUNCTION(this);
157 return m_scope;
158}
159
160bool
162{
163 NS_LOG_FUNCTION(this);
164
165 Ipv6Address aAddr = m_address;
166 aAddr = aAddr.CombinePrefix(m_prefix);
167 Ipv6Address bAddr = b;
168 bAddr = bAddr.CombinePrefix(m_prefix);
169
170 if (aAddr == bAddr)
171 {
172 return true;
173 }
174
175 if ((bAddr.IsLinkLocalMulticast() && aAddr.IsLinkLocal()) ||
176 (aAddr.IsLinkLocalMulticast() && bAddr.IsLinkLocal()))
177 {
178 return true;
179 }
180
181 return false;
182}
183
184std::ostream&
185operator<<(std::ostream& os, const Ipv6InterfaceAddress& addr)
186{
187 os << "address: " << addr.GetAddress() << addr.GetPrefix() << "; scope: ";
188 switch (addr.GetScope())
189 {
191 os << "HOST";
192 break;
194 os << "LINK-LOCAL";
195 break;
197 os << "GLOBAL";
198 break;
199 default:
200 os << "UNKNOWN";
201 break;
202 }
203 return os;
204}
205
208{
209 NS_LOG_FUNCTION(this);
210 return m_nsDadUid;
211}
212
213void
215{
216 NS_LOG_FUNCTION(this << nsDadUid);
217 m_nsDadUid = nsDadUid;
218}
219
220bool
222{
223 NS_LOG_FUNCTION(this);
224 return m_onLink;
225}
226
227void
229{
230 NS_LOG_FUNCTION(this << onLink);
231 m_onLink = onLink;
232}
233
234#if 0
235void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
236{
237 NS_LOG_FUNCTION (this << interface);
238 m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
239 m_dadTimer.SetArguments (interface, m_address);
240 m_dadTimer.Schedule (Seconds (1));
242}
243
244void Ipv6InterfaceAddress::StopDadTimer ()
245{
246 NS_LOG_FUNCTION (this);
247 m_dadTimer.Cancel ();
248 Simulator::Cancel (m_dadId);
249}
250#endif
251
252} /* namespace ns3 */
virtual void FunctionDadTimeout(Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
Describes an IPv6 address.
Definition: ipv6-address.h:49
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.
Definition: ipv6-address.h:455
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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:285
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:1326
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:159