A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-static-routing-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
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
19
20#include "ns3/assert.h"
21#include "ns3/ipv6-address.h"
22#include "ns3/ipv6-list-routing.h"
23#include "ns3/ipv6-route.h"
24#include "ns3/ipv6-routing-protocol.h"
25#include "ns3/ipv6.h"
26#include "ns3/log.h"
27#include "ns3/names.h"
28#include "ns3/node.h"
29#include "ns3/ptr.h"
30
31#include <vector>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("Ipv6StaticRoutingHelper");
37
39{
40}
41
43{
44}
45
48{
49 return new Ipv6StaticRoutingHelper(*this);
50}
51
54{
55 return CreateObject<Ipv6StaticRouting>();
56}
57
60{
61 NS_LOG_FUNCTION(this);
62 Ptr<Ipv6RoutingProtocol> ipv6rp = ipv6->GetRoutingProtocol();
63 NS_ASSERT_MSG(ipv6rp, "No routing protocol associated with Ipv6");
64 if (DynamicCast<Ipv6StaticRouting>(ipv6rp))
65 {
66 NS_LOG_LOGIC("Static routing found as the main IPv4 routing protocol.");
67 return DynamicCast<Ipv6StaticRouting>(ipv6rp);
68 }
69 if (DynamicCast<Ipv6ListRouting>(ipv6rp))
70 {
71 Ptr<Ipv6ListRouting> lrp = DynamicCast<Ipv6ListRouting>(ipv6rp);
72 int16_t priority;
73 for (uint32_t i = 0; i < lrp->GetNRoutingProtocols(); i++)
74 {
75 NS_LOG_LOGIC("Searching for static routing in list");
76 Ptr<Ipv6RoutingProtocol> temp = lrp->GetRoutingProtocol(i, priority);
77 if (DynamicCast<Ipv6StaticRouting>(temp))
78 {
79 NS_LOG_LOGIC("Found static routing in list");
80 return DynamicCast<Ipv6StaticRouting>(temp);
81 }
82 }
83 }
84 NS_LOG_LOGIC("Static routing not found");
85 return nullptr;
86}
87
88void
90 Ipv6Address source,
91 Ipv6Address group,
92 Ptr<NetDevice> input,
93 NetDeviceContainer output)
94{
95 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6>();
96
97 // We need to convert the NetDeviceContainer to an array of interface
98 // numbers
99 std::vector<uint32_t> outputInterfaces;
100 for (auto i = output.Begin(); i != output.End(); ++i)
101 {
102 Ptr<NetDevice> nd = *i;
103 int32_t interface = ipv6->GetInterfaceForDevice(nd);
104 NS_ASSERT_MSG(interface >= 0,
105 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
106 "Expected an interface associated with the device nd");
107 outputInterfaces.push_back(interface);
108 }
109
110 int32_t inputInterface = ipv6->GetInterfaceForDevice(input);
111 NS_ASSERT_MSG(inputInterface >= 0,
112 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
113 "Expected an interface associated with the device input");
115 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting(ipv6);
116 if (!ipv6StaticRouting)
117 {
118 NS_ASSERT_MSG(ipv6StaticRouting,
119 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
120 "Expected an Ipv6StaticRouting associated with this node");
121 }
122 ipv6StaticRouting->AddMulticastRoute(source, group, inputInterface, outputInterfaces);
123}
124
125void
127 Ipv6Address source,
128 Ipv6Address group,
129 std::string inputName,
130 NetDeviceContainer output)
131{
132 Ptr<NetDevice> input = Names::Find<NetDevice>(inputName);
133 AddMulticastRoute(n, source, group, input, output);
134}
135
136void
138 Ipv6Address source,
139 Ipv6Address group,
140 Ptr<NetDevice> input,
141 NetDeviceContainer output)
142{
143 Ptr<Node> n = Names::Find<Node>(nName);
144 AddMulticastRoute(n, source, group, input, output);
145}
146
147void
149 Ipv6Address source,
150 Ipv6Address group,
151 std::string inputName,
152 NetDeviceContainer output)
153{
154 Ptr<NetDevice> input = Names::Find<NetDevice>(inputName);
155 Ptr<Node> n = Names::Find<Node>(nName);
156 AddMulticastRoute(n, source, group, input, output);
157}
158
159#if 0
160void
161Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
162 Ptr<Node> n,
164{
165 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
166 int32_t interfaceSrc = ipv6->GetInterfaceForDevice (nd);
167 NS_ASSERT_MSG (interfaceSrc >= 0,
168 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
169 "Expected an interface associated with the device");
171 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting (ipv6);
172 if (!ipv6StaticRouting)
173 {
174 NS_ASSERT_MSG (ipv6StaticRouting,
175 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
176 "Expected an Ipv6StaticRouting associated with this node");
177 }
178 ipv6StaticRouting->SetDefaultMulticastRoute (interfaceSrc);
179}
180
181void
182Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
183 Ptr<Node> n,
184 std::string ndName)
185{
186 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
187 SetDefaultMulticastRoute (n, nd);
188}
189
190void
191Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
192 std::string nName,
193 Ptr<NetDevice> nd)
194{
195 Ptr<Node> n = Names::Find<Node> (nName);
196 SetDefaultMulticastRoute (n, nd);
197}
198
199void
200Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
201 std::string nName,
202 std::string ndName)
203{
204 Ptr<Node> n = Names::Find<Node> (nName);
205 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
206 SetDefaultMulticastRoute (n, nd);
207}
208#endif
209
210} // namespace ns3
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const override
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
void AddMulticastRoute(Ptr< Node > n, Ipv6Address source, Ipv6Address group, Ptr< NetDevice > input, NetDeviceContainer output)
Add a multicast route to a node and net device using explicit Ptr<Node> and Ptr<NetDevice>
Ipv6StaticRoutingHelper * Copy() const override
holds a vector of ns3::NetDevice pointers
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.