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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#include "radvd-helper.h"
10
11#include "ns3/assert.h"
12#include "ns3/log.h"
13#include "ns3/radvd-interface.h"
14#include "ns3/radvd-prefix.h"
15#include "ns3/radvd.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("RadvdHelper");
21
26
27void
29 const Ipv6Address& prefix,
30 uint32_t prefixLength,
31 bool slaac)
32{
33 NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength));
34 if (prefixLength != 64)
35 {
37 "Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work.");
38 }
39
40 bool prefixFound = false;
41 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
42 {
43 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
44 }
45 else
46 {
47 RadvdInterface::RadvdPrefixList prefixList = m_radvdInterfaces[interface]->GetPrefixes();
49 for (iter = prefixList.begin(); iter != prefixList.end(); iter++)
50 {
51 if ((*iter)->GetNetwork() == prefix)
52 {
53 NS_LOG_LOGIC("Not adding the same prefix twice, skipping " << prefix << " "
54 << int(prefixLength));
55 prefixFound = true;
56 break;
57 }
58 }
59 }
60 if (!prefixFound)
61 {
62 Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix>(prefix, prefixLength);
63 routerPrefix->SetAutonomousFlag(slaac);
64 m_radvdInterfaces[interface]->AddPrefix(routerPrefix);
65 }
66}
67
68void
70{
71 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
72 {
73 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
74 }
75 uint32_t maxRtrAdvInterval = m_radvdInterfaces[interface]->GetMaxRtrAdvInterval();
76 m_radvdInterfaces[interface]->SetDefaultLifeTime(3 * maxRtrAdvInterval / 1000);
77}
78
79void
81{
82 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
83 {
84 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
85 }
86 m_radvdInterfaces[interface]->SetDefaultLifeTime(0);
87}
88
91{
92 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
93 {
94 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
95 }
96 return m_radvdInterfaces[interface];
97}
98
99void
104
107{
108 auto radvd = m_factory.Create<Radvd>();
109 for (auto [index, interface] : m_radvdInterfaces)
110 {
111 if (!interface->GetPrefixes().empty())
112 {
113 radvd->AddConfiguration(interface);
114 }
115 }
116 node->AddApplication(radvd);
117 return radvd;
118}
119
120} /* 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.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
Smart pointer class similar to boost::intrusive_ptr.
void EnableDefaultRouterForInterface(uint32_t interface)
Enable the router as default router for the interface.
RadvdHelper()
Constructor.
void AddAnnouncedPrefix(uint32_t interface, const Ipv6Address &prefix, uint32_t prefixLength, bool slaac=true)
Add a new prefix to be announced through an interface.
void DisableDefaultRouterForInterface(uint32_t interface)
Disable the router as default router for the interface.
RadvdInterfaceMap m_radvdInterfaces
RadvdInterface(s)
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.
void ClearPrefixes()
Clear the stored Prefixes.
Router advertisement daemon.
Definition radvd.h:36
void AddConfiguration(Ptr< RadvdInterface > routerInterface)
Add configuration for an interface;.
Definition radvd.cc:171
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:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:250
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.