A Discrete-Event Network Simulator
API
 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 
35 {
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();
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 
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 
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 
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 
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 
112 {
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 
holds a vector of ns3::Application pointers.
void EnableDefaultRouterForInterface(uint32_t interface)
Enable the router as default router for the interface.
Definition: radvd-helper.cc:73
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:147
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Ptr< RadvdInterface > GetRadvdInterface(uint32_t interface)
Get the low-level RadvdInterface specification for an interface.
Definition: radvd-helper.cc:92
Router advertisement daemon.
Definition: radvd.h:47
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:56
RadvdHelper()
Constructor.
Definition: radvd-helper.cc:34
void SetTypeId(TypeId tid)
std::map< uint32_t, Ptr< RadvdInterface > >::iterator RadvdInterfaceMapI
Container Iterator: interface index, RadvdInterface.
Definition: radvd-helper.h:108
ApplicationContainer Install(Ptr< Node > node)
Install the application in a Node.
void ClearPrefixes()
Clear the stored Prefixes.
NS_LOG_COMPONENT_DEFINE("RadvdHelper")
ObjectFactory m_factory
An object factory.
Definition: radvd-helper.h:103
Ptr< Object > Create(void) const
std::list< Ptr< RadvdPrefix > > RadvdPrefixList
Container: Ptr to RadvdPrefix.
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
void DisableDefaultRouterForInterface(uint32_t interface)
Disable the router as default router for the interface.
Definition: radvd-helper.cc:83
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
RadvdInterfaceMap m_radvdInterfaces
RadvdInterface(s)
Definition: radvd-helper.h:110
void Set(std::string name, const AttributeValue &value)
Describes an IPv6 address.
Definition: ipv6-address.h:46
#define NS_LOG_WARN(msg)
Definition: log.h:280
static TypeId GetTypeId(void)
Get the type ID.
Definition: radvd.cc:49
std::list< Ptr< RadvdPrefix > >::const_iterator RadvdPrefixListCI
Container Const Iterator: Ptr to RadvdPrefix.