A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
Ipv6InterfaceAddress::Ipv6InterfaceAddress
()
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
43
Ipv6InterfaceAddress::Ipv6InterfaceAddress
(
Ipv6Address
address)
44
{
45
NS_LOG_FUNCTION
(
this
<< address);
46
m_prefix
=
Ipv6Prefix
(64);
47
SetAddress
(address);
48
SetState
(
TENTATIVE_OPTIMISTIC
);
49
m_nsDadUid
= 0;
50
}
51
52
Ipv6InterfaceAddress::Ipv6InterfaceAddress
(
Ipv6Address
address,
Ipv6Prefix
prefix)
53
{
54
NS_LOG_FUNCTION
(
this
<< address << prefix);
55
m_prefix
= prefix;
56
SetAddress
(address);
57
SetState
(
TENTATIVE_OPTIMISTIC
);
58
m_nsDadUid
= 0;
59
}
60
61
Ipv6InterfaceAddress::Ipv6InterfaceAddress
(
const
Ipv6InterfaceAddress
& o)
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
70
Ipv6InterfaceAddress::~Ipv6InterfaceAddress
()
71
{
72
NS_LOG_FUNCTION_NOARGS
();
73
}
74
75
Ipv6Address
Ipv6InterfaceAddress::GetAddress
()
const
76
{
77
NS_LOG_FUNCTION_NOARGS
();
78
return
m_address
;
79
}
80
81
void
Ipv6InterfaceAddress::SetAddress
(
Ipv6Address
address)
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
{
94
m_scope
=
LINKLOCAL
;
95
/* link-local address is always /64 prefix */
96
m_prefix
=
Ipv6Prefix
(64);
97
}
98
else
99
{
100
m_scope
=
GLOBAL
;
101
}
102
}
103
104
Ipv6Prefix
Ipv6InterfaceAddress::GetPrefix
()
const
105
{
106
NS_LOG_FUNCTION_NOARGS
();
107
return
m_prefix
;
108
}
109
110
void
Ipv6InterfaceAddress::SetState
(
Ipv6InterfaceAddress::State_e
state)
111
{
112
NS_LOG_FUNCTION
(
this
<< state);
113
m_state
= state;
114
}
115
116
Ipv6InterfaceAddress::State_e
Ipv6InterfaceAddress::GetState
()
const
117
{
118
NS_LOG_FUNCTION_NOARGS
();
119
return
m_state
;
120
}
121
122
void
Ipv6InterfaceAddress::SetScope
(
Ipv6InterfaceAddress::Scope_e
scope)
123
{
124
NS_LOG_FUNCTION
(
this
<< scope);
125
m_scope
= scope;
126
}
127
128
Ipv6InterfaceAddress::Scope_e
Ipv6InterfaceAddress::GetScope
()
const
129
{
130
NS_LOG_FUNCTION_NOARGS
();
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
141
uint32_t
Ipv6InterfaceAddress::GetNsDadUid
()
const
142
{
143
NS_LOG_FUNCTION_NOARGS
();
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));
160
m_dadId =
Simulator::Schedule
(
Seconds
(1.), &
Icmpv6L4Protocol::FunctionDadTimeout
, interface,
m_address
);
161
}
162
163
void
Ipv6InterfaceAddress::StopDadTimer ()
164
{
165
NS_LOG_FUNCTION_NOARGS
();
166
m_dadTimer.Cancel ();
167
Simulator::Cancel
(m_dadId);
168
}
169
#endif
170
171
}
/* namespace ns3 */
172
src
internet
model
ipv6-interface-address.cc
Generated on Tue May 14 2013 11:08:22 for ns-3 by
1.8.1.2