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_nsDadUid (0)
39 {
40  NS_LOG_FUNCTION (this);
41 }
42 
44 {
45  NS_LOG_FUNCTION (this << address);
46  m_prefix = Ipv6Prefix (64);
49  m_nsDadUid = 0;
50 }
51 
53 {
54  NS_LOG_FUNCTION (this << address << prefix);
55  m_prefix = prefix;
58  m_nsDadUid = 0;
59 }
60 
62  : m_address (o.m_address),
63  m_prefix (o.m_prefix),
64  m_state (o.m_state),
65  m_scope (o.m_scope),
66  m_nsDadUid (o.m_nsDadUid)
67 {
68 }
69 
71 {
73 }
74 
76 {
78  return m_address;
79 }
80 
82 {
83  NS_LOG_FUNCTION (this << address);
85 
86  if (address.IsLocalhost ())
87  {
88  m_scope = HOST;
89  /* localhost address is always /128 prefix */
90  m_prefix = Ipv6Prefix (128);
91  }
92  else if (address.IsLinkLocal ())
93  {
95  /* link-local address is always /64 prefix */
96  m_prefix = Ipv6Prefix (64);
97  }
98  else if (address.IsLinkLocalMulticast ())
99  {
100  m_scope = LINKLOCAL;
101  /* link-local multicast address is always /16 prefix */
102  m_prefix = Ipv6Prefix (16);
103  }
104  else
105  {
106  m_scope = GLOBAL;
107  }
108 }
109 
111 {
113  return m_prefix;
114 }
115 
117 {
118  NS_LOG_FUNCTION (this << state);
119  m_state = state;
120 }
121 
123 {
125  return m_state;
126 }
127 
129 {
130  NS_LOG_FUNCTION (this << scope);
131  m_scope = scope;
132 }
133 
135 {
137  return m_scope;
138 }
139 
141 {
143 
144  Ipv6Address aAddr = m_address;
145  aAddr = aAddr.CombinePrefix (m_prefix);
146  Ipv6Address bAddr = b;
147  bAddr = bAddr.CombinePrefix (m_prefix);
148 
149  if (aAddr == bAddr)
150  {
151  return true;
152  }
153 
154  if ((bAddr.IsLinkLocalMulticast () && aAddr.IsLinkLocal ()) ||
155  (aAddr.IsLinkLocalMulticast () && bAddr.IsLinkLocal ()))
156  {
157  return true;
158  }
159 
160  return false;
161 }
162 
163 std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr)
164 {
165  os << "address: " << addr.GetAddress () << addr.GetPrefix () << "; scope: ";
166  switch (addr.GetScope ())
167  {
169  os << "HOST";
170  break;
172  os << "LINK-LOCAL";
173  break;
175  os << "GLOBAL";
176  break;
177  default:
178  os << "UNKNOWN";
179  break;
180  }
181  return os;
182 }
183 
185 {
187  return m_nsDadUid;
188 }
189 
190 void Ipv6InterfaceAddress::SetNsDadUid (uint32_t nsDadUid)
191 {
192  NS_LOG_FUNCTION (this << nsDadUid);
193  m_nsDadUid = nsDadUid;
194 }
195 
196 #if 0
197 void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
198 {
199  NS_LOG_FUNCTION (this << interface);
200  m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
201  m_dadTimer.SetArguments (interface, m_address);
202  m_dadTimer.Schedule (Seconds (1));
204 }
205 
206 void Ipv6InterfaceAddress::StopDadTimer ()
207 {
209  m_dadTimer.Cancel ();
210  Simulator::Cancel (m_dadId);
211 }
212 #endif
213 
214 } /* namespace ns3 */
215 
State_e m_state
State of the address.
void SetScope(Ipv6InterfaceAddress::Scope_e scope)
Set the scope.
Ipv6Address GetAddress() const
Get the IPv6 address.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool IsInSameSubnet(Ipv6Address b) const
Checks if the address is in the same subnet.
void SetNsDadUid(uint32_t uid)
Set the latest DAD probe packet UID.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
IPv6 address associated with an interface.
Link-local address (fe80::/64)
uint32_t m_nsDadUid
Last DAD probe packet UID.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
Definition: simulator.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint32_t GetNsDadUid() const
Get the latest DAD probe packet UID.
static void FunctionDadTimeout(Ptr< Icmpv6L4Protocol > icmpv6, Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
Ipv6InterfaceAddress()
Default constructor.
Ipv6Address m_address
The IPv6 address.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
void SetState(Ipv6InterfaceAddress::State_e state)
Set the state.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void SetAddress(Ipv6Address address)
Set IPv6 address (and scope).
Ipv6Prefix m_prefix
The IPv6 prefix.
State_e
State of an address associated with an interface.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
Scope_e m_scope
Scope of the address.
Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished...
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.