blob: 8c4033aae34209fbe5c68c4482ed34a65c9aeb1a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -04002/*
Davide Pesavento070ee3b2023-03-16 22:36:36 -04003 * Copyright (c) 2014-2023, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande57a87172020-05-09 19:47:06 -070020 */
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050021
Laqin Fan54a43f02017-03-08 12:31:30 -060022#include "nlsr.hpp"
23#include "adjacent.hpp"
24#include "logger.hpp"
25
akmhoque298385a2014-02-13 14:13:09 -060026#include <cstdlib>
akmhoque05d5fcf2014-04-15 14:58:45 -050027#include <cstdio>
akmhoque0494c252014-07-23 23:46:44 -050028#include <unistd.h>
akmhoque298385a2014-02-13 14:13:09 -060029
Davide Pesavento070ee3b2023-03-16 22:36:36 -040030#include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050031#include <ndn-cxx/net/face-uri.hpp>
akmhoque298385a2014-02-13 14:13:09 -060032
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
34
dmcoomescf8d0ed2017-02-21 11:39:01 -060035INIT_LOGGER(Nlsr);
akmhoque674b0b12014-05-20 14:33:28 -050036
Ashlesh Gawande85998a12017-12-07 22:22:13 -060037Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
38 : m_face(face)
39 , m_scheduler(face.getIoService())
Ashlesh Gawande85998a12017-12-07 22:22:13 -060040 , m_confParam(confParam)
41 , m_adjacencyList(confParam.getAdjacencyList())
42 , m_namePrefixList(confParam.getNamePrefixList())
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070043 , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, keyChain)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070044 , m_lsdb(m_face, keyChain, m_confParam)
45 , m_routingTable(m_scheduler, m_lsdb, m_confParam)
46 , m_namePrefixTable(confParam.getRouterPrefix(), m_fib, m_routingTable,
47 m_routingTable.afterRoutingChange, m_lsdb.onLsdbModified)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070048 , m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb)
Davide Pesavento1954a0c2022-09-30 15:56:04 -040049 , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa.connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050050 [this] (const ndn::Name& updateName, uint64_t sequenceNumber,
Alexander Afanasyev135288c2022-04-23 23:06:56 -040051 const ndn::Name& originRouter, uint64_t incomingFaceId) {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050052 registerStrategyForCerts(originRouter);
53 }))
54 , m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect(
55 [this] (const ndn::Name& name) {
56 m_helloProtocol.sendHelloInterest(name);
57 }))
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -070058 , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050059 [this] (const ndn::Name& neighbor) {
60 auto it = m_adjacencyList.findAdjacent(neighbor);
61 if (it != m_adjacencyList.end()) {
62 m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
63 ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
64 }
65 }))
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070066 , m_dispatcher(m_face, keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060067 , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070068 , m_controller(m_face, keyChain)
69 , m_faceDatasetController(m_face, keyChain)
laqinfan35731852017-08-08 06:17:39 -050070 , m_prefixUpdateProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050071 m_confParam.getPrefixUpdateValidator(),
72 m_namePrefixList,
73 m_lsdb,
74 m_confParam.getConfFileNameDynamic())
laqinfan35731852017-08-08 06:17:39 -050075 , m_nfdRibCommandProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050076 m_namePrefixList,
77 m_lsdb)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060078 , m_statsCollector(m_lsdb, m_helloProtocol)
79 , m_faceMonitor(m_face)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050080{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050081 NLSR_LOG_DEBUG("Initializing Nlsr");
82
dmcoomes9f936662017-03-02 10:33:09 -060083 m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050084 m_faceMonitor.start();
Ashlesh Gawande85998a12017-12-07 22:22:13 -060085
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070086 m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0);
87 m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050088
Saurab Dulal427e0122019-11-28 11:58:02 -060089 NLSR_LOG_DEBUG("Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName());
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050090
Saurab Dulal427e0122019-11-28 11:58:02 -060091 // Add top-level prefixes: router and localhost prefix
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050092 addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
93 addDispatcherTopPrefix(LOCALHOST_PREFIX);
94
95 enableIncomingFaceIdIndication();
96
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050097 initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
98 std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
99
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700100 m_adjacencyList.writeLog();
101 NLSR_LOG_DEBUG(m_namePrefixList);
102
103 // Need to set direct neighbors' costs to 0 for hyperbolic routing
104 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
105 for (auto&& neighbor : m_adjacencyList.getAdjList()) {
106 neighbor.setLinkCost(0);
107 }
108 }
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500109}
110
akmhoque53353462014-04-22 08:43:45 -0500111void
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500112Nlsr::registerStrategyForCerts(const ndn::Name& originRouter)
113{
114 for (const ndn::Name& router : m_strategySetOnRouters) {
115 if (router == originRouter) {
116 // Have already set strategy for this router's certs once
117 return;
118 }
119 }
120
121 m_strategySetOnRouters.push_back(originRouter);
122
123 ndn::Name routerKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700124 routerKey.append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500125 ndn::Name instanceKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700126 instanceKey.append("nlsr").append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500127
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400128 m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_STRATEGY, 0);
129 m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500130
131 ndn::Name siteKey;
132 for (size_t i = 0; i < originRouter.size(); ++i) {
133 if (originRouter[i].toUri() == "%C1.Router") {
134 break;
135 }
136 siteKey.append(originRouter[i]);
137 }
138 ndn::Name opPrefix(siteKey);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700139 siteKey.append(ndn::security::Certificate::KEY_COMPONENT);
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400140 m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500141
142 opPrefix.append(std::string("%C1.Operator"));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400143 m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500144}
145
146void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500147Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
148{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700149 registerPrefix(topPrefix);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500150 try {
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500151 // false since we want to have control over the registration process
Saurab Dulal427e0122019-11-28 11:58:02 -0600152 m_dispatcher.addTopPrefix(topPrefix, false, m_confParam.getSigningInfo());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500153 }
154 catch (const std::exception& e) {
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700155 NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500156 }
157}
158
akmhoque53353462014-04-22 08:43:45 -0500159void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700160Nlsr::registerPrefix(const ndn::Name& prefix)
akmhoque157b0a42014-05-13 00:26:37 -0500161{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700162 m_face.registerPrefix(prefix,
163 [] (const ndn::Name& name) {
164 NLSR_LOG_DEBUG("Successfully registered prefix: " << name);
165 },
166 [] (const ndn::Name& name, const std::string& reason) {
167 NLSR_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon");
168 NDN_THROW(Error("Error: Prefix registration failed: " + reason));
169 });
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500170}
171
172void
akmhoquec04e7272014-07-02 11:00:14 -0500173Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
akmhoquee1765152014-06-30 11:32:01 -0500174{
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500175 NLSR_LOG_TRACE("onFaceEventNotification called");
Vince Lehman02e32992015-03-11 12:31:20 -0500176
Nick Gordond5c1a372016-10-31 13:56:23 -0500177 switch (faceEventNotification.getKind()) {
178 case ndn::nfd::FACE_EVENT_DESTROYED: {
179 uint64_t faceId = faceEventNotification.getFaceId();
Vince Lehman02e32992015-03-11 12:31:20 -0500180
Nick Gordond5c1a372016-10-31 13:56:23 -0500181 auto adjacent = m_adjacencyList.findAdjacent(faceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500182
Nick Gordond5c1a372016-10-31 13:56:23 -0500183 if (adjacent != m_adjacencyList.end()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500184 NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed");
Vince Lehman02e32992015-03-11 12:31:20 -0500185
Nick Gordond5c1a372016-10-31 13:56:23 -0500186 adjacent->setFaceId(0);
Vince Lehman02e32992015-03-11 12:31:20 -0500187
Nick Gordond5c1a372016-10-31 13:56:23 -0500188 // Only trigger an Adjacency LSA build if this node is changing
189 // from ACTIVE to INACTIVE since this rebuild will effectively
190 // cancel the previous Adjacency LSA refresh event and schedule
191 // a new one further in the future.
192 //
193 // Continuously scheduling the refresh in the future will block
194 // the router from refreshing its Adjacency LSA. Since other
195 // routers' Name prefixes' expiration times are updated when
196 // this router refreshes its Adjacency LSA, the other routers'
197 // prefixes will expire and be removed from the RIB.
198 //
199 // This check is required to fix Bug #2733 for now. This check
200 // would be unnecessary to fix Bug #2733 when Issue #2732 is
201 // completed, but the check also helps with optimization so it
202 // can remain even when Issue #2732 is implemented.
203 if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) {
204 adjacent->setStatus(Adjacent::STATUS_INACTIVE);
Vince Lehman02e32992015-03-11 12:31:20 -0500205
Nick Gordond5c1a372016-10-31 13:56:23 -0500206 // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and
207 // has met the HELLO retry threshold
208 adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
Vince Lehman199e9cf2015-04-07 13:22:16 -0500209
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500210 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600211 m_routingTable.scheduleRoutingTableCalculation();
Nick Gordond5c1a372016-10-31 13:56:23 -0500212 }
213 else {
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500214 // Will call scheduleRoutingTableCalculation internally
215 // if needed in case of LS or DRY_RUN
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600216 m_lsdb.scheduleAdjLsaBuild();
Nick Gordond5c1a372016-10-31 13:56:23 -0500217 }
Nick Gordone8e03ac2016-07-07 14:24:38 -0500218 }
Vince Lehman199e9cf2015-04-07 13:22:16 -0500219 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500220 break;
akmhoquec04e7272014-07-02 11:00:14 -0500221 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500222 case ndn::nfd::FACE_EVENT_CREATED: {
223 // Find the neighbor in our adjacency list
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600224 ndn::FaceUri faceUri;
225 try {
226 faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
227 }
228 catch (const std::exception& e) {
229 NLSR_LOG_WARN(e.what());
230 return;
231 }
232 auto adjacent = m_adjacencyList.findAdjacent(faceUri);
Ashlesh Gawande41878572019-09-29 00:16:02 -0500233 uint64_t faceId = faceEventNotification.getFaceId();
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600234
Ashlesh Gawande41878572019-09-29 00:16:02 -0500235 // If we have a neighbor by that FaceUri and it has no FaceId or
236 // the FaceId is different from ours, we have a match.
237 if (adjacent != m_adjacencyList.end() &&
238 (adjacent->getFaceId() == 0 || adjacent->getFaceId() != faceId))
239 {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500240 NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName()
Ashlesh Gawande41878572019-09-29 00:16:02 -0500241 << ". New Face ID: " << faceId << ". Registering prefixes.");
242 adjacent->setFaceId(faceId);
Nick Gordond5c1a372016-10-31 13:56:23 -0500243
244 registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500245
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500246 // We should not do scheduleRoutingTableCalculation or scheduleAdjLsaBuild here
247 // because once the prefixes are registered, we send a HelloInterest
248 // to the prefix (see NLSR ctor). HelloProtocol will call these functions
249 // once HelloData is received and validated.
Nick Gordond5c1a372016-10-31 13:56:23 -0500250 }
251 break;
252 }
253 default:
254 break;
akmhoquec04e7272014-07-02 11:00:14 -0500255 }
akmhoquee1765152014-06-30 11:32:01 -0500256}
257
Nick Gordond5c1a372016-10-31 13:56:23 -0500258void
259Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess,
260 const FetchDatasetTimeoutCallback& onFetchFailure)
261{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500262 NLSR_LOG_TRACE("Initializing Faces...");
Nick Gordond5c1a372016-10-31 13:56:23 -0500263 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
Nick Gordond5c1a372016-10-31 13:56:23 -0500264}
265
266void
267Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
268{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500269 NLSR_LOG_DEBUG("Processing face dataset");
Nick Gordond5c1a372016-10-31 13:56:23 -0500270
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500271 // Iterate over each neighbor listed in nlsr.conf
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500272 for (auto&& adjacent : m_adjacencyList.getAdjList()) {
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500273
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500274 const std::string& faceUriString = adjacent.getFaceUri().toString();
Nick Gordond5c1a372016-10-31 13:56:23 -0500275 // Check the list of FaceStatus objects we got for a match
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500276 for (const auto& faceStatus : faces) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500277 // Set the adjacency FaceID if we find a URI match and it was
278 // previously unset. Change the boolean to true.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500279 if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500280 NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() <<
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500281 " FaceId: "<< faceStatus.getFaceId());
282 adjacent.setFaceId(faceStatus.getFaceId());
Nick Gordond5c1a372016-10-31 13:56:23 -0500283 // Register the prefixes for each neighbor
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500284 this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max());
Nick Gordond5c1a372016-10-31 13:56:23 -0500285 }
286 }
287 // If this adjacency has no information in this dataset, then one
288 // of two things is happening: 1. NFD is starting slowly and this
289 // Face wasn't ready yet, or 2. NFD is configured
290 // incorrectly and this Face isn't available.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500291 if (adjacent.getFaceId() == 0) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500292 NLSR_LOG_WARN("The adjacency " << adjacent.getName() <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500293 " has no Face information in this dataset.");
294 }
295 }
296
Nick Gordond5c1a372016-10-31 13:56:23 -0500297 scheduleDatasetFetch();
298}
299
300void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700301Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout)
Nick Gordond5c1a372016-10-31 13:56:23 -0500302{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500303 ndn::FaceUri faceUri = adj.getFaceUri();
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500304 double linkCost = adj.getLinkCost();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500305 const ndn::Name& adjName = adj.getName();
Nick Gordond5c1a372016-10-31 13:56:23 -0500306
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500307 m_fib.registerPrefix(adjName, faceUri, linkCost,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500308 timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500309
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500310 m_fib.registerPrefix(m_confParam.getLsaPrefix(),
311 faceUri, linkCost, timeout,
312 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500313}
314
315void
316Nlsr::onFaceDatasetFetchTimeout(uint32_t code,
317 const std::string& msg,
318 uint32_t nRetriesSoFar)
319{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500320 NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout");
Nick Gordond5c1a372016-10-31 13:56:23 -0500321 // If we have exceeded the maximum attempt count, do not try again.
322 if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500323 NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar);
Nick Gordond5c1a372016-10-31 13:56:23 -0500324 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset,
325 this, _1),
326 std::bind(&Nlsr::onFaceDatasetFetchTimeout,
327 this, _1, _2, nRetriesSoFar));
328 }
329 else {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500330 NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500331 m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time.");
332 // If we fail to fetch it, just do nothing until the next
333 // interval. Since this is a backup mechanism, we aren't as
334 // concerned with retrying.
335 scheduleDatasetFetch();
336 }
337}
338
339void
340Nlsr::scheduleDatasetFetch()
341{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500342 NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval());
343
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400344 m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(),
Nick Gordond5c1a372016-10-31 13:56:23 -0500345 [this] {
346 this->initializeFaces(
347 [this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
348 this->processFaceDataset(faces);
349 },
350 [this] (uint32_t code, const std::string& msg) {
351 this->onFaceDatasetFetchTimeout(code, msg, 0);
352 });
353 });
354}
akmhoquee1765152014-06-30 11:32:01 -0500355
356void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500357Nlsr::enableIncomingFaceIdIndication()
358{
359 NLSR_LOG_DEBUG("Enabling incoming face id indication for local face.");
360
361 m_controller.start<ndn::nfd::FaceUpdateCommand>(
362 ndn::nfd::ControlParameters()
363 .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true),
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700364 [] (const ndn::nfd::ControlParameters& cp) {
365 NLSR_LOG_DEBUG("Successfully enabled incoming face id indication"
366 << "for face id " << cp.getFaceId());
367 },
368 [] (const ndn::nfd::ControlResponse& cr) {
369 NLSR_LOG_WARN("Failed to enable incoming face id indication feature: " <<
370 "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")");
371 });
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500372}
373
akmhoqueb1710aa2014-02-19 17:13:36 -0600374} // namespace nlsr