blob: c43ad47eedcf6e6c33a219cbf0521dbaf23c59a0 [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/*
Alexander Afanasyev135288c2022-04-23 23:06:56 -04003 * Copyright (c) 2014-2022, 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
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050030#include <ndn-cxx/net/face-uri.hpp>
akmhoque298385a2014-02-13 14:13:09 -060031
akmhoque53353462014-04-22 08:43:45 -050032namespace nlsr {
33
dmcoomescf8d0ed2017-02-21 11:39:01 -060034INIT_LOGGER(Nlsr);
akmhoque674b0b12014-05-20 14:33:28 -050035
Ashlesh Gawande85998a12017-12-07 22:22:13 -060036Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
37 : m_face(face)
38 , m_scheduler(face.getIoService())
Ashlesh Gawande85998a12017-12-07 22:22:13 -060039 , m_confParam(confParam)
40 , m_adjacencyList(confParam.getAdjacencyList())
41 , m_namePrefixList(confParam.getNamePrefixList())
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070042 , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, keyChain)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070043 , m_lsdb(m_face, keyChain, m_confParam)
44 , m_routingTable(m_scheduler, m_lsdb, m_confParam)
45 , m_namePrefixTable(confParam.getRouterPrefix(), m_fib, m_routingTable,
46 m_routingTable.afterRoutingChange, m_lsdb.onLsdbModified)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070047 , m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb)
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -050048 , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050049 [this] (const ndn::Name& updateName, uint64_t sequenceNumber,
Alexander Afanasyev135288c2022-04-23 23:06:56 -040050 const ndn::Name& originRouter, uint64_t incomingFaceId) {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050051 registerStrategyForCerts(originRouter);
52 }))
53 , m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect(
54 [this] (const ndn::Name& name) {
55 m_helloProtocol.sendHelloInterest(name);
56 }))
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -070057 , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050058 [this] (const ndn::Name& neighbor) {
59 auto it = m_adjacencyList.findAdjacent(neighbor);
60 if (it != m_adjacencyList.end()) {
61 m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
62 ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
63 }
64 }))
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070065 , m_dispatcher(m_face, keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060066 , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070067 , m_controller(m_face, keyChain)
68 , m_faceDatasetController(m_face, keyChain)
laqinfan35731852017-08-08 06:17:39 -050069 , m_prefixUpdateProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050070 m_confParam.getPrefixUpdateValidator(),
71 m_namePrefixList,
72 m_lsdb,
73 m_confParam.getConfFileNameDynamic())
laqinfan35731852017-08-08 06:17:39 -050074 , m_nfdRibCommandProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050075 m_namePrefixList,
76 m_lsdb)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060077 , m_statsCollector(m_lsdb, m_helloProtocol)
78 , m_faceMonitor(m_face)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050079{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050080 NLSR_LOG_DEBUG("Initializing Nlsr");
81
dmcoomes9f936662017-03-02 10:33:09 -060082 m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050083 m_faceMonitor.start();
Ashlesh Gawande85998a12017-12-07 22:22:13 -060084
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070085 m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0);
86 m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050087
Saurab Dulal427e0122019-11-28 11:58:02 -060088 NLSR_LOG_DEBUG("Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName());
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050089
Saurab Dulal427e0122019-11-28 11:58:02 -060090 // Add top-level prefixes: router and localhost prefix
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050091 addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
92 addDispatcherTopPrefix(LOCALHOST_PREFIX);
93
94 enableIncomingFaceIdIndication();
95
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050096 initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
97 std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
98
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070099 m_adjacencyList.writeLog();
100 NLSR_LOG_DEBUG(m_namePrefixList);
101
102 // Need to set direct neighbors' costs to 0 for hyperbolic routing
103 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
104 for (auto&& neighbor : m_adjacencyList.getAdjList()) {
105 neighbor.setLinkCost(0);
106 }
107 }
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500108}
109
akmhoque53353462014-04-22 08:43:45 -0500110void
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500111Nlsr::registerStrategyForCerts(const ndn::Name& originRouter)
112{
113 for (const ndn::Name& router : m_strategySetOnRouters) {
114 if (router == originRouter) {
115 // Have already set strategy for this router's certs once
116 return;
117 }
118 }
119
120 m_strategySetOnRouters.push_back(originRouter);
121
122 ndn::Name routerKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700123 routerKey.append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500124 ndn::Name instanceKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700125 instanceKey.append("nlsr").append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500126
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400127 m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_STRATEGY, 0);
128 m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500129
130 ndn::Name siteKey;
131 for (size_t i = 0; i < originRouter.size(); ++i) {
132 if (originRouter[i].toUri() == "%C1.Router") {
133 break;
134 }
135 siteKey.append(originRouter[i]);
136 }
137 ndn::Name opPrefix(siteKey);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700138 siteKey.append(ndn::security::Certificate::KEY_COMPONENT);
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400139 m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500140
141 opPrefix.append(std::string("%C1.Operator"));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400142 m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500143}
144
145void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500146Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
147{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700148 registerPrefix(topPrefix);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500149 try {
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500150 // false since we want to have control over the registration process
Saurab Dulal427e0122019-11-28 11:58:02 -0600151 m_dispatcher.addTopPrefix(topPrefix, false, m_confParam.getSigningInfo());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500152 }
153 catch (const std::exception& e) {
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700154 NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500155 }
156}
157
akmhoque53353462014-04-22 08:43:45 -0500158void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700159Nlsr::registerPrefix(const ndn::Name& prefix)
akmhoque157b0a42014-05-13 00:26:37 -0500160{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700161 m_face.registerPrefix(prefix,
162 [] (const ndn::Name& name) {
163 NLSR_LOG_DEBUG("Successfully registered prefix: " << name);
164 },
165 [] (const ndn::Name& name, const std::string& reason) {
166 NLSR_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon");
167 NDN_THROW(Error("Error: Prefix registration failed: " + reason));
168 });
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500169}
170
171void
akmhoquec04e7272014-07-02 11:00:14 -0500172Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
akmhoquee1765152014-06-30 11:32:01 -0500173{
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500174 NLSR_LOG_TRACE("onFaceEventNotification called");
Vince Lehman02e32992015-03-11 12:31:20 -0500175
Nick Gordond5c1a372016-10-31 13:56:23 -0500176 switch (faceEventNotification.getKind()) {
177 case ndn::nfd::FACE_EVENT_DESTROYED: {
178 uint64_t faceId = faceEventNotification.getFaceId();
Vince Lehman02e32992015-03-11 12:31:20 -0500179
Nick Gordond5c1a372016-10-31 13:56:23 -0500180 auto adjacent = m_adjacencyList.findAdjacent(faceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500181
Nick Gordond5c1a372016-10-31 13:56:23 -0500182 if (adjacent != m_adjacencyList.end()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500183 NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed");
Vince Lehman02e32992015-03-11 12:31:20 -0500184
Nick Gordond5c1a372016-10-31 13:56:23 -0500185 adjacent->setFaceId(0);
Vince Lehman02e32992015-03-11 12:31:20 -0500186
Nick Gordond5c1a372016-10-31 13:56:23 -0500187 // Only trigger an Adjacency LSA build if this node is changing
188 // from ACTIVE to INACTIVE since this rebuild will effectively
189 // cancel the previous Adjacency LSA refresh event and schedule
190 // a new one further in the future.
191 //
192 // Continuously scheduling the refresh in the future will block
193 // the router from refreshing its Adjacency LSA. Since other
194 // routers' Name prefixes' expiration times are updated when
195 // this router refreshes its Adjacency LSA, the other routers'
196 // prefixes will expire and be removed from the RIB.
197 //
198 // This check is required to fix Bug #2733 for now. This check
199 // would be unnecessary to fix Bug #2733 when Issue #2732 is
200 // completed, but the check also helps with optimization so it
201 // can remain even when Issue #2732 is implemented.
202 if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) {
203 adjacent->setStatus(Adjacent::STATUS_INACTIVE);
Vince Lehman02e32992015-03-11 12:31:20 -0500204
Nick Gordond5c1a372016-10-31 13:56:23 -0500205 // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and
206 // has met the HELLO retry threshold
207 adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
Vince Lehman199e9cf2015-04-07 13:22:16 -0500208
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500209 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600210 m_routingTable.scheduleRoutingTableCalculation();
Nick Gordond5c1a372016-10-31 13:56:23 -0500211 }
212 else {
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500213 // Will call scheduleRoutingTableCalculation internally
214 // if needed in case of LS or DRY_RUN
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600215 m_lsdb.scheduleAdjLsaBuild();
Nick Gordond5c1a372016-10-31 13:56:23 -0500216 }
Nick Gordone8e03ac2016-07-07 14:24:38 -0500217 }
Vince Lehman199e9cf2015-04-07 13:22:16 -0500218 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500219 break;
akmhoquec04e7272014-07-02 11:00:14 -0500220 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500221 case ndn::nfd::FACE_EVENT_CREATED: {
222 // Find the neighbor in our adjacency list
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600223 ndn::FaceUri faceUri;
224 try {
225 faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
226 }
227 catch (const std::exception& e) {
228 NLSR_LOG_WARN(e.what());
229 return;
230 }
231 auto adjacent = m_adjacencyList.findAdjacent(faceUri);
Ashlesh Gawande41878572019-09-29 00:16:02 -0500232 uint64_t faceId = faceEventNotification.getFaceId();
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600233
Ashlesh Gawande41878572019-09-29 00:16:02 -0500234 // If we have a neighbor by that FaceUri and it has no FaceId or
235 // the FaceId is different from ours, we have a match.
236 if (adjacent != m_adjacencyList.end() &&
237 (adjacent->getFaceId() == 0 || adjacent->getFaceId() != faceId))
238 {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500239 NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName()
Ashlesh Gawande41878572019-09-29 00:16:02 -0500240 << ". New Face ID: " << faceId << ". Registering prefixes.");
241 adjacent->setFaceId(faceId);
Nick Gordond5c1a372016-10-31 13:56:23 -0500242
243 registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500244
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500245 // We should not do scheduleRoutingTableCalculation or scheduleAdjLsaBuild here
246 // because once the prefixes are registered, we send a HelloInterest
247 // to the prefix (see NLSR ctor). HelloProtocol will call these functions
248 // once HelloData is received and validated.
Nick Gordond5c1a372016-10-31 13:56:23 -0500249 }
250 break;
251 }
252 default:
253 break;
akmhoquec04e7272014-07-02 11:00:14 -0500254 }
akmhoquee1765152014-06-30 11:32:01 -0500255}
256
Nick Gordond5c1a372016-10-31 13:56:23 -0500257void
258Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess,
259 const FetchDatasetTimeoutCallback& onFetchFailure)
260{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500261 NLSR_LOG_TRACE("Initializing Faces...");
Nick Gordond5c1a372016-10-31 13:56:23 -0500262 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
Nick Gordond5c1a372016-10-31 13:56:23 -0500263}
264
265void
266Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
267{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500268 NLSR_LOG_DEBUG("Processing face dataset");
Nick Gordond5c1a372016-10-31 13:56:23 -0500269
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500270 // Iterate over each neighbor listed in nlsr.conf
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500271 for (auto&& adjacent : m_adjacencyList.getAdjList()) {
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500272
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500273 const std::string& faceUriString = adjacent.getFaceUri().toString();
Nick Gordond5c1a372016-10-31 13:56:23 -0500274 // Check the list of FaceStatus objects we got for a match
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500275 for (const auto& faceStatus : faces) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500276 // Set the adjacency FaceID if we find a URI match and it was
277 // previously unset. Change the boolean to true.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500278 if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500279 NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() <<
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500280 " FaceId: "<< faceStatus.getFaceId());
281 adjacent.setFaceId(faceStatus.getFaceId());
Nick Gordond5c1a372016-10-31 13:56:23 -0500282 // Register the prefixes for each neighbor
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500283 this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max());
Nick Gordond5c1a372016-10-31 13:56:23 -0500284 }
285 }
286 // If this adjacency has no information in this dataset, then one
287 // of two things is happening: 1. NFD is starting slowly and this
288 // Face wasn't ready yet, or 2. NFD is configured
289 // incorrectly and this Face isn't available.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500290 if (adjacent.getFaceId() == 0) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500291 NLSR_LOG_WARN("The adjacency " << adjacent.getName() <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500292 " has no Face information in this dataset.");
293 }
294 }
295
Nick Gordond5c1a372016-10-31 13:56:23 -0500296 scheduleDatasetFetch();
297}
298
299void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700300Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout)
Nick Gordond5c1a372016-10-31 13:56:23 -0500301{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500302 ndn::FaceUri faceUri = adj.getFaceUri();
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500303 double linkCost = adj.getLinkCost();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500304 const ndn::Name& adjName = adj.getName();
Nick Gordond5c1a372016-10-31 13:56:23 -0500305
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500306 m_fib.registerPrefix(adjName, faceUri, linkCost,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500307 timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500308
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500309 m_fib.registerPrefix(m_confParam.getLsaPrefix(),
310 faceUri, linkCost, timeout,
311 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500312}
313
314void
315Nlsr::onFaceDatasetFetchTimeout(uint32_t code,
316 const std::string& msg,
317 uint32_t nRetriesSoFar)
318{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500319 NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout");
Nick Gordond5c1a372016-10-31 13:56:23 -0500320 // If we have exceeded the maximum attempt count, do not try again.
321 if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500322 NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar);
Nick Gordond5c1a372016-10-31 13:56:23 -0500323 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset,
324 this, _1),
325 std::bind(&Nlsr::onFaceDatasetFetchTimeout,
326 this, _1, _2, nRetriesSoFar));
327 }
328 else {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500329 NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500330 m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time.");
331 // If we fail to fetch it, just do nothing until the next
332 // interval. Since this is a backup mechanism, we aren't as
333 // concerned with retrying.
334 scheduleDatasetFetch();
335 }
336}
337
338void
339Nlsr::scheduleDatasetFetch()
340{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500341 NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval());
342
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400343 m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(),
Nick Gordond5c1a372016-10-31 13:56:23 -0500344 [this] {
345 this->initializeFaces(
346 [this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
347 this->processFaceDataset(faces);
348 },
349 [this] (uint32_t code, const std::string& msg) {
350 this->onFaceDatasetFetchTimeout(code, msg, 0);
351 });
352 });
353}
akmhoquee1765152014-06-30 11:32:01 -0500354
355void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500356Nlsr::enableIncomingFaceIdIndication()
357{
358 NLSR_LOG_DEBUG("Enabling incoming face id indication for local face.");
359
360 m_controller.start<ndn::nfd::FaceUpdateCommand>(
361 ndn::nfd::ControlParameters()
362 .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true),
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700363 [] (const ndn::nfd::ControlParameters& cp) {
364 NLSR_LOG_DEBUG("Successfully enabled incoming face id indication"
365 << "for face id " << cp.getFaceId());
366 },
367 [] (const ndn::nfd::ControlResponse& cr) {
368 NLSR_LOG_WARN("Failed to enable incoming face id indication feature: " <<
369 "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")");
370 });
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500371}
372
akmhoqueb1710aa2014-02-19 17:13:36 -0600373} // namespace nlsr