A Discrete-Event Network Simulator
API
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 "radvd-helper.h"
22 #include "ns3/log.h"
23 #include "ns3/assert.h"
24 #include "ns3/radvd.h"
25 #include "ns3/radvd-interface.h"
26 #include "ns3/radvd-prefix.h"
27 
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE ("RadvdHelper");
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)
Associate an Application to this Node.
Definition: node.cc:157
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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:46
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:68
RadvdHelper()
Constructor.
Definition: radvd-helper.cc:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
std::map< uint32_t, Ptr< RadvdInterface > >::iterator RadvdInterfaceMapI
Container Iterator: interface index, RadvdInterface.
Definition: radvd-helper.h:107
ApplicationContainer Install(Ptr< Node > node)
Install the application in a Node.
void ClearPrefixes()
Clear the stored Prefixes.
ObjectFactory m_factory
An object factory.
Definition: radvd-helper.h:102
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
std::list< Ptr< RadvdPrefix > > RadvdPrefixList
Container: Ptr to RadvdPrefix.
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
void DisableDefaultRouterForInterface(uint32_t interface)
Disable the router as default router for the interface.
Definition: radvd-helper.cc:83
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:109
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Describes an IPv6 address.
Definition: ipv6-address.h:49
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
static TypeId GetTypeId(void)
Get the type ID.
Definition: radvd.cc:51
std::list< Ptr< RadvdPrefix > >::const_iterator RadvdPrefixListCI
Container Const Iterator: Ptr to RadvdPrefix.