A Discrete-Event Network Simulator
API
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"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE ("Ipv6AutoconfiguredPrefix");
31
33
34Ipv6AutoconfiguredPrefix::Ipv6AutoconfiguredPrefix (Ptr<Node> node, uint32_t interface, Ipv6Address prefix, Ipv6Prefix mask, uint32_t preferredLifeTime, uint32_t validLifeTime, Ipv6Address router)
35{
36 if (preferredLifeTime+validLifeTime == 0)
37 {
38 NS_LOG_WARN ("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address will be removed immediately.");
39 }
40 m_node = node;
41 m_interface = interface;
42 m_validLifeTime = validLifeTime;
43 m_preferredLifeTime = preferredLifeTime;
45 m_prefixId++;
46 m_preferred = false;
47 m_valid = false;
48 m_prefix = prefix;
49 m_mask = mask;
51}
52
54{
55}
56
58{
60}
61
63{
65}
66
68{
69 m_interface = interface;
70}
71
73{
74 return m_interface;
75}
76
78{
81 {
82 NS_LOG_WARN ("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address will be removed immediately.");
83 }
84}
85
87{
89}
90
92{
95 {
96 NS_LOG_WARN ("Ipv6AutoconfiguredPrefix: Preferred and Valid Lifetimes are zero, the address will be removed immediately.");
97 }
98}
99
101{
102 return m_validLifeTime;
103}
104
106{
107 m_preferred = true;
108}
109
111{
112 m_preferred = false;
113 m_valid = true;
114}
115
117{
118 NS_LOG_INFO ("Preferred Time expired for " << m_prefix);
119 m_preferred = false;
120 MarkValidTime ();
122}
123
125{
126 NS_LOG_INFO ("Valid Time expired for " << m_prefix);
127 m_valid = false;
128 RemoveMe ();
129}
130
132{
133 if (m_preferredLifeTime != 0xffffffff)
134 {
135 NS_LOG_INFO ("Start PreferredTimer for " << m_prefix);
139 }
140}
141
143{
144 if (m_validLifeTime != 0xffffffff)
145 {
146 NS_LOG_INFO ("Start ValidTimer for " << m_prefix);
150 }
151}
152
154{
156 {
157 NS_LOG_INFO ("Stop PreferredTimer for " << m_prefix);
159 }
160}
161
163{
165 {
166 NS_LOG_INFO ("Stop ValidTimer for " << m_prefix);
168 }
169}
170
172{
173 NS_LOG_INFO ("The prefix " << m_prefix << " will be removed on interface " << m_interface);
175 ipv6->RemoveAutoconfiguredAddress (m_interface, m_prefix, m_mask, m_defaultGatewayRouter);
176}
177
179{
180 m_preferred = true;
181}
182
184{
185 m_preferred = false;
186 m_valid = true;
187}
188
190{
191 return m_id;
192}
193
195{
196 return m_preferred;
197}
198
200{
201 return m_valid;
202}
203
205{
206 return m_prefix;
207}
208
210{
211 m_prefix = prefix;
212}
213
215{
216 return m_mask;
217}
218
220{
221 m_mask = mask;
222}
223
224} /* namespace ns3 */
225
Describes an IPv6 address.
Definition: ipv6-address.h:50
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.
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 GetValidLifeTime(void) const
Get the prefix valid life time.
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:456
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void SetDelay(const Time &delay)
Definition: timer.cc:75
void SetFunction(FN fn)
Definition: timer.h:278
bool IsRunning(void) const
Definition: timer.cc:127
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:158
void Cancel(void)
Cancel the currently-running event if there is one.
Definition: timer.cc:109
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.