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