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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "ns3/assert.h"
10#include "ns3/ipv6-address.h"
11#include "ns3/ipv6-list-routing.h"
12#include "ns3/ipv6-route.h"
13#include "ns3/ipv6-routing-protocol.h"
14#include "ns3/ipv6.h"
15#include "ns3/log.h"
16#include "ns3/names.h"
17#include "ns3/node.h"
18#include "ns3/ptr.h"
19
20#include <vector>
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("Ipv6StaticRoutingHelper");
26
30
34
37{
38 return new Ipv6StaticRoutingHelper(*this);
39}
40
46
49{
50 NS_LOG_FUNCTION(this);
51 Ptr<Ipv6RoutingProtocol> ipv6rp = ipv6->GetRoutingProtocol();
52 NS_ASSERT_MSG(ipv6rp, "No routing protocol associated with Ipv6");
54 {
55 NS_LOG_LOGIC("Static routing found as the main IPv4 routing protocol.");
56 return DynamicCast<Ipv6StaticRouting>(ipv6rp);
57 }
59 {
61 int16_t priority;
62 for (uint32_t i = 0; i < lrp->GetNRoutingProtocols(); i++)
63 {
64 NS_LOG_LOGIC("Searching for static routing in list");
65 Ptr<Ipv6RoutingProtocol> temp = lrp->GetRoutingProtocol(i, priority);
67 {
68 NS_LOG_LOGIC("Found static routing in list");
70 }
71 }
72 }
73 NS_LOG_LOGIC("Static routing not found");
74 return nullptr;
75}
76
77void
79 Ipv6Address source,
80 Ipv6Address group,
81 Ptr<NetDevice> input,
82 NetDeviceContainer output)
83{
84 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6>();
85
86 // We need to convert the NetDeviceContainer to an array of interface
87 // numbers
88 std::vector<uint32_t> outputInterfaces;
89 for (auto i = output.Begin(); i != output.End(); ++i)
90 {
91 Ptr<NetDevice> nd = *i;
92 int32_t interface = ipv6->GetInterfaceForDevice(nd);
93 NS_ASSERT_MSG(interface >= 0,
94 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
95 "Expected an interface associated with the device nd");
96 outputInterfaces.push_back(interface);
97 }
98
99 int32_t inputInterface = ipv6->GetInterfaceForDevice(input);
100 NS_ASSERT_MSG(inputInterface >= 0,
101 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
102 "Expected an interface associated with the device input");
104 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting(ipv6);
105 if (!ipv6StaticRouting)
106 {
107 NS_ASSERT_MSG(ipv6StaticRouting,
108 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
109 "Expected an Ipv6StaticRouting associated with this node");
110 }
111 ipv6StaticRouting->AddMulticastRoute(source, group, inputInterface, outputInterfaces);
112}
113
114void
116 Ipv6Address source,
117 Ipv6Address group,
118 std::string inputName,
119 NetDeviceContainer output)
120{
121 Ptr<NetDevice> input = Names::Find<NetDevice>(inputName);
122 AddMulticastRoute(n, source, group, input, output);
123}
124
125void
127 Ipv6Address source,
128 Ipv6Address group,
129 Ptr<NetDevice> input,
130 NetDeviceContainer output)
131{
132 Ptr<Node> n = Names::Find<Node>(nName);
133 AddMulticastRoute(n, source, group, input, output);
134}
135
136void
138 Ipv6Address source,
139 Ipv6Address group,
140 std::string inputName,
141 NetDeviceContainer output)
142{
143 Ptr<NetDevice> input = Names::Find<NetDevice>(inputName);
144 Ptr<Node> n = Names::Find<Node>(nName);
145 AddMulticastRoute(n, source, group, input, output);
146}
147
148#if 0
149void
150Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
151 Ptr<Node> n,
153{
154 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
155 int32_t interfaceSrc = ipv6->GetInterfaceForDevice (nd);
156 NS_ASSERT_MSG (interfaceSrc >= 0,
157 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
158 "Expected an interface associated with the device");
160 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting (ipv6);
161 if (!ipv6StaticRouting)
162 {
163 NS_ASSERT_MSG (ipv6StaticRouting,
164 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
165 "Expected an Ipv6StaticRouting associated with this node");
166 }
167 ipv6StaticRouting->SetDefaultMulticastRoute (interfaceSrc);
168}
169
170void
171Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
172 Ptr<Node> n,
173 std::string ndName)
174{
175 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
176 SetDefaultMulticastRoute (n, nd);
177}
178
179void
180Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
181 std::string nName,
182 Ptr<NetDevice> nd)
183{
184 Ptr<Node> n = Names::Find<Node> (nName);
185 SetDefaultMulticastRoute (n, nd);
186}
187
188void
189Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
190 std::string nName,
191 std::string ndName)
192{
193 Ptr<Node> n = Names::Find<Node> (nName);
194 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
195 SetDefaultMulticastRoute (n, nd);
196}
197#endif
198
199} // namespace ns3
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
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
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
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.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
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