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); |
| 291 | certificate.setFreshnessPeriod(ndn::time::days(7300)); |
| 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() |
| 300 | + ndn::time::days(20 * 365))); |
| 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 |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 459 | auto adjacent = m_adjacencyList.findAdjacent( |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 460 | ndn::FaceUri(faceEventNotification.getRemoteUri())); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 461 | // If we have a neighbor by that FaceUri and it has no FaceId, we |
| 462 | // have a match. |
| 463 | if (adjacent != m_adjacencyList.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 464 | NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName() |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 465 | << ". New Face ID: " << faceEventNotification.getFaceId() |
| 466 | << ". Registering prefixes."); |
| 467 | adjacent->setFaceId(faceEventNotification.getFaceId()); |
| 468 | |
| 469 | registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 470 | |
| 471 | if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) { |
| 472 | getRoutingTable().scheduleRoutingTableCalculation(*this); |
| 473 | } |
| 474 | else { |
| 475 | m_nlsrLsdb.scheduleAdjLsaBuild(); |
| 476 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 477 | } |
| 478 | break; |
| 479 | } |
| 480 | default: |
| 481 | break; |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 482 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 485 | void |
| 486 | Nlsr::initializeFaces(const FetchDatasetCallback& onFetchSuccess, |
| 487 | const FetchDatasetTimeoutCallback& onFetchFailure) |
| 488 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 489 | NLSR_LOG_TRACE("Initializing Faces..."); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 490 | |
| 491 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | void |
| 496 | Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces) |
| 497 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 498 | NLSR_LOG_DEBUG("Processing face dataset"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 499 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 500 | // Iterate over each neighbor listed in nlsr.conf |
| 501 | for (auto& adjacent : m_adjacencyList.getAdjList()) { |
| 502 | |
| 503 | const std::string faceUriString = adjacent.getFaceUri().toString(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 504 | // Check the list of FaceStatus objects we got for a match |
| 505 | for (const ndn::nfd::FaceStatus& faceStatus : faces) { |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 506 | // Set the adjacency FaceID if we find a URI match and it was |
| 507 | // previously unset. Change the boolean to true. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 508 | if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 509 | NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() << |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 510 | " FaceId: "<< faceStatus.getFaceId()); |
| 511 | adjacent.setFaceId(faceStatus.getFaceId()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 512 | // Register the prefixes for each neighbor |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 513 | this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max()); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | // If this adjacency has no information in this dataset, then one |
| 517 | // of two things is happening: 1. NFD is starting slowly and this |
| 518 | // Face wasn't ready yet, or 2. NFD is configured |
| 519 | // incorrectly and this Face isn't available. |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 520 | if (adjacent.getFaceId() == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 521 | NLSR_LOG_WARN("The adjacency " << adjacent.getName() << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 522 | " has no Face information in this dataset."); |
| 523 | } |
| 524 | } |
| 525 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 526 | scheduleDatasetFetch(); |
| 527 | } |
| 528 | |
| 529 | void |
| 530 | Nlsr::registerAdjacencyPrefixes(const Adjacent& adj, |
| 531 | const ndn::time::milliseconds& timeout) |
| 532 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 533 | ndn::FaceUri faceUri = adj.getFaceUri(); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 534 | double linkCost = adj.getLinkCost(); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 535 | const ndn::Name& adjName = adj.getName(); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 536 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 537 | m_fib.registerPrefix(adjName, faceUri, linkCost, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 538 | timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 539 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 540 | m_fib.registerPrefix(m_confParam.getChronosyncPrefix(), |
| 541 | faceUri, linkCost, timeout, |
| 542 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 543 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 544 | m_fib.registerPrefix(m_confParam.getLsaPrefix(), |
| 545 | faceUri, linkCost, timeout, |
| 546 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void |
| 550 | Nlsr::onFaceDatasetFetchTimeout(uint32_t code, |
| 551 | const std::string& msg, |
| 552 | uint32_t nRetriesSoFar) |
| 553 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 554 | NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout"); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 555 | // If we have exceeded the maximum attempt count, do not try again. |
| 556 | if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 557 | NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 558 | m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset, |
| 559 | this, _1), |
| 560 | std::bind(&Nlsr::onFaceDatasetFetchTimeout, |
| 561 | this, _1, _2, nRetriesSoFar)); |
| 562 | } |
| 563 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 564 | NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " << |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 565 | m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time."); |
| 566 | // If we fail to fetch it, just do nothing until the next |
| 567 | // interval. Since this is a backup mechanism, we aren't as |
| 568 | // concerned with retrying. |
| 569 | scheduleDatasetFetch(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void |
| 574 | Nlsr::scheduleDatasetFetch() |
| 575 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 576 | NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval()); |
| 577 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 578 | m_scheduler.scheduleEvent(m_confParam.getFaceDatasetFetchInterval(), |
| 579 | [this] { |
| 580 | this->initializeFaces( |
| 581 | [this] (const std::vector<ndn::nfd::FaceStatus>& faces) { |
| 582 | this->processFaceDataset(faces); |
| 583 | }, |
| 584 | [this] (uint32_t code, const std::string& msg) { |
| 585 | this->onFaceDatasetFetchTimeout(code, msg, 0); |
| 586 | }); |
| 587 | }); |
| 588 | } |
akmhoque | e176515 | 2014-06-30 11:32:01 -0500 | [diff] [blame] | 589 | |
| 590 | void |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 591 | Nlsr::enableIncomingFaceIdIndication() |
| 592 | { |
| 593 | NLSR_LOG_DEBUG("Enabling incoming face id indication for local face."); |
| 594 | |
| 595 | m_controller.start<ndn::nfd::FaceUpdateCommand>( |
| 596 | ndn::nfd::ControlParameters() |
| 597 | .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true), |
| 598 | bind(&Nlsr::onFaceIdIndicationSuccess, this, _1), |
| 599 | bind(&Nlsr::onFaceIdIndicationFailure, this, _1)); |
| 600 | } |
| 601 | |
| 602 | void |
| 603 | Nlsr::onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp) |
| 604 | { |
| 605 | NLSR_LOG_DEBUG("Successfully enabled incoming face id indication" |
| 606 | << "for face id " << cp.getFaceId()); |
| 607 | } |
| 608 | |
| 609 | void |
| 610 | Nlsr::onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr) |
| 611 | { |
| 612 | std::ostringstream os; |
| 613 | os << "Failed to enable incoming face id indication feature: " << |
| 614 | "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")"; |
| 615 | |
| 616 | NLSR_LOG_DEBUG(os.str()); |
| 617 | } |
| 618 | |
| 619 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 620 | Nlsr::startEventLoop() |
| 621 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 622 | m_nlsrFace.processEvents(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 623 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 624 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 625 | } // namespace nlsr |