A Discrete-Event Network Simulator
API
ipv6-interface-address.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include <iostream>
22 
23 #include "ns3/log.h"
24 #include "ns3/assert.h"
25 
26 #include "ipv6-interface-address.h"
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE ("Ipv6InterfaceAddress");
32 
34  : m_address (Ipv6Address ()),
35  m_prefix (Ipv6Prefix ()),
36  m_state (TENTATIVE_OPTIMISTIC),
37  m_scope (HOST),
38  m_onLink (true),
39  m_nsDadUid (0)
40 {
41  NS_LOG_FUNCTION (this);
42 }
43 
45 {
46  NS_LOG_FUNCTION (this << address);
47  m_prefix = Ipv6Prefix (64);
50  m_onLink = true;
51  m_nsDadUid = 0;
52 }
53 
55 {
56  NS_LOG_FUNCTION (this << address << prefix);
57  m_prefix = prefix;
60  m_onLink = true;
61  m_nsDadUid = 0;
62 }
63 
65 {
66  NS_LOG_FUNCTION (this << address << prefix << onLink);
67  m_prefix = prefix;
70  m_onLink = onLink;
71  m_nsDadUid = 0;
72 }
73 
75  : m_address (o.m_address),
76  m_prefix (o.m_prefix),
77  m_state (o.m_state),
78  m_scope (o.m_scope),
79  m_onLink (o.m_onLink),
80  m_nsDadUid (o.m_nsDadUid)
81 {
82 }
83 
85 {
86  NS_LOG_FUNCTION (this);
87 }
88 
90 {
91  NS_LOG_FUNCTION (this);
92  return m_address;
93 }
94 
96 {
97  NS_LOG_FUNCTION (this << address);
99 
100  if (address.IsLocalhost ())
101  {
102  m_scope = HOST;
103  /* localhost address is always /128 prefix */
104  m_prefix = Ipv6Prefix (128);
105  }
106  else if (address.IsLinkLocal ())
107  {
108  m_scope = LINKLOCAL;
109  /* link-local address is always /64 prefix */
110  m_prefix = Ipv6Prefix (64);
111  }
112  else if (address.IsLinkLocalMulticast ())
113  {
114  m_scope = LINKLOCAL;
115  /* link-local multicast address is always /16 prefix */
116  m_prefix = Ipv6Prefix (16);
117  }
118  else
119  {
120  m_scope = GLOBAL;
121  }
122 }
123 
125 {
126  NS_LOG_FUNCTION (this);
127  return m_prefix;
128 }
129 
131 {
132  NS_LOG_FUNCTION (this << state);
133  m_state = state;
134 }
135 
137 {
138  NS_LOG_FUNCTION (this);
139  return m_state;
140 }
141 
143 {
144  NS_LOG_FUNCTION (this << scope);
145  m_scope = scope;
146 }
147 
149 {
150  NS_LOG_FUNCTION (this);
151  return m_scope;
152 }
153 
155 {
156  NS_LOG_FUNCTION (this);
157 
158  Ipv6Address aAddr = m_address;
159  aAddr = aAddr.CombinePrefix (m_prefix);
160  Ipv6Address bAddr = b;
161  bAddr = bAddr.CombinePrefix (m_prefix);
162 
163  if (aAddr == bAddr)
164  {
165  return true;
166  }
167 
168  if ((bAddr.IsLinkLocalMulticast () && aAddr.IsLinkLocal ()) ||
169  (aAddr.IsLinkLocalMulticast () && bAddr.IsLinkLocal ()))
170  {
171  return true;
172  }
173 
174  return false;
175 }
176 
177 std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr)
178 {
179  os << "address: " << addr.GetAddress () << addr.GetPrefix () << "; scope: ";
180  switch (addr.GetScope ())
181  {
183  os << "HOST";
184  break;
186  os << "LINK-LOCAL";
187  break;
189  os << "GLOBAL";
190  break;
191  default:
192  os << "UNKNOWN";
193  break;
194  }
195  return os;
196 }
197 
199 {
200  NS_LOG_FUNCTION (this);
201  return m_nsDadUid;
202 }
203 
204 void Ipv6InterfaceAddress::SetNsDadUid (uint32_t nsDadUid)
205 {
206  NS_LOG_FUNCTION (this << nsDadUid);
207  m_nsDadUid = nsDadUid;
208 }
209 
211 {
212  NS_LOG_FUNCTION (this);
213  return m_onLink;
214 }
215 
217 {
218  NS_LOG_FUNCTION (this << onLink);
219  m_onLink = onLink;
220 }
221 
222 #if 0
223 void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
224 {
225  NS_LOG_FUNCTION (this << interface);
226  m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
227  m_dadTimer.SetArguments (interface, m_address);
228  m_dadTimer.Schedule (Seconds (1));
230 }
231 
232 void Ipv6InterfaceAddress::StopDadTimer ()
233 {
234  NS_LOG_FUNCTION (this);
235  m_dadTimer.Cancel ();
236  Simulator::Cancel (m_dadId);
237 }
238 #endif
239 
240 } /* namespace ns3 */
241 
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::Ipv6InterfaceAddress::m_prefix
Ipv6Prefix m_prefix
The IPv6 prefix.
Definition: ipv6-interface-address.h:198
ns3::Ipv6InterfaceAddress::GetPrefix
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
Definition: ipv6-interface-address.cc:124
ns3::Ipv6InterfaceAddress
IPv6 address associated with an interface.
Definition: ipv6-interface-address.h:38
ns3::Ipv6InterfaceAddress::m_nsDadUid
uint32_t m_nsDadUid
Last DAD probe packet UID.
Definition: ipv6-interface-address.h:236
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6InterfaceAddress::GetAddress
Ipv6Address GetAddress() const
Get the IPv6 address.
Definition: ipv6-interface-address.cc:89
ns3::Ipv6InterfaceAddress::m_state
State_e m_state
State of the address.
Definition: ipv6-interface-address.h:203
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::Ipv6InterfaceAddress::Scope_e
Scope_e
Address scope.
Definition: ipv6-interface-address.h:60
ns3::Ipv6InterfaceAddress::LINKLOCAL
@ LINKLOCAL
Link-local address (fe80::/64)
Definition: ipv6-interface-address.h:62
ns3::Ipv6InterfaceAddress::State_e
State_e
State of an address associated with an interface.
Definition: ipv6-interface-address.h:45
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::Ipv6InterfaceAddress::SetNsDadUid
void SetNsDadUid(uint32_t uid)
Set the latest DAD probe packet UID.
Definition: ipv6-interface-address.cc:204
ns3::Ipv6InterfaceAddress::m_address
Ipv6Address m_address
The IPv6 address.
Definition: ipv6-interface-address.h:193
ns3::Icmpv6L4Protocol::FunctionDadTimeout
void FunctionDadTimeout(Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
Definition: icmpv6-l4-protocol.cc:1450
ns3::Ptr< Ipv6Interface >
ns3::Ipv6Address::IsLinkLocal
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
Definition: ipv6-address.cc:917
ns3::Ipv6Address::CombinePrefix
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix) const
Combine this address with a prefix.
Definition: ipv6-address.cc:746
ns3::Ipv6InterfaceAddress::m_onLink
bool m_onLink
The address belongs to an on-link network.
Definition: ipv6-interface-address.h:213
ns3::Simulator::Cancel
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:268
first.address
address
Definition: first.py:44
ns3::Ipv6InterfaceAddress::SetScope
void SetScope(Ipv6InterfaceAddress::Scope_e scope)
Set the scope.
Definition: ipv6-interface-address.cc:142
ns3::Ipv6InterfaceAddress::TENTATIVE_OPTIMISTIC
@ TENTATIVE_OPTIMISTIC
Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished.
Definition: ipv6-interface-address.h:51
ns3::Ipv6Address::IsLinkLocalMulticast
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Definition: ipv6-address.cc:724
ns3::Ipv6InterfaceAddress::GetOnLink
bool GetOnLink() const
Get the on-link property.
Definition: ipv6-interface-address.cc:210
ns3::Ipv6InterfaceAddress::SetAddress
void SetAddress(Ipv6Address address)
Set IPv6 address (and scope).
Definition: ipv6-interface-address.cc:95
ns3::Ipv6InterfaceAddress::GetScope
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
Definition: ipv6-interface-address.cc:148
ns3::Ipv6InterfaceAddress::IsInSameSubnet
bool IsInSameSubnet(Ipv6Address b) const
Checks if the address is in the same subnet.
Definition: ipv6-interface-address.cc:154
ns3::Ipv6InterfaceAddress::GetNsDadUid
uint32_t GetNsDadUid() const
Get the latest DAD probe packet UID.
Definition: ipv6-interface-address.cc:198
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ipv6-interface-address.h
ns3::Ipv6InterfaceAddress::GLOBAL
@ GLOBAL
Global address (2000::/3)
Definition: ipv6-interface-address.h:63
ns3::Ipv6InterfaceAddress::SetOnLink
void SetOnLink(bool onLink)
Get the on-link property.
Definition: ipv6-interface-address.cc:216
ns3::Ipv6InterfaceAddress::GetState
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
Definition: ipv6-interface-address.cc:136
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
ns3::Ipv6InterfaceAddress::Ipv6InterfaceAddress
Ipv6InterfaceAddress()
Default constructor.
Definition: ipv6-interface-address.cc:33
ns3::Ipv6InterfaceAddress::HOST
@ HOST
Localhost (::1/128)
Definition: ipv6-interface-address.h:61
ns3::Ipv6InterfaceAddress::SetState
void SetState(Ipv6InterfaceAddress::State_e state)
Set the state.
Definition: ipv6-interface-address.cc:130
ns3::Ipv6InterfaceAddress::m_scope
Scope_e m_scope
Scope of the address.
Definition: ipv6-interface-address.h:208
ns3::Ipv6InterfaceAddress::~Ipv6InterfaceAddress
~Ipv6InterfaceAddress()
Destructor.
Definition: ipv6-interface-address.cc:84