blob: 4d52fa04363b12d618d47f6ebd91a5b374a9475d [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 Pesavento968eb1a2025-01-07 00:46:05 -05003 * Copyright (c) 2014-2025, 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 Pesavento20e60a22025-01-07 01:50:10 -050030#include <ndn-cxx/mgmt/nfd/control-command.hpp>
Davide Pesavento070ee3b2023-03-16 22:36:36 -040031#include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050032#include <ndn-cxx/net/face-uri.hpp>
akmhoque298385a2014-02-13 14:13:09 -060033
akmhoque53353462014-04-22 08:43:45 -050034namespace nlsr {
35
dmcoomescf8d0ed2017-02-21 11:39:01 -060036INIT_LOGGER(Nlsr);
akmhoque674b0b12014-05-20 14:33:28 -050037
Ashlesh Gawande85998a12017-12-07 22:22:13 -060038Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
39 : m_face(face)
Davide Pesaventofd1e9402023-11-13 15:40:41 -050040 , m_scheduler(face.getIoContext())
Ashlesh Gawande85998a12017-12-07 22:22:13 -060041 , m_confParam(confParam)
42 , m_adjacencyList(confParam.getAdjacencyList())
43 , m_namePrefixList(confParam.getNamePrefixList())
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070044 , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, keyChain)
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070045 , m_lsdb(m_face, keyChain, m_confParam)
46 , m_routingTable(m_scheduler, m_lsdb, m_confParam)
47 , m_namePrefixTable(confParam.getRouterPrefix(), m_fib, m_routingTable,
48 m_routingTable.afterRoutingChange, m_lsdb.onLsdbModified)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070049 , m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb)
Davide Pesavento1954a0c2022-09-30 15:56:04 -040050 , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa.connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050051 [this] (const ndn::Name& updateName, uint64_t sequenceNumber,
Alexander Afanasyev135288c2022-04-23 23:06:56 -040052 const ndn::Name& originRouter, uint64_t incomingFaceId) {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050053 registerStrategyForCerts(originRouter);
54 }))
55 , m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect(
56 [this] (const ndn::Name& name) {
57 m_helloProtocol.sendHelloInterest(name);
58 }))
Ashlesh Gawandee63b7fa2021-04-06 21:43:17 -070059 , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect(
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050060 [this] (const ndn::Name& neighbor) {
61 auto it = m_adjacencyList.findAdjacent(neighbor);
62 if (it != m_adjacencyList.end()) {
63 m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
64 ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
65 }
66 }))
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070067 , m_dispatcher(m_face, keyChain)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060068 , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070069 , m_controller(m_face, keyChain)
70 , m_faceDatasetController(m_face, keyChain)
laqinfan35731852017-08-08 06:17:39 -050071 , m_prefixUpdateProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050072 m_confParam.getPrefixUpdateValidator(),
73 m_namePrefixList,
74 m_lsdb,
75 m_confParam.getConfFileNameDynamic())
laqinfan35731852017-08-08 06:17:39 -050076 , m_nfdRibCommandProcessor(m_dispatcher,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050077 m_namePrefixList,
78 m_lsdb)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060079 , m_statsCollector(m_lsdb, m_helloProtocol)
80 , m_faceMonitor(m_face)
awlane834ffb12025-01-24 20:11:51 -060081 , m_terminateSignals(face.getIoContext(), SIGINT, SIGTERM)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050082{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050083 NLSR_LOG_DEBUG("Initializing Nlsr");
84
dmcoomes9f936662017-03-02 10:33:09 -060085 m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050086 m_faceMonitor.start();
Ashlesh Gawande85998a12017-12-07 22:22:13 -060087
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -070088 m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0);
89 m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050090
Saurab Dulal427e0122019-11-28 11:58:02 -060091 NLSR_LOG_DEBUG("Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName());
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050092
Saurab Dulal427e0122019-11-28 11:58:02 -060093 // Add top-level prefixes: router and localhost prefix
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050094 addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
95 addDispatcherTopPrefix(LOCALHOST_PREFIX);
96
97 enableIncomingFaceIdIndication();
98
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050099 initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
100 std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
101
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700102 m_adjacencyList.writeLog();
103 NLSR_LOG_DEBUG(m_namePrefixList);
104
105 // Need to set direct neighbors' costs to 0 for hyperbolic routing
106 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
107 for (auto&& neighbor : m_adjacencyList.getAdjList()) {
108 neighbor.setLinkCost(0);
109 }
110 }
awlane834ffb12025-01-24 20:11:51 -0600111
112 m_terminateSignals.async_wait([this] (auto&&... args) {
113 terminate(std::forward<decltype(args)>(args)...);
114 });
Vince Lehmand6bb3fa2015-04-24 14:21:39 -0500115}
116
akmhoque53353462014-04-22 08:43:45 -0500117void
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500118Nlsr::registerStrategyForCerts(const ndn::Name& originRouter)
119{
120 for (const ndn::Name& router : m_strategySetOnRouters) {
121 if (router == originRouter) {
122 // Have already set strategy for this router's certs once
123 return;
124 }
125 }
126
127 m_strategySetOnRouters.push_back(originRouter);
128
129 ndn::Name routerKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700130 routerKey.append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500131 ndn::Name instanceKey(originRouter);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700132 instanceKey.append("nlsr").append(ndn::security::Certificate::KEY_COMPONENT);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500133
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400134 m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_STRATEGY, 0);
135 m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500136
137 ndn::Name siteKey;
138 for (size_t i = 0; i < originRouter.size(); ++i) {
139 if (originRouter[i].toUri() == "%C1.Router") {
140 break;
141 }
142 siteKey.append(originRouter[i]);
143 }
144 ndn::Name opPrefix(siteKey);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700145 siteKey.append(ndn::security::Certificate::KEY_COMPONENT);
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400146 m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500147
148 opPrefix.append(std::string("%C1.Operator"));
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400149 m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_STRATEGY, 0);
Ashlesh Gawande08bce9c2019-04-05 11:08:07 -0500150}
151
152void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500153Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
154{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700155 registerPrefix(topPrefix);
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500156 try {
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500157 // false since we want to have control over the registration process
Saurab Dulal427e0122019-11-28 11:58:02 -0600158 m_dispatcher.addTopPrefix(topPrefix, false, m_confParam.getSigningInfo());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500159 }
160 catch (const std::exception& e) {
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700161 NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500162 }
163}
164
akmhoque53353462014-04-22 08:43:45 -0500165void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700166Nlsr::registerPrefix(const ndn::Name& prefix)
akmhoque157b0a42014-05-13 00:26:37 -0500167{
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700168 m_face.registerPrefix(prefix,
169 [] (const ndn::Name& name) {
Davide Pesavento968eb1a2025-01-07 00:46:05 -0500170 NLSR_LOG_DEBUG("Successfully registered prefix " << name);
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700171 },
172 [] (const ndn::Name& name, const std::string& reason) {
Davide Pesavento968eb1a2025-01-07 00:46:05 -0500173 NLSR_LOG_ERROR("Failed to register prefix " << name << " (" << reason << ")");
174 NDN_THROW(Error("Prefix registration failed: " + reason));
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700175 });
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500176}
177
178void
akmhoquec04e7272014-07-02 11:00:14 -0500179Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
akmhoquee1765152014-06-30 11:32:01 -0500180{
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500181 NLSR_LOG_TRACE("onFaceEventNotification called");
Vince Lehman02e32992015-03-11 12:31:20 -0500182
Nick Gordond5c1a372016-10-31 13:56:23 -0500183 switch (faceEventNotification.getKind()) {
184 case ndn::nfd::FACE_EVENT_DESTROYED: {
185 uint64_t faceId = faceEventNotification.getFaceId();
Vince Lehman02e32992015-03-11 12:31:20 -0500186
Nick Gordond5c1a372016-10-31 13:56:23 -0500187 auto adjacent = m_adjacencyList.findAdjacent(faceId);
Vince Lehman02e32992015-03-11 12:31:20 -0500188
Nick Gordond5c1a372016-10-31 13:56:23 -0500189 if (adjacent != m_adjacencyList.end()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500190 NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed");
Vince Lehman02e32992015-03-11 12:31:20 -0500191
Nick Gordond5c1a372016-10-31 13:56:23 -0500192 adjacent->setFaceId(0);
Vince Lehman02e32992015-03-11 12:31:20 -0500193
Nick Gordond5c1a372016-10-31 13:56:23 -0500194 // Only trigger an Adjacency LSA build if this node is changing
195 // from ACTIVE to INACTIVE since this rebuild will effectively
196 // cancel the previous Adjacency LSA refresh event and schedule
197 // a new one further in the future.
198 //
199 // Continuously scheduling the refresh in the future will block
200 // the router from refreshing its Adjacency LSA. Since other
201 // routers' Name prefixes' expiration times are updated when
202 // this router refreshes its Adjacency LSA, the other routers'
203 // prefixes will expire and be removed from the RIB.
204 //
205 // This check is required to fix Bug #2733 for now. This check
206 // would be unnecessary to fix Bug #2733 when Issue #2732 is
207 // completed, but the check also helps with optimization so it
208 // can remain even when Issue #2732 is implemented.
209 if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) {
210 adjacent->setStatus(Adjacent::STATUS_INACTIVE);
Vince Lehman02e32992015-03-11 12:31:20 -0500211
Nick Gordond5c1a372016-10-31 13:56:23 -0500212 // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and
213 // has met the HELLO retry threshold
214 adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
Vince Lehman199e9cf2015-04-07 13:22:16 -0500215
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500216 if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600217 m_routingTable.scheduleRoutingTableCalculation();
Nick Gordond5c1a372016-10-31 13:56:23 -0500218 }
219 else {
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500220 // Will call scheduleRoutingTableCalculation internally
221 // if needed in case of LS or DRY_RUN
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600222 m_lsdb.scheduleAdjLsaBuild();
Nick Gordond5c1a372016-10-31 13:56:23 -0500223 }
Nick Gordone8e03ac2016-07-07 14:24:38 -0500224 }
Vince Lehman199e9cf2015-04-07 13:22:16 -0500225 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500226 break;
akmhoquec04e7272014-07-02 11:00:14 -0500227 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500228 case ndn::nfd::FACE_EVENT_CREATED: {
229 // Find the neighbor in our adjacency list
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600230 ndn::FaceUri faceUri;
231 try {
232 faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
233 }
234 catch (const std::exception& e) {
235 NLSR_LOG_WARN(e.what());
236 return;
237 }
238 auto adjacent = m_adjacencyList.findAdjacent(faceUri);
Ashlesh Gawande41878572019-09-29 00:16:02 -0500239 uint64_t faceId = faceEventNotification.getFaceId();
Ashlesh Gawande0d2c3822018-01-24 17:17:15 -0600240
Ashlesh Gawande41878572019-09-29 00:16:02 -0500241 // If we have a neighbor by that FaceUri and it has no FaceId or
242 // the FaceId is different from ours, we have a match.
243 if (adjacent != m_adjacencyList.end() &&
244 (adjacent->getFaceId() == 0 || adjacent->getFaceId() != faceId))
245 {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500246 NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName()
Ashlesh Gawande41878572019-09-29 00:16:02 -0500247 << ". New Face ID: " << faceId << ". Registering prefixes.");
248 adjacent->setFaceId(faceId);
Nick Gordond5c1a372016-10-31 13:56:23 -0500249
250 registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500251
Ashlesh Gawande214032e2020-12-22 17:20:14 -0500252 // We should not do scheduleRoutingTableCalculation or scheduleAdjLsaBuild here
253 // because once the prefixes are registered, we send a HelloInterest
254 // to the prefix (see NLSR ctor). HelloProtocol will call these functions
255 // once HelloData is received and validated.
Nick Gordond5c1a372016-10-31 13:56:23 -0500256 }
257 break;
258 }
259 default:
260 break;
akmhoquec04e7272014-07-02 11:00:14 -0500261 }
akmhoquee1765152014-06-30 11:32:01 -0500262}
263
Nick Gordond5c1a372016-10-31 13:56:23 -0500264void
265Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess,
266 const FetchDatasetTimeoutCallback& onFetchFailure)
267{
Davide Pesaventofd1e9402023-11-13 15:40:41 -0500268 NLSR_LOG_TRACE("Initializing faces");
Nick Gordond5c1a372016-10-31 13:56:23 -0500269 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
Nick Gordond5c1a372016-10-31 13:56:23 -0500270}
271
272void
273Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
274{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500275 NLSR_LOG_DEBUG("Processing face dataset");
Nick Gordond5c1a372016-10-31 13:56:23 -0500276
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500277 // Iterate over each neighbor listed in nlsr.conf
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500278 for (auto&& adjacent : m_adjacencyList.getAdjList()) {
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500279
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500280 const std::string& faceUriString = adjacent.getFaceUri().toString();
Nick Gordond5c1a372016-10-31 13:56:23 -0500281 // Check the list of FaceStatus objects we got for a match
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500282 for (const auto& faceStatus : faces) {
Nick Gordond5c1a372016-10-31 13:56:23 -0500283 // Set the adjacency FaceID if we find a URI match and it was
284 // previously unset. Change the boolean to true.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500285 if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500286 NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() <<
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500287 " FaceId: "<< faceStatus.getFaceId());
288 adjacent.setFaceId(faceStatus.getFaceId());
Nick Gordond5c1a372016-10-31 13:56:23 -0500289 // Register the prefixes for each neighbor
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500290 this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max());
Nick Gordond5c1a372016-10-31 13:56:23 -0500291 }
292 }
293 // If this adjacency has no information in this dataset, then one
294 // of two things is happening: 1. NFD is starting slowly and this
295 // Face wasn't ready yet, or 2. NFD is configured
296 // incorrectly and this Face isn't available.
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500297 if (adjacent.getFaceId() == 0) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500298 NLSR_LOG_WARN("The adjacency " << adjacent.getName() <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500299 " has no Face information in this dataset.");
300 }
301 }
302
Nick Gordond5c1a372016-10-31 13:56:23 -0500303 scheduleDatasetFetch();
304}
305
306void
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700307Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout)
Nick Gordond5c1a372016-10-31 13:56:23 -0500308{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500309 ndn::FaceUri faceUri = adj.getFaceUri();
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500310 double linkCost = adj.getLinkCost();
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500311 const ndn::Name& adjName = adj.getName();
Nick Gordond5c1a372016-10-31 13:56:23 -0500312
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500313 m_fib.registerPrefix(adjName, faceUri, linkCost,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500314 timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500315
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500316 m_fib.registerPrefix(m_confParam.getLsaPrefix(),
317 faceUri, linkCost, timeout,
318 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
Nick Gordond5c1a372016-10-31 13:56:23 -0500319}
320
321void
322Nlsr::onFaceDatasetFetchTimeout(uint32_t code,
323 const std::string& msg,
324 uint32_t nRetriesSoFar)
325{
326 // If we have exceeded the maximum attempt count, do not try again.
327 if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500328 NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar);
Davide Pesaventofd1e9402023-11-13 15:40:41 -0500329 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset, this, _1),
330 std::bind(&Nlsr::onFaceDatasetFetchTimeout,
331 this, _1, _2, nRetriesSoFar));
Nick Gordond5c1a372016-10-31 13:56:23 -0500332 }
333 else {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500334 NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " <<
Nick Gordond5c1a372016-10-31 13:56:23 -0500335 m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time.");
336 // If we fail to fetch it, just do nothing until the next
337 // interval. Since this is a backup mechanism, we aren't as
338 // concerned with retrying.
339 scheduleDatasetFetch();
340 }
341}
342
343void
344Nlsr::scheduleDatasetFetch()
345{
Davide Pesaventofd1e9402023-11-13 15:40:41 -0500346 NLSR_LOG_DEBUG("Scheduling dataset fetch in " << m_confParam.getFaceDatasetFetchInterval());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500347
Davide Pesaventofd1e9402023-11-13 15:40:41 -0500348 m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(), [this] {
349 initializeFaces(
350 [this] (const auto& faces) { processFaceDataset(faces); },
351 [this] (uint32_t code, const std::string& msg) { onFaceDatasetFetchTimeout(code, msg, 0); });
Nick Gordond5c1a372016-10-31 13:56:23 -0500352 });
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
awlane834ffb12025-01-24 20:11:51 -0600373void
374Nlsr::terminate(const boost::system::error_code& error, int signalNo)
375{
376 if (error)
377 return;
378 NLSR_LOG_INFO("Caught signal " << signalNo << " (" << ::strsignal(signalNo) << "), exiting...");
379 m_face.getIoContext().stop();
380}
381
akmhoqueb1710aa2014-02-19 17:13:36 -0600382} // namespace nlsr