A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ripng-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "ripng-helper.h"
21
22#include "ns3/ipv6-list-routing.h"
23#include "ns3/node-list.h"
24#include "ns3/node.h"
25#include "ns3/ripng.h"
26
27#include <map>
28
29namespace ns3
30{
31
33{
34 m_factory.SetTypeId("ns3::RipNg");
35}
36
38 : m_factory(o.m_factory)
39{
42}
43
45{
47 m_interfaceMetrics.clear();
48}
49
52{
53 return new RipNgHelper(*this);
54}
55
58{
60
61 std::map<Ptr<Node>, std::set<uint32_t>>::const_iterator it = m_interfaceExclusions.find(node);
62
63 if (it != m_interfaceExclusions.end())
64 {
65 ripng->SetInterfaceExclusions(it->second);
66 }
67
68 std::map<Ptr<Node>, std::map<uint32_t, uint8_t>>::const_iterator iter =
69 m_interfaceMetrics.find(node);
70
71 if (iter != m_interfaceMetrics.end())
72 {
73 std::map<uint32_t, uint8_t>::const_iterator subiter;
74 for (subiter = iter->second.begin(); subiter != iter->second.end(); subiter++)
75 {
76 ripng->SetInterfaceMetric(subiter->first, subiter->second);
77 }
78 }
79
80 node->AggregateObject(ripng);
81 return ripng;
82}
83
84void
85RipNgHelper::Set(std::string name, const AttributeValue& value)
86{
87 m_factory.Set(name, value);
88}
89
90int64_t
92{
93 int64_t currentStream = stream;
94 Ptr<Node> node;
95 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i)
96 {
97 node = (*i);
98 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
99 NS_ASSERT_MSG(ipv6, "Ipv6 not installed on node");
100 Ptr<Ipv6RoutingProtocol> proto = ipv6->GetRoutingProtocol();
101 NS_ASSERT_MSG(proto, "Ipv6 routing not installed on node");
102 Ptr<RipNg> ripng = DynamicCast<RipNg>(proto);
103 if (ripng)
104 {
105 currentStream += ripng->AssignStreams(currentStream);
106 continue;
107 }
108 // RIPng may also be in a list
109 Ptr<Ipv6ListRouting> list = DynamicCast<Ipv6ListRouting>(proto);
110 if (list)
111 {
112 int16_t priority;
113 Ptr<Ipv6RoutingProtocol> listProto;
114 Ptr<RipNg> listRipng;
115 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
116 {
117 listProto = list->GetRoutingProtocol(i, priority);
118 listRipng = DynamicCast<RipNg>(listProto);
119 if (listRipng)
120 {
121 currentStream += listRipng->AssignStreams(currentStream);
122 break;
123 }
124 }
125 }
126 }
127 return (currentStream - stream);
128}
129
130void
132{
133 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
134 NS_ASSERT_MSG(ipv6, "Ipv6 not installed on node");
135 Ptr<Ipv6RoutingProtocol> proto = ipv6->GetRoutingProtocol();
136 NS_ASSERT_MSG(proto, "Ipv6 routing not installed on node");
137 Ptr<RipNg> ripng = DynamicCast<RipNg>(proto);
138 if (ripng)
139 {
140 ripng->AddDefaultRouteTo(nextHop, interface);
141 }
142 // RIPng may also be in a list
143 Ptr<Ipv6ListRouting> list = DynamicCast<Ipv6ListRouting>(proto);
144 if (list)
145 {
146 int16_t priority;
147 Ptr<Ipv6RoutingProtocol> listProto;
148 Ptr<RipNg> listRipng;
149 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
150 {
151 listProto = list->GetRoutingProtocol(i, priority);
152 listRipng = DynamicCast<RipNg>(listProto);
153 if (listRipng)
154 {
155 listRipng->AddDefaultRouteTo(nextHop, interface);
156 break;
157 }
158 }
159 }
160}
161
162void
164{
165 std::map<Ptr<Node>, std::set<uint32_t>>::iterator it = m_interfaceExclusions.find(node);
166
167 if (it == m_interfaceExclusions.end())
168 {
169 std::set<uint32_t> interfaces;
170 interfaces.insert(interface);
171
172 m_interfaceExclusions.insert(std::make_pair(node, interfaces));
173 }
174 else
175 {
176 it->second.insert(interface);
177 }
178}
179
180void
181RipNgHelper::SetInterfaceMetric(Ptr<Node> node, uint32_t interface, uint8_t metric)
182{
183 m_interfaceMetrics[node][interface] = metric;
184}
185
186} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Helper class that adds RIPng routing to nodes.
Definition: ripng-helper.h:43
void SetDefaultRouter(Ptr< Node > node, Ipv6Address nextHop, uint32_t interface)
Install a default route in the node.
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
Exclude an interface from RIPng protocol.
Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const override
Definition: ripng-helper.cc:57
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: ripng-helper.cc:91
RipNgHelper * Copy() const override
Definition: ripng-helper.cc:51
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
Interface Exclusion set.
Definition: ripng-helper.h:142
void Set(std::string name, const AttributeValue &value)
Definition: ripng-helper.cc:85
~RipNgHelper() override
Definition: ripng-helper.cc:44
std::map< Ptr< Node >, std::map< uint32_t, uint8_t > > m_interfaceMetrics
Interface Metric set.
Definition: ripng-helper.h:143
ObjectFactory m_factory
Object Factory.
Definition: ripng-helper.h:140
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:177
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list