A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  ;
33 
35  : m_address (Ipv6Address ()),
36  m_prefix (Ipv6Prefix ()),
37  m_state (TENTATIVE_OPTIMISTIC),
38  m_scope (HOST),
39  m_nsDadUid (0)
40 {
41  NS_LOG_FUNCTION (this);
42 }
43 
45 {
46  NS_LOG_FUNCTION (this << address);
47  m_prefix = Ipv6Prefix (64);
48  SetAddress (address);
50  m_nsDadUid = 0;
51 }
52 
54 {
55  NS_LOG_FUNCTION (this << address << prefix);
56  m_prefix = prefix;
57  SetAddress (address);
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_nsDadUid (o.m_nsDadUid)
68 {
69 }
70 
72 {
74 }
75 
77 {
79  return m_address;
80 }
81 
83 {
84  NS_LOG_FUNCTION (this << address);
86 
87  if (address.IsLocalhost ())
88  {
89  m_scope = HOST;
90  /* localhost address is always /128 prefix */
91  m_prefix = Ipv6Prefix (128);
92  }
93  else if (address.IsLinkLocal ())
94  {
96  /* link-local address is always /64 prefix */
97  m_prefix = Ipv6Prefix (64);
98  }
99  else if (address.IsLinkLocalMulticast ())
100  {
101  m_scope = LINKLOCAL;
102  /* link-local multicast address is always /16 prefix */
103  m_prefix = Ipv6Prefix (16);
104  }
105  else
106  {
107  m_scope = GLOBAL;
108  }
109 }
110 
112 {
114  return m_prefix;
115 }
116 
118 {
119  NS_LOG_FUNCTION (this << state);
120  m_state = state;
121 }
122 
124 {
126  return m_state;
127 }
128 
130 {
131  NS_LOG_FUNCTION (this << scope);
132  m_scope = scope;
133 }
134 
136 {
138  return m_scope;
139 }
140 
141 std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr)
142 {
143  os << "address: " << addr.GetAddress () << addr.GetPrefix () << "; scope: ";
144  switch (addr.GetScope ())
145  {
147  os << "HOST";
148  break;
150  os << "LINK-LOCAL";
151  break;
153  os << "GLOBAL";
154  break;
155  default:
156  os << "UNKNOWN";
157  break;
158  }
159  return os;
160 }
161 
163 {
165  return m_nsDadUid;
166 }
167 
168 void Ipv6InterfaceAddress::SetNsDadUid (uint32_t nsDadUid)
169 {
170  NS_LOG_FUNCTION (this << nsDadUid);
171  m_nsDadUid = nsDadUid;
172 }
173 
174 #if 0
175 void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
176 {
177  NS_LOG_FUNCTION (this << interface);
178  m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
179  m_dadTimer.SetArguments (interface, m_address);
180  m_dadTimer.Schedule (Seconds (1));
181  m_dadId = Simulator::Schedule (Seconds (1.), &Icmpv6L4Protocol::FunctionDadTimeout, interface, m_address);
182 }
183 
184 void Ipv6InterfaceAddress::StopDadTimer ()
185 {
187  m_dadTimer.Cancel ();
188  Simulator::Cancel (m_dadId);
189 }
190 #endif
191 
192 } /* namespace ns3 */
193 
State_e m_state
State of the address.
void SetScope(Ipv6InterfaceAddress::Scope_e scope)
Set the scope.
uint32_t GetNsDadUid() const
Get the latest DAD probe packet UID.
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
void SetNsDadUid(uint32_t uid)
Set the latest DAD probe packet UID.
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's associated function will not be invoked when it expires...
Definition: simulator.cc:268
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
static void FunctionDadTimeout(Ptr< Icmpv6L4Protocol > icmpv6, Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
Ipv6Address GetAddress() const
Get the IPv6 address.
Ipv6InterfaceAddress()
Default constructor.
Ipv6Address m_address
The IPv6 address.
void SetState(Ipv6InterfaceAddress::State_e state)
Set the state.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
Describes an IPv6 address.
Definition: ipv6-address.h:46
void SetAddress(Ipv6Address address)
Set IPv6 address (and scope).
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
Ipv6Prefix m_prefix
The IPv6 prefix.
State_e
State of an address associated with an interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:387
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...
tuple address
Definition: first.py:37
bool IsLocalhost() const
If the IPv6 address is localhost (::1).