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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#include "ripng-helper.h"
10
11#include "ns3/ipv6-list-routing.h"
12#include "ns3/node-list.h"
13#include "ns3/node.h"
14#include "ns3/ripng.h"
15
16#include <map>
17
18namespace ns3
19{
20
22{
23 m_factory.SetTypeId("ns3::RipNg");
24}
25
32
38
41{
42 return new RipNgHelper(*this);
43}
44
47{
49
50 auto it = m_interfaceExclusions.find(node);
51
52 if (it != m_interfaceExclusions.end())
53 {
54 ripng->SetInterfaceExclusions(it->second);
55 }
56
57 auto iter = m_interfaceMetrics.find(node);
58
59 if (iter != m_interfaceMetrics.end())
60 {
61 for (auto subiter = iter->second.begin(); subiter != iter->second.end(); subiter++)
62 {
63 ripng->SetInterfaceMetric(subiter->first, subiter->second);
64 }
65 }
66
67 node->AggregateObject(ripng);
68 return ripng;
69}
70
71void
72RipNgHelper::Set(std::string name, const AttributeValue& value)
73{
74 m_factory.Set(name, value);
75}
76
77int64_t
79{
80 int64_t currentStream = stream;
81 Ptr<Node> node;
82 for (auto i = c.Begin(); i != c.End(); ++i)
83 {
84 node = (*i);
85 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
86 NS_ASSERT_MSG(ipv6, "Ipv6 not installed on node");
87 Ptr<Ipv6RoutingProtocol> proto = ipv6->GetRoutingProtocol();
88 NS_ASSERT_MSG(proto, "Ipv6 routing not installed on node");
89 Ptr<RipNg> ripng = DynamicCast<RipNg>(proto);
90 if (ripng)
91 {
92 currentStream += ripng->AssignStreams(currentStream);
93 continue;
94 }
95 // RIPng may also be in a list
97 if (list)
98 {
99 int16_t priority;
100 Ptr<Ipv6RoutingProtocol> listProto;
101 Ptr<RipNg> listRipng;
102 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
103 {
104 listProto = list->GetRoutingProtocol(i, priority);
105 listRipng = DynamicCast<RipNg>(listProto);
106 if (listRipng)
107 {
108 currentStream += listRipng->AssignStreams(currentStream);
109 break;
110 }
111 }
112 }
113 }
114 return (currentStream - stream);
115}
116
117void
119{
120 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
121 NS_ASSERT_MSG(ipv6, "Ipv6 not installed on node");
122 Ptr<Ipv6RoutingProtocol> proto = ipv6->GetRoutingProtocol();
123 NS_ASSERT_MSG(proto, "Ipv6 routing not installed on node");
124 Ptr<RipNg> ripng = DynamicCast<RipNg>(proto);
125 if (ripng)
126 {
127 ripng->AddDefaultRouteTo(nextHop, interface);
128 }
129 // RIPng may also be in a list
131 if (list)
132 {
133 int16_t priority;
134 Ptr<Ipv6RoutingProtocol> listProto;
135 Ptr<RipNg> listRipng;
136 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
137 {
138 listProto = list->GetRoutingProtocol(i, priority);
139 listRipng = DynamicCast<RipNg>(listProto);
140 if (listRipng)
141 {
142 listRipng->AddDefaultRouteTo(nextHop, interface);
143 break;
144 }
145 }
146 }
147}
148
149void
151{
152 auto it = m_interfaceExclusions.find(node);
153
154 if (it == m_interfaceExclusions.end())
155 {
156 std::set<uint32_t> interfaces;
157 interfaces.insert(interface);
158
159 m_interfaceExclusions.insert(std::make_pair(node, interfaces));
160 }
161 else
162 {
163 it->second.insert(interface);
164 }
165}
166
167void
168RipNgHelper::SetInterfaceMetric(Ptr<Node> node, uint32_t interface, uint8_t metric)
169{
170 m_interfaceMetrics[node][interface] = metric;
171}
172
173} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
keep track of a set of node pointers.
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.
Helper class that adds RIPng routing to nodes.
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
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
RipNgHelper * Copy() const override
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.
void Set(std::string name, const AttributeValue &value)
~RipNgHelper() override
std::map< Ptr< Node >, std::map< uint32_t, uint8_t > > m_interfaceMetrics
Interface Metric set.
ObjectFactory m_factory
Object Factory.
RIPng Routing Protocol, defined in RFC 2080 .
Definition ripng.h:167
#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:75
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580