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 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv6AutoconfiguredPrefix");
31 
33 
34 Ipv6AutoconfiguredPrefix::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;
44  m_id = m_prefixId;
45  m_prefixId++;
46  m_preferred = false;
47  m_valid = false;
48  m_prefix = prefix;
49  m_mask = mask;
50  m_defaultGatewayRouter = router;
51 }
52 
54 {
55 }
56 
58 {
59  m_defaultGatewayRouter = router;
60 }
61 
63 {
65 }
66 
67 void Ipv6AutoconfiguredPrefix::SetInterface (uint32_t interface)
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 {
88  return m_preferredLifeTime;
89 }
90 
92 {
93  m_validLifeTime = t;
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 ();
121  StartValidTimer ();
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 {
164  if (m_validTimer.IsRunning())
165  {
166  NS_LOG_INFO ("Stop ValidTimer for " << m_prefix);
167  m_validTimer.Cancel ();
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 
void SetDefaultGatewayRouter(Ipv6Address router)
Set the default gateway router.
void SetInterface(uint32_t interface)
Set the interface.
IPv6 layer implementation.
void RemoveMe()
Remove this prefix from the prefix list.
Ipv6AutoconfiguredPrefix(Ptr< Node > node, uint32_t interface, Ipv6Address prefix, Ipv6Prefix mask, uint32_t preferredLifeTime, uint32_t validLifeTime, Ipv6Address router=Ipv6Address("::"))
Constructor.
void SetValidLifeTime(uint32_t v)
Set the prefix valid life time.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
bool IsPreferred() const
Test if the prefix is preferred.
Ipv6Address m_defaultGatewayRouter
Default gateway router.
Ipv6Address GetPrefix() const
Get the prefix address.
uint32_t GetInterface() const
Get the interface index.
uint32_t GetId() const
Get the prefix identifier.
void SetMask(Ipv6Prefix mask)
Set the bitmask prefix.
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition: timer.cc:158
void StopValidTimer()
Stop the valid timer.
void SetFunction(FN fn)
Definition: timer.h:309
void StartValidTimer()
Start the valid timer.
void FunctionValidTimeout()
Signal that the valid time expired.
void SetValid()
Set the prefix as valid.
uint32_t m_id
the identifier of this prefix.
uint32_t GetValidLifeTime(void) const
Get the prefix valid life time.
void SetDelay(const Time &delay)
Definition: timer.cc:75
uint32_t m_interface
The interface index (which is stored the address corresponding of the prefix).
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
void SetPreferredLifeTime(uint32_t p)
Set the prefix preferred life time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv6Address m_prefix
The prefix IPv6 address.
static uint32_t m_prefixId
a static identifier.
void FunctionPreferredTimeout()
Signal that the preferred time expired and start the valid timer.
Timer m_validTimer
the timer for valid life time.
uint32_t m_validLifeTime
the valid life time.
bool IsRunning(void) const
Definition: timer.cc:127
void MarkValidTime()
Set the prefix as valid.
Describes an IPv6 address.
Definition: ipv6-address.h:49
uint32_t m_preferredLifeTime
the preferred life time.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:264
void SetPreferred()
Set the prefix as preferred.
bool IsValid() const
Test if the prefix is valid.
bool m_preferred
true if the prefix is preferred.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void Cancel(void)
Cancel the currently-running event if there is one.
Definition: timer.cc:109
Describes an IPv6 prefix.
Definition: ipv6-address.h:449
Ipv6Prefix m_mask
The prefix bitmask (length).
void StopPreferredTimer()
Stop the preferred timer.
bool m_valid
true if the prefix is valid.
Ipv6Address GetDefaultGatewayRouter() const
Get the default gateway address.
Ipv6Prefix GetMask() const
Get the bitmask prefix.
uint32_t GetPreferredLifeTime() const
Get the prefix preferred life time.
void StartPreferredTimer()
Start the preferred timer.
void SetPrefix(Ipv6Address prefix)
Set the prefix address.
Timer m_preferredTimer
the timer for preferred life time.
void MarkPreferredTime()
Set the prefix as preferred.