conf-parameter.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2024, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
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/>.
20  */
21 
22 #ifndef NLSR_CONF_PARAMETER_HPP
23 #define NLSR_CONF_PARAMETER_HPP
24 
25 #include "common.hpp"
26 #include "test-access-control.hpp"
27 #include "adjacency-list.hpp"
28 #include "name-prefix-list.hpp"
29 
30 #include <ndn-cxx/face.hpp>
31 #include <ndn-cxx/security/validator-config.hpp>
32 #include <ndn-cxx/security/certificate-fetcher-direct-fetch.hpp>
33 
34 #include <optional>
35 
36 namespace nlsr {
37 
38 enum class SyncProtocol {
39  CHRONOSYNC,
40  PSYNC,
41  SVS,
42 };
43 
44 enum {
48 };
49 
50 enum {
54 };
55 
56 enum {
60 };
61 
62 enum {
66 };
67 
68 
69 enum {
73 };
74 
75 enum {
79 };
80 
81 enum {
85 };
86 
87 enum {
91 };
92 
93 enum {
97 };
98 
99 enum {
103 };
104 
110 };
111 
112 enum {
116 };
117 
130 {
131 public:
132  ConfParameter(ndn::Face& face, ndn::KeyChain& keyChain,
133  const std::string& confFileName = "nlsr.conf");
134 
135  const std::string&
137  {
138  return m_confFileName;
139  }
140 
141  void
142  setNetwork(const ndn::Name& networkName);
143 
144  const ndn::Name&
145  getNetwork() const
146  {
147  return m_network;
148  }
149 
150  void
151  setRouterName(const ndn::Name& routerName)
152  {
153  m_routerName = routerName;
154  }
155 
156  const ndn::Name&
158  {
159  return m_routerName;
160  }
161 
162  void
163  setSiteName(const ndn::Name& siteName)
164  {
165  m_siteName = siteName;
166  }
167 
168  const ndn::Name&
169  getSiteName() const
170  {
171  return m_siteName;
172  }
173 
174  void
176  {
177  m_routerPrefix = m_network;
178  m_routerPrefix.append(m_siteName);
179  m_routerPrefix.append(m_routerName);
180 
181  m_syncUserPrefix = m_lsaPrefix;
182  m_syncUserPrefix.append(m_siteName);
183  m_syncUserPrefix.append(m_routerName);
184  }
185 
186  const ndn::Name&
188  {
189  return m_routerPrefix;
190  }
191 
192  const ndn::Name&
194  {
195  return m_syncUserPrefix;
196  }
197 
198  const ndn::Name&
200  {
201  return m_syncPrefix;
202  }
203 
204  const ndn::Name&
205  getLsaPrefix() const
206  {
207  return m_lsaPrefix;
208  }
209 
210  void
211  setLsaRefreshTime(uint32_t lrt)
212  {
213  m_lsaRefreshTime = lrt;
214  }
215 
218  {
219  return m_syncProtocol;
220  }
221 
222  void
224  {
225  m_syncProtocol = syncProtocol;
226  }
227 
228  uint32_t
230  {
231  return m_lsaRefreshTime;
232  }
233 
234  void
235  setLsaInterestLifetime(const ndn::time::seconds& lifetime)
236  {
237  m_lsaInterestLifetime = lifetime;
238  }
239 
240  const ndn::time::seconds&
242  {
243  return m_lsaInterestLifetime;
244  }
245 
246  void
247  setAdjLsaBuildInterval(uint32_t interval)
248  {
249  m_adjLsaBuildInterval = interval;
250  }
251 
252  uint32_t
254  {
255  return m_adjLsaBuildInterval;
256  }
257 
258  void
259  setRoutingCalcInterval(uint32_t interval)
260  {
261  m_routingCalcInterval = interval;
262  }
263 
264  uint32_t
266  {
267  return m_routingCalcInterval;
268  }
269 
270  void
271  setRouterDeadInterval(uint32_t rdt)
272  {
273  m_routerDeadInterval = rdt;
274  }
275 
276  uint32_t
278  {
279  return m_routerDeadInterval;
280  }
281 
282  void
283  setFaceDatasetFetchTries(uint32_t count)
284  {
285  m_faceDatasetFetchTries = count;
286  }
287 
288  uint32_t
290  {
291  return m_faceDatasetFetchTries;
292  }
293 
294  void
295  setFaceDatasetFetchInterval(uint32_t interval)
296  {
297  m_faceDatasetFetchInterval = ndn::time::seconds(interval);
298  }
299 
300  const ndn::time::seconds
302  {
303  return m_faceDatasetFetchInterval;
304  }
305 
306  void
308  {
309  m_interestRetryNumber = irn;
310  }
311 
312  uint32_t
314  {
315  return m_interestRetryNumber;
316  }
317 
318  void
319  setInterestResendTime(uint32_t irt)
320  {
321  m_interestResendTime = irt;
322  }
323 
324  uint32_t
326  {
327  return m_interestResendTime;
328  }
329 
330  uint32_t
332  {
333  return m_infoInterestInterval;
334  }
335 
336  void
338  {
339  m_infoInterestInterval = iii;
340  }
341 
342  void
344  {
345  m_hyperbolicState = ihc;
346  }
347 
350  {
351  return m_hyperbolicState;
352  }
353 
354  bool
355  setCorR(double cr)
356  {
357  if ( cr >= 0 ) {
358  m_corR = cr;
359  return true;
360  }
361  return false;
362  }
363 
364  double
365  getCorR() const
366  {
367  return m_corR;
368  }
369 
370  void
371  setCorTheta(const std::vector<double>& ct)
372  {
373  m_corTheta = ct;
374  }
375 
376  std::vector<double>
377  getCorTheta() const
378  {
379  return m_corTheta;
380  }
381 
382  void
383  setMaxFacesPerPrefix(uint32_t mfpp)
384  {
385  m_maxFacesPerPrefix = mfpp;
386  }
387 
388  uint32_t
390  {
391  return m_maxFacesPerPrefix;
392  }
393 
394  void
395  setStateFileDir(const std::string& ssfd)
396  {
397  m_stateFileDir = ssfd;
398  }
399 
400  const std::string&
402  {
403  return m_stateFileDir;
404  }
405 
406  void
407  setConfFileNameDynamic(const std::string& confFileDynamic)
408  {
409  m_confFileNameDynamic = confFileDynamic;
410  }
411 
412  const std::string&
414  {
415  return m_confFileNameDynamic;
416  }
417 
418  void
419  setSyncInterestLifetime(uint32_t syncInterestLifetime)
420  {
421  m_syncInterestLifetime = ndn::time::milliseconds(syncInterestLifetime);
422  }
423 
424  const ndn::time::milliseconds&
426  {
427  return m_syncInterestLifetime;
428  }
429 
432  {
433  return m_adjl;
434  }
435 
438  {
439  return m_npl;
440  }
441 
442  ndn::security::ValidatorConfig&
444  {
445  return m_validator;
446  }
447 
448  ndn::security::ValidatorConfig&
450  {
451  return m_prefixUpdateValidator;
452  }
453 
454  const ndn::security::SigningInfo&
456  {
457  return m_signingInfo;
458  }
459 
460  void
461  addCertPath(const std::string& certPath)
462  {
463  m_certs.insert(certPath);
464  }
465 
466  const std::unordered_set<std::string>&
467  getIdCerts() const
468  {
469  return m_certs;
470  }
471 
472  const ndn::KeyChain&
473  getKeyChain() const
474  {
475  return m_keyChain;
476  }
477 
478  std::optional<ndn::security::Certificate>
479  initializeKey();
480 
481  void
482  loadCertToValidator(const ndn::security::Certificate& cert);
483 
486  void
487  writeLog();
488 
490  std::string m_confFileName;
491  std::string m_confFileNameDynamic;
492 
493 private:
494  ndn::Name m_routerName;
495  ndn::Name m_siteName;
496  ndn::Name m_network;
497 
498  ndn::Name m_routerPrefix;
499  ndn::Name m_syncUserPrefix;
500 
501  ndn::Name m_syncPrefix;
502  ndn::Name m_lsaPrefix;
503 
504  uint32_t m_lsaRefreshTime;
505 
506  uint32_t m_adjLsaBuildInterval;
507  uint32_t m_routingCalcInterval;
508 
509  uint32_t m_faceDatasetFetchTries;
510  ndn::time::seconds m_faceDatasetFetchInterval;
511 
512  ndn::time::seconds m_lsaInterestLifetime;
513  uint32_t m_routerDeadInterval;
514 
515  uint32_t m_interestRetryNumber;
516  uint32_t m_interestResendTime;
517 
518  uint32_t m_infoInterestInterval;
519 
520  HyperbolicState m_hyperbolicState;
521  double m_corR;
522  std::vector<double> m_corTheta;
523 
524  uint32_t m_maxFacesPerPrefix;
525 
526  std::string m_stateFileDir;
527 
528  ndn::time::milliseconds m_syncInterestLifetime;
529 
530  SyncProtocol m_syncProtocol = SyncProtocol::PSYNC;
531 
533  // must be incremented when breaking changes are made to sync
534  static constexpr uint64_t SYNC_VERSION = 12;
535 
536  AdjacencyList m_adjl;
537  NamePrefixList m_npl;
538  ndn::security::ValidatorConfig m_validator;
539  ndn::security::ValidatorConfig m_prefixUpdateValidator;
540  ndn::security::SigningInfo m_signingInfo;
541  std::unordered_set<std::string> m_certs;
542  ndn::KeyChain& m_keyChain;
543 };
544 
545 } // namespace nlsr
546 
547 #endif // NLSR_CONF_PARAMETER_HPP
A class to house all the configuration parameters for NLSR.
const ndn::security::SigningInfo & getSigningInfo() const
std::optional< ndn::security::Certificate > initializeKey()
void setHyperbolicState(HyperbolicState ihc)
void setRouterName(const ndn::Name &routerName)
const std::string & getConfFileNameDynamic() const
void setSiteName(const ndn::Name &siteName)
void setInterestRetryNumber(uint32_t irn)
void setMaxFacesPerPrefix(uint32_t mfpp)
uint32_t getInfoInterestInterval() const
void setRouterDeadInterval(uint32_t rdt)
uint32_t getRoutingCalcInterval() const
const std::string & getConfFileName()
std::vector< double > getCorTheta() const
const ndn::Name & getSyncUserPrefix() const
void writeLog()
Dump the current state of all attributes to the log.
const ndn::Name & getLsaPrefix() const
void setSyncProtocol(SyncProtocol syncProtocol)
const ndn::Name & getSiteName() const
const std::string & getStateFileDir() const
SyncProtocol getSyncProtocol() const
const std::unordered_set< std::string > & getIdCerts() const
void setStateFileDir(const std::string &ssfd)
void setLsaRefreshTime(uint32_t lrt)
void setInterestResendTime(uint32_t irt)
uint32_t getInterestRetryNumber() const
const ndn::Name & getNetwork() const
uint32_t getRouterDeadInterval() const
const ndn::Name & getRouterPrefix() const
const ndn::time::milliseconds & getSyncInterestLifetime() const
void loadCertToValidator(const ndn::security::Certificate &cert)
double getCorR() const
ConfParameter(ndn::Face &face, ndn::KeyChain &keyChain, const std::string &confFileName="nlsr.conf")
const ndn::time::seconds & getLsaInterestLifetime() const
const ndn::time::seconds getFaceDatasetFetchInterval() const
uint32_t getLsaRefreshTime() const
uint32_t getInterestResendTime() const
void setAdjLsaBuildInterval(uint32_t interval)
void setConfFileNameDynamic(const std::string &confFileDynamic)
const ndn::Name & getSyncPrefix() const
void setInfoInterestInterval(uint32_t iii)
NamePrefixList & getNamePrefixList()
void addCertPath(const std::string &certPath)
AdjacencyList & getAdjacencyList()
void setFaceDatasetFetchTries(uint32_t count)
ndn::security::ValidatorConfig & getValidator()
void setLsaInterestLifetime(const ndn::time::seconds &lifetime)
void setSyncInterestLifetime(uint32_t syncInterestLifetime)
void setCorTheta(const std::vector< double > &ct)
bool setCorR(double cr)
ndn::security::ValidatorConfig & getPrefixUpdateValidator()
void setFaceDatasetFetchInterval(uint32_t interval)
uint32_t getMaxFacesPerPrefix() const
const ndn::Name & getRouterName() const
const ndn::KeyChain & getKeyChain() const
HyperbolicState getHyperbolicState() const
void setNetwork(const ndn::Name &networkName)
uint32_t getFaceDatasetFetchTries() const
uint32_t getAdjLsaBuildInterval() const
void setRoutingCalcInterval(uint32_t interval)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
@ FACE_DATASET_FETCH_TRIES_DEFAULT
@ FACE_DATASET_FETCH_TRIES_MIN
@ FACE_DATASET_FETCH_TRIES_MAX
@ LSA_REFRESH_TIME_MIN
@ LSA_REFRESH_TIME_MAX
@ LSA_REFRESH_TIME_DEFAULT
@ HELLO_RETRIES_MAX
@ HELLO_RETRIES_DEFAULT
@ HELLO_RETRIES_MIN
@ ROUTING_CALC_INTERVAL_DEFAULT
@ ROUTING_CALC_INTERVAL_MIN
@ ROUTING_CALC_INTERVAL_MAX
@ MAX_FACES_PER_PREFIX_MIN
@ MAX_FACES_PER_PREFIX_DEFAULT
@ MAX_FACES_PER_PREFIX_MAX
@ FACE_DATASET_FETCH_INTERVAL_DEFAULT
@ FACE_DATASET_FETCH_INTERVAL_MIN
@ FACE_DATASET_FETCH_INTERVAL_MAX
@ ADJ_LSA_BUILD_INTERVAL_DEFAULT
@ ADJ_LSA_BUILD_INTERVAL_MIN
@ ADJ_LSA_BUILD_INTERVAL_MAX
@ HYPERBOLIC_STATE_ON
@ HYPERBOLIC_STATE_DRY_RUN
@ HYPERBOLIC_STATE_OFF
@ HYPERBOLIC_STATE_DEFAULT
@ LSA_INTEREST_LIFETIME_MAX
@ LSA_INTEREST_LIFETIME_DEFAULT
@ LSA_INTEREST_LIFETIME_MIN
@ HELLO_INTERVAL_MIN
@ HELLO_INTERVAL_DEFAULT
@ HELLO_INTERVAL_MAX
@ HELLO_TIMEOUT_DEFAULT
@ HELLO_TIMEOUT_MIN
@ HELLO_TIMEOUT_MAX
@ SYNC_INTEREST_LIFETIME_MIN
@ SYNC_INTEREST_LIFETIME_MAX
@ SYNC_INTEREST_LIFETIME_DEFAULT
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE