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