A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-autoconfigured-prefix.cc
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"
25 #include "ipv6-autoconfigured-prefix.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("Ipv6AutoconfiguredPrefix");
28 
29 namespace ns3
30 {
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  m_node = node;
37  m_interface = interface;
38  m_validLifeTime = validLifeTime;
39  m_preferredLifeTime = preferredLifeTime;
40  m_id = m_prefixId;
41  m_prefixId++;
42  m_preferred = false;
43  m_valid = false;
44  m_prefix = prefix;
45  m_mask = mask;
46  m_defaultGatewayRouter = router;
47 }
48 
50 {
51 }
52 
54 {
55  m_defaultGatewayRouter = router;
56 }
57 
59 {
61 }
62 
63 void Ipv6AutoconfiguredPrefix::SetInterface (uint32_t interface)
64 {
65  m_interface = interface;
66 }
67 
69 {
70  return m_interface;
71 }
72 
74 {
76 }
77 
79 {
80  return m_preferredLifeTime;
81 }
82 
84 {
85  m_validLifeTime = t;
86 }
87 
89 {
90  return m_validLifeTime;
91 }
92 
94 {
95  m_preferred = true;
96 }
97 
99 {
100  m_preferred = false;
101  m_valid = true;
102 }
103 
105 {
106  NS_LOG_INFO ("Preferred Time expired for " << m_prefix);
107  m_preferred = false;
108  MarkValidTime ();
109  StartValidTimer ();
110 }
111 
113 {
114  NS_LOG_INFO ("Valid Time expired for " << m_prefix);
115  m_valid = false;
116  RemoveMe ();
117 }
118 
120 {
121  NS_LOG_INFO ("Start PreferredTimer for " << m_prefix);
125 }
126 
128 {
129  NS_LOG_INFO ("Start ValidTimer for " << m_prefix);
133 }
134 
136 {
137  NS_LOG_INFO ("Stop PreferredTimer for " << m_prefix);
139 }
140 
142 {
143  NS_LOG_INFO ("Stop ValidTimer for " << m_prefix);
144  m_validTimer.Cancel ();
145 }
146 
148 {
149  NS_LOG_INFO ("The prefix " << m_prefix << " will be removed on interface " << m_interface);
151  ipv6->RemoveAutoconfiguredAddress (m_interface, m_prefix, m_mask, m_defaultGatewayRouter);
152 }
153 
155 {
156  m_preferred = true;
157 }
158 
160 {
161  m_preferred = false;
162  m_valid = true;
163 }
164 
166 {
167  return m_id;
168 }
169 
171 {
172  return m_preferred;
173 }
174 
176 {
177  return m_valid;
178 }
179 
181 {
182  return m_prefix;
183 }
184 
186 {
187  m_prefix = prefix;
188 }
189 
191 {
192  return m_mask;
193 }
194 
196 {
197  m_mask = mask;
198 }
199 
200 } /* namespace ns3 */
201 
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)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
Ipv6Address m_defaultGatewayRouter
Default gateway router.
void SetMask(Ipv6Prefix mask)
Set the bitmask prefix.
void Schedule(void)
Definition: timer.cc:152
void StopValidTimer()
Stop the valid timer.
void SetFunction(FN fn)
Definition: timer.h:254
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.
void SetDelay(const Time &delay)
Definition: timer.cc:69
uint32_t m_interface
The interface index (which is stored the address corresponding of the prefix).
void SetPreferredLifeTime(uint32_t p)
Set the prefix preferred life time.
uint32_t GetId() const
Get the prefix identifier.
Ipv6Address m_prefix
The prefix IP6 address.
Ipv6Address GetPrefix() const
Get the prefix address.
bool IsValid() const
Test if the prefix is valid.
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.
Ipv6Prefix GetMask() const
Get the bitmask prefix.
uint32_t m_validLifeTime
the valid life time.
void MarkValidTime()
Set the prefix as valid.
Describes an IPv6 address.
Definition: ipv6-address.h:44
uint32_t GetInterface() const
Get the interface index.
uint32_t m_preferredLifeTime
the preferred life time.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void SetPreferred()
Set the prefix as preferred.
bool m_preferred
true if the prefix is preferred.
void Cancel(void)
Definition: timer.cc:103
uint32_t GetPreferredLifeTime() const
Get the prefix preferred life time.
uint32_t GetValidLifeTime(void) const
Get the prefix valid life time.
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
Definition: ipv6-address.h:326
Ipv6Prefix m_mask
The prefix bitmask (length).
bool IsPreferred() const
Test if the prefix is preferred.
void StopPreferredTimer()
Stop the preferred timer.
bool m_valid
true if the prefix is valid.
Ipv6Address GetDefaultGatewayRouter() const
Get the default gateway address.
Ptr< T > GetObject(void) const
Definition: object.h:332
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.