A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
radvd-interface.cc
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;
53 }
54 
55 RadvdInterface::RadvdInterface (uint32_t interface, uint32_t maxRtrAdvInterval, uint32_t minRtrAdvInterval)
56  : m_interface (interface)
57 {
58  NS_LOG_FUNCTION (this << interface << maxRtrAdvInterval << minRtrAdvInterval);
59  NS_ASSERT (maxRtrAdvInterval > minRtrAdvInterval);
60  m_sendAdvert = true;
61  m_maxRtrAdvInterval = maxRtrAdvInterval;
62  m_minRtrAdvInterval = minRtrAdvInterval;
63  m_minDelayBetweenRAs = 3000;
64  m_managedFlag = false;
65  m_otherConfigFlag = false;
66  m_linkMtu = 0; /* 0 means not sending MTU option in RA */
67  m_reachableTime = 0; /* means unspecified for the router */
68  m_retransTimer = 0; /* means unspecified for the router */
69  m_curHopLimit = 64;
72  m_sourceLLAddress = true;
73  m_homeAgentFlag = false;
74  m_homeAgentInfo = false;
77  m_mobRtrSupportFlag = false;
78  m_intervalOpt = false;
79 }
80 
82 {
83  NS_LOG_FUNCTION (this);
84  /* clear prefixes */
85  for (RadvdPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
86  {
87  (*it) = 0;
88  }
89  m_prefixes.clear ();
90 }
91 
93 {
94  NS_LOG_FUNCTION (this << routerPrefix);
95  m_prefixes.push_back (routerPrefix);
96 }
97 
98 
100 {
101  NS_LOG_FUNCTION (this);
102  return m_interface;
103 }
104 
105 std::list<Ptr<RadvdPrefix> > RadvdInterface::GetPrefixes () const
106 {
107  NS_LOG_FUNCTION (this);
108  return m_prefixes;
109 }
110 
112 {
113  NS_LOG_FUNCTION (this);
114  return m_sendAdvert;
115 }
116 
117 void RadvdInterface::SetSendAdvert (bool sendAdvert)
118 {
119  NS_LOG_FUNCTION (this << sendAdvert);
120  m_sendAdvert = sendAdvert;
121 }
122 
124 {
125  NS_LOG_FUNCTION (this);
126  return m_maxRtrAdvInterval;
127 }
128 
129 void RadvdInterface::SetMaxRtrAdvInterval (uint32_t maxRtrAdvInterval)
130 {
131  NS_LOG_FUNCTION (this << maxRtrAdvInterval);
132  m_maxRtrAdvInterval = maxRtrAdvInterval;
133 }
134 
136 {
137  NS_LOG_FUNCTION (this);
138  return m_minRtrAdvInterval;
139 }
140 
141 void RadvdInterface::SetMinRtrAdvInterval (uint32_t minRtrAdvInterval)
142 {
143  NS_LOG_FUNCTION (this << minRtrAdvInterval);
144  m_minRtrAdvInterval = minRtrAdvInterval;
145 }
146 
148 {
149  NS_LOG_FUNCTION (this);
150  return m_minDelayBetweenRAs;
151 }
152 
153 void RadvdInterface::SetMinDelayBetweenRAs (uint32_t minDelayBetweenRAs)
154 {
155  NS_LOG_FUNCTION (this << minDelayBetweenRAs);
156  m_minDelayBetweenRAs = minDelayBetweenRAs;
157 }
158 
160 {
161  NS_LOG_FUNCTION (this);
162  return m_managedFlag;
163 }
164 
165 void RadvdInterface::SetManagedFlag (bool managedFlag)
166 {
167  NS_LOG_FUNCTION (this << managedFlag);
168  m_managedFlag = managedFlag;
169 }
170 
172 {
173  NS_LOG_FUNCTION (this);
174  return m_otherConfigFlag;
175 }
176 
177 void RadvdInterface::SetOtherConfigFlag (bool otherConfigFlag)
178 {
179  NS_LOG_FUNCTION (this << otherConfigFlag);
180  m_otherConfigFlag = otherConfigFlag;
181 }
182 
183 uint32_t RadvdInterface::GetLinkMtu () const
184 {
185  NS_LOG_FUNCTION (this);
186  return m_linkMtu;
187 }
188 
189 void RadvdInterface::SetLinkMtu (uint32_t linkMtu)
190 {
191  NS_LOG_FUNCTION (this << linkMtu);
192  m_linkMtu = linkMtu;
193 }
194 
196 {
197  NS_LOG_FUNCTION (this);
198  return m_reachableTime;
199 }
200 
201 void RadvdInterface::SetReachableTime (uint32_t reachableTime)
202 {
203  NS_LOG_FUNCTION (this << reachableTime);
204  m_reachableTime = reachableTime;
205 }
206 
208 {
209  NS_LOG_FUNCTION (this);
210  return m_defaultLifeTime;
211 }
212 
213 void RadvdInterface::SetDefaultLifeTime (uint32_t defaultLifeTime)
214 {
215  NS_LOG_FUNCTION (this << defaultLifeTime);
216  m_defaultLifeTime = defaultLifeTime;
217 }
218 
220 {
221  NS_LOG_FUNCTION (this);
222  return m_retransTimer;
223 }
224 
225 void RadvdInterface::SetRetransTimer (uint32_t retransTimer)
226 {
227  NS_LOG_FUNCTION (this << retransTimer);
228  m_retransTimer = retransTimer;
229 }
230 
232 {
233  NS_LOG_FUNCTION (this);
234  return m_curHopLimit;
235 }
236 
237 void RadvdInterface::SetCurHopLimit (uint8_t curHopLimit)
238 {
239  NS_LOG_FUNCTION (this << curHopLimit);
240  m_curHopLimit = curHopLimit;
241 }
242 
244 {
245  NS_LOG_FUNCTION (this);
246  return m_defaultPreference;
247 }
248 
249 void RadvdInterface::SetDefaultPreference (uint8_t defaultPreference)
250 {
251  NS_LOG_FUNCTION (this << defaultPreference);
252  m_defaultPreference = defaultPreference;
253 }
254 
256 {
257  NS_LOG_FUNCTION (this);
258  return m_sourceLLAddress;
259 }
260 
261 void RadvdInterface::SetSourceLLAddress (bool sourceLLAddress)
262 {
263  NS_LOG_FUNCTION (this << sourceLLAddress);
264  m_sourceLLAddress = sourceLLAddress;
265 }
266 
268 {
269  NS_LOG_FUNCTION (this);
270  return m_homeAgentFlag;
271 }
272 
273 void RadvdInterface::SetHomeAgentFlag (bool homeAgentFlag)
274 {
275  NS_LOG_FUNCTION (this << homeAgentFlag);
276  m_homeAgentFlag = homeAgentFlag;
277 }
278 
280 {
281  NS_LOG_FUNCTION (this);
282  return m_homeAgentInfo;
283 }
284 
285 void RadvdInterface::SetHomeAgentInfo (bool homeAgentInfo)
286 {
287  NS_LOG_FUNCTION (this << homeAgentInfo);
288  m_homeAgentInfo = homeAgentInfo;
289 }
290 
292 {
293  NS_LOG_FUNCTION (this);
294  return m_homeAgentLifeTime;
295 }
296 
297 void RadvdInterface::SetHomeAgentLifeTime (uint32_t homeAgentLifeTime)
298 {
299  NS_LOG_FUNCTION (this << homeAgentLifeTime);
300  m_homeAgentLifeTime = homeAgentLifeTime;
301 }
302 
304 {
305  NS_LOG_FUNCTION (this);
306  return m_homeAgentPreference;
307 }
308 
309 void RadvdInterface::SetHomeAgentPreference (uint32_t homeAgentPreference)
310 {
311  NS_LOG_FUNCTION (this << homeAgentPreference);
312  m_homeAgentPreference = homeAgentPreference;
313 }
314 
316 {
317  NS_LOG_FUNCTION (this);
318  return m_mobRtrSupportFlag;
319 }
320 
321 void RadvdInterface::SetMobRtrSupportFlag (bool mobRtrSupportFlag)
322 {
323  NS_LOG_FUNCTION (this << mobRtrSupportFlag);
324  m_mobRtrSupportFlag = mobRtrSupportFlag;
325 }
326 
328 {
329  NS_LOG_FUNCTION (this);
330  return m_intervalOpt;
331 }
332 
333 void RadvdInterface::SetIntervalOpt (bool intervalOpt)
334 {
335  NS_LOG_FUNCTION (this << intervalOpt);
336  m_intervalOpt = intervalOpt;
337 }
338 } /* namespace ns3 */
339 
std::list< Ptr< RadvdPrefix > > GetPrefixes() const
Get list of prefixes advertised for this interface.
bool m_sendAdvert
Flag whether or not router sends periodic RA and respond to RS.
uint32_t GetMinRtrAdvInterval() const
Get minimum RA interval.
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
uint32_t GetLinkMtu() const
Get link MTU.
void SetMinDelayBetweenRAs(uint32_t minDelayBetweenRAs)
Set minimum delay between RAs.
uint32_t GetInterface() const
Get interface index for this configuration.
void SetDefaultLifeTime(uint32_t defaultLifeTime)
Set default lifetime.
uint32_t m_linkMtu
Link MTU to use.
bool m_intervalOpt
Flag to add Advertisement Interval option in RA.
uint32_t m_interface
Interface to advertise RA.
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetRetransTimer() const
Get retransmission timer.
uint8_t GetCurHopLimit() const
Get current hop limit.
uint32_t m_curHopLimit
Current hop limit (TTL).
void SetMobRtrSupportFlag(bool mobRtrSupportFlag)
Set "mobile router support" flag.
void SetSendAdvert(bool sendAdvert)
Set send advert flag.
bool m_otherConfigFlag
Other configuration flag. If true host use stateful protocol for other (non-address) information...
bool m_mobRtrSupportFlag
Flag for HA to signals it supports Mobile Router registrations (NEMO Basic).
void AddPrefix(Ptr< RadvdPrefix > routerPrefix)
Add a prefix to advertise on interface.
bool IsManagedFlag() const
Is managed flag enabled ?
bool m_homeAgentInfo
Flag to add Home Agent Information option (Mobile IPv6). Currently not implemented.
uint32_t m_minDelayBetweenRAs
Minimum delay between RA in milliseconds.
uint32_t GetMinDelayBetweenRAs() const
Get minimum delay between RAs.
bool IsMobRtrSupportFlag() const
Is "mobile router support" flag enabled ?
uint32_t m_homeAgentPreference
Home agent preference. Ignored if home agent info is not set.
bool IsHomeAgentInfo() const
Is Home Agent Information option should be included in RA ?
bool IsOtherConfigFlag() const
Is "other config" flag enabled ?
uint32_t m_reachableTime
Reachable time in milliseconds.
uint32_t m_retransTimer
Retransmission timer in milliseconds.
void SetRetransTimer(uint32_t retransTimer)
Set retransmission timer.
bool IsIntervalOpt() const
Is advertisement interval option should be included in RA ?
uint8_t m_defaultPreference
Preference associated with default router. 0 = low 1 = medium 2 = high.
void SetDefaultPreference(uint8_t defaultPreference)
Set default preference.
RadvdPrefixList m_prefixes
List of prefixes to advertise.
void SetReachableTime(uint32_t reachableTime)
Set reachable time.
bool m_sourceLLAddress
Flag to add link-layer address in RA.
void SetHomeAgentPreference(uint32_t homeAgentPreference)
Set home agent preference.
void SetHomeAgentInfo(bool homeAgentFlag)
Set flag to add or not HA information option to RA.
void SetIntervalOpt(bool intervalOpt)
Set flag to add or not advertisement interval to RA.
~RadvdInterface()
Destructor.
bool m_homeAgentFlag
Flag to add HA (home agent) flag in RA.
void SetMinRtrAdvInterval(uint32_t minRtrAdvInterval)
Get minimum RA interval.
bool IsSendAdvert() const
Is send advert enabled (periodic RA and reply to RS) ?
void SetLinkMtu(uint32_t linkMtu)
Set link MTU.
bool m_managedFlag
Managed flag. If true host use the stateful protocol for address autoconfiguration.
uint32_t m_defaultLifeTime
Default life time in seconds.
void SetOtherConfigFlag(bool otherConfigFlag)
Set "other config" flag.
RadvdInterface(uint32_t interface)
Constructor.
void SetManagedFlag(bool managedFlag)
Set managed flag.
uint8_t GetDefaultPreference() const
Get default preference.
uint32_t GetHomeAgentPreference() const
Get home agent preference.
uint32_t GetMaxRtrAdvInterval() const
Get maximum RA interval.
uint32_t GetDefaultLifeTime() const
Get default lifetime.
void SetHomeAgentFlag(bool homeAgentFlag)
Set "home agent" flag.
void SetMaxRtrAdvInterval(uint32_t maxRtrAdvInterval)
Get maximum RA interval.
uint32_t GetHomeAgentLifeTime() const
Get home agent lifetime.
bool IsSourceLLAddress() const
Is source LLA option should be included in RA ?
void SetHomeAgentLifeTime(uint32_t homeAgentLifeTime)
Set home agent lifetime.
uint32_t m_homeAgentLifeTime
Home agent lifetime in seconds. Ignored if home agent info is not set.
void SetSourceLLAddress(bool sourceLLAddress)
Set flag to add or not LLA to RA.
uint32_t m_minRtrAdvInterval
Minimum RA interval in milliseconds.
void SetCurHopLimit(uint8_t curHopLimit)
Set current hop limit.
uint32_t GetReachableTime() const
Get reachable time.
bool IsHomeAgentFlag() const
Is "home agent" flag enabled ?
uint32_t m_maxRtrAdvInterval
Maximum RA interval in milliseconds.