blob: e8f7cccea198e4dc530b1db81e7358935b249c72 [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
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070032#include "ndn-net-device-link-service.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080033
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080034#include "../helper/ndn-stack-helper.hpp"
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080035#include "cs/ndn-content-store.hpp"
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080036
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080037#include <boost/property_tree/info_parser.hpp>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080039#include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070040#include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
41#include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080042#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"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070045#include "ns3/ndnSIM/NFD/daemon/mgmt/forwarder-status-manager.hpp"
46// #include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp"
47#include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp"
48#include "ns3/ndnSIM/NFD/daemon/mgmt/command-validator.hpp"
49
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -070050#include "ns3/ndnSIM/NFD/rib/rib-manager.hpp"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080051
52#include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070053#include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp"
54
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080055#include "ns3/ndnSIM/NFD/core/config-file.hpp"
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070056
57#include <ndn-cxx/mgmt/dispatcher.hpp>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080058
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060
61namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070063
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070064const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070065const uint16_t L3Protocol::IP_STACK_PORT = 9695;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067NS_OBJECT_ENSURE_REGISTERED(L3Protocol);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080069TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070L3Protocol::GetTypeId(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 static TypeId tid =
73 TypeId("ns3::ndn::L3Protocol")
74 .SetGroupName("ndn")
75 .SetParent<Object>()
76 .AddConstructor<L3Protocol>()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080077
78 .AddTraceSource("OutInterests", "OutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070079 MakeTraceSourceAccessor(&L3Protocol::m_outInterests),
80 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080081 .AddTraceSource("InInterests", "InInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070082 MakeTraceSourceAccessor(&L3Protocol::m_inInterests),
83 "ns3::ndn::L3Protocol::InterestTraceCallback")
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080084
85 ////////////////////////////////////////////////////////////////////
86
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070087 .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData),
88 "ns3::ndn::L3Protocol::DataTraceCallback")
89 .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData),
90 "ns3::ndn::L3Protocol::DataTraceCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080091
92 ////////////////////////////////////////////////////////////////////
93
94 .AddTraceSource("SatisfiedInterests", "SatisfiedInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070095 MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests),
96 "ns3::ndn::L3Protocol::SatisfiedInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080097 .AddTraceSource("TimedOutInterests", "TimedOutInterests",
Alexander Afanasyevd6453cd2015-08-20 21:45:36 -070098 MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests),
99 "ns3::ndn::L3Protocol::TimedOutInterestsCallback")
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800100 ;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101 return tid;
102}
103
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800104class L3Protocol::Impl {
105private:
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800106 Impl()
107 {
108 // Do not modify initial config file. Use helpers to set specific NFD parameters
109 std::string initialConfig =
110 "general\n"
111 "{\n"
112 "}\n"
113 "\n"
114 "tables\n"
115 "{\n"
116 " cs_max_packets 100\n"
117 "\n"
118 " strategy_choice\n"
119 " {\n"
120 " / /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700121 " /localhost /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800122 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -0700123 " /ndn/multicast /localhost/nfd/strategy/multicast\n"
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800124 " }\n"
125 "}\n"
126 "\n"
127 // "face_system\n"
128 // "{\n"
129 // "}\n"
130 "\n"
131 "authorizations\n"
132 "{\n"
133 " authorize\n"
134 " {\n"
135 " certfile any\n"
136 " privileges\n"
137 " {\n"
138 " faces\n"
139 " fib\n"
140 " strategy-choice\n"
141 " }\n"
142 " }\n"
143 "}\n"
144 "\n"
145 "rib\n"
146 "{\n"
147 " localhost_security\n"
148 " {\n"
149 " trust-anchor\n"
150 " {\n"
151 " type any\n"
152 " }\n"
153 " }\n"
154 "}\n"
155 "\n";
156
157 std::istringstream input(initialConfig);
158 boost::property_tree::read_info(input, m_config);
159 }
160
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800161 friend class L3Protocol;
162
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700163 std::shared_ptr<nfd::Forwarder> m_forwarder;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800164
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700165 std::shared_ptr<nfd::Face> m_internalFace;
166 std::shared_ptr<::ndn::Face> m_internalClientFace;
167 std::unique_ptr<nfd::CommandValidator> m_validator;
168
169 std::shared_ptr<nfd::Face> m_internalRibFace;
170 std::shared_ptr<::ndn::Face> m_internalRibClientFace;
171
172 std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher;
173 std::shared_ptr<nfd::FibManager> m_fibManager;
174 std::shared_ptr<nfd::FaceManager> m_faceManager;
175 std::shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
176 std::shared_ptr<nfd::ForwarderStatusManager> m_forwarderStatusManager;
177 std::shared_ptr<nfd::rib::RibManager> m_ribManager;
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800178
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800179 nfd::ConfigSection m_config;
180
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800181 Ptr<ContentStore> m_csFromNdnSim;
spirosmastorakis34eed982016-11-02 15:20:50 -0700182 PolicyCreationCallback m_policy;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800183};
184
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800185L3Protocol::L3Protocol()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800186 : m_impl(new Impl())
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700187{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800188 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700189}
190
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800191L3Protocol::~L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700192{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800193 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700194}
195
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800196void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800197L3Protocol::initialize()
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800198{
199 m_impl->m_forwarder = make_shared<nfd::Forwarder>();
200
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800201 initializeManagement();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800202
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700203 nfd::FaceTable& faceTable = m_impl->m_forwarder->getFaceTable();
204 faceTable.addReserved(nfd::face::makeNullFace(), nfd::face::FACEID_NULL);
205 faceTable.addReserved(nfd::face::makeNullFace(FaceUri("contentstore://")), nfd::face::FACEID_CONTENT_STORE);
206
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800207 if (!this->getConfig().get<bool>("ndnSIM.disable_rib_manager", false)) {
208 Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager, this);
209 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800210
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800211 m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests));
212 m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests));
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800213}
214
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800215class IgnoreSections
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800216{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800217public:
218 IgnoreSections(const std::vector<std::string>& ignored)
219 : m_ignored(ignored)
220 {
221 }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800222
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800223 void
224 operator()(const std::string& filename, const std::string& sectionName,
225 const nfd::ConfigSection& section, bool isDryRun)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800226
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800227 {
228 if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) {
229 nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
230 }
231 }
232private:
233 std::vector<std::string> m_ignored;
234};
235
236void
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -0700237L3Protocol::injectInterest(const Interest& interest)
238{
239 m_impl->m_internalFace->sendInterest(interest);
240}
241
242void
spirosmastorakis34eed982016-11-02 15:20:50 -0700243L3Protocol::setCsReplacementPolicy(const PolicyCreationCallback& policy)
244{
245 m_impl->m_policy = policy;
246}
247
248void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800249L3Protocol::initializeManagement()
250{
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800251 auto& forwarder = m_impl->m_forwarder;
252 using namespace nfd;
253
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700254 std::tie(m_impl->m_internalFace, m_impl->m_internalClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
255 forwarder->getFaceTable().addReserved(m_impl->m_internalFace, face::FACEID_INTERNAL_FACE);
256 m_impl->m_dispatcher.reset(new ::ndn::mgmt::Dispatcher(*m_impl->m_internalClientFace, StackHelper::getKeyChain()));
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800257
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700258 m_impl->m_validator.reset(new CommandValidator());
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800259
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700260 m_impl->m_fibManager.reset(new FibManager(forwarder->getFib(),
261 bind(&Forwarder::getFace, forwarder.get(), _1),
262 *m_impl->m_dispatcher,
263 *m_impl->m_validator));
264
265 // Cannot be disabled for now
266 // if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) {
267 m_impl->m_faceManager.reset(new FaceManager(forwarder->getFaceTable(),
268 *m_impl->m_dispatcher,
269 *m_impl->m_validator));
270 // }
271 // else {
272 // this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("faces");
273 // }
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800274
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800275 if (!this->getConfig().get<bool>("ndnSIM.disable_strategy_choice_manager", false)) {
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700276 m_impl->m_strategyChoiceManager.reset(new StrategyChoiceManager(forwarder->getStrategyChoice(),
277 *m_impl->m_dispatcher,
278 *m_impl->m_validator));
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800279 }
280 else {
281 this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("strategy-choice");
282 }
283
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700284 if (!this->getConfig().get<bool>("ndnSIM.disable_forwarder_status_manager", false)) {
285 m_impl->m_forwarderStatusManager.reset(new ForwarderStatusManager(*forwarder, *m_impl->m_dispatcher));
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800286 }
287
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700288 ConfigFile config(&ConfigFile::ignoreUnknownSection);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800289
spirosmastorakis34eed982016-11-02 15:20:50 -0700290 // if we use NFD's CS, we have to specify a replacement policy
291 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
292 if (m_impl->m_csFromNdnSim == nullptr) {
293 forwarder->getCs().setPolicy(m_impl->m_policy());
294 }
295
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800296 TablesConfigSection tablesConfig(forwarder->getCs(),
297 forwarder->getPit(),
298 forwarder->getFib(),
299 forwarder->getStrategyChoice(),
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700300 forwarder->getMeasurements(),
301 forwarder->getNetworkRegionTable());
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800302 tablesConfig.setConfigFile(config);
303
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700304 m_impl->m_validator->setConfigFile(config);
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800305
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700306 // if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) {
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800307 m_impl->m_faceManager->setConfigFile(config);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700308 // }
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800309
310 // apply config
311 config.parse(m_impl->m_config, false, "ndnSIM.conf");
312
313 tablesConfig.ensureTablesAreConfigured();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800314
315 // add FIB entry for NFD Management Protocol
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700316 Name topPrefix("/localhost/nfd");
317 auto entry = forwarder->getFib().insert(topPrefix).first;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800318 entry->addNextHop(m_impl->m_internalFace, 0);
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700319 m_impl->m_dispatcher->addTopPrefix(topPrefix, false);
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800320}
321
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700322void
323L3Protocol::initializeRibManager()
324{
325 using namespace nfd;
326
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700327 std::tie(m_impl->m_internalRibFace, m_impl->m_internalRibClientFace) = face::makeInternalFace(StackHelper::getKeyChain());
328 m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace);
329 m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_internalRibClientFace),
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700330 StackHelper::getKeyChain());
331
332 ConfigFile config([] (const std::string& filename, const std::string& sectionName,
333 const ConfigSection& section, bool isDryRun) {
334 // Ignore "log" and sections belonging to NFD,
335 // but raise an error if we're missing a handler for a "rib" section.
336 if (sectionName != "rib" || sectionName == "log") {
337 // do nothing
338 }
339 else {
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700340 // missing RIB section
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700341 ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
342 }
343 });
344
345 m_impl->m_ribManager->setConfigFile(config);
346
347 // apply config
348 config.parse(m_impl->m_config, false, "ndnSIM.conf");
349
350 m_impl->m_ribManager->registerWithNfd();
351
352 m_impl->m_ribManager->enableLocalControlHeader();
353}
354
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800355shared_ptr<nfd::Forwarder>
356L3Protocol::getForwarder()
357{
358 return m_impl->m_forwarder;
359}
360
361shared_ptr<nfd::FibManager>
362L3Protocol::getFibManager()
363{
364 return m_impl->m_fibManager;
365}
366
367shared_ptr<nfd::StrategyChoiceManager>
368L3Protocol::getStrategyChoiceManager()
369{
370 return m_impl->m_strategyChoiceManager;
371}
372
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800373nfd::ConfigSection&
374L3Protocol::getConfig()
375{
376 return m_impl->m_config;
377}
378
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700379/*
380 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700381 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700382 */
383void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800384L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700385{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800386 if (m_node == nullptr) {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800387 m_node = GetObject<Node>();
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800388 if (m_node != nullptr) {
Spyridon Mastorakis8fde22b2015-08-19 23:12:44 -0700389 initialize();
390
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -0800391 NS_ASSERT(m_impl->m_forwarder != nullptr);
392 m_impl->m_csFromNdnSim = GetObject<ContentStore>();
393 if (m_impl->m_csFromNdnSim != nullptr) {
394 m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
395 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700396 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800397 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700398
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800399 Object::NotifyNewAggregate();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700400}
401
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800402void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800403L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700404{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800405 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700406
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700407 // MUST HAPPEN BEFORE Simulator IS DESTROYED
408 m_impl.reset();
409
410 nfd::scheduler::getGlobalScheduler().cancelAllEvents();
411
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700412 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800413
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800414 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700415}
416
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800417nfd::FaceId
418L3Protocol::addFace(shared_ptr<Face> face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700419{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800420 NS_LOG_FUNCTION(this << face.get());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700421
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800422 m_impl->m_forwarder->addFace(face);
423
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700424 std::weak_ptr<Face> weakFace = face;
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800425
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700426 // // Connect Signals to TraceSource
427 face->afterReceiveInterest.connect([this, weakFace](const Interest& interest) {
428 shared_ptr<Face> face = weakFace.lock();
429 if (face != nullptr) {
430 this->m_inInterests(interest, *face);
431 }
432 });
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800433
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700434 face->afterReceiveData.connect([this, weakFace](const Data& data) {
435 shared_ptr<Face> face = weakFace.lock();
436 if (face != nullptr) {
437 this->m_inData(data, *face);
438 }
439 });
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700440 // TODO Add nack signals
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800441
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700442 auto tracingLink = face->getLinkService();
443 NS_LOG_LOGIC("Adding trace sources for afterSendInterest and afterSendData");
444 tracingLink->afterSendInterest.connect([this, weakFace](const Interest& interest) {
445 shared_ptr<Face> face = weakFace.lock();
446 if (face != nullptr) {
447 this->m_outInterests(interest, *face);
448 }
449 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700450
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700451 tracingLink->afterSendData.connect([this, weakFace](const Data& data) {
452 shared_ptr<Face> face = weakFace.lock();
453 if (face != nullptr) {
454 this->m_outData(data, *face);
455 }
456 });
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700457
Alexander Afanasyevac541b12016-09-12 19:45:53 -0700458 // TODO Add nack signals
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800459
460 return face->getId();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700461}
462
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800463shared_ptr<Face>
464L3Protocol::getFaceById(nfd::FaceId id) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700465{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800466 return m_impl->m_forwarder->getFaceTable().get(id);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700467}
468
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700469shared_ptr<Face>
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800470L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700471{
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800472 for (const auto& i : m_impl->m_forwarder->getFaceTable()) {
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700473 auto linkService = dynamic_cast<NetDeviceLinkService*>(i->getLinkService());
474 if (linkService == nullptr)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800475 continue;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700476
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700477 if (linkService->GetNetDevice() == netDevice)
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800478 return i;
479 }
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700480 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700481}
482
Alexander Afanasyev6b2a3c02015-01-03 02:04:23 -0800483Ptr<L3Protocol>
484L3Protocol::getL3Protocol(Ptr<Object> node)
485{
486 Ptr<L3Protocol> retval = node->GetObject<L3Protocol>();
487 NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object");
488 return retval;
489}
490
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800491} // namespace ndn
492} // namespace ns3