A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-interface-address.cc
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);
47  SetAddress (address);
49  m_nsDadUid = 0;
50 }
51 
53 {
54  NS_LOG_FUNCTION (this << address << prefix);
55  m_prefix = prefix;
56  SetAddress (address);
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);
84  m_address = 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
99  {
100  m_scope = GLOBAL;
101  }
102 }
103 
105 {
107  return m_prefix;
108 }
109 
111 {
112  NS_LOG_FUNCTION (this << state);
113  m_state = state;
114 }
115 
117 {
119  return m_state;
120 }
121 
123 {
124  NS_LOG_FUNCTION (this << scope);
125  m_scope = scope;
126 }
127 
129 {
131  return m_scope;
132 }
133 
134 std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr)
135 {
136  os << "address=" << addr.GetAddress () << "; prefix=" <<
137  addr.GetPrefix () << "; scope=" << addr.GetScope ();
138  return os;
139 }
140 
142 {
144  return m_nsDadUid;
145 }
146 
147 void Ipv6InterfaceAddress::SetNsDadUid (uint32_t nsDadUid)
148 {
149  NS_LOG_FUNCTION (this << nsDadUid);
150  m_nsDadUid = nsDadUid;
151 }
152 
153 #if 0
154 void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
155 {
156  NS_LOG_FUNCTION (this << interface);
157  m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
158  m_dadTimer.SetArguments (interface, m_address);
159  m_dadTimer.Schedule (Seconds (1));
161 }
162 
163 void Ipv6InterfaceAddress::StopDadTimer ()
164 {
166  m_dadTimer.Cancel ();
167  Simulator::Cancel (m_dadId);
168 }
169 #endif
170 
171 } /* namespace ns3 */
172 
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:311
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
IPv6 address associated with an interface.
uint32_t m_nsDadUid
Last DAD probe packet UID.
static void Cancel(const EventId &id)
Definition: simulator.cc:267
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
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)
Definition: angles.cc:43
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
Describes an IPv6 address.
Definition: ipv6-address.h:44
void SetAddress(Ipv6Address address)
Set IPv6 address (and scope).
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
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. It is just a bitmask like Ipv4Mask.
Definition: ipv6-address.h:326
Scope_e m_scope
Scope of the address.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).