A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rip-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 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 "rip-helper.h"
10
11#include "ns3/ipv4-list-routing.h"
12#include "ns3/node-list.h"
13#include "ns3/node.h"
14#include "ns3/rip.h"
15
16namespace ns3
17{
18
20{
21 m_factory.SetTypeId("ns3::Rip");
22}
23
30
36
39{
40 return new RipHelper(*this);
41}
42
45{
47
48 auto it = m_interfaceExclusions.find(node);
49
50 if (it != m_interfaceExclusions.end())
51 {
52 rip->SetInterfaceExclusions(it->second);
53 }
54
55 auto iter = m_interfaceMetrics.find(node);
56
57 if (iter != m_interfaceMetrics.end())
58 {
59 for (auto subiter = iter->second.begin(); subiter != iter->second.end(); subiter++)
60 {
61 rip->SetInterfaceMetric(subiter->first, subiter->second);
62 }
63 }
64
65 node->AggregateObject(rip);
66 return rip;
67}
68
69void
70RipHelper::Set(std::string name, const AttributeValue& value)
71{
72 m_factory.Set(name, value);
73}
74
75int64_t
77{
78 int64_t currentStream = stream;
79 Ptr<Node> node;
80 for (auto i = c.Begin(); i != c.End(); ++i)
81 {
82 node = (*i);
83 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
84 NS_ASSERT_MSG(ipv4, "Ipv4 not installed on node");
85 Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol();
86 NS_ASSERT_MSG(proto, "Ipv4 routing not installed on node");
87 Ptr<Rip> rip = DynamicCast<Rip>(proto);
88 if (rip)
89 {
90 currentStream += rip->AssignStreams(currentStream);
91 continue;
92 }
93 // RIP may also be in a list
95 if (list)
96 {
97 int16_t priority;
99 Ptr<Rip> listRip;
100 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
101 {
102 listProto = list->GetRoutingProtocol(i, priority);
103 listRip = DynamicCast<Rip>(listProto);
104 if (listRip)
105 {
106 currentStream += listRip->AssignStreams(currentStream);
107 break;
108 }
109 }
110 }
111 }
112 return (currentStream - stream);
113}
114
115void
117{
118 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
119 NS_ASSERT_MSG(ipv4, "Ipv4 not installed on node");
120 Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol();
121 NS_ASSERT_MSG(proto, "Ipv4 routing not installed on node");
122 Ptr<Rip> rip = DynamicCast<Rip>(proto);
123 if (rip)
124 {
125 rip->AddDefaultRouteTo(nextHop, interface);
126 }
127 // RIP may also be in a list
129 if (list)
130 {
131 int16_t priority;
132 Ptr<Ipv4RoutingProtocol> listProto;
133 Ptr<Rip> listRip;
134 for (uint32_t i = 0; i < list->GetNRoutingProtocols(); i++)
135 {
136 listProto = list->GetRoutingProtocol(i, priority);
137 listRip = DynamicCast<Rip>(listProto);
138 if (listRip)
139 {
140 listRip->AddDefaultRouteTo(nextHop, interface);
141 break;
142 }
143 }
144 }
145}
146
147void
149{
150 auto it = m_interfaceExclusions.find(node);
151
152 if (it == m_interfaceExclusions.end())
153 {
154 std::set<uint32_t> interfaces;
155 interfaces.insert(interface);
156
157 m_interfaceExclusions.insert(std::make_pair(node, interfaces));
158 }
159 else
160 {
161 it->second.insert(interface);
162 }
163}
164
165void
166RipHelper::SetInterfaceMetric(Ptr<Node> node, uint32_t interface, uint8_t metric)
167{
168 m_interfaceMetrics[node][interface] = metric;
169}
170
171} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
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 RIP routing to nodes.
Definition rip-helper.h:31
std::map< Ptr< Node >, std::map< uint32_t, uint8_t > > m_interfaceMetrics
Interface Metric set.
Definition rip-helper.h:131
~RipHelper() override
Definition rip-helper.cc:31
Ptr< Ipv4RoutingProtocol > Create(Ptr< Node > node) const override
Definition rip-helper.cc:44
RipHelper * Copy() const override
Definition rip-helper.cc:38
void Set(std::string name, const AttributeValue &value)
Definition rip-helper.cc:70
void ExcludeInterface(Ptr< Node > node, uint32_t interface)
Exclude an interface from RIP protocol.
void SetDefaultRouter(Ptr< Node > node, Ipv4Address nextHop, uint32_t interface)
Install a default route in the node.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition rip-helper.cc:76
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
ObjectFactory m_factory
Object Factory.
Definition rip-helper.h:128
std::map< Ptr< Node >, std::set< uint32_t > > m_interfaceExclusions
Interface Exclusion set.
Definition rip-helper.h:130
RIP Routing Protocol, defined in RFC 2453 .
Definition rip.h:165
#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