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-autoconfigured-prefix.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008-2009 Telecom Bretagne
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: Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
19
*/
20
21
#include "ns3/log.h"
22
#include "ns3/node.h"
23
24
#include "
ipv6-l3-protocol.h
"
25
#include "
ipv6-autoconfigured-prefix.h
"
26
27
NS_LOG_COMPONENT_DEFINE
(
"Ipv6AutoconfiguredPrefix"
);
28
29
namespace
ns3
30
{
31
32
uint32_t
Ipv6AutoconfiguredPrefix::m_prefixId
= 0;
33
34
Ipv6AutoconfiguredPrefix::Ipv6AutoconfiguredPrefix
(
Ptr<Node>
node, uint32_t interface,
Ipv6Address
prefix,
Ipv6Prefix
mask, uint32_t preferredLifeTime, uint32_t validLifeTime,
Ipv6Address
router)
35
{
36
m_node
= node;
37
m_interface
= interface;
38
m_validLifeTime
= validLifeTime;
39
m_preferredLifeTime
= preferredLifeTime;
40
m_id
=
m_prefixId
;
41
m_prefixId
++;
42
m_preferred
=
false
;
43
m_valid
=
false
;
44
m_prefix
= prefix;
45
m_mask
= mask;
46
m_defaultGatewayRouter
= router;
47
}
48
49
Ipv6AutoconfiguredPrefix::~Ipv6AutoconfiguredPrefix
()
50
{
51
}
52
53
void
Ipv6AutoconfiguredPrefix::SetDefaultGatewayRouter
(
Ipv6Address
router)
54
{
55
m_defaultGatewayRouter
= router;
56
}
57
58
Ipv6Address
Ipv6AutoconfiguredPrefix::GetDefaultGatewayRouter
()
const
59
{
60
return
m_defaultGatewayRouter
;
61
}
62
63
void
Ipv6AutoconfiguredPrefix::SetInterface
(uint32_t interface)
64
{
65
m_interface
= interface;
66
}
67
68
uint32_t
Ipv6AutoconfiguredPrefix::GetInterface
()
const
69
{
70
return
m_interface
;
71
}
72
73
void
Ipv6AutoconfiguredPrefix::SetPreferredLifeTime
(uint32_t t)
74
{
75
m_preferredLifeTime
= t;
76
}
77
78
uint32_t
Ipv6AutoconfiguredPrefix::GetPreferredLifeTime
()
const
79
{
80
return
m_preferredLifeTime
;
81
}
82
83
void
Ipv6AutoconfiguredPrefix::SetValidLifeTime
(uint32_t t)
84
{
85
m_validLifeTime
= t;
86
}
87
88
uint32_t
Ipv6AutoconfiguredPrefix::GetValidLifeTime
()
const
89
{
90
return
m_validLifeTime
;
91
}
92
93
void
Ipv6AutoconfiguredPrefix::MarkPreferredTime
()
94
{
95
m_preferred
=
true
;
96
}
97
98
void
Ipv6AutoconfiguredPrefix::MarkValidTime
()
99
{
100
m_preferred
=
false
;
101
m_valid
=
true
;
102
}
103
104
void
Ipv6AutoconfiguredPrefix::FunctionPreferredTimeout
()
105
{
106
NS_LOG_INFO
(
"Preferred Time expired for "
<<
m_prefix
);
107
m_preferred
=
false
;
108
MarkValidTime
();
109
StartValidTimer
();
110
}
111
112
void
Ipv6AutoconfiguredPrefix::FunctionValidTimeout
()
113
{
114
NS_LOG_INFO
(
"Valid Time expired for "
<<
m_prefix
);
115
m_valid
=
false
;
116
RemoveMe
();
117
}
118
119
void
Ipv6AutoconfiguredPrefix::StartPreferredTimer
()
120
{
121
if
(
m_preferredLifeTime
!= 0xffffffff)
122
{
123
NS_LOG_INFO
(
"Start PreferredTimer for "
<<
m_prefix
);
124
m_preferredTimer
.
SetFunction
(&
Ipv6AutoconfiguredPrefix::FunctionPreferredTimeout
,
this
);
125
m_preferredTimer
.
SetDelay
(Seconds (
m_preferredLifeTime
));
126
m_preferredTimer
.
Schedule
();
127
}
128
}
129
130
void
Ipv6AutoconfiguredPrefix::StartValidTimer
()
131
{
132
if
(
m_validLifeTime
!= 0xffffffff)
133
{
134
NS_LOG_INFO
(
"Start ValidTimer for "
<<
m_prefix
);
135
m_validTimer
.
SetFunction
(&
Ipv6AutoconfiguredPrefix::FunctionValidTimeout
,
this
);
136
m_validTimer
.
SetDelay
(Seconds (
m_validLifeTime
-
m_preferredLifeTime
));
137
m_validTimer
.
Schedule
();
138
}
139
}
140
141
void
Ipv6AutoconfiguredPrefix::StopPreferredTimer
()
142
{
143
if
(
m_preferredTimer
.
IsRunning
())
144
{
145
NS_LOG_INFO
(
"Stop PreferredTimer for "
<<
m_prefix
);
146
m_preferredTimer
.
Cancel
();
147
}
148
}
149
150
void
Ipv6AutoconfiguredPrefix::StopValidTimer
()
151
{
152
if
(
m_validTimer
.
IsRunning
())
153
{
154
NS_LOG_INFO
(
"Stop ValidTimer for "
<<
m_prefix
);
155
m_validTimer
.
Cancel
();
156
}
157
}
158
159
void
Ipv6AutoconfiguredPrefix::RemoveMe
()
160
{
161
NS_LOG_INFO
(
"The prefix "
<<
m_prefix
<<
" will be removed on interface "
<<
m_interface
);
162
Ptr<Ipv6L3Protocol>
ipv6 =
m_node
->
GetObject
<
Ipv6L3Protocol
> ();
163
ipv6->RemoveAutoconfiguredAddress (
m_interface
,
m_prefix
,
m_mask
,
m_defaultGatewayRouter
);
164
}
165
166
void
Ipv6AutoconfiguredPrefix::SetPreferred
()
167
{
168
m_preferred
=
true
;
169
}
170
171
void
Ipv6AutoconfiguredPrefix::SetValid
()
172
{
173
m_preferred
=
false
;
174
m_valid
=
true
;
175
}
176
177
uint32_t
Ipv6AutoconfiguredPrefix::GetId
()
const
178
{
179
return
m_id
;
180
}
181
182
bool
Ipv6AutoconfiguredPrefix::IsPreferred
()
const
183
{
184
return
m_preferred
;
185
}
186
187
bool
Ipv6AutoconfiguredPrefix::IsValid
()
const
188
{
189
return
m_valid
;
190
}
191
192
Ipv6Address
Ipv6AutoconfiguredPrefix::GetPrefix
()
const
193
{
194
return
m_prefix
;
195
}
196
197
void
Ipv6AutoconfiguredPrefix::SetPrefix
(
Ipv6Address
prefix)
198
{
199
m_prefix
= prefix;
200
}
201
202
Ipv6Prefix
Ipv6AutoconfiguredPrefix::GetMask
()
const
203
{
204
return
m_mask
;
205
}
206
207
void
Ipv6AutoconfiguredPrefix::SetMask
(
Ipv6Prefix
mask)
208
{
209
m_mask
= mask;
210
}
211
212
}
/* namespace ns3 */
213
src
internet
model
ipv6-autoconfigured-prefix.cc
Generated on Fri Aug 30 2013 01:42:51 for ns-3 by
1.8.1.2