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 | /* |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/net/face-uri.hpp> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | namespace nlsr { |
| 33 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 34 | INIT_LOGGER(Nlsr); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 35 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 36 | Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam) |
| 37 | : m_face(face) |
| 38 | , m_scheduler(face.getIoService()) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 39 | , m_confParam(confParam) |
| 40 | , m_adjacencyList(confParam.getAdjacencyList()) |
| 41 | , m_namePrefixList(confParam.getNamePrefixList()) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 42 | , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, keyChain) |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 43 | , 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 Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 47 | , m_helloProtocol(m_face, keyChain, confParam, m_routingTable, m_lsdb) |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 48 | , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect( |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 49 | [this] (const ndn::Name& updateName, uint64_t sequenceNumber, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 50 | const ndn::Name& originRouter, uint64_t incomingFaceId) { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 51 | registerStrategyForCerts(originRouter); |
| 52 | })) |
| 53 | , m_onPrefixRegistrationSuccess(m_fib.onPrefixRegistrationSuccess.connect( |
| 54 | [this] (const ndn::Name& name) { |
| 55 | m_helloProtocol.sendHelloInterest(name); |
| 56 | })) |
Ashlesh Gawande | e63b7fa | 2021-04-06 21:43:17 -0700 | [diff] [blame] | 57 | , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect( |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 58 | [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 Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 65 | , m_dispatcher(m_face, keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 66 | , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 67 | , m_controller(m_face, keyChain) |
| 68 | , m_faceDatasetController(m_face, keyChain) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 69 | , m_prefixUpdateProcessor(m_dispatcher, |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 70 | m_confParam.getPrefixUpdateValidator(), |
| 71 | m_namePrefixList, |
| 72 | m_lsdb, |
| 73 | m_confParam.getConfFileNameDynamic()) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 74 | , m_nfdRibCommandProcessor(m_dispatcher, |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 75 | m_namePrefixList, |
| 76 | m_lsdb) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 77 | , m_statsCollector(m_lsdb, m_helloProtocol) |
| 78 | , m_faceMonitor(m_face) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 79 | { |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 80 | NLSR_LOG_DEBUG("Initializing Nlsr"); |
| 81 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 82 | m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 83 | m_faceMonitor.start(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 84 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 85 | m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0); |
| 86 | m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 87 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 88 | NLSR_LOG_DEBUG("Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName()); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 89 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 90 | // Add top-level prefixes: router and localhost prefix |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 91 | addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr")); |
| 92 | addDispatcherTopPrefix(LOCALHOST_PREFIX); |
| 93 | |
| 94 | enableIncomingFaceIdIndication(); |
| 95 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 96 | initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1), |
| 97 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0)); |
| 98 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 99 | 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 Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 108 | } |
| 109 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | void |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 111 | Nlsr::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 Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 123 | routerKey.append(ndn::security::Certificate::KEY_COMPONENT); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 124 | ndn::Name instanceKey(originRouter); |
Ashlesh Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 125 | instanceKey.append("nlsr").append(ndn::security::Certificate::KEY_COMPONENT); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 126 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 127 | m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_STRATEGY, 0); |
| 128 | m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 129 | |
| 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 Gawande | 7a231c0 | 2020-06-12 20:06:44 -0700 | [diff] [blame] | 138 | siteKey.append(ndn::security::Certificate::KEY_COMPONENT); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 139 | m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 140 | |
| 141 | opPrefix.append(std::string("%C1.Operator")); |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 142 | m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_STRATEGY, 0); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 146 | Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix) |
| 147 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 148 | registerPrefix(topPrefix); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 149 | try { |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 150 | // false since we want to have control over the registration process |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 151 | m_dispatcher.addTopPrefix(topPrefix, false, m_confParam.getSigningInfo()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 152 | } |
| 153 | catch (const std::exception& e) { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 154 | NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 158 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 159 | Nlsr::registerPrefix(const ndn::Name& prefix) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 160 | { |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 161 | 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 Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 172 | Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification) |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 173 | { |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 174 | NLSR_LOG_TRACE("onFaceEventNotification called"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 175 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 176 | switch (faceEventNotification.getKind()) { |
| 177 | case ndn::nfd::FACE_EVENT_DESTROYED: { |
| 178 | uint64_t faceId = faceEventNotification.getFaceId(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 179 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 180 | auto adjacent = m_adjacencyList.findAdjacent(faceId); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 181 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 182 | if (adjacent != m_adjacencyList.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 183 | NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 184 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 185 | adjacent->setFaceId(0); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 186 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 187 | // 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 Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 204 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 205 | // 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 Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 208 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 209 | if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 210 | m_routingTable.scheduleRoutingTableCalculation(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 211 | } |
| 212 | else { |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 213 | // Will call scheduleRoutingTableCalculation internally |
| 214 | // if needed in case of LS or DRY_RUN |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 215 | m_lsdb.scheduleAdjLsaBuild(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 216 | } |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 217 | } |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 218 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 219 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 220 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 221 | case ndn::nfd::FACE_EVENT_CREATED: { |
| 222 | // Find the neighbor in our adjacency list |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 223 | 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 Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 232 | uint64_t faceId = faceEventNotification.getFaceId(); |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 233 | |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 234 | // 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 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 239 | NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName() |
Ashlesh Gawande | 4187857 | 2019-09-29 00:16:02 -0500 | [diff] [blame] | 240 | << ". New Face ID: " << faceId << ". Registering prefixes."); |
| 241 | adjacent->setFaceId(faceId); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 242 | |
| 243 | registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 244 | |
Ashlesh Gawande | 214032e | 2020-12-22 17:20:14 -0500 | [diff] [blame] | 245 | // 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 Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 249 | } |
| 250 | break; |
| 251 | } |
| 252 | default: |
| 253 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 254 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 257 | void |
| 258 | Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 259 | const FetchDatasetTimeoutCallback& onFetchFailure) |
| 260 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 261 | NLSR_LOG_TRACE("Initializing Faces..."); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 262 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void |
| 266 | Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces) |
| 267 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 268 | NLSR_LOG_DEBUG("Processing face dataset"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 269 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 270 | // Iterate over each neighbor listed in nlsr.conf |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 271 | for (auto&& adjacent : m_adjacencyList.getAdjList()) { |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 272 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 273 | const std::string& faceUriString = adjacent.getFaceUri().toString(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 274 | // Check the list of FaceStatus objects we got for a match |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 275 | for (const auto& faceStatus : faces) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 276 | // Set the adjacency FaceID if we find a URI match and it was |
| 277 | // previously unset. Change the boolean to true. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 278 | if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 279 | NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() << |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 280 | " FaceId: "<< faceStatus.getFaceId()); |
| 281 | adjacent.setFaceId(faceStatus.getFaceId()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 282 | // Register the prefixes for each neighbor |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 283 | this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 284 | } |
| 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 Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 290 | if (adjacent.getFaceId() == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 291 | NLSR_LOG_WARN("The adjacency " << adjacent.getName() << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 292 | " has no Face information in this dataset."); |
| 293 | } |
| 294 | } |
| 295 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 296 | scheduleDatasetFetch(); |
| 297 | } |
| 298 | |
| 299 | void |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 300 | Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, ndn::time::milliseconds timeout) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 301 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 302 | ndn::FaceUri faceUri = adj.getFaceUri(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 303 | double linkCost = adj.getLinkCost(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 304 | const ndn::Name& adjName = adj.getName(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 305 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 306 | m_fib.registerPrefix(adjName, faceUri, linkCost, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 307 | timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 308 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 309 | m_fib.registerPrefix(m_confParam.getLsaPrefix(), |
| 310 | faceUri, linkCost, timeout, |
| 311 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void |
| 315 | Nlsr::onFaceDatasetFetchTimeout(uint32_t code, |
| 316 | const std::string& msg, |
| 317 | uint32_t nRetriesSoFar) |
| 318 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 319 | NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 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); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 323 | 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 { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 329 | NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 330 | 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 | |
| 338 | void |
| 339 | Nlsr::scheduleDatasetFetch() |
| 340 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 341 | NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval()); |
| 342 | |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 343 | m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(), |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 344 | [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 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 354 | |
| 355 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 356 | Nlsr::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 Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 363 | [] (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 Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 371 | } |
| 372 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 373 | } // namespace nlsr |