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
NS_LOG_INFO
(
"Start PreferredTimer for "
<<
m_prefix
);
122
m_preferredTimer
.
SetFunction
(&
Ipv6AutoconfiguredPrefix::FunctionPreferredTimeout
,
this
);
123
m_preferredTimer
.
SetDelay
(
Seconds
(
m_preferredLifeTime
));
124
m_preferredTimer
.
Schedule
();
125
}
126
127
void
Ipv6AutoconfiguredPrefix::StartValidTimer
()
128
{
129
NS_LOG_INFO
(
"Start ValidTimer for "
<<
m_prefix
);
130
m_validTimer
.
SetFunction
(&
Ipv6AutoconfiguredPrefix::FunctionValidTimeout
,
this
);
131
m_validTimer
.
SetDelay
(
Seconds
(
m_validLifeTime
-
m_preferredLifeTime
));
132
m_validTimer
.
Schedule
();
133
}
134
135
void
Ipv6AutoconfiguredPrefix::StopPreferredTimer
()
136
{
137
NS_LOG_INFO
(
"Stop PreferredTimer for "
<<
m_prefix
);
138
m_preferredTimer
.
Cancel
();
139
}
140
141
void
Ipv6AutoconfiguredPrefix::StopValidTimer
()
142
{
143
NS_LOG_INFO
(
"Stop ValidTimer for "
<<
m_prefix
);
144
m_validTimer
.
Cancel
();
145
}
146
147
void
Ipv6AutoconfiguredPrefix::RemoveMe
()
148
{
149
NS_LOG_INFO
(
"The prefix "
<<
m_prefix
<<
" will be removed on interface "
<<
m_interface
);
150
Ptr<Ipv6L3Protocol>
ipv6 =
m_node
->
GetObject
<
Ipv6L3Protocol
> ();
151
ipv6->RemoveAutoconfiguredAddress (
m_interface
,
m_prefix
,
m_mask
,
m_defaultGatewayRouter
);
152
}
153
154
void
Ipv6AutoconfiguredPrefix::SetPreferred
()
155
{
156
m_preferred
=
true
;
157
}
158
159
void
Ipv6AutoconfiguredPrefix::SetValid
()
160
{
161
m_preferred
=
false
;
162
m_valid
=
true
;
163
}
164
165
uint32_t
Ipv6AutoconfiguredPrefix::GetId
()
const
166
{
167
return
m_id
;
168
}
169
170
bool
Ipv6AutoconfiguredPrefix::IsPreferred
()
const
171
{
172
return
m_preferred
;
173
}
174
175
bool
Ipv6AutoconfiguredPrefix::IsValid
()
const
176
{
177
return
m_valid
;
178
}
179
180
Ipv6Address
Ipv6AutoconfiguredPrefix::GetPrefix
()
const
181
{
182
return
m_prefix
;
183
}
184
185
void
Ipv6AutoconfiguredPrefix::SetPrefix
(
Ipv6Address
prefix)
186
{
187
m_prefix
= prefix;
188
}
189
190
Ipv6Prefix
Ipv6AutoconfiguredPrefix::GetMask
()
const
191
{
192
return
m_mask
;
193
}
194
195
void
Ipv6AutoconfiguredPrefix::SetMask
(
Ipv6Prefix
mask)
196
{
197
m_mask
= mask;
198
}
199
200
}
/* namespace ns3 */
201
src
internet
model
ipv6-autoconfigured-prefix.cc
Generated on Fri Dec 21 2012 19:00:37 for ns-3 by
1.8.1.2