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
27{
28 static TypeId tid =
29 TypeId("ns3::Ipv6AutoconfiguredPrefix").SetParent<Object>().SetGroupName("Internet");
30 return tid;
31}
32
34 uint32_t interface,
35 Ipv6Address prefix,
36 Ipv6Prefix mask,
37 uint32_t preferredLifeTime,
38 uint32_t validLifeTime,
39 Ipv6Address router)
40{
41 if (preferredLifeTime + validLifeTime == 0)
42 {
43 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
44 "will be removed immediately.");
45 }
46 m_node = node;
47 m_interface = interface;
48 m_validLifeTime = validLifeTime;
49 m_preferredLifeTime = preferredLifeTime;
51 m_prefixId++;
52 m_preferred = false;
53 m_valid = false;
54 m_prefix = prefix;
55 m_mask = mask;
57}
58
62
63void
68
74
75void
80
86
87void
89{
92 {
93 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
94 "will be removed immediately.");
95 }
96}
97
103
104void
106{
107 m_validLifeTime = t;
109 {
110 NS_LOG_WARN("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address "
111 "will be removed immediately.");
112 }
113}
114
120
121void
126
127void
133
134void
136{
137 NS_LOG_INFO("Preferred Time expired for " << m_prefix);
138 m_preferred = false;
141}
142
143void
145{
146 NS_LOG_INFO("Valid Time expired for " << m_prefix);
147 m_valid = false;
148 RemoveMe();
149}
150
151void
153{
154 if (m_preferredLifeTime != 0xffffffff)
155 {
156 NS_LOG_INFO("Start PreferredTimer for " << m_prefix);
159 m_preferredTimer.Schedule();
160 }
161}
162
163void
165{
166 if (m_validLifeTime != 0xffffffff)
167 {
168 NS_LOG_INFO("Start ValidTimer for " << m_prefix);
171 m_validTimer.Schedule();
172 }
173}
174
175void
177{
178 if (m_preferredTimer.IsRunning())
179 {
180 NS_LOG_INFO("Stop PreferredTimer for " << m_prefix);
181 m_preferredTimer.Cancel();
182 }
183}
184
185void
187{
188 if (m_validTimer.IsRunning())
189 {
190 NS_LOG_INFO("Stop ValidTimer for " << m_prefix);
191 m_validTimer.Cancel();
192 }
193}
194
195void
197{
198 NS_LOG_INFO("The prefix " << m_prefix << " will be removed on interface " << m_interface);
199 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
200 ipv6->RemoveAutoconfiguredAddress(m_interface, m_prefix, m_mask, m_defaultGatewayRouter);
201}
202
203void
208
209void
211{
212 m_preferred = false;
213 m_valid = true;
214}
215
218{
219 return m_id;
220}
221
222bool
227
228bool
230{
231 return m_valid;
232}
233
236{
237 return m_prefix;
238}
239
240void
245
248{
249 return m_mask;
250}
251
252void
257
258} /* namespace ns3 */
Describes an IPv6 address.
void SetPreferred()
Set the prefix as preferred.
void FunctionValidTimeout()
Signal that the valid time expired.
static TypeId GetTypeId()
Get the type ID.
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.
Object()
Constructor.
Definition object.cc:96
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Every class exported by the ns3 library is enclosed in the ns3 namespace.