blob: 8f77b72ba765291d908a3a0e5b47a17cd366a5d4 [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();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800189
190 if (!this->getConfig().get<bool>("ndnSIM.disable_rib_manager", false)) {
191 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager, this);
192 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800193
194 m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL);
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800195
196 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
197 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800198}
199
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800200class IgnoreSections
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800201{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800202public:
203 IgnoreSections(const std::vector<std::string>& ignored)
204 : m_ignored(ignored)
205 {
206 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800207
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800208 void
209 operator()(const std::string& filename, const std::string& sectionName,
210 const nfd::ConfigSection& section, bool isDryRun)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800211
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800212 {
213 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
214 nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
215 }
216 }
217private:
218 std::vector<std::string> m_ignored;
219};
220
221void
222L3Protocol::initializeManagement()
223{
Alexander Afanasyev5b4c4672015-08-21 12:23:55 -0700224 auto& keyChain = StackHelper::getKeyChain();
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800225 auto& forwarder = m_impl->m_forwarder;
226 using namespace nfd;
227
228 m_impl->m_internalFace = make_shared<InternalFace>();
229
230 m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()),
231 bind(&Forwarder::getFace, forwarder.get(), _1),
232 m_impl->m_internalFace, keyChain);
233
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800234 if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) {
235 m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()),
236 m_impl->m_internalFace,
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800237 keyChain);
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800238 }
239 else {
240 this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("faces");
241 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800242
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800243 if (!this->getConfig().get<bool>("ndnSIM.disable_strategy_choice_manager", false)) {
244 m_impl->m_strategyChoiceManager =
245 make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()),
246 m_impl->m_internalFace,
247 keyChain);
248 }
249 else {
250 this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("strategy-choice");
251 }
252
253 if (!this->getConfig().get<bool>("ndnSIM.disable_status_server", false)) {
254 m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace,
255 ref(*forwarder),
256 keyChain);
257 }
258
259 ConfigFile config((IgnoreSections({"general", "log", "rib", "ndnSIM"})));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800260
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800261 TablesConfigSection tablesConfig(forwarder->getCs(),
262 forwarder->getPit(),
263 forwarder->getFib(),
264 forwarder->getStrategyChoice(),
265 forwarder->getMeasurements());
266 tablesConfig.setConfigFile(config);
267
268 m_impl->m_internalFace->getValidator().setConfigFile(config);
269
270 forwarder->getFaceTable().addReserved(m_impl->m_internalFace, FACEID_INTERNAL_FACE);
271
272 m_impl->m_faceManager->setConfigFile(config);
273
274 // apply config
275 config.parse(m_impl->m_config, false, "ndnSIM.conf");
276
277 tablesConfig.ensureTablesAreConfigured();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800278
279 // add FIB entry for NFD Management Protocol
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800280 shared_ptr<fib::Entry> entry = forwarder->getFib().insert("/localhost/nfd").first;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800281 entry->addNextHop(m_impl->m_internalFace, 0);
282}
283
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700284void
285L3Protocol::initializeRibManager()
286{
287 using namespace nfd;
288
289 m_impl->m_face = make_shared< ::ndn::Face>();
290 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_face),
291 StackHelper::getKeyChain());
292
293 ConfigFile config([] (const std::string& filename, const std::string& sectionName,
294 const ConfigSection& section, bool isDryRun) {
295 // Ignore "log" and sections belonging to NFD,
296 // but raise an error if we're missing a handler for a "rib" section.
297 if (sectionName != "rib" || sectionName == "log") {
298 // do nothing
299 }
300 else {
301 // missing NRD section
302 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
303 }
304 });
305
306 m_impl->m_ribManager->setConfigFile(config);
307
308 // apply config
309 config.parse(m_impl->m_config, false, "ndnSIM.conf");
310
311 m_impl->m_ribManager->registerWithNfd();
312
313 m_impl->m_ribManager->enableLocalControlHeader();
314}
315
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800316shared_ptr<nfd::Forwarder>
317L3Protocol::getForwarder()
318{
319 return m_impl->m_forwarder;
320}
321
322shared_ptr<nfd::FibManager>
323L3Protocol::getFibManager()
324{
325 return m_impl->m_fibManager;
326}
327
328shared_ptr<nfd::StrategyChoiceManager>
329L3Protocol::getStrategyChoiceManager()
330{
331 return m_impl->m_strategyChoiceManager;
332}
333
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800334nfd::ConfigSection&
335L3Protocol::getConfig()
336{
337 return m_impl->m_config;
338}
339
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700340/*
341 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700342 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700343 */
344void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800345L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700346{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800347 if (m_node == nullptr) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800348 m_node = GetObject<Node>();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800349 if (m_node != nullptr) {
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700350 initialize();
351
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800352 NS_ASSERT(m_impl->m_forwarder != nullptr);
353 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
354 if (m_impl->m_csFromNdnSim != nullptr) {
355 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
356 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700357 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800358 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700359
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800360 Object::NotifyNewAggregate();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700361}
362
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800363void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800364L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700365{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800366 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700367
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700368 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800369
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800370 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700371}
372
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800373nfd::FaceId
374L3Protocol::addFace(shared_ptr<Face> face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700375{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800376 NS_LOG_FUNCTION(this << face.get());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700377
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800378 m_impl->m_forwarder->addFace(face);
379
380 // Connect Signals to TraceSource
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700381 face->onReceiveInterest.connect
382 ([this, face](const Interest& interest) { this->m_inInterests(interest, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800383
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700384 face->onSendInterest.connect
385 ([this, face](const Interest& interest) { this->m_outInterests(interest, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800386
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700387 face->onReceiveData.connect([this, face](const Data& data) { this->m_inData(data, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800388
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700389 face->onSendData.connect([this, face](const Data& data) { this->m_outData(data, *face); });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800390
391 return face->getId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700392}
393
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800394// void
395// L3Protocol::removeFace(shared_ptr<Face> face)
396// {
397// NS_LOG_FUNCTION(this << std::cref(*face));
398// }
399
400shared_ptr<Face>
401L3Protocol::getFaceById(nfd::FaceId id) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700402{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800403 return m_impl->m_forwarder->getFaceTable().get(id);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700404}
405
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700406shared_ptr<Face>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800407L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700408{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800409 for (const auto& i : m_impl->m_forwarder->getFaceTable()) {
410 shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i);
411 if (netDeviceFace == nullptr)
412 continue;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700413
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800414 if (netDeviceFace->GetNetDevice() == netDevice)
415 return i;
416 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700417 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700418}
419
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800420Ptr<L3Protocol>
421L3Protocol::getL3Protocol(Ptr<Object> node)
422{
423 Ptr<L3Protocol> retval = node->GetObject<L3Protocol>();
424 NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object");
425 return retval;
426}
427
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800428} // namespace ndn
429} // namespace ns3