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 : ApplicationHelper(Radvd::GetTypeId())
35{
36}
37
38void
40 const Ipv6Address& prefix,
41 uint32_t prefixLength)
42{
43 NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength));
44 if (prefixLength != 64)
45 {
47 "Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work.");
48 }
49
50 bool prefixFound = false;
51 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
52 {
53 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
54 }
55 else
56 {
57 RadvdInterface::RadvdPrefixList prefixList = m_radvdInterfaces[interface]->GetPrefixes();
59 for (iter = prefixList.begin(); iter != prefixList.end(); iter++)
60 {
61 if ((*iter)->GetNetwork() == prefix)
62 {
63 NS_LOG_LOGIC("Not adding the same prefix twice, skipping " << prefix << " "
64 << int(prefixLength));
65 prefixFound = true;
66 break;
67 }
68 }
69 }
70 if (!prefixFound)
71 {
72 Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix>(prefix, prefixLength);
73 m_radvdInterfaces[interface]->AddPrefix(routerPrefix);
74 }
75}
76
77void
79{
80 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
81 {
82 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
83 }
84 uint32_t maxRtrAdvInterval = m_radvdInterfaces[interface]->GetMaxRtrAdvInterval();
85 m_radvdInterfaces[interface]->SetDefaultLifeTime(3 * maxRtrAdvInterval / 1000);
86}
87
88void
90{
91 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
92 {
93 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
94 }
95 m_radvdInterfaces[interface]->SetDefaultLifeTime(0);
96}
97
100{
101 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
102 {
103 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
104 }
105 return m_radvdInterfaces[interface];
106}
107
108void
110{
111 m_radvdInterfaces.clear();
112}
113
116{
117 auto radvd = m_factory.Create<Radvd>();
118 for (auto [index, interface] : m_radvdInterfaces)
119 {
120 if (!interface->GetPrefixes().empty())
121 {
122 radvd->AddConfiguration(interface);
123 }
124 }
125 node->AddApplication(radvd);
126 return radvd;
127}
128
129} /* namespace ns3 */
A helper to make it easier to instantiate an application on a set of nodes.
ObjectFactory m_factory
Object factory.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
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:78
void AddAnnouncedPrefix(uint32_t interface, const Ipv6Address &prefix, uint32_t prefixLength)
Add a new prefix to be announced through an interface.
Definition: radvd-helper.cc:39
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:89
RadvdInterfaceMap m_radvdInterfaces
RadvdInterface(s)
Definition: radvd-helper.h:87
Ptr< Application > DoInstall(Ptr< Node > node) override
Install an application on the node configured with all the attributes set with SetAttribute.
Ptr< RadvdInterface > GetRadvdInterface(uint32_t interface)
Get the low-level RadvdInterface specification for an interface.
Definition: radvd-helper.cc:99
void ClearPrefixes()
Clear the stored Prefixes.
Router advertisement daemon.
Definition: radvd.h:47
void AddConfiguration(Ptr< RadvdInterface > routerInterface)
Add configuration for an interface;.
Definition: radvd.cc:176
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.