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