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 | /* |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [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 | 92afde4 | 2014-02-18 14:04:07 -0600 | [diff] [blame] | 27 | #include <string> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 28 | #include <sstream> |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 29 | #include <cstdio> |
akmhoque | 0494c25 | 2014-07-23 23:46:44 -0500 | [diff] [blame] | 30 | #include <unistd.h> |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 31 | #include <vector> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 32 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 33 | #include <ndn-cxx/net/face-uri.hpp> |
| 34 | #include <ndn-cxx/signature.hpp> |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 35 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | namespace nlsr { |
| 37 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 38 | INIT_LOGGER(Nlsr); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 39 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 40 | const ndn::Name Nlsr::LOCALHOST_PREFIX = ndn::Name("/localhost/nlsr"); |
| 41 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 42 | Nlsr::Nlsr(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam) |
| 43 | : m_face(face) |
| 44 | , m_scheduler(face.getIoService()) |
Laqin Fan | a4cf402 | 2017-01-03 18:57:35 +0000 | [diff] [blame] | 45 | , m_keyChain(keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 46 | , m_confParam(confParam) |
| 47 | , m_adjacencyList(confParam.getAdjacencyList()) |
| 48 | , m_namePrefixList(confParam.getNamePrefixList()) |
| 49 | , m_validator(m_confParam.getValidator()) |
| 50 | , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, m_keyChain) |
| 51 | , m_routingTable(m_scheduler, m_fib, m_lsdb, m_namePrefixTable, m_confParam) |
| 52 | , m_namePrefixTable(m_fib, m_routingTable, m_routingTable.afterRoutingChange) |
| 53 | , m_lsdb(m_face, m_keyChain, m_signingInfo, |
| 54 | m_confParam, m_namePrefixTable, m_routingTable) |
| 55 | , m_afterSegmentValidatedConnection(m_lsdb.afterSegmentValidatedSignal.connect( |
| 56 | std::bind(&Nlsr::afterFetcherSignalEmitted, this, _1))) |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 57 | , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect( |
| 58 | [this] (const ndn::Name& updateName, uint64_t sequenceNumber, |
| 59 | const ndn::Name& originRouter) { |
| 60 | registerStrategyForCerts(originRouter); |
| 61 | })) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 62 | , m_dispatcher(m_face, m_keyChain) |
| 63 | , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable) |
| 64 | , m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb) |
| 65 | , m_certStore(m_confParam.getCertStore()) |
| 66 | , m_controller(m_face, m_keyChain) |
| 67 | , m_faceDatasetController(m_face, m_keyChain) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 68 | , m_prefixUpdateProcessor(m_dispatcher, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 69 | m_confParam.getPrefixUpdateValidator(), |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 70 | m_namePrefixList, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 71 | m_lsdb, |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 72 | m_confParam.getConfFileNameDynamic()) |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 73 | , m_nfdRibCommandProcessor(m_dispatcher, |
Nick Gordon | 4d2c6c0 | 2017-01-20 13:18:46 -0600 | [diff] [blame] | 74 | m_namePrefixList, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 75 | m_lsdb) |
| 76 | , m_statsCollector(m_lsdb, m_helloProtocol) |
| 77 | , m_faceMonitor(m_face) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 78 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 79 | m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1)); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 80 | m_faceMonitor.start(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 81 | |
| 82 | setStrategies(); |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 83 | } |
| 84 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | void |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 86 | Nlsr::registerStrategyForCerts(const ndn::Name& originRouter) |
| 87 | { |
| 88 | for (const ndn::Name& router : m_strategySetOnRouters) { |
| 89 | if (router == originRouter) { |
| 90 | // Have already set strategy for this router's certs once |
| 91 | return; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | m_strategySetOnRouters.push_back(originRouter); |
| 96 | |
| 97 | ndn::Name routerKey(originRouter); |
| 98 | routerKey.append("KEY"); |
| 99 | ndn::Name instanceKey(originRouter); |
| 100 | instanceKey.append("nlsr").append("KEY"); |
| 101 | |
| 102 | m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_V2_STRATEGY, 0); |
| 103 | m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_V2_STRATEGY, 0); |
| 104 | |
| 105 | ndn::Name siteKey; |
| 106 | for (size_t i = 0; i < originRouter.size(); ++i) { |
| 107 | if (originRouter[i].toUri() == "%C1.Router") { |
| 108 | break; |
| 109 | } |
| 110 | siteKey.append(originRouter[i]); |
| 111 | } |
| 112 | ndn::Name opPrefix(siteKey); |
| 113 | siteKey.append("KEY"); |
| 114 | m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_V2_STRATEGY, 0); |
| 115 | |
| 116 | opPrefix.append(std::string("%C1.Operator")); |
| 117 | m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_V2_STRATEGY, 0); |
| 118 | } |
| 119 | |
| 120 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 121 | Nlsr::registrationFailed(const ndn::Name& name) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 122 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 123 | NLSR_LOG_ERROR("ERROR: Failed to register prefix in local hub's daemon"); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 124 | BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed")); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 125 | } |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 126 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 127 | void |
| 128 | Nlsr::onRegistrationSuccess(const ndn::Name& name) |
| 129 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 130 | NLSR_LOG_DEBUG("Successfully registered prefix: " << name); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 134 | Nlsr::setInfoInterestFilter() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 135 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 136 | ndn::Name name(m_confParam.getRouterPrefix()); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 137 | name.append("nlsr"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 138 | name.append("INFO"); |
| 139 | |
| 140 | NLSR_LOG_DEBUG("Setting interest filter for Hello interest: " << name); |
| 141 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 142 | m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), |
| 143 | std::bind(&HelloProtocol::processInterest, &m_helloProtocol, _1, _2), |
| 144 | std::bind(&Nlsr::onRegistrationSuccess, this, _1), |
| 145 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 146 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void |
| 150 | Nlsr::setLsaInterestFilter() |
| 151 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 152 | ndn::Name name = m_confParam.getLsaPrefix(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 153 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 154 | NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 155 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 156 | m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), |
| 157 | std::bind(&Lsdb::processInterest, &m_lsdb, _1, _2), |
| 158 | std::bind(&Nlsr::onRegistrationSuccess, this, _1), |
| 159 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 160 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 163 | void |
| 164 | Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix) |
| 165 | { |
| 166 | try { |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 167 | // false since we want to have control over the registration process |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 168 | m_dispatcher.addTopPrefix(topPrefix, false, m_signingInfo); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 169 | } |
| 170 | catch (const std::exception& e) { |
| 171 | NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what() << "\n"); |
| 172 | } |
| 173 | } |
| 174 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 175 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 176 | Nlsr::setStrategies() |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 177 | { |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 178 | m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0); |
| 179 | m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 183 | Nlsr::loadCertToPublish(const ndn::security::v2::Certificate& certificate) |
| 184 | { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 185 | NLSR_LOG_TRACE("Loading cert to publish."); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 186 | m_certStore.insert(certificate); |
| 187 | m_validator.loadAnchor("Authoritative-Certificate", |
| 188 | ndn::security::v2::Certificate(certificate)); |
| 189 | m_prefixUpdateProcessor.getValidator(). |
| 190 | loadAnchor("Authoritative-Certificate", |
| 191 | ndn::security::v2::Certificate(certificate)); |
| 192 | } |
| 193 | |
Nick Gordon | 9461afb | 2017-04-25 15:54:50 -0500 | [diff] [blame] | 194 | void |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 195 | Nlsr::afterFetcherSignalEmitted(const ndn::Data& lsaSegment) |
| 196 | { |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 197 | ndn::Name keyName = lsaSegment.getSignature().getKeyLocator().getName(); |
| 198 | if (getCertificate(keyName) == nullptr) { |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 199 | NLSR_LOG_TRACE("Publishing certificate for: " << keyName); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 200 | publishCertFromCache(keyName); |
| 201 | } |
| 202 | else { |
| 203 | NLSR_LOG_TRACE("Certificate is already in the store: " << keyName); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | Nlsr::publishCertFromCache(const ndn::Name& keyName) |
| 209 | { |
| 210 | const ndn::security::v2::Certificate* cert = m_validator.getUnverifiedCertCache() |
| 211 | .find(keyName); |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 212 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 213 | if (cert != nullptr) { |
| 214 | m_certStore.insert(*cert); |
| 215 | NLSR_LOG_TRACE(*cert); |
Ashlesh Gawande | 3494f73 | 2018-11-06 16:04:03 -0600 | [diff] [blame] | 216 | ndn::Name certName = ndn::security::v2::extractKeyNameFromCertName(cert->getName()); |
| 217 | NLSR_LOG_TRACE("Setting interest filter for: " << certName); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 218 | m_face.setInterestFilter(ndn::InterestFilter(certName).allowLoopback(false), |
| 219 | std::bind(&Nlsr::onKeyInterest, this, _1, _2), |
| 220 | std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1), |
| 221 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 222 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 223 | |
| 224 | if (!cert->getKeyName().equals(cert->getSignature().getKeyLocator().getName())) { |
| 225 | publishCertFromCache(cert->getSignature().getKeyLocator().getName()); |
| 226 | } |
| 227 | } |
| 228 | else { |
Ashlesh Gawande | 08bce9c | 2019-04-05 11:08:07 -0500 | [diff] [blame^] | 229 | // Happens for root cert |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 230 | NLSR_LOG_TRACE("Cert for " << keyName << " was not found in the Validator's cache. "); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 235 | Nlsr::initialize() |
| 236 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 237 | NLSR_LOG_DEBUG("Initializing Nlsr"); |
Vince Lehman | c11cc20 | 2015-01-20 11:41:33 -0600 | [diff] [blame] | 238 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 239 | // Logging start |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 240 | m_adjacencyList.writeLog(); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 241 | NLSR_LOG_DEBUG(m_namePrefixList); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 242 | |
akmhoque | 443ad81 | 2014-07-29 10:26:56 -0500 | [diff] [blame] | 243 | initializeKey(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 244 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 245 | NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 246 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 247 | // Can be moved to HelloProtocol and Lsdb ctor if initializeKey is set |
| 248 | // earlier in the Nlsr constructor so as to set m_signingInfo |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 249 | setInfoInterestFilter(); |
| 250 | setLsaInterestFilter(); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 251 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 252 | // add top-level prefixes: router and localhost prefix |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 253 | addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr")); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 254 | addDispatcherTopPrefix(LOCALHOST_PREFIX); |
| 255 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 256 | initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1), |
| 257 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0)); |
| 258 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 259 | enableIncomingFaceIdIndication(); |
| 260 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 261 | m_lsdb.buildAndInstallOwnNameLsa(); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 262 | |
| 263 | // Install coordinate LSAs if using HR or dry-run HR. |
| 264 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 265 | m_lsdb.buildAndInstallOwnCoordinateLsa(); |
Nick Gordon | 5c467f0 | 2016-07-13 13:40:10 -0500 | [diff] [blame] | 266 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 267 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 268 | registerKeyPrefix(); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 269 | registerLocalhostPrefix(); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 270 | registerRouterPrefix(); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 271 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 272 | m_helloProtocol.scheduleInterest(m_confParam.getFirstHelloInterval()); |
Vince Lehman | 0913112 | 2014-09-09 17:10:11 -0500 | [diff] [blame] | 273 | |
| 274 | // Need to set direct neighbors' costs to 0 for hyperbolic routing |
| 275 | if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 276 | |
| 277 | std::list<Adjacent>& neighbors = m_adjacencyList.getAdjList(); |
| 278 | |
| 279 | for (std::list<Adjacent>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) { |
| 280 | it->setLinkCost(0); |
| 281 | } |
| 282 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void |
akmhoque | 443ad81 | 2014-07-29 10:26:56 -0500 | [diff] [blame] | 286 | Nlsr::initializeKey() |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 287 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 288 | NLSR_LOG_DEBUG("Initializing Key ..."); |
| 289 | |
| 290 | ndn::Name nlsrInstanceName = m_confParam.getRouterPrefix(); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 291 | nlsrInstanceName.append("nlsr"); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 292 | |
Joao Pereira | 97473d4 | 2015-07-03 16:57:27 -0400 | [diff] [blame] | 293 | try { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 294 | m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName)); |
| 295 | } catch (const std::exception& e) { |
| 296 | NLSR_LOG_WARN(e.what()); |
| 297 | } |
| 298 | |
| 299 | auto nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName); |
| 300 | auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey(); |
| 301 | |
| 302 | ndn::security::v2::Certificate certificate; |
| 303 | |
| 304 | ndn::Name certificateName = nlsrInstanceKey.getName(); |
| 305 | certificateName.append("NA"); |
| 306 | certificateName.appendVersion(); |
| 307 | certificate.setName(certificateName); |
| 308 | |
| 309 | // set metainfo |
| 310 | certificate.setContentType(ndn::tlv::ContentType_Key); |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 311 | certificate.setFreshnessPeriod(ndn::time::days(365)); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 312 | |
| 313 | // set content |
| 314 | certificate.setContent(nlsrInstanceKey.getPublicKey().data(), nlsrInstanceKey.getPublicKey().size()); |
| 315 | |
| 316 | // set signature-info |
| 317 | ndn::SignatureInfo signatureInfo; |
| 318 | signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(ndn::time::system_clock::TimePoint(), |
| 319 | ndn::time::system_clock::now() |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 320 | + ndn::time::days(365))); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 321 | try { |
| 322 | m_keyChain.sign(certificate, |
| 323 | ndn::security::SigningInfo(m_keyChain.getPib().getIdentity(m_confParam.getRouterPrefix())) |
| 324 | .setSignatureInfo(signatureInfo)); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 325 | } |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 326 | catch (const std::exception& e) { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 327 | NLSR_LOG_WARN("ERROR: Router's " << e.what() |
| 328 | << "NLSR is running without security." |
| 329 | << " If security is enabled NLSR will not converge."); |
| 330 | |
Muktadir Chowdhury | c3ea26f | 2018-01-05 21:40:59 +0000 | [diff] [blame] | 331 | std::cerr << "Router's " << e.what() << ". NLSR is running without security " |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 332 | << "(Only for testing, should not be used in production.)" |
| 333 | << " If security is enabled NLSR will not converge." << std::endl; |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 334 | } |
akmhoque | 443ad81 | 2014-07-29 10:26:56 -0500 | [diff] [blame] | 335 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 336 | m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID, |
| 337 | nlsrInstanceName); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 338 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 339 | loadCertToPublish(certificate); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void |
| 343 | Nlsr::registerKeyPrefix() |
| 344 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 345 | // Start listening for the interest of this router's NLSR certificate |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 346 | ndn::Name nlsrKeyPrefix = m_confParam.getRouterPrefix(); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 347 | nlsrKeyPrefix.append("nlsr"); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 348 | nlsrKeyPrefix.append("KEY"); |
| 349 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 350 | m_face.setInterestFilter(ndn::InterestFilter(nlsrKeyPrefix).allowLoopback(false), |
| 351 | std::bind(&Nlsr::onKeyInterest, this, _1, _2), |
| 352 | std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1), |
| 353 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 354 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 355 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 356 | // Start listening for the interest of this router's certificate |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 357 | ndn::Name routerKeyPrefix = m_confParam.getRouterPrefix(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 358 | routerKeyPrefix.append("KEY"); |
| 359 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 360 | m_face.setInterestFilter(ndn::InterestFilter(routerKeyPrefix).allowLoopback(false), |
| 361 | std::bind(&Nlsr::onKeyInterest, this, _1, _2), |
| 362 | std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1), |
| 363 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 364 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 365 | |
| 366 | // Start listening for the interest of this router's operator's certificate |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 367 | ndn::Name operatorKeyPrefix = m_confParam.getNetwork(); |
| 368 | operatorKeyPrefix.append(m_confParam.getSiteName()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 369 | operatorKeyPrefix.append(std::string("%C1.Operator")); |
| 370 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 371 | m_face.setInterestFilter(ndn::InterestFilter(operatorKeyPrefix).allowLoopback(false), |
| 372 | std::bind(&Nlsr::onKeyInterest, this, _1, _2), |
| 373 | std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1), |
| 374 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 375 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 376 | |
| 377 | // Start listening for the interest of this router's site's certificate |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 378 | ndn::Name siteKeyPrefix = m_confParam.getNetwork(); |
| 379 | siteKeyPrefix.append(m_confParam.getSiteName()); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 380 | siteKeyPrefix.append("KEY"); |
| 381 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 382 | m_face.setInterestFilter(ndn::InterestFilter(siteKeyPrefix).allowLoopback(false), |
| 383 | std::bind(&Nlsr::onKeyInterest, this, _1, _2), |
| 384 | std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1), |
| 385 | std::bind(&Nlsr::registrationFailed, this, _1), |
| 386 | m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 390 | Nlsr::registerLocalhostPrefix() |
| 391 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 392 | m_face.registerPrefix(LOCALHOST_PREFIX, |
| 393 | std::bind(&Nlsr::onRegistrationSuccess, this, _1), |
| 394 | std::bind(&Nlsr::registrationFailed, this, _1)); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 398 | Nlsr::registerRouterPrefix() |
| 399 | { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 400 | m_face.registerPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"), |
| 401 | std::bind(&Nlsr::onRegistrationSuccess, this, _1), |
| 402 | std::bind(&Nlsr::registrationFailed, this, _1)); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 406 | Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest) |
| 407 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 408 | NLSR_LOG_DEBUG("Got interest for certificate. Interest: " << interest.getName()); |
| 409 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 410 | const ndn::Name& interestName = interest.getName(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 411 | const ndn::security::v2::Certificate* cert = getCertificate(interestName); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 412 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 413 | if (cert == nullptr) { |
| 414 | NLSR_LOG_DEBUG("Certificate is not found for: " << interest); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 415 | return; // cert is not found |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 416 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 417 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 418 | m_face.put(*cert); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void |
| 422 | Nlsr::onKeyPrefixRegSuccess(const ndn::Name& name) |
| 423 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 424 | NLSR_LOG_DEBUG("KEY prefix: " << name << " registration is successful."); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 425 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 426 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 427 | void |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 428 | Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification) |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 429 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 430 | NLSR_LOG_TRACE("Nlsr::onFaceEventNotification called"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 431 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 432 | switch (faceEventNotification.getKind()) { |
| 433 | case ndn::nfd::FACE_EVENT_DESTROYED: { |
| 434 | uint64_t faceId = faceEventNotification.getFaceId(); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 435 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 436 | auto adjacent = m_adjacencyList.findAdjacent(faceId); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 437 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 438 | if (adjacent != m_adjacencyList.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 439 | NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed"); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 440 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 441 | adjacent->setFaceId(0); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 442 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 443 | // Only trigger an Adjacency LSA build if this node is changing |
| 444 | // from ACTIVE to INACTIVE since this rebuild will effectively |
| 445 | // cancel the previous Adjacency LSA refresh event and schedule |
| 446 | // a new one further in the future. |
| 447 | // |
| 448 | // Continuously scheduling the refresh in the future will block |
| 449 | // the router from refreshing its Adjacency LSA. Since other |
| 450 | // routers' Name prefixes' expiration times are updated when |
| 451 | // this router refreshes its Adjacency LSA, the other routers' |
| 452 | // prefixes will expire and be removed from the RIB. |
| 453 | // |
| 454 | // This check is required to fix Bug #2733 for now. This check |
| 455 | // would be unnecessary to fix Bug #2733 when Issue #2732 is |
| 456 | // completed, but the check also helps with optimization so it |
| 457 | // can remain even when Issue #2732 is implemented. |
| 458 | if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) { |
| 459 | adjacent->setStatus(Adjacent::STATUS_INACTIVE); |
Vince Lehman | 02e3299 | 2015-03-11 12:31:20 -0500 | [diff] [blame] | 460 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 461 | // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and |
| 462 | // has met the HELLO retry threshold |
| 463 | adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber()); |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 464 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 465 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 466 | m_routingTable.scheduleRoutingTableCalculation(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 467 | } |
| 468 | else { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 469 | m_lsdb.scheduleAdjLsaBuild(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 470 | } |
Nick Gordon | e8e03ac | 2016-07-07 14:24:38 -0500 | [diff] [blame] | 471 | } |
Vince Lehman | 199e9cf | 2015-04-07 13:22:16 -0500 | [diff] [blame] | 472 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 473 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 474 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 475 | case ndn::nfd::FACE_EVENT_CREATED: { |
| 476 | // Find the neighbor in our adjacency list |
Ashlesh Gawande | 0d2c382 | 2018-01-24 17:17:15 -0600 | [diff] [blame] | 477 | ndn::FaceUri faceUri; |
| 478 | try { |
| 479 | faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri()); |
| 480 | } |
| 481 | catch (const std::exception& e) { |
| 482 | NLSR_LOG_WARN(e.what()); |
| 483 | return; |
| 484 | } |
| 485 | auto adjacent = m_adjacencyList.findAdjacent(faceUri); |
| 486 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 487 | // If we have a neighbor by that FaceUri and it has no FaceId, we |
| 488 | // have a match. |
| 489 | if (adjacent != m_adjacencyList.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 490 | NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName() |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 491 | << ". New Face ID: " << faceEventNotification.getFaceId() |
| 492 | << ". Registering prefixes."); |
| 493 | adjacent->setFaceId(faceEventNotification.getFaceId()); |
| 494 | |
| 495 | registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 496 | |
| 497 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 498 | m_routingTable.scheduleRoutingTableCalculation(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 499 | } |
| 500 | else { |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 501 | m_lsdb.scheduleAdjLsaBuild(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 502 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 503 | } |
| 504 | break; |
| 505 | } |
| 506 | default: |
| 507 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 508 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 509 | } |
| 510 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 511 | void |
| 512 | Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 513 | const FetchDatasetTimeoutCallback& onFetchFailure) |
| 514 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 515 | NLSR_LOG_TRACE("Initializing Faces..."); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 516 | |
| 517 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure); |
| 518 | |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces) |
| 523 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 524 | NLSR_LOG_DEBUG("Processing face dataset"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 525 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 526 | // Iterate over each neighbor listed in nlsr.conf |
| 527 | for (auto& adjacent : m_adjacencyList.getAdjList()) { |
| 528 | |
| 529 | const std::string faceUriString = adjacent.getFaceUri().toString(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 530 | // Check the list of FaceStatus objects we got for a match |
| 531 | for (const ndn::nfd::FaceStatus& faceStatus : faces) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 532 | // Set the adjacency FaceID if we find a URI match and it was |
| 533 | // previously unset. Change the boolean to true. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 534 | if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 535 | NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() << |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 536 | " FaceId: "<< faceStatus.getFaceId()); |
| 537 | adjacent.setFaceId(faceStatus.getFaceId()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 538 | // Register the prefixes for each neighbor |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 539 | this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | // If this adjacency has no information in this dataset, then one |
| 543 | // of two things is happening: 1. NFD is starting slowly and this |
| 544 | // Face wasn't ready yet, or 2. NFD is configured |
| 545 | // incorrectly and this Face isn't available. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 546 | if (adjacent.getFaceId() == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 547 | NLSR_LOG_WARN("The adjacency " << adjacent.getName() << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 548 | " has no Face information in this dataset."); |
| 549 | } |
| 550 | } |
| 551 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 552 | scheduleDatasetFetch(); |
| 553 | } |
| 554 | |
| 555 | void |
| 556 | Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, |
| 557 | const ndn::time::milliseconds& timeout) |
| 558 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 559 | ndn::FaceUri faceUri = adj.getFaceUri(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 560 | double linkCost = adj.getLinkCost(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 561 | const ndn::Name& adjName = adj.getName(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 562 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 563 | m_fib.registerPrefix(adjName, faceUri, linkCost, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 564 | timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 565 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 566 | m_fib.registerPrefix(m_confParam.getSyncPrefix(), |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 567 | faceUri, linkCost, timeout, |
| 568 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 569 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 570 | m_fib.registerPrefix(m_confParam.getLsaPrefix(), |
| 571 | faceUri, linkCost, timeout, |
| 572 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | void |
| 576 | Nlsr::onFaceDatasetFetchTimeout(uint32_t code, |
| 577 | const std::string& msg, |
| 578 | uint32_t nRetriesSoFar) |
| 579 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 580 | NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 581 | // If we have exceeded the maximum attempt count, do not try again. |
| 582 | if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 583 | NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 584 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset, |
| 585 | this, _1), |
| 586 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, |
| 587 | this, _1, _2, nRetriesSoFar)); |
| 588 | } |
| 589 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 590 | NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 591 | m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time."); |
| 592 | // If we fail to fetch it, just do nothing until the next |
| 593 | // interval. Since this is a backup mechanism, we aren't as |
| 594 | // concerned with retrying. |
| 595 | scheduleDatasetFetch(); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void |
| 600 | Nlsr::scheduleDatasetFetch() |
| 601 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 602 | NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval()); |
| 603 | |
Davide Pesavento | af7a211 | 2019-03-19 14:55:20 -0400 | [diff] [blame] | 604 | m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(), |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 605 | [this] { |
| 606 | this->initializeFaces( |
| 607 | [this] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 608 | this->processFaceDataset(faces); |
| 609 | }, |
| 610 | [this] (uint32_t code, const std::string& msg) { |
| 611 | this->onFaceDatasetFetchTimeout(code, msg, 0); |
| 612 | }); |
| 613 | }); |
| 614 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 615 | |
| 616 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 617 | Nlsr::enableIncomingFaceIdIndication() |
| 618 | { |
| 619 | NLSR_LOG_DEBUG("Enabling incoming face id indication for local face."); |
| 620 | |
| 621 | m_controller.start<ndn::nfd::FaceUpdateCommand>( |
| 622 | ndn::nfd::ControlParameters() |
| 623 | .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true), |
| 624 | bind(&Nlsr::onFaceIdIndicationSuccess, this, _1), |
| 625 | bind(&Nlsr::onFaceIdIndicationFailure, this, _1)); |
| 626 | } |
| 627 | |
| 628 | void |
| 629 | Nlsr::onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp) |
| 630 | { |
| 631 | NLSR_LOG_DEBUG("Successfully enabled incoming face id indication" |
| 632 | << "for face id " << cp.getFaceId()); |
| 633 | } |
| 634 | |
| 635 | void |
| 636 | Nlsr::onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr) |
| 637 | { |
| 638 | std::ostringstream os; |
| 639 | os << "Failed to enable incoming face id indication feature: " << |
| 640 | "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")"; |
| 641 | |
| 642 | NLSR_LOG_DEBUG(os.str()); |
| 643 | } |
| 644 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 645 | } // namespace nlsr |