A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-autoconfigured-prefix.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Telecom Bretagne
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
7 */
8
10
11#include "ipv6-l3-protocol.h"
12
13#include "ns3/log.h"
14#include "ns3/node.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("Ipv6AutoconfiguredPrefix");
20
22
24 uint32_t interface,
25 Ipv6Address prefix,
26 Ipv6Prefix mask,
27 uint32_t preferredLifeTime,
28 uint32_t validLifeTime,
29 Ipv6Address router)
30{
31 if (preferredLifeTime + validLifeTime == 0)
32 {
33 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
34 "will be removed immediately.");
35 }
36 m_node = node;
37 m_interface = interface;
38 m_validLifeTime = validLifeTime;
39 m_preferredLifeTime = preferredLifeTime;
41 m_prefixId++;
42 m_preferred = false;
43 m_valid = false;
44 m_prefix = prefix;
45 m_mask = mask;
47}
48
52
53void
58
64
65void
70
76
77void
79{
82 {
83 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
84 "will be removed immediately.");
85 }
86}
87
93
94void
96{
99 {
100 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
101 "will be removed immediately.");
102 }
103}
104
110
111void
116
117void
123
124void
126{
127 NS_LOG_INFO("Preferred Time expired for " << m_prefix);
128 m_preferred = false;
131}
132
133void
135{
136 NS_LOG_INFO("Valid Time expired for " << m_prefix);
137 m_valid = false;
138 RemoveMe();
139}
140
141void
143{
144 if (m_preferredLifeTime != 0xffffffff)
145 {
146 NS_LOG_INFO("Start PreferredTimer for " << m_prefix);
149 m_preferredTimer.Schedule();
150 }
151}
152
153void
155{
156 if (m_validLifeTime != 0xffffffff)
157 {
158 NS_LOG_INFO("Start ValidTimer for " << m_prefix);
161 m_validTimer.Schedule();
162 }
163}
164
165void
167{
168 if (m_preferredTimer.IsRunning())
169 {
170 NS_LOG_INFO("Stop PreferredTimer for " << m_prefix);
171 m_preferredTimer.Cancel();
172 }
173}
174
175void
177{
178 if (m_validTimer.IsRunning())
179 {
180 NS_LOG_INFO("Stop ValidTimer for " << m_prefix);
181 m_validTimer.Cancel();
182 }
183}
184
185void
187{
188 NS_LOG_INFO("The prefix " << m_prefix << " will be removed on interface " << m_interface);
189 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
190 ipv6->RemoveAutoconfiguredAddress(m_interface, m_prefix, m_mask, m_defaultGatewayRouter);
191}
192
193void
198
199void
201{
202 m_preferred = false;
203 m_valid = true;
204}
205
208{
209 return m_id;
210}
211
212bool
217
218bool
220{
221 return m_valid;
222}
223
226{
227 return m_prefix;
228}
229
230void
235
238{
239 return m_mask;
240}
241
242void
247
248} /* namespace ns3 */
Describes an IPv6 address.
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.