A Discrete-Event Network Simulator
API
ipv6-static-routing-helper.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 University of Washington
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <vector>
20
21#include "ns3/log.h"
22#include "ns3/ptr.h"
23#include "ns3/names.h"
24#include "ns3/node.h"
25#include "ns3/ipv6.h"
26#include "ns3/ipv6-route.h"
27#include "ns3/ipv6-list-routing.h"
28#include "ns3/assert.h"
29#include "ns3/ipv6-address.h"
30#include "ns3/ipv6-routing-protocol.h"
31
33
34namespace ns3 {
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 0;
86}
87
88void
90 Ptr<Node> n,
91 Ipv6Address source,
92 Ipv6Address group,
93 Ptr<NetDevice> input,
94 NetDeviceContainer output)
95{
96 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
97
98 // We need to convert the NetDeviceContainer to an array of interface
99 // numbers
100 std::vector<uint32_t> outputInterfaces;
101 for (NetDeviceContainer::Iterator i = output.Begin (); i != output.End (); ++i)
102 {
103 Ptr<NetDevice> nd = *i;
104 int32_t interface = ipv6->GetInterfaceForDevice (nd);
105 NS_ASSERT_MSG (interface >= 0,
106 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
107 "Expected an interface associated with the device nd");
108 outputInterfaces.push_back (interface);
109 }
110
111 int32_t inputInterface = ipv6->GetInterfaceForDevice (input);
112 NS_ASSERT_MSG (inputInterface >= 0,
113 "Ipv6StaticRoutingHelper::AddMulticastRoute (): "
114 "Expected an interface associated with the device input");
116 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting (ipv6);
117 if (!ipv6StaticRouting)
118 {
119 NS_ASSERT_MSG (ipv6StaticRouting,
120 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
121 "Expected an Ipv6StaticRouting associated with this node");
122 }
123 ipv6StaticRouting->AddMulticastRoute (source, group, inputInterface, outputInterfaces);
124}
125
126void
128 Ptr<Node> n,
129 Ipv6Address source,
130 Ipv6Address group,
131 std::string inputName,
132 NetDeviceContainer output)
133{
134 Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
135 AddMulticastRoute (n, source, group, input, output);
136}
137
138void
140 std::string nName,
141 Ipv6Address source,
142 Ipv6Address group,
143 Ptr<NetDevice> input,
144 NetDeviceContainer output)
145{
146 Ptr<Node> n = Names::Find<Node> (nName);
147 AddMulticastRoute (n, source, group, input, output);
148}
149
150void
152 std::string nName,
153 Ipv6Address source,
154 Ipv6Address group,
155 std::string inputName,
156 NetDeviceContainer output)
157{
158 Ptr<NetDevice> input = Names::Find<NetDevice> (inputName);
159 Ptr<Node> n = Names::Find<Node> (nName);
160 AddMulticastRoute (n, source, group, input, output);
161}
162
163#if 0
164void
165Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
166 Ptr<Node> n,
168{
169 Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
170 int32_t interfaceSrc = ipv6->GetInterfaceForDevice (nd);
171 NS_ASSERT_MSG (interfaceSrc >= 0,
172 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
173 "Expected an interface associated with the device");
175 Ptr<Ipv6StaticRouting> ipv6StaticRouting = helper.GetStaticRouting (ipv6);
176 if (!ipv6StaticRouting)
177 {
178 NS_ASSERT_MSG (ipv6StaticRouting,
179 "Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (): "
180 "Expected an Ipv6StaticRouting associated with this node");
181 }
182 ipv6StaticRouting->SetDefaultMulticastRoute (interfaceSrc);
183}
184
185void
186Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
187 Ptr<Node> n,
188 std::string ndName)
189{
190 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
191 SetDefaultMulticastRoute (n, nd);
192}
193
194void
195Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
196 std::string nName,
197 Ptr<NetDevice> nd)
198{
199 Ptr<Node> n = Names::Find<Node> (nName);
200 SetDefaultMulticastRoute (n, nd);
201}
202
203void
204Ipv6StaticRoutingHelper::SetDefaultMulticastRoute (
205 std::string nName,
206 std::string ndName)
207{
208 Ptr<Node> n = Names::Find<Node> (nName);
209 Ptr<NetDevice> nd = Names::Find<NetDevice> (ndName);
210 SetDefaultMulticastRoute (n, nd);
211}
212#endif
213
214} // namespace ns3
Describes an IPv6 address.
Definition: ipv6-address.h:50
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Helper class that adds ns3::Ipv6StaticRouting objects.
virtual Ptr< Ipv6RoutingProtocol > Create(Ptr< Node > node) const
Ipv6StaticRoutingHelper * Copy(void) const
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>
holds a vector of ns3::NetDevice pointers
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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.