A Discrete-Event Network Simulator
API
ipv6-autoconfigured-prefix.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2009 Telecom Bretagne
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
18  */
19 
21 
22 #include "ipv6-l3-protocol.h"
23 
24 #include "ns3/log.h"
25 #include "ns3/node.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("Ipv6AutoconfiguredPrefix");
31 
33 
35  uint32_t interface,
36  Ipv6Address prefix,
37  Ipv6Prefix mask,
38  uint32_t preferredLifeTime,
39  uint32_t validLifeTime,
40  Ipv6Address router)
41 {
42  if (preferredLifeTime + validLifeTime == 0)
43  {
44  NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
45  "will be removed immediately.");
46  }
47  m_node = node;
48  m_interface = interface;
49  m_validLifeTime = validLifeTime;
50  m_preferredLifeTime = preferredLifeTime;
51  m_id = m_prefixId;
52  m_prefixId++;
53  m_preferred = false;
54  m_valid = false;
55  m_prefix = prefix;
56  m_mask = mask;
57  m_defaultGatewayRouter = router;
58 }
59 
61 {
62 }
63 
64 void
66 {
67  m_defaultGatewayRouter = router;
68 }
69 
72 {
74 }
75 
76 void
78 {
79  m_interface = interface;
80 }
81 
82 uint32_t
84 {
85  return m_interface;
86 }
87 
88 void
90 {
93  {
94  NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
95  "will be removed immediately.");
96  }
97 }
98 
99 uint32_t
101 {
102  return m_preferredLifeTime;
103 }
104 
105 void
107 {
108  m_validLifeTime = t;
110  {
111  NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
112  "will be removed immediately.");
113  }
114 }
115 
116 uint32_t
118 {
119  return m_validLifeTime;
120 }
121 
122 void
124 {
125  m_preferred = true;
126 }
127 
128 void
130 {
131  m_preferred = false;
132  m_valid = true;
133 }
134 
135 void
137 {
138  NS_LOG_INFO("Preferred Time expired for " << m_prefix);
139  m_preferred = false;
140  MarkValidTime();
141  StartValidTimer();
142 }
143 
144 void
146 {
147  NS_LOG_INFO("Valid Time expired for " << m_prefix);
148  m_valid = false;
149  RemoveMe();
150 }
151 
152 void
154 {
155  if (m_preferredLifeTime != 0xffffffff)
156  {
157  NS_LOG_INFO("Start PreferredTimer for " << m_prefix);
161  }
162 }
163 
164 void
166 {
167  if (m_validLifeTime != 0xffffffff)
168  {
169  NS_LOG_INFO("Start ValidTimer for " << m_prefix);
173  }
174 }
175 
176 void
178 {
180  {
181  NS_LOG_INFO("Stop PreferredTimer for " << m_prefix);
183  }
184 }
185 
186 void
188 {
189  if (m_validTimer.IsRunning())
190  {
191  NS_LOG_INFO("Stop ValidTimer for " << m_prefix);
193  }
194 }
195 
196 void
198 {
199  NS_LOG_INFO("The prefix " << m_prefix << " will be removed on interface " << m_interface);
201  ipv6->RemoveAutoconfiguredAddress(m_interface, m_prefix, m_mask, m_defaultGatewayRouter);
202 }
203 
204 void
206 {
207  m_preferred = true;
208 }
209 
210 void
212 {
213  m_preferred = false;
214  m_valid = true;
215 }
216 
217 uint32_t
219 {
220  return m_id;
221 }
222 
223 bool
225 {
226  return m_preferred;
227 }
228 
229 bool
231 {
232  return m_valid;
233 }
234 
237 {
238  return m_prefix;
239 }
240 
241 void
243 {
244  m_prefix = prefix;
245 }
246 
249 {
250  return m_mask;
251 }
252 
253 void
255 {
256  m_mask = mask;
257 }
258 
259 } /* namespace ns3 */
Describes an IPv6 address.
Definition: ipv6-address.h:49
void SetPreferred()
Set the prefix as preferred.
void FunctionValidTimeout()
Signal that the valid time expired.
Ipv6Address m_prefix
The prefix IPv6 address.
void StopValidTimer()
Stop the valid timer.
void SetInterface(uint32_t interface)
Set the interface.
uint32_t GetValidLifeTime() const
Get the prefix valid life time.
Ipv6Prefix m_mask
The prefix bitmask (length).
uint32_t GetPreferredLifeTime() const
Get the prefix preferred life time.
void RemoveMe()
Remove this prefix from the prefix list.
uint32_t m_preferredLifeTime
the preferred life time.
void SetMask(Ipv6Prefix mask)
Set the bitmask prefix.
void SetValid()
Set the prefix as valid.
static uint32_t m_prefixId
a static identifier.
bool m_preferred
true if the prefix is preferred.
void FunctionPreferredTimeout()
Signal that the preferred time expired and start the valid timer.
Ipv6Address GetPrefix() const
Get the prefix address.
void SetPrefix(Ipv6Address prefix)
Set the prefix address.
void StartPreferredTimer()
Start the preferred timer.
Ipv6Prefix GetMask() const
Get the bitmask prefix.
~Ipv6AutoconfiguredPrefix() override
Destructor.
void SetPreferredLifeTime(uint32_t p)
Set the prefix preferred life time.
uint32_t GetInterface() const
Get the interface index.
Timer m_validTimer
the timer for valid life time.
uint32_t m_validLifeTime
the valid life time.
Timer m_preferredTimer
the timer for preferred life time.
bool m_valid
true if the prefix is valid.
bool IsValid() const
Test if the prefix is valid.
void SetValidLifeTime(uint32_t v)
Set the prefix valid life time.
uint32_t m_id
the identifier of this prefix.
void StopPreferredTimer()
Stop the preferred timer.
uint32_t m_interface
The interface index (which is stored the address corresponding of the prefix).
void SetDefaultGatewayRouter(Ipv6Address router)
Set the default gateway router.
Ipv6Address GetDefaultGatewayRouter() const
Get the default gateway address.
void StartValidTimer()
Start the valid timer.
void MarkPreferredTime()
Set the prefix as preferred.
Ipv6Address m_defaultGatewayRouter
Default gateway router.
bool IsPreferred() const
Test if the prefix is preferred.
Ipv6AutoconfiguredPrefix(Ptr< Node > node, uint32_t interface, Ipv6Address prefix, Ipv6Prefix mask, uint32_t preferredLifeTime, uint32_t validLifeTime, Ipv6Address router=Ipv6Address("::"))
Constructor.
uint32_t GetId() const
Get the prefix identifier.
void MarkValidTime()
Set the prefix as valid.
IPv6 layer implementation.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void SetDelay(const Time &delay)
Definition: timer.cc:76
void SetFunction(FN fn)
Definition: timer.h:275
void Cancel()
Cancel the currently-running event if there is one.
Definition: timer.cc:108
void Schedule()
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:162
bool IsRunning() const
Definition: timer.cc:129
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.