blob: 983c8cf6190f1f5d38e6d223db55e4115e4db5c3 [file] [log] [blame]
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07002/*
3 * Copyright (c) 2011 UCLA
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 *
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenkofbd0a8b2011-10-28 13:07:16 -070019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070020 */
21
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070022#include "ns3/assert.h"
23#include "ns3/log.h"
24#include "ns3/object.h"
25#include "ns3/names.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070026#include "ns3/packet-socket-factory.h"
27#include "ns3/config.h"
28#include "ns3/simulator.h"
29#include "ns3/string.h"
30#include "ns3/net-device.h"
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080031#include "ns3/channel.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070032#include "ns3/callback.h"
33#include "ns3/node.h"
34#include "ns3/core-config.h"
Alexander Afanasyev07827182011-12-13 01:07:32 -080035#include "ns3/point-to-point-net-device.h"
36#include "ns3/point-to-point-helper.h"
37
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038#include "../model/ndn-net-device-face.h"
39#include "../model/ndn-l3-protocol.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070040
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041#include "ns3/ndn-forwarding-strategy.h"
42#include "ns3/ndn-fib.h"
43#include "ns3/ndn-pit.h"
44#include "ns3/ndn-name-components.h"
45#include "ns3/ndn-content-store.h"
Alexander Afanasyev07827182011-12-13 01:07:32 -080046
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080047#include "ns3/node-list.h"
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -070048// #include "ns3/loopback-net-device.h"
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080049
Alexander Afanasyev11453142011-11-25 16:13:33 -080050#include "ns3/data-rate.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070051
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052#include "ndn-face-container.h"
53#include "ndn-stack-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070054
55#include <limits>
56#include <map>
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080057#include <boost/foreach.hpp>
Alexander Afanasyevb7626842012-01-12 13:43:33 -080058#include <boost/lexical_cast.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060NS_LOG_COMPONENT_DEFINE ("ndn.StackHelper");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070061
62namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063namespace ndn {
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065StackHelper::StackHelper ()
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080066 : m_limitsEnabled (false)
67 , m_needSetDefaultRoutes (false)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070068{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 m_ndnFactory. SetTypeId ("ns3::ndn::L3Protocol");
70 m_strategyFactory. SetTypeId ("ns3::ndn::fw::Flooding");
71 m_contentStoreFactory.SetTypeId ("ns3::ndn::cs::Lru");
72 m_fibFactory. SetTypeId ("ns3::ndn::fib::Default");
73 m_pitFactory. SetTypeId ("ns3::ndn::pit::Persistent");
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070074}
75
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076StackHelper::~StackHelper ()
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070077{
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070078}
79
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070080void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081StackHelper::SetStackAttributes (const std::string &attr1, const std::string &value1,
82 const std::string &attr2, const std::string &value2,
83 const std::string &attr3, const std::string &value3,
84 const std::string &attr4, const std::string &value4)
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070085{
86 if (attr1 != "")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087 m_ndnFactory.Set (attr1, StringValue (value1));
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070088 if (attr2 != "")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070089 m_ndnFactory.Set (attr2, StringValue (value2));
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070090 if (attr3 != "")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070091 m_ndnFactory.Set (attr3, StringValue (value3));
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070092 if (attr4 != "")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070093 m_ndnFactory.Set (attr4, StringValue (value4));
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070094}
95
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070096void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097StackHelper::SetForwardingStrategy (const std::string &strategy,
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070098 const std::string &attr1, const std::string &value1,
99 const std::string &attr2, const std::string &value2,
100 const std::string &attr3, const std::string &value3,
101 const std::string &attr4, const std::string &value4)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700102{
Alexander Afanasyev11453142011-11-25 16:13:33 -0800103 m_strategyFactory.SetTypeId (strategy);
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700104 if (attr1 != "")
105 m_strategyFactory.Set (attr1, StringValue (value1));
106 if (attr2 != "")
107 m_strategyFactory.Set (attr2, StringValue (value2));
108 if (attr3 != "")
109 m_strategyFactory.Set (attr3, StringValue (value3));
110 if (attr4 != "")
111 m_strategyFactory.Set (attr4, StringValue (value4));
Alexander Afanasyev11453142011-11-25 16:13:33 -0800112}
113
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700114void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700115StackHelper::SetContentStore (const std::string &contentStore,
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700116 const std::string &attr1, const std::string &value1,
117 const std::string &attr2, const std::string &value2,
118 const std::string &attr3, const std::string &value3,
119 const std::string &attr4, const std::string &value4)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700120{
121 m_contentStoreFactory.SetTypeId (contentStore);
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700122 if (attr1 != "")
123 m_contentStoreFactory.Set (attr1, StringValue (value1));
124 if (attr2 != "")
125 m_contentStoreFactory.Set (attr2, StringValue (value2));
126 if (attr3 != "")
127 m_contentStoreFactory.Set (attr3, StringValue (value3));
128 if (attr4 != "")
129 m_contentStoreFactory.Set (attr4, StringValue (value4));
130}
131
132void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700133StackHelper::SetPit (const std::string &pitClass,
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700134 const std::string &attr1, const std::string &value1,
135 const std::string &attr2, const std::string &value2,
136 const std::string &attr3, const std::string &value3,
137 const std::string &attr4, const std::string &value4)
138{
139 m_pitFactory.SetTypeId (pitClass);
140 if (attr1 != "")
141 m_pitFactory.Set (attr1, StringValue (value1));
142 if (attr2 != "")
143 m_pitFactory.Set (attr2, StringValue (value2));
144 if (attr3 != "")
145 m_pitFactory.Set (attr3, StringValue (value3));
146 if (attr4 != "")
147 m_pitFactory.Set (attr4, StringValue (value4));
148}
149
150void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151StackHelper::SetFib (const std::string &fibClass,
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700152 const std::string &attr1, const std::string &value1,
153 const std::string &attr2, const std::string &value2,
154 const std::string &attr3, const std::string &value3,
155 const std::string &attr4, const std::string &value4)
156{
157 m_fibFactory.SetTypeId (fibClass);
158 if (attr1 != "")
159 m_fibFactory.Set (attr1, StringValue (value1));
160 if (attr2 != "")
161 m_fibFactory.Set (attr2, StringValue (value2));
162 if (attr3 != "")
163 m_fibFactory.Set (attr3, StringValue (value3));
164 if (attr4 != "")
165 m_fibFactory.Set (attr4, StringValue (value4));
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700166}
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800167
168void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169StackHelper::SetDefaultRoutes (bool needSet)
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800170{
171 NS_LOG_FUNCTION (this << needSet);
172 m_needSetDefaultRoutes = needSet;
173}
174
Alexander Afanasyev11453142011-11-25 16:13:33 -0800175void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700176StackHelper::EnableLimits (bool enable/* = true*/,
Alexander Afanasyev33d62312012-01-09 13:50:20 -0800177 Time avgRtt/*=Seconds(0.1)*/,
178 uint32_t avgContentObject/*=1100*/,
179 uint32_t avgInterest/*=40*/)
Alexander Afanasyev11453142011-11-25 16:13:33 -0800180{
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800181 NS_LOG_INFO ("EnableLimits: " << enable);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800182 m_limitsEnabled = enable;
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800183 m_avgRtt = avgRtt;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800184 m_avgContentObjectSize = avgContentObject;
185 m_avgInterestSize = avgInterest;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700186}
187
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700188Ptr<FaceContainer>
189StackHelper::Install (NodeContainer c) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700190{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700191 Ptr<FaceContainer> faces = Create<FaceContainer> ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700192 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
193 {
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700194 faces->AddAll (Install (*i));
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700195 }
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700196 return faces;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700197}
198
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700199Ptr<FaceContainer>
200StackHelper::InstallAll (void) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700201{
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700202 return Install (NodeContainer::GetGlobal ());
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700203}
204
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700205Ptr<FaceContainer>
206StackHelper::Install (Ptr<Node> node) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700207{
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700208 // NS_ASSERT_MSG (m_forwarding, "SetForwardingHelper() should be set prior calling Install() method");
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700209 Ptr<FaceContainer> faces = Create<FaceContainer> ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700210
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700211 if (node->GetObject<L3Protocol> () != 0)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700212 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213 NS_FATAL_ERROR ("StackHelper::Install (): Installing "
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700214 "a NdnStack to a node with an existing Ndn object");
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700215 return 0;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700216 }
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700217
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218 // Create L3Protocol
219 Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol> ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700220
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700221 // Create and aggregate FIB
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700222 Ptr<Fib> fib = m_fibFactory.Create<Fib> ();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700223 ndn->AggregateObject (fib);
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700224
225 // Create and aggregate PIT
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700226 ndn->AggregateObject (m_pitFactory.Create<Pit> ());
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700227
228 // Create and aggregate forwarding strategy
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700229 ndn->AggregateObject (m_strategyFactory.Create<ForwardingStrategy> ());
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700230
231 // Create and aggregate content store
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700232 ndn->AggregateObject (m_contentStoreFactory.Create<ContentStore> ());
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700233
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700234 // Aggregate L3Protocol on node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700235 node->AggregateObject (ndn);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800236
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700237 for (uint32_t index=0; index < node->GetNDevices (); index++)
238 {
Alexander Afanasyev11453142011-11-25 16:13:33 -0800239 Ptr<NetDevice> device = node->GetDevice (index);
Alexander Afanasyev57bcbc32012-06-01 01:46:24 -0700240 // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed,
241 // Normally, ndnSIM works without IP stack, so no reason to check
242 // if (DynamicCast<LoopbackNetDevice> (device) != 0)
243 // continue; // don't create face for a LoopbackNetDevice
Alexander Afanasyev11453142011-11-25 16:13:33 -0800244
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700245 Ptr<NetDeviceFace> face = CreateObject<NetDeviceFace> (node, device);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800246
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700247 ndn->AddFace (face);
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700248 NS_LOG_LOGIC ("Node " << node->GetId () << ": added NetDeviceFace as face #" << *face);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800249
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800250 if (m_needSetDefaultRoutes)
251 {
252 // default route with lowest priority possible
Alexander Afanasyev463fe222012-05-31 13:46:51 -0700253 AddRoute (node, "/", face, std::numeric_limits<int32_t>::max ());
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800254 }
255
Alexander Afanasyev11453142011-11-25 16:13:33 -0800256 if (m_limitsEnabled)
257 {
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700258 Ptr<Limits> limits = face->GetObject<Limits> ();
259 if (limits == 0)
260 {
261 NS_FATAL_ERROR ("Limits are enabled, but the selected forwarding strategy does not support limits. Please revise your scenario");
262 exit (1);
263 }
264
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800265 NS_LOG_INFO ("Limits are enabled");
Alexander Afanasyev11453142011-11-25 16:13:33 -0800266 Ptr<PointToPointNetDevice> p2p = DynamicCast<PointToPointNetDevice> (device);
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800267 if (p2p != 0)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800268 {
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800269 // Setup bucket filtering
270 // Assume that we know average data packet size, and this size is equal default size
271 // Set maximum buckets (averaging over 1 second)
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700272
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800273 DataRateValue dataRate; device->GetAttribute ("DataRate", dataRate);
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800274 TimeValue linkDelay; device->GetChannel ()->GetAttribute ("Delay", linkDelay);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800275
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800276 NS_LOG_INFO("DataRate for this link is " << dataRate.Get());
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800277
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800278 double maxInterestPackets = 1.0 * dataRate.Get ().GetBitRate () / 8.0 / (m_avgContentObjectSize + m_avgInterestSize);
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700279 // NS_LOG_INFO ("Max packets per second: " << maxInterestPackets);
280 // NS_LOG_INFO ("Max burst: " << m_avgRtt.ToDouble (Time::S) * maxInterestPackets);
281 NS_LOG_INFO ("MaxLimit: " << (int)(m_avgRtt.ToDouble (Time::S) * maxInterestPackets));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800282
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700283 // Set max to BDP
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700284 limits->SetLimits (maxInterestPackets, m_avgRtt.ToDouble (Time::S));
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800285 limits->SetLinkDelay (linkDelay.Get ().ToDouble (Time::S));
Alexander Afanasyev3f1c8b02012-01-19 19:41:34 -0800286 }
Alexander Afanasyev11453142011-11-25 16:13:33 -0800287 }
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700288
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700289 face->SetUp ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700290 faces->Add (face);
291 }
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700292
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700293 return faces;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700294}
295
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700296Ptr<FaceContainer>
297StackHelper::Install (std::string nodeName) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700298{
299 Ptr<Node> node = Names::Find<Node> (nodeName);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700300 return Install (node);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700301}
302
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700303
304void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700305StackHelper::AddRoute (Ptr<Node> node, std::string prefix, Ptr<Face> face, int32_t metric)
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800306{
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800307 NS_LOG_LOGIC ("[" << node->GetId () << "]$ route add " << prefix << " via " << *face << " metric " << metric);
308
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700309 Ptr<Fib> fib = node->GetObject<Fib> ();
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800310
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700311 NameComponentsValue prefixValue;
312 prefixValue.DeserializeFromString (prefix, MakeNameComponentsChecker ());
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800313 fib->Add (prefixValue.Get (), face, metric);
314}
315
316void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700317StackHelper::AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric)
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700318{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700319 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol> ();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700320 NS_ASSERT_MSG (ndn != 0, "Ndn stack should be installed on the node");
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700321
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700322 Ptr<Face> face = ndn->GetFace (faceId);
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700323 NS_ASSERT_MSG (face != 0, "Face with ID [" << faceId << "] does not exist on node [" << node->GetId () << "]");
324
325 AddRoute (node, prefix, face, metric);
326}
327
328void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700329StackHelper::AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700330{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700331 Ptr<Node> node = Names::Find<Node> (nodeName);
332 NS_ASSERT_MSG (node != 0, "Node [" << nodeName << "] does not exist");
Alexander Afanasyeva4e3f852011-11-15 20:39:33 -0800333
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700334 Ptr<L3Protocol> ndn = node->GetObject<L3Protocol> ();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700335 NS_ASSERT_MSG (ndn != 0, "Ndn stack should be installed on the node");
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800336
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700337 Ptr<Face> face = ndn->GetFace (faceId);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800338 NS_ASSERT_MSG (face != 0, "Face with ID [" << faceId << "] does not exist on node [" << nodeName << "]");
339
340 AddRoute (node, prefix, face, metric);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700341}
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800342
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700343} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700344} // namespace ns3