A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
radvd-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Universita' di Firenze
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "radvd-helper.h"
21
22#include "ns3/assert.h"
23#include "ns3/log.h"
24#include "ns3/radvd-interface.h"
25#include "ns3/radvd-prefix.h"
26#include "ns3/radvd.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("RadvdHelper");
32
34{
36}
37
38void
40{
41 NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength));
42 if (prefixLength != 64)
43 {
45 "Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work.");
46 }
47
48 bool prefixFound = false;
49 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
50 {
51 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
52 }
53 else
54 {
55 RadvdInterface::RadvdPrefixList prefixList = m_radvdInterfaces[interface]->GetPrefixes();
57 for (iter = prefixList.begin(); iter != prefixList.end(); iter++)
58 {
59 if ((*iter)->GetNetwork() == prefix)
60 {
61 NS_LOG_LOGIC("Not adding the same prefix twice, skipping " << prefix << " "
62 << int(prefixLength));
63 prefixFound = true;
64 break;
65 }
66 }
67 }
68 if (!prefixFound)
69 {
70 Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix>(prefix, prefixLength);
71 m_radvdInterfaces[interface]->AddPrefix(routerPrefix);
72 }
73}
74
75void
77{
78 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
79 {
80 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
81 }
82 uint32_t maxRtrAdvInterval = m_radvdInterfaces[interface]->GetMaxRtrAdvInterval();
83 m_radvdInterfaces[interface]->SetDefaultLifeTime(3 * maxRtrAdvInterval / 1000);
84}
85
86void
88{
89 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
90 {
91 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
92 }
93 m_radvdInterfaces[interface]->SetDefaultLifeTime(0);
94}
95
98{
99 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
100 {
101 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
102 }
103 return m_radvdInterfaces[interface];
104}
105
106void
108{
109 m_radvdInterfaces.clear();
110}
111
112void
113RadvdHelper::SetAttribute(std::string name, const AttributeValue& value)
114{
115 m_factory.Set(name, value);
116}
117
120{
122 Ptr<Radvd> radvd = m_factory.Create<Radvd>();
123 for (auto iter = m_radvdInterfaces.begin(); iter != m_radvdInterfaces.end(); iter++)
124 {
125 if (!iter->second->GetPrefixes().empty())
126 {
127 radvd->AddConfiguration(iter->second);
128 }
129 }
130 node->AddApplication(radvd);
131 apps.Add(radvd);
132 return apps;
133}
134
135} /* namespace ns3 */
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Hold a value for an Attribute.
Definition: attribute.h:70
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
void EnableDefaultRouterForInterface(uint32_t interface)
Enable the router as default router for the interface.
Definition: radvd-helper.cc:76
ObjectFactory m_factory
An object factory.
Definition: radvd-helper.h:101
void AddAnnouncedPrefix(uint32_t interface, Ipv6Address prefix, uint32_t prefixLength)
Add a new prefix to be announced through an interface.
Definition: radvd-helper.cc:39
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
RadvdHelper()
Constructor.
Definition: radvd-helper.cc:33
void DisableDefaultRouterForInterface(uint32_t interface)
Disable the router as default router for the interface.
Definition: radvd-helper.cc:87
RadvdInterfaceMap m_radvdInterfaces
RadvdInterface(s)
Definition: radvd-helper.h:108
ApplicationContainer Install(Ptr< Node > node)
Install the application in a Node.
Ptr< RadvdInterface > GetRadvdInterface(uint32_t interface)
Get the low-level RadvdInterface specification for an interface.
Definition: radvd-helper.cc:97
void ClearPrefixes()
Clear the stored Prefixes.
Router advertisement daemon.
Definition: radvd.h:47
static TypeId GetTypeId()
Get the type ID.
Definition: radvd.cc:53
std::list< Ptr< RadvdPrefix > > RadvdPrefixList
Container: Ptr to RadvdPrefix.
std::list< Ptr< RadvdPrefix > >::const_iterator RadvdPrefixListCI
Container Const Iterator: Ptr to RadvdPrefix.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
Every class exported by the ns3 library is enclosed in the ns3 namespace.