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{
32 NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength));
33 if (prefixLength != 64)
34 {
36 "Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work.");
37 }
38
39 bool prefixFound = false;
40 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
41 {
42 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
43 }
44 else
45 {
46 RadvdInterface::RadvdPrefixList prefixList = m_radvdInterfaces[interface]->GetPrefixes();
48 for (iter = prefixList.begin(); iter != prefixList.end(); iter++)
49 {
50 if ((*iter)->GetNetwork() == prefix)
51 {
52 NS_LOG_LOGIC("Not adding the same prefix twice, skipping " << prefix << " "
53 << int(prefixLength));
54 prefixFound = true;
55 break;
56 }
57 }
58 }
59 if (!prefixFound)
60 {
61 Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix>(prefix, prefixLength);
62 m_radvdInterfaces[interface]->AddPrefix(routerPrefix);
63 }
64}
65
66void
68{
69 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
70 {
71 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
72 }
73 uint32_t maxRtrAdvInterval = m_radvdInterfaces[interface]->GetMaxRtrAdvInterval();
74 m_radvdInterfaces[interface]->SetDefaultLifeTime(3 * maxRtrAdvInterval / 1000);
75}
76
77void
79{
80 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
81 {
82 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
83 }
84 m_radvdInterfaces[interface]->SetDefaultLifeTime(0);
85}
86
89{
90 if (m_radvdInterfaces.find(interface) == m_radvdInterfaces.end())
91 {
92 m_radvdInterfaces[interface] = Create<RadvdInterface>(interface);
93 }
94 return m_radvdInterfaces[interface];
95}
96
97void
102
105{
106 auto radvd = m_factory.Create<Radvd>();
107 for (auto [index, interface] : m_radvdInterfaces)
108 {
109 if (!interface->GetPrefixes().empty())
110 {
111 radvd->AddConfiguration(interface);
112 }
113 }
114 node->AddApplication(radvd);
115 return radvd;
116}
117
118} /* 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.
void AddAnnouncedPrefix(uint32_t interface, const Ipv6Address &prefix, uint32_t prefixLength)
Add a new prefix to be announced through an interface.
RadvdHelper()
Constructor.
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:165
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.