akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 070ee3b | 2023-03-16 22:36:36 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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 Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 21 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 22 | #include "nlsr.hpp" |
| 23 | #include "adjacent.hpp" |
| 24 | #include "logger.hpp" |
| 25 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 26 | #include <cstdlib> |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 27 | #include <cstdio> |
akmhoque | 0494c25 | 2014-07-23 23:46:44 -0500 | [diff] [blame] | 28 | #include <unistd.h> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 29 | |
Davide Pesavento | 070ee3b | 2023-03-16 22:36:36 -0400 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/nfd/status-dataset.hpp> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/net/face-uri.hpp> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 32 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | namespace nlsr { |
| 34 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 35 | INIT_LOGGER(Nlsr); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 36 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 37 | Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam) |
| 38 | : m_face(face) |
Davide Pesavento | fd1e940 | 2023-11-13 15:40:41 -0500 | [diff] [blame] | 39 | , m_scheduler(face.getIoContext()) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 40 | , m_confParam(confParam) |
| 41 | , m_adjacencyList(confParam.getAdjacencyList()) |
| 42 | , m_namePrefixList(confParam.getNamePrefixList()) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 43 | , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, keyChain) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 44 | , 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 Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 48 | , m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb) |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 49 | , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa.connect( |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 50 | [this] (const ndn::Name& updateName, uint64_t sequenceNumber, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 51 | const ndn::Name& originRouter, uint64_t incomingFaceId) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 52 | registerStrategyForCerts(originRouter); |
| 53 | })) |
| 54 | , m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect( |
| 55 | [this] (const ndn::Name& name) { |
| 56 | m_helloProtocol.sendHelloInterest(name); |
| 57 | })) |
Ashlesh Gawande | e63b7fa | 2021-04-06 21:43:17 -0700 | [diff] [blame] | 58 | , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect( |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 59 | [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 Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 66 | , m_dispatcher(m_face, keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 67 | , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 68 | , m_controller(m_face, keyChain) |
| 69 | , m_faceDatasetController(m_face, keyChain) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 70 | , m_prefixUpdateProcessor(m_dispatcher, |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 71 | m_confParam.getPrefixUpdateValidator(), |
| 72 | m_namePrefixList, |
| 73 | m_lsdb, |
| 74 | m_confParam.getConfFileNameDynamic()) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 75 | , m_nfdRibCommandProcessor(m_dispatcher, |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 76 | m_namePrefixList, |
| 77 | m_lsdb) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 78 | , m_statsCollector(m_lsdb, m_helloProtocol) |
| 79 | , m_faceMonitor(m_face) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 80 | { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 81 | NLSR_LOG_DEBUG("Initializing Nlsr"); |
| 82 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 83 | m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 84 | m_faceMonitor.start(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 85 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 86 | m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0); |
| 87 | m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 88 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 89 | NLSR_LOG_DEBUG("Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName()); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 90 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 91 | // Add top-level prefixes: router and localhost prefix |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 92 | addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr")); |
| 93 | addDispatcherTopPrefix(LOCALHOST_PREFIX); |
| 94 | |
| 95 | enableIncomingFaceIdIndication(); |
| 96 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 97 | initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1), |
| 98 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0)); |
| 99 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 100 | 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 Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 109 | } |
| 110 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 111 | void |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 112 | Nlsr::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 Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 124 | routerKey.append(ndn::security::Certificate::KEY_COMPONENT); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 125 | ndn::Name instanceKey(originRouter); |
Ashlesh Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 126 | instanceKey.append("nlsr").append(ndn::security::Certificate::KEY_COMPONENT); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 127 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 128 | m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_STRATEGY, 0); |
| 129 | m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 130 | |
| 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 Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 139 | siteKey.append(ndn::security::Certificate::KEY_COMPONENT); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 140 | m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 141 | |
| 142 | opPrefix.append(std::string("%C1.Operator")); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 143 | m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 147 | Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix) |
| 148 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 149 | registerPrefix(topPrefix); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 150 | try { |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 151 | // false since we want to have control over the registration process |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 152 | m_dispatcher.addTopPrefix(topPrefix, false, m_confParam.getSigningInfo()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 153 | } |
| 154 | catch (const std::exception& e) { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 155 | NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 160 | Nlsr::registerPrefix(const ndn::Name& prefix) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 161 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 162 | 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 Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 173 | Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification) |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 174 | { |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 175 | NLSR_LOG_TRACE("onFaceEventNotification called"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 176 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 177 | switch (faceEventNotification.getKind()) { |
| 178 | case ndn::nfd::FACE_EVENT_DESTROYED: { |
| 179 | uint64_t faceId = faceEventNotification.getFaceId(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 180 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 181 | auto adjacent = m_adjacencyList.findAdjacent(faceId); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 182 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 183 | if (adjacent != m_adjacencyList.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 184 | NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 185 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 186 | adjacent->setFaceId(0); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 187 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 188 | // 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 Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 205 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 206 | // 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 Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 209 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 210 | if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 211 | m_routingTable.scheduleRoutingTableCalculation(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 212 | } |
| 213 | else { |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 214 | // Will call scheduleRoutingTableCalculation internally |
| 215 | // if needed in case of LS or DRY_RUN |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 216 | m_lsdb.scheduleAdjLsaBuild(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 217 | } |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 218 | } |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 219 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 220 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 221 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 222 | case ndn::nfd::FACE_EVENT_CREATED: { |
| 223 | // Find the neighbor in our adjacency list |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 224 | 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 Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 233 | uint64_t faceId = faceEventNotification.getFaceId(); |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 234 | |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 235 | // 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 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 240 | NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName() |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 241 | << ". New Face ID: " << faceId << ". Registering prefixes."); |
| 242 | adjacent->setFaceId(faceId); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 243 | |
| 244 | registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 245 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 246 | // 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 Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 250 | } |
| 251 | break; |
| 252 | } |
| 253 | default: |
| 254 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 255 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 256 | } |
| 257 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 258 | void |
| 259 | Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 260 | const FetchDatasetTimeoutCallback& onFetchFailure) |
| 261 | { |
Davide Pesavento | fd1e940 | 2023-11-13 15:40:41 -0500 | [diff] [blame] | 262 | NLSR_LOG_TRACE("Initializing faces"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 263 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void |
| 267 | Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces) |
| 268 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 269 | NLSR_LOG_DEBUG("Processing face dataset"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 270 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 271 | // Iterate over each neighbor listed in nlsr.conf |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 272 | for (auto&& adjacent : m_adjacencyList.getAdjList()) { |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 273 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 274 | const std::string& faceUriString = adjacent.getFaceUri().toString(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 275 | // Check the list of FaceStatus objects we got for a match |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 276 | for (const auto& faceStatus : faces) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 277 | // Set the adjacency FaceID if we find a URI match and it was |
| 278 | // previously unset. Change the boolean to true. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 279 | if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 280 | NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() << |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 281 | " FaceId: "<< faceStatus.getFaceId()); |
| 282 | adjacent.setFaceId(faceStatus.getFaceId()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 283 | // Register the prefixes for each neighbor |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 284 | this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 285 | } |
| 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 Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 291 | if (adjacent.getFaceId() == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 292 | NLSR_LOG_WARN("The adjacency " << adjacent.getName() << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 293 | " has no Face information in this dataset."); |
| 294 | } |
| 295 | } |
| 296 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 297 | scheduleDatasetFetch(); |
| 298 | } |
| 299 | |
| 300 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 301 | Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 302 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 303 | ndn::FaceUri faceUri = adj.getFaceUri(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 304 | double linkCost = adj.getLinkCost(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 305 | const ndn::Name& adjName = adj.getName(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 306 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 307 | m_fib.registerPrefix(adjName, faceUri, linkCost, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 308 | timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 309 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 310 | m_fib.registerPrefix(m_confParam.getLsaPrefix(), |
| 311 | faceUri, linkCost, timeout, |
| 312 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void |
| 316 | Nlsr::onFaceDatasetFetchTimeout(uint32_t code, |
| 317 | const std::string& msg, |
| 318 | uint32_t nRetriesSoFar) |
| 319 | { |
| 320 | // If we have exceeded the maximum attempt count, do not try again. |
| 321 | if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 322 | NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar); |
Davide Pesavento | fd1e940 | 2023-11-13 15:40:41 -0500 | [diff] [blame] | 323 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset, this, _1), |
| 324 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, |
| 325 | this, _1, _2, nRetriesSoFar)); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 326 | } |
| 327 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 328 | NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 329 | m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time."); |
| 330 | // If we fail to fetch it, just do nothing until the next |
| 331 | // interval. Since this is a backup mechanism, we aren't as |
| 332 | // concerned with retrying. |
| 333 | scheduleDatasetFetch(); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void |
| 338 | Nlsr::scheduleDatasetFetch() |
| 339 | { |
Davide Pesavento | fd1e940 | 2023-11-13 15:40:41 -0500 | [diff] [blame] | 340 | NLSR_LOG_DEBUG("Scheduling dataset fetch in " << m_confParam.getFaceDatasetFetchInterval()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 341 | |
Davide Pesavento | fd1e940 | 2023-11-13 15:40:41 -0500 | [diff] [blame] | 342 | m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(), [this] { |
| 343 | initializeFaces( |
| 344 | [this] (const auto& faces) { processFaceDataset(faces); }, |
| 345 | [this] (uint32_t code, const std::string& msg) { onFaceDatasetFetchTimeout(code, msg, 0); }); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 346 | }); |
| 347 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 348 | |
| 349 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 350 | Nlsr::enableIncomingFaceIdIndication() |
| 351 | { |
| 352 | NLSR_LOG_DEBUG("Enabling incoming face id indication for local face."); |
| 353 | |
| 354 | m_controller.start<ndn::nfd::FaceUpdateCommand>( |
| 355 | ndn::nfd::ControlParameters() |
| 356 | .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true), |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 357 | [] (const ndn::nfd::ControlParameters& cp) { |
| 358 | NLSR_LOG_DEBUG("Successfully enabled incoming face id indication" |
| 359 | << "for face id " << cp.getFaceId()); |
| 360 | }, |
| 361 | [] (const ndn::nfd::ControlResponse& cr) { |
| 362 | NLSR_LOG_WARN("Failed to enable incoming face id indication feature: " << |
| 363 | "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")"); |
| 364 | }); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 365 | } |
| 366 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 367 | } // namespace nlsr |