akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 19 | */ |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 20 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 21 | #include "conf-parameter.hpp" |
| 22 | #include "logger.hpp" |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 23 | #include <ndn-cxx/security/signing-helpers.hpp> |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 24 | |
| 25 | namespace nlsr { |
| 26 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 27 | INIT_LOGGER(ConfParameter); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 28 | |
Ashlesh Gawande | 982a58f | 2018-02-14 17:39:12 -0600 | [diff] [blame] | 29 | // To be changed when breaking changes are made to sync |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 30 | const uint64_t ConfParameter::SYNC_VERSION = 10; |
Ashlesh Gawande | 982a58f | 2018-02-14 17:39:12 -0600 | [diff] [blame] | 31 | |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 32 | static std::unique_ptr<ndn::security::CertificateFetcherDirectFetch> |
Ashlesh Gawande | dec85d2 | 2019-03-21 21:39:39 -0500 | [diff] [blame] | 33 | makeCertificateFetcher(ndn::Face& face) |
| 34 | { |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 35 | auto fetcher = std::make_unique<ndn::security::CertificateFetcherDirectFetch>(face); |
Ashlesh Gawande | dec85d2 | 2019-03-21 21:39:39 -0500 | [diff] [blame] | 36 | fetcher->setSendDirectInterestOnly(true); |
| 37 | return fetcher; |
| 38 | } |
| 39 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 40 | ConfParameter::ConfParameter(ndn::Face& face, ndn::KeyChain& keyChain, |
| 41 | const std::string& confFileName) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 42 | : m_confFileName(confFileName) |
| 43 | , m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT) |
| 44 | , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 45 | , m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT) |
| 46 | , m_faceDatasetFetchInterval(ndn::time::seconds(static_cast<int>(FACE_DATASET_FETCH_INTERVAL_DEFAULT))) |
| 47 | , m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT))) |
| 48 | , m_routerDeadInterval(2 * LSA_REFRESH_TIME_DEFAULT) |
| 49 | , m_interestRetryNumber(HELLO_RETRIES_DEFAULT) |
| 50 | , m_interestResendTime(HELLO_TIMEOUT_DEFAULT) |
| 51 | , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT) |
| 52 | , m_hyperbolicState(HYPERBOLIC_STATE_OFF) |
| 53 | , m_corR(0) |
| 54 | , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN) |
| 55 | , m_syncInterestLifetime(ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT)) |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 56 | , m_syncProtocol(SYNC_PROTOCOL_PSYNC) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 57 | , m_adjl() |
| 58 | , m_npl() |
Ashlesh Gawande | dec85d2 | 2019-03-21 21:39:39 -0500 | [diff] [blame] | 59 | , m_validator(makeCertificateFetcher(face)) |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 60 | , m_prefixUpdateValidator(std::make_unique<ndn::security::CertificateFetcherDirectFetch>(face)) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 61 | , m_keyChain(keyChain) |
Ashlesh Gawande | dec85d2 | 2019-03-21 21:39:39 -0500 | [diff] [blame] | 62 | { |
| 63 | } |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 64 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 65 | void |
| 66 | ConfParameter::writeLog() |
| 67 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 68 | NLSR_LOG_INFO("Router Name: " << m_routerName); |
| 69 | NLSR_LOG_INFO("Site Name: " << m_siteName); |
| 70 | NLSR_LOG_INFO("Network: " << m_network); |
| 71 | NLSR_LOG_INFO("Router Prefix: " << m_routerPrefix); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 72 | NLSR_LOG_INFO("Sync Prefix: " << m_syncPrefix); |
| 73 | NLSR_LOG_INFO("Sync LSA prefix: " << m_lsaPrefix); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 74 | NLSR_LOG_INFO("Hello Interest retry number: " << m_interestRetryNumber); |
| 75 | NLSR_LOG_INFO("Hello Interest resend second: " << m_interestResendTime); |
| 76 | NLSR_LOG_INFO("Info Interest interval: " << m_infoInterestInterval); |
| 77 | NLSR_LOG_INFO("LSA refresh time: " << m_lsaRefreshTime); |
| 78 | NLSR_LOG_INFO("FIB Entry refresh time: " << m_lsaRefreshTime * 2); |
| 79 | NLSR_LOG_INFO("LSA Interest lifetime: " << getLsaInterestLifetime()); |
| 80 | NLSR_LOG_INFO("Router dead interval: " << getRouterDeadInterval()); |
| 81 | NLSR_LOG_INFO("Max Faces Per Prefix: " << m_maxFacesPerPrefix); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 82 | if (m_hyperbolicState == HYPERBOLIC_STATE_ON || m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) { |
| 83 | NLSR_LOG_INFO("Hyperbolic Routing: " << m_hyperbolicState); |
| 84 | NLSR_LOG_INFO("Hyp R: " << m_corR); |
| 85 | int i=0; |
| 86 | for (auto const& value: m_corTheta) { |
| 87 | NLSR_LOG_INFO("Hyp Angle " << i++ << ": "<< value); |
| 88 | } |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 89 | } |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 90 | NLSR_LOG_INFO("State Directory: " << m_stateFileDir); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 91 | |
| 92 | // Event Intervals |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 93 | NLSR_LOG_INFO("Adjacency LSA build interval: " << m_adjLsaBuildInterval); |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 94 | NLSR_LOG_INFO("Routing calculation interval: " << m_routingCalcInterval); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Ashlesh Gawande | 982a58f | 2018-02-14 17:39:12 -0600 | [diff] [blame] | 97 | void |
| 98 | ConfParameter::setNetwork(const ndn::Name& networkName) |
| 99 | { |
| 100 | m_network = networkName; |
| 101 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 102 | m_syncPrefix.append("localhop"); |
| 103 | m_syncPrefix.append(m_network); |
| 104 | m_syncPrefix.append("nlsr"); |
| 105 | m_syncPrefix.append("sync"); |
| 106 | m_syncPrefix.appendVersion(SYNC_VERSION); |
Ashlesh Gawande | 982a58f | 2018-02-14 17:39:12 -0600 | [diff] [blame] | 107 | |
| 108 | m_lsaPrefix.append("localhop"); |
| 109 | m_lsaPrefix.append(m_network); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 110 | m_lsaPrefix.append("nlsr"); |
Ashlesh Gawande | 982a58f | 2018-02-14 17:39:12 -0600 | [diff] [blame] | 111 | m_lsaPrefix.append("LSA"); |
| 112 | } |
| 113 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 114 | void |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 115 | ConfParameter::loadCertToValidator(const ndn::security::Certificate& cert) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 116 | { |
| 117 | NLSR_LOG_TRACE("Loading Certificate Name: " << cert.getName()); |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 118 | m_validator.loadAnchor("Authoritative-Certificate", ndn::security::Certificate(cert)); |
| 119 | m_prefixUpdateValidator.loadAnchor("Authoritative-Certificate", ndn::security::Certificate(cert)); |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 120 | } |
| 121 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 122 | ndn::optional<ndn::security::Certificate> |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 123 | ConfParameter::initializeKey() |
| 124 | { |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 125 | using namespace ndn::security; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 126 | NLSR_LOG_DEBUG("Initializing Key ..."); |
| 127 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 128 | Identity routerIdentity; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 129 | try { |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 130 | routerIdentity = m_keyChain.getPib().getIdentity(m_routerPrefix); |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 131 | } |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 132 | catch (const Pib::Error&) { |
| 133 | NLSR_LOG_ERROR("Router identity " << m_routerPrefix << " not found. " |
| 134 | "NLSR is running without security. " |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 135 | "If security is enabled in the configuration, NLSR will not converge."); |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 136 | return ndn::nullopt; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 137 | } |
| 138 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 139 | auto instanceName = ndn::Name(m_routerPrefix).append("nlsr"); |
| 140 | try { |
| 141 | m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(instanceName)); |
| 142 | } |
| 143 | catch (const Pib::Error&) { |
| 144 | // old instance identity does not exist |
| 145 | } |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 146 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 147 | auto key = m_keyChain.createIdentity(instanceName).getDefaultKey(); |
| 148 | auto cert = m_keyChain.makeCertificate(key, signingByIdentity(routerIdentity)); |
| 149 | m_keyChain.setDefaultCertificate(key, cert); |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 150 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame^] | 151 | m_signingInfo = signingByCertificate(cert); |
| 152 | loadCertToValidator(cert); |
| 153 | return cert; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 154 | } |
| 155 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 156 | } // namespace nlsr |