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