A Discrete-Event Network Simulator
API
radvd-interface.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "radvd-interface.h"
22 #include <ns3/log.h>
23 
24 namespace ns3
25 {
26 
27 NS_LOG_COMPONENT_DEFINE ("RadvdInterface");
28 
29 RadvdInterface::RadvdInterface (uint32_t interface)
30  : m_interface (interface)
31 {
32  NS_LOG_FUNCTION (this << interface);
33  /* initialize default value as specified in radvd.conf manpage */
34  m_sendAdvert = true;
35  m_maxRtrAdvInterval = 600000;
36  m_minRtrAdvInterval = (uint32_t)(double) (0.33 * m_maxRtrAdvInterval);
37  m_minDelayBetweenRAs = 3000;
38  m_managedFlag = false;
39  m_otherConfigFlag = false;
40  m_linkMtu = 0; /* 0 means not sending MTU option in RA */
41  m_reachableTime = 0; /* means unspecified for the router */
42  m_retransTimer = 0; /* means unspecified for the router */
43  m_curHopLimit = 64;
46  m_sourceLLAddress = true;
47  m_homeAgentFlag = false;
48  m_homeAgentInfo = false;
51  m_mobRtrSupportFlag = false;
52  m_intervalOpt = false;
54 }
55 
56 RadvdInterface::RadvdInterface (uint32_t interface, uint32_t maxRtrAdvInterval, uint32_t minRtrAdvInterval)
57  : m_interface (interface)
58 {
59  NS_LOG_FUNCTION (this << interface << maxRtrAdvInterval << minRtrAdvInterval);
60  NS_ASSERT (maxRtrAdvInterval > minRtrAdvInterval);
61  m_sendAdvert = true;
62  m_maxRtrAdvInterval = maxRtrAdvInterval;
63  m_minRtrAdvInterval = minRtrAdvInterval;
64  m_minDelayBetweenRAs = 3000;
65  m_managedFlag = false;
66  m_otherConfigFlag = false;
67  m_linkMtu = 0; /* 0 means not sending MTU option in RA */
68  m_reachableTime = 0; /* means unspecified for the router */
69  m_retransTimer = 0; /* means unspecified for the router */
70  m_curHopLimit = 64;
73  m_sourceLLAddress = true;
74  m_homeAgentFlag = false;
75  m_homeAgentInfo = false;
78  m_mobRtrSupportFlag = false;
79  m_intervalOpt = false;
81 }
82 
84 {
85  NS_LOG_FUNCTION (this);
86  /* clear prefixes */
87  for (RadvdPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
88  {
89  (*it) = 0;
90  }
91  m_prefixes.clear ();
92 }
93 
95 {
96  NS_LOG_FUNCTION (this << routerPrefix);
97  m_prefixes.push_back (routerPrefix);
98 }
99 
100 
102 {
103  NS_LOG_FUNCTION (this);
104  return m_interface;
105 }
106 
107 std::list<Ptr<RadvdPrefix> > RadvdInterface::GetPrefixes () const
108 {
109  NS_LOG_FUNCTION (this);
110  return m_prefixes;
111 }
112 
114 {
115  NS_LOG_FUNCTION (this);
116  return m_sendAdvert;
117 }
118 
119 void RadvdInterface::SetSendAdvert (bool sendAdvert)
120 {
121  NS_LOG_FUNCTION (this << sendAdvert);
122  m_sendAdvert = sendAdvert;
123 }
124 
126 {
127  NS_LOG_FUNCTION (this);
128  return m_maxRtrAdvInterval;
129 }
130 
131 void RadvdInterface::SetMaxRtrAdvInterval (uint32_t maxRtrAdvInterval)
132 {
133  NS_LOG_FUNCTION (this << maxRtrAdvInterval);
134  m_maxRtrAdvInterval = maxRtrAdvInterval;
135 }
136 
138 {
139  NS_LOG_FUNCTION (this);
140  return m_minRtrAdvInterval;
141 }
142 
143 void RadvdInterface::SetMinRtrAdvInterval (uint32_t minRtrAdvInterval)
144 {
145  NS_LOG_FUNCTION (this << minRtrAdvInterval);
146  m_minRtrAdvInterval = minRtrAdvInterval;
147 }
148 
150 {
151  NS_LOG_FUNCTION (this);
152  return m_minDelayBetweenRAs;
153 }
154 
155 void RadvdInterface::SetMinDelayBetweenRAs (uint32_t minDelayBetweenRAs)
156 {
157  NS_LOG_FUNCTION (this << minDelayBetweenRAs);
158  m_minDelayBetweenRAs = minDelayBetweenRAs;
159 }
160 
162 {
163  NS_LOG_FUNCTION (this);
164  return m_managedFlag;
165 }
166 
167 void RadvdInterface::SetManagedFlag (bool managedFlag)
168 {
169  NS_LOG_FUNCTION (this << managedFlag);
170  m_managedFlag = managedFlag;
171 }
172 
174 {
175  NS_LOG_FUNCTION (this);
176  return m_otherConfigFlag;
177 }
178 
179 void RadvdInterface::SetOtherConfigFlag (bool otherConfigFlag)
180 {
181  NS_LOG_FUNCTION (this << otherConfigFlag);
182  m_otherConfigFlag = otherConfigFlag;
183 }
184 
185 uint32_t RadvdInterface::GetLinkMtu () const
186 {
187  NS_LOG_FUNCTION (this);
188  return m_linkMtu;
189 }
190 
191 void RadvdInterface::SetLinkMtu (uint32_t linkMtu)
192 {
193  NS_LOG_FUNCTION (this << linkMtu);
194  m_linkMtu = linkMtu;
195 }
196 
198 {
199  NS_LOG_FUNCTION (this);
200  return m_reachableTime;
201 }
202 
203 void RadvdInterface::SetReachableTime (uint32_t reachableTime)
204 {
205  NS_LOG_FUNCTION (this << reachableTime);
206  m_reachableTime = reachableTime;
207 }
208 
210 {
211  NS_LOG_FUNCTION (this);
212  return m_defaultLifeTime;
213 }
214 
215 void RadvdInterface::SetDefaultLifeTime (uint32_t defaultLifeTime)
216 {
217  NS_LOG_FUNCTION (this << defaultLifeTime);
218  m_defaultLifeTime = defaultLifeTime;
219 }
220 
222 {
223  NS_LOG_FUNCTION (this);
224  return m_retransTimer;
225 }
226 
227 void RadvdInterface::SetRetransTimer (uint32_t retransTimer)
228 {
229  NS_LOG_FUNCTION (this << retransTimer);
230  m_retransTimer = retransTimer;
231 }
232 
234 {
235  NS_LOG_FUNCTION (this);
236  return m_curHopLimit;
237 }
238 
239 void RadvdInterface::SetCurHopLimit (uint8_t curHopLimit)
240 {
241  NS_LOG_FUNCTION (this << curHopLimit);
242  m_curHopLimit = curHopLimit;
243 }
244 
246 {
247  NS_LOG_FUNCTION (this);
248  return m_defaultPreference;
249 }
250 
251 void RadvdInterface::SetDefaultPreference (uint8_t defaultPreference)
252 {
253  NS_LOG_FUNCTION (this << defaultPreference);
254  m_defaultPreference = defaultPreference;
255 }
256 
258 {
259  NS_LOG_FUNCTION (this);
260  return m_sourceLLAddress;
261 }
262 
263 void RadvdInterface::SetSourceLLAddress (bool sourceLLAddress)
264 {
265  NS_LOG_FUNCTION (this << sourceLLAddress);
266  m_sourceLLAddress = sourceLLAddress;
267 }
268 
270 {
271  NS_LOG_FUNCTION (this);
272  return m_homeAgentFlag;
273 }
274 
275 void RadvdInterface::SetHomeAgentFlag (bool homeAgentFlag)
276 {
277  NS_LOG_FUNCTION (this << homeAgentFlag);
278  m_homeAgentFlag = homeAgentFlag;
279 }
280 
282 {
283  NS_LOG_FUNCTION (this);
284  return m_homeAgentInfo;
285 }
286 
287 void RadvdInterface::SetHomeAgentInfo (bool homeAgentInfo)
288 {
289  NS_LOG_FUNCTION (this << homeAgentInfo);
290  m_homeAgentInfo = homeAgentInfo;
291 }
292 
294 {
295  NS_LOG_FUNCTION (this);
296  return m_homeAgentLifeTime;
297 }
298 
299 void RadvdInterface::SetHomeAgentLifeTime (uint32_t homeAgentLifeTime)
300 {
301  NS_LOG_FUNCTION (this << homeAgentLifeTime);
302  m_homeAgentLifeTime = homeAgentLifeTime;
303 }
304 
306 {
307  NS_LOG_FUNCTION (this);
308  return m_homeAgentPreference;
309 }
310 
311 void RadvdInterface::SetHomeAgentPreference (uint32_t homeAgentPreference)
312 {
313  NS_LOG_FUNCTION (this << homeAgentPreference);
314  m_homeAgentPreference = homeAgentPreference;
315 }
316 
318 {
319  NS_LOG_FUNCTION (this);
320  return m_mobRtrSupportFlag;
321 }
322 
323 void RadvdInterface::SetMobRtrSupportFlag (bool mobRtrSupportFlag)
324 {
325  NS_LOG_FUNCTION (this << mobRtrSupportFlag);
326  m_mobRtrSupportFlag = mobRtrSupportFlag;
327 }
328 
330 {
331  NS_LOG_FUNCTION (this);
332  return m_intervalOpt;
333 }
334 
335 void RadvdInterface::SetIntervalOpt (bool intervalOpt)
336 {
337  NS_LOG_FUNCTION (this << intervalOpt);
338  m_intervalOpt = intervalOpt;
339 }
340 
342 {
343  return m_lastSendTime;
344 }
345 
347 {
348  m_lastSendTime = now;
350  {
352  }
353 }
354 
356 {
358 }
359 
360 } /* namespace ns3 */
361 
RadvdInterface(uint32_t interface)
Constructor.
bool IsMobRtrSupportFlag() const
Is "mobile router support" flag enabled ?
void SetMinDelayBetweenRAs(uint32_t minDelayBetweenRAs)
Set minimum delay between RAs.
uint8_t m_initialRtrAdvertisementsLeft
Number of fast announcement to do.
void SetSourceLLAddress(bool sourceLLAddress)
Set flag to add or not LLA to RA.
bool IsIntervalOpt() const
Is advertisement interval option should be included in RA ?
uint32_t m_reachableTime
Reachable time in milliseconds.
uint32_t GetMinDelayBetweenRAs() const
Get minimum delay between RAs.
~RadvdInterface()
Destructor.
uint32_t m_defaultLifeTime
Default life time in seconds.
bool IsInitialRtrAdv()
Checks if the interface is subject to the initial Rtr Advertisements rule.
void SetSendAdvert(bool sendAdvert)
Set send advert flag.
std::list< Ptr< RadvdPrefix > >::iterator RadvdPrefixListI
Container Iterator: Ptr to RadvdPrefix.
void SetLinkMtu(uint32_t linkMtu)
Set link MTU.
void SetDefaultLifeTime(uint32_t defaultLifeTime)
Set default lifetime.
uint32_t m_maxRtrAdvInterval
Maximum RA interval in milliseconds.
void SetHomeAgentFlag(bool homeAgentFlag)
Set "home agent" flag.
bool m_sourceLLAddress
Flag to add link-layer address in RA.
uint32_t GetDefaultLifeTime() const
Get default lifetime.
bool m_sendAdvert
Flag whether or not router sends periodic RA and respond to RS.
void AddPrefix(Ptr< RadvdPrefix > routerPrefix)
Add a prefix to advertise on interface.
bool IsHomeAgentInfo() const
Is Home Agent Information option should be included in RA ?
uint8_t m_defaultPreference
Preference associated with default router.
void SetMobRtrSupportFlag(bool mobRtrSupportFlag)
Set "mobile router support" flag.
Time GetLastRaTxTime()
Get the last time a RA has been sent.
bool m_homeAgentInfo
Flag to add Home Agent Information option (Mobile IPv6).
void SetLastRaTxTime(Time now)
Set the last RA send time.
uint32_t m_homeAgentLifeTime
Home agent lifetime in seconds.
bool m_intervalOpt
Flag to add Advertisement Interval option in RA.
uint32_t GetMaxRtrAdvInterval() const
Get maximum RA interval.
uint32_t GetInterface() const
Get interface index for this configuration.
bool m_otherConfigFlag
Other configuration flag.
uint32_t GetMinRtrAdvInterval() const
Get minimum RA interval.
Time m_lastSendTime
Last RA send time.
uint32_t m_retransTimer
Retransmission timer in milliseconds.
RadvdPrefixList GetPrefixes() const
Get list of prefixes advertised for this interface.
void SetHomeAgentPreference(uint32_t homeAgentPreference)
Set home agent preference.
uint32_t GetRetransTimer() const
Get retransmission timer.
RadvdPrefixList m_prefixes
List of prefixes to advertise.
bool IsHomeAgentFlag() const
Is "home agent" flag enabled ?
uint32_t GetReachableTime() const
Get reachable time.
bool m_managedFlag
Managed flag.
void SetIntervalOpt(bool intervalOpt)
Set flag to add or not advertisement interval to RA.
void SetRetransTimer(uint32_t retransTimer)
Set retransmission timer.
void SetCurHopLimit(uint8_t curHopLimit)
Set current hop limit.
void SetDefaultPreference(uint8_t defaultPreference)
Set default preference.
void SetMaxRtrAdvInterval(uint32_t maxRtrAdvInterval)
Get maximum RA interval.
uint32_t m_interface
Interface to advertise RA.
bool m_homeAgentFlag
Flag to add HA (home agent) flag in RA.
void SetOtherConfigFlag(bool otherConfigFlag)
Set "other config" flag.
bool IsSendAdvert() const
Is send advert enabled (periodic RA and reply to RS) ?
uint8_t GetDefaultPreference() const
Get default preference.
void SetMinRtrAdvInterval(uint32_t minRtrAdvInterval)
Get minimum RA interval.
bool IsOtherConfigFlag() const
Is "other config" flag enabled ?
uint32_t GetHomeAgentLifeTime() const
Get home agent lifetime.
bool m_mobRtrSupportFlag
Flag for HA to signals it supports Mobile Router registrations (NEMO Basic).
uint32_t m_minDelayBetweenRAs
Minimum delay between RA in milliseconds.
uint8_t GetCurHopLimit() const
Get current hop limit.
uint32_t m_curHopLimit
Current hop limit (TTL).
uint32_t GetLinkMtu() const
Get link MTU.
uint32_t m_minRtrAdvInterval
Minimum RA interval in milliseconds.
uint32_t m_homeAgentPreference
Home agent preference.
uint32_t GetHomeAgentPreference() const
Get home agent preference.
void SetManagedFlag(bool managedFlag)
Set managed flag.
void SetHomeAgentInfo(bool homeAgentFlag)
Set flag to add or not HA information option to RA.
bool IsSourceLLAddress() const
Is source LLA option should be included in RA ?
uint32_t m_linkMtu
Link MTU to use.
bool IsManagedFlag() const
Is managed flag enabled ?
void SetHomeAgentLifeTime(uint32_t homeAgentLifeTime)
Set home agent lifetime.
void SetReachableTime(uint32_t reachableTime)
Set reachable time.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.