blob: f8c037af790417a0fd569fc4566be695b1795aea [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevab1d5602011-08-17 19:17:18 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevab1d5602011-08-17 19:17:18 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-l3-protocol.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070021
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022#include "ns3/packet.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070023#include "ns3/node.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070024#include "ns3/log.h"
25#include "ns3/callback.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include "ns3/uinteger.h"
27#include "ns3/trace-source-accessor.h"
28#include "ns3/object-vector.h"
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080029#include "ns3/pointer.h"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080030#include "ns3/simulator.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070032#include "ndn-face.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080033
Alexander Afanasyev0c395372014-12-20 15:54:02 -080034#include "ndn-net-device-face.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080035#include "../helper/ndn-stack-helper.hpp"
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080036#include "cs/ndn-content-store.hpp"
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080037
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080038#include <boost/property_tree/info_parser.hpp>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080040#include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
41#include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.hpp"
42#include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp"
43#include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp"
44#include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
45#include "ns3/ndnSIM/NFD/daemon/mgmt/status-server.hpp"
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -070046#include "ns3/ndnSIM/NFD/rib/rib-manager.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080047
48#include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp"
49#include "ns3/ndnSIM/NFD/core/config-file.hpp"
50#include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp"
51#include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp"
52
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054
55namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070059const uint16_t L3Protocol::IP_STACK_PORT = 9695;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061NS_OBJECT_ENSURE_REGISTERED(L3Protocol);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070062
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080063TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064L3Protocol::GetTypeId(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 static TypeId tid =
67 TypeId("ns3::ndn::L3Protocol")
68 .SetGroupName("ndn")
69 .SetParent<Object>()
70 .AddConstructor<L3Protocol>()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080071
72 .AddTraceSource("OutInterests", "OutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070073 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
74 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080075 .AddTraceSource("InInterests", "InInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070076 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
77 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080078
79 ////////////////////////////////////////////////////////////////////
80
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070081 .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData),
82 "ns3::ndn::L3Protocol::DataTraceCallback")
83 .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData),
84 "ns3::ndn::L3Protocol::DataTraceCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080085
86 ////////////////////////////////////////////////////////////////////
87
88 .AddTraceSource("SatisfiedInterests", "SatisfiedInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070089 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
90 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080091 .AddTraceSource("TimedOutInterests", "TimedOutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070092 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
93 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080094 ;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095 return tid;
96}
97
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080098class L3Protocol::Impl {
99private:
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800100 Impl()
101 {
102 // Do not modify initial config file. Use helpers to set specific NFD parameters
103 std::string initialConfig =
104 "general\n"
105 "{\n"
106 "}\n"
107 "\n"
108 "tables\n"
109 "{\n"
110 " cs_max_packets 100\n"
111 "\n"
112 " strategy_choice\n"
113 " {\n"
114 " / /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700115 " /localhost /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800116 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700117 " /ndn/multicast /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800118 " }\n"
119 "}\n"
120 "\n"
121 // "face_system\n"
122 // "{\n"
123 // "}\n"
124 "\n"
125 "authorizations\n"
126 "{\n"
127 " authorize\n"
128 " {\n"
129 " certfile any\n"
130 " privileges\n"
131 " {\n"
132 " faces\n"
133 " fib\n"
134 " strategy-choice\n"
135 " }\n"
136 " }\n"
137 "}\n"
138 "\n"
139 "rib\n"
140 "{\n"
141 " localhost_security\n"
142 " {\n"
143 " trust-anchor\n"
144 " {\n"
145 " type any\n"
146 " }\n"
147 " }\n"
148 "}\n"
149 "\n";
150
151 std::istringstream input(initialConfig);
152 boost::property_tree::read_info(input, m_config);
153 }
154
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800155 friend class L3Protocol;
156
157 shared_ptr<nfd::Forwarder> m_forwarder;
158
159 shared_ptr<nfd::InternalFace> m_internalFace;
160 shared_ptr<nfd::FibManager> m_fibManager;
161 shared_ptr<nfd::FaceManager> m_faceManager;
162 shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
163 shared_ptr<nfd::StatusServer> m_statusServer;
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700164 shared_ptr<nfd::rib::RibManager> m_ribManager;
165 shared_ptr< ::ndn::Face> m_face;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800166
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800167 nfd::ConfigSection m_config;
168
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800169 Ptr<ContentStore> m_csFromNdnSim;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800170};
171
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800172L3Protocol::L3Protocol()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800173 : m_impl(new Impl())
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700174{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700176}
177
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800178L3Protocol::~L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700179{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800180 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700181}
182
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800183void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800184L3Protocol::initialize()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800185{
186 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
187
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800188 initializeManagement();
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700189 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager, this);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800190
191 m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL);
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800192
193 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
194 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800195}
196
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800197class IgnoreSections
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800198{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800199public:
200 IgnoreSections(const std::vector<std::string>& ignored)
201 : m_ignored(ignored)
202 {
203 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800204
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800205 void
206 operator()(const std::string& filename, const std::string& sectionName,
207 const nfd::ConfigSection& section, bool isDryRun)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800208
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800209 {
210 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
211 nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
212 }
213 }
214private:
215 std::vector<std::string> m_ignored;
216};
217
218void
219L3Protocol::initializeManagement()
220{
Alexander Afanasyev5b4c4672015-08-21 12:23:55 -0700221 auto& keyChain = StackHelper::getKeyChain();
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800222 auto& forwarder = m_impl->m_forwarder;
223 using namespace nfd;
224
225 m_impl->m_internalFace = make_shared<InternalFace>();
226
227 m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()),
228 bind(&Forwarder::getFace, forwarder.get(), _1),
229 m_impl->m_internalFace, keyChain);
230
231 m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()),
232 m_impl->m_internalFace,
233 keyChain);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800234
235 m_impl->m_strategyChoiceManager =
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800236 make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()),
237 m_impl->m_internalFace,
238 keyChain);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800239
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800240 m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace,
241 ref(*forwarder),
242 keyChain);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800243
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800244 ConfigFile config((IgnoreSections({"general", "log", "rib"})));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800245
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800246 TablesConfigSection tablesConfig(forwarder->getCs(),
247 forwarder->getPit(),
248 forwarder->getFib(),
249 forwarder->getStrategyChoice(),
250 forwarder->getMeasurements());
251 tablesConfig.setConfigFile(config);
252
253 m_impl->m_internalFace->getValidator().setConfigFile(config);
254
255 forwarder->getFaceTable().addReserved(m_impl->m_internalFace, FACEID_INTERNAL_FACE);
256
257 m_impl->m_faceManager->setConfigFile(config);
258
259 // apply config
260 config.parse(m_impl->m_config, false, "ndnSIM.conf");
261
262 tablesConfig.ensureTablesAreConfigured();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800263
264 // add FIB entry for NFD Management Protocol
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800265 shared_ptr<fib::Entry> entry = forwarder->getFib().insert("/localhost/nfd").first;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800266 entry->addNextHop(m_impl->m_internalFace, 0);
267}
268
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700269void
270L3Protocol::initializeRibManager()
271{
272 using namespace nfd;
273
274 m_impl->m_face = make_shared< ::ndn::Face>();
275 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_face),
276 StackHelper::getKeyChain());
277
278 ConfigFile config([] (const std::string& filename, const std::string& sectionName,
279 const ConfigSection& section, bool isDryRun) {
280 // Ignore "log" and sections belonging to NFD,
281 // but raise an error if we're missing a handler for a "rib" section.
282 if (sectionName != "rib" || sectionName == "log") {
283 // do nothing
284 }
285 else {
286 // missing NRD section
287 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
288 }
289 });
290
291 m_impl->m_ribManager->setConfigFile(config);
292
293 // apply config
294 config.parse(m_impl->m_config, false, "ndnSIM.conf");
295
296 m_impl->m_ribManager->registerWithNfd();
297
298 m_impl->m_ribManager->enableLocalControlHeader();
299}
300
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800301shared_ptr<nfd::Forwarder>
302L3Protocol::getForwarder()
303{
304 return m_impl->m_forwarder;
305}
306
307shared_ptr<nfd::FibManager>
308L3Protocol::getFibManager()
309{
310 return m_impl->m_fibManager;
311}
312
313shared_ptr<nfd::StrategyChoiceManager>
314L3Protocol::getStrategyChoiceManager()
315{
316 return m_impl->m_strategyChoiceManager;
317}
318
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800319nfd::ConfigSection&
320L3Protocol::getConfig()
321{
322 return m_impl->m_config;
323}
324
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700325/*
326 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700327 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700328 */
329void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800330L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700331{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800332 if (m_node == nullptr) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800333 m_node = GetObject<Node>();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800334 if (m_node != nullptr) {
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700335 initialize();
336
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800337 NS_ASSERT(m_impl->m_forwarder != nullptr);
338 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
339 if (m_impl->m_csFromNdnSim != nullptr) {
340 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
341 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700342 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800343 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700344
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800345 Object::NotifyNewAggregate();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700346}
347
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800348void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800349L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700350{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800351 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700352
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700353 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800354
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800355 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700356}
357
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800358nfd::FaceId
359L3Protocol::addFace(shared_ptr<Face> face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700360{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800361 NS_LOG_FUNCTION(this << face.get());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700362
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800363 m_impl->m_forwarder->addFace(face);
364
365 // Connect Signals to TraceSource
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700366 face->onReceiveInterest.connect
367 ([this, face](const Interest& interest) { this->m_inInterests(interest, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800368
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700369 face->onSendInterest.connect
370 ([this, face](const Interest& interest) { this->m_outInterests(interest, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800371
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700372 face->onReceiveData.connect([this, face](const Data& data) { this->m_inData(data, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800373
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700374 face->onSendData.connect([this, face](const Data& data) { this->m_outData(data, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800375
376 return face->getId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700377}
378
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800379// void
380// L3Protocol::removeFace(shared_ptr<Face> face)
381// {
382// NS_LOG_FUNCTION(this << std::cref(*face));
383// }
384
385shared_ptr<Face>
386L3Protocol::getFaceById(nfd::FaceId id) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700387{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800388 return m_impl->m_forwarder->getFaceTable().get(id);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700389}
390
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700391shared_ptr<Face>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800392L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700393{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800394 for (const auto& i : m_impl->m_forwarder->getFaceTable()) {
395 shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i);
396 if (netDeviceFace == nullptr)
397 continue;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700398
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800399 if (netDeviceFace->GetNetDevice() == netDevice)
400 return i;
401 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700402 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700403}
404
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800405Ptr<L3Protocol>
406L3Protocol::getL3Protocol(Ptr<Object> node)
407{
408 Ptr<L3Protocol> retval = node->GetObject<L3Protocol>();
409 NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object");
410 return retval;
411}
412
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800413} // namespace ndn
414} // namespace ns3