conf-parameter.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2021, The University of Memphis,
4  * Regents of the University of California
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/>.
19  */
20 
21 #include "conf-parameter.hpp"
22 #include "logger.hpp"
23 
24 namespace nlsr {
25 
26 INIT_LOGGER(ConfParameter);
27 
28 // To be changed when breaking changes are made to sync
29 const uint64_t ConfParameter::SYNC_VERSION = 9;
30 
31 static std::unique_ptr<ndn::security::CertificateFetcherDirectFetch>
32 makeCertificateFetcher(ndn::Face& face)
33 {
34  auto fetcher = std::make_unique<ndn::security::CertificateFetcherDirectFetch>(face);
35  fetcher->setSendDirectInterestOnly(true);
36  return fetcher;
37 }
38 
39 ConfParameter::ConfParameter(ndn::Face& face, ndn::KeyChain& keyChain,
40  const std::string& confFileName)
41  : m_confFileName(confFileName)
42  , m_lsaRefreshTime(LSA_REFRESH_TIME_DEFAULT)
43  , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
44  , m_routingCalcInterval(ROUTING_CALC_INTERVAL_DEFAULT)
45  , m_faceDatasetFetchInterval(ndn::time::seconds(static_cast<int>(FACE_DATASET_FETCH_INTERVAL_DEFAULT)))
46  , m_lsaInterestLifetime(ndn::time::seconds(static_cast<int>(LSA_INTEREST_LIFETIME_DEFAULT)))
47  , m_routerDeadInterval(2 * LSA_REFRESH_TIME_DEFAULT)
48  , m_interestRetryNumber(HELLO_RETRIES_DEFAULT)
49  , m_interestResendTime(HELLO_TIMEOUT_DEFAULT)
50  , m_infoInterestInterval(HELLO_INTERVAL_DEFAULT)
51  , m_hyperbolicState(HYPERBOLIC_STATE_OFF)
52  , m_corR(0)
53  , m_maxFacesPerPrefix(MAX_FACES_PER_PREFIX_MIN)
54  , m_syncInterestLifetime(ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT))
55  , m_syncProtocol(SYNC_PROTOCOL_CHRONOSYNC)
56  , m_adjl()
57  , m_npl()
58  , m_validator(makeCertificateFetcher(face))
59  , m_prefixUpdateValidator(std::make_unique<ndn::security::CertificateFetcherDirectFetch>(face))
60  , m_keyChain(keyChain)
61 {
62 }
63 
64 void
66 {
67  NLSR_LOG_INFO("Router Name: " << m_routerName);
68  NLSR_LOG_INFO("Site Name: " << m_siteName);
69  NLSR_LOG_INFO("Network: " << m_network);
70  NLSR_LOG_INFO("Router Prefix: " << m_routerPrefix);
71  NLSR_LOG_INFO("Sync Prefix: " << m_syncPrefix);
72  NLSR_LOG_INFO("Sync LSA prefix: " << m_lsaPrefix);
73  NLSR_LOG_INFO("Hello Interest retry number: " << m_interestRetryNumber);
74  NLSR_LOG_INFO("Hello Interest resend second: " << m_interestResendTime);
75  NLSR_LOG_INFO("Info Interest interval: " << m_infoInterestInterval);
76  NLSR_LOG_INFO("LSA refresh time: " << m_lsaRefreshTime);
77  NLSR_LOG_INFO("FIB Entry refresh time: " << m_lsaRefreshTime * 2);
78  NLSR_LOG_INFO("LSA Interest lifetime: " << getLsaInterestLifetime());
79  NLSR_LOG_INFO("Router dead interval: " << getRouterDeadInterval());
80  NLSR_LOG_INFO("Max Faces Per Prefix: " << m_maxFacesPerPrefix);
81  if (m_hyperbolicState == HYPERBOLIC_STATE_ON || m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
82  NLSR_LOG_INFO("Hyperbolic Routing: " << m_hyperbolicState);
83  NLSR_LOG_INFO("Hyp R: " << m_corR);
84  int i=0;
85  for (auto const& value: m_corTheta) {
86  NLSR_LOG_INFO("Hyp Angle " << i++ << ": "<< value);
87  }
88  }
89  NLSR_LOG_INFO("State Directory: " << m_stateFileDir);
90 
91  // Event Intervals
92  NLSR_LOG_INFO("Adjacency LSA build interval: " << m_adjLsaBuildInterval);
93  NLSR_LOG_INFO("Routing calculation interval: " << m_routingCalcInterval);
94 }
95 
96 void
97 ConfParameter::setNetwork(const ndn::Name& networkName)
98 {
99  m_network = networkName;
100 
101  m_syncPrefix.append("localhop");
102  m_syncPrefix.append(m_network);
103  m_syncPrefix.append("nlsr");
104  m_syncPrefix.append("sync");
105  m_syncPrefix.appendVersion(SYNC_VERSION);
106 
107  m_lsaPrefix.append("localhop");
108  m_lsaPrefix.append(m_network);
109  m_lsaPrefix.append("nlsr");
110  m_lsaPrefix.append("LSA");
111 }
112 
113 void
114 ConfParameter::loadCertToValidator(const ndn::security::Certificate& cert)
115 {
116  NLSR_LOG_TRACE("Loading Certificate Name: " << cert.getName());
117  m_validator.loadAnchor("Authoritative-Certificate", ndn::security::Certificate(cert));
118  m_prefixUpdateValidator.loadAnchor("Authoritative-Certificate", ndn::security::Certificate(cert));
119 }
120 
121 std::shared_ptr<ndn::security::Certificate>
123 {
124  NLSR_LOG_DEBUG("Initializing Key ...");
125 
126  ndn::Name nlsrInstanceName(m_routerPrefix);
127  nlsrInstanceName.append("nlsr");
128 
129  try {
130  m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
131  }
132  catch (const std::exception& e) {
133  NLSR_LOG_WARN(e.what());
134  }
135 
136  ndn::security::Identity nlsrInstanceIdentity;
137  try {
138  nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
139  }
140  catch (const std::exception& e) {
141  NLSR_LOG_ERROR(e.what());
142  NLSR_LOG_ERROR("Unable to create identity, NLSR will run without security!");
143  NLSR_LOG_ERROR("Can be ignored if running in non-production environments.");
144  return nullptr;
145  }
146  auto certificate = std::make_shared<ndn::security::Certificate>();
147  auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
148  ndn::Name certificateName = nlsrInstanceKey.getName();
149  certificateName.append("NA");
150  certificateName.appendVersion();
151 
152  certificate->setName(certificateName);
153 
154  // set metainfo
155  certificate->setContentType(ndn::tlv::ContentType_Key);
156  certificate->setFreshnessPeriod(365_days);
157 
158  // set content
159  certificate->setContent(nlsrInstanceKey.getPublicKey().data(),
160  nlsrInstanceKey.getPublicKey().size());
161 
162  // set signature-info
163  ndn::SignatureInfo signatureInfo;
164  signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(ndn::time::system_clock::TimePoint(),
165  ndn::time::system_clock::now()
166  + 365_days));
167 
168  try {
169  m_keyChain.sign(*certificate,
170  ndn::security::SigningInfo(m_keyChain.getPib().getIdentity(m_routerPrefix))
171  .setSignatureInfo(signatureInfo));
172  }
173  catch (const std::exception& e) {
174  NLSR_LOG_ERROR("Router's " << e.what() << ", NLSR is running without security. " <<
175  "If security is enabled in the configuration, NLSR will not converge.");
176 
177  }
178 
179  m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
180  nlsrInstanceName);
181 
182  loadCertToValidator(*certificate);
183 
184  return certificate;
185 }
186 
187 } // namespace nlsr
void writeLog()
Dump the current state of all attributes to the log.
uint32_t getRouterDeadInterval() const
void loadCertToValidator(const ndn::security::Certificate &cert)
ConfParameter(ndn::Face &face, ndn::KeyChain &keyChain, const std::string &confFileName="nlsr.conf")
const ndn::time::seconds & getLsaInterestLifetime() const
std::shared_ptr< ndn::security::Certificate > initializeKey()
void setNetwork(const ndn::Name &networkName)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:38
#define INIT_LOGGER(name)
Definition: logger.hpp:35
#define NLSR_LOG_WARN(x)
Definition: logger.hpp:40
#define NLSR_LOG_ERROR(x)
Definition: logger.hpp:41
#define NLSR_LOG_TRACE(x)
Definition: logger.hpp:37
#define NLSR_LOG_INFO(x)
Definition: logger.hpp:39
Definition: tlv-nlsr.hpp:25
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...
@ SYNC_INTEREST_LIFETIME_DEFAULT
static std::unique_ptr< ndn::security::CertificateFetcherDirectFetch > makeCertificateFetcher(ndn::Face &face)
@ ROUTING_CALC_INTERVAL_DEFAULT
@ LSA_REFRESH_TIME_DEFAULT
@ FACE_DATASET_FETCH_INTERVAL_DEFAULT
@ ADJ_LSA_BUILD_INTERVAL_DEFAULT
@ HELLO_INTERVAL_DEFAULT
@ LSA_INTEREST_LIFETIME_DEFAULT
@ HYPERBOLIC_STATE_ON
@ HYPERBOLIC_STATE_DRY_RUN
@ HYPERBOLIC_STATE_OFF
@ SYNC_PROTOCOL_CHRONOSYNC
@ HELLO_TIMEOUT_DEFAULT
@ HELLO_RETRIES_DEFAULT
@ MAX_FACES_PER_PREFIX_MIN