A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
radvd-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013 Universita' di Firenze
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19
*/
20
21
#include "ns3/log.h"
22
#include "ns3/assert.h"
23
#include "ns3/radvd.h"
24
#include "ns3/radvd-interface.h"
25
#include "ns3/radvd-prefix.h"
26
27
#include "
radvd-helper.h
"
28
29
NS_LOG_COMPONENT_DEFINE
(
"RadvdHelper"
);
30
31
namespace
ns3
32
{
33
34
RadvdHelper::RadvdHelper
()
35
{
36
m_factory
.
SetTypeId
(
Radvd::GetTypeId
());
37
}
38
39
void
RadvdHelper::AddAnnouncedPrefix
(uint32_t interface,
Ipv6Address
prefix, uint32_t prefixLength)
40
{
41
NS_LOG_FUNCTION
(
this
<<
int
(interface) << prefix <<
int
(prefixLength));
42
if
(prefixLength != 64)
43
{
44
NS_LOG_WARN
(
"Adding a non-64 prefix is generally a bad idea. Autoconfiguration might not work."
);
45
}
46
47
bool
prefixFound =
false
;
48
if
(
m_radvdInterfaces
.find(interface) ==
m_radvdInterfaces
.end())
49
{
50
m_radvdInterfaces
[interface] = Create<RadvdInterface> (interface);
51
}
52
else
53
{
54
RadvdInterface::RadvdPrefixList
prefixList =
m_radvdInterfaces
[interface]->GetPrefixes();
55
RadvdInterface::RadvdPrefixListCI
iter;
56
for
(iter=prefixList.begin(); iter!=prefixList.end(); iter++)
57
{
58
if
((*iter)->GetNetwork() == prefix)
59
{
60
NS_LOG_LOGIC
(
"Not adding the same prefix twice, skipping "
<< prefix <<
" "
<<
int
(prefixLength));
61
prefixFound =
true
;
62
break
;
63
}
64
}
65
}
66
if
(!prefixFound)
67
{
68
Ptr<RadvdPrefix>
routerPrefix = Create<RadvdPrefix> (prefix, prefixLength);
69
m_radvdInterfaces
[interface]->AddPrefix(routerPrefix);
70
}
71
}
72
73
void
RadvdHelper::EnableDefaultRouterForInterface
(uint32_t interface)
74
{
75
if
(
m_radvdInterfaces
.find(interface) ==
m_radvdInterfaces
.end())
76
{
77
m_radvdInterfaces
[interface] = Create<RadvdInterface> (interface);
78
}
79
uint32_t maxRtrAdvInterval =
m_radvdInterfaces
[interface]->GetMaxRtrAdvInterval();
80
m_radvdInterfaces
[interface]->SetDefaultLifeTime(3*maxRtrAdvInterval/1000);
81
}
82
83
void
RadvdHelper::DisableDefaultRouterForInterface
(uint32_t interface)
84
{
85
if
(
m_radvdInterfaces
.find(interface) ==
m_radvdInterfaces
.end())
86
{
87
m_radvdInterfaces
[interface] = Create<RadvdInterface> (interface);
88
}
89
m_radvdInterfaces
[interface]->SetDefaultLifeTime(0);
90
}
91
92
Ptr<RadvdInterface>
RadvdHelper::GetRadvdInterface
(uint32_t interface)
93
{
94
if
(
m_radvdInterfaces
.find(interface) ==
m_radvdInterfaces
.end())
95
{
96
m_radvdInterfaces
[interface] = Create<RadvdInterface> (interface);
97
}
98
return
m_radvdInterfaces
[interface];
99
}
100
101
void
RadvdHelper::ClearPrefixes
()
102
{
103
m_radvdInterfaces
.clear();
104
}
105
106
void
RadvdHelper::SetAttribute
(std::string name,
const
AttributeValue
& value)
107
{
108
m_factory
.
Set
(name, value);
109
}
110
111
ApplicationContainer
RadvdHelper::Install
(
Ptr<Node>
node)
112
{
113
ApplicationContainer
apps;
114
Ptr<Radvd>
radvd =
m_factory
.
Create
<
Radvd
> ();
115
for
(
RadvdInterfaceMapI
iter =
m_radvdInterfaces
.begin(); iter !=
m_radvdInterfaces
.end(); iter ++)
116
{
117
if
(!iter->second->GetPrefixes().empty())
118
{
119
radvd->AddConfiguration(iter->second);
120
}
121
}
122
node->
AddApplication
(radvd);
123
apps.
Add
(radvd);
124
return
apps;
125
}
126
127
}
/* namespace ns3 */
128
src
applications
helper
radvd-helper.cc
Generated on Fri Aug 30 2013 01:42:45 for ns-3 by
1.8.1.2