blob: d13b415223b1c463d9188c570ddaf5926e172cb3 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehmanc2e51f62015-01-20 15:03:11 -060021
Ashlesh Gawande3909aa12017-07-28 16:01:35 -050022#include "conf-file-processor.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050023#include "conf-parameter.hpp"
Ashlesh Gawande3909aa12017-07-28 16:01:35 -050024#include "adjacent.hpp"
25#include "utility/name-helper.hpp"
26#include "update/prefix-update-processor.hpp"
27
Nick Gordone98480b2017-05-24 11:23:03 -050028#include <boost/cstdint.hpp>
Alexander Afanasyevb669f9c2014-11-14 12:41:54 -080029
30#include <ndn-cxx/name.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050031#include <ndn-cxx/net/face-uri.hpp>
Alexander Afanasyevb669f9c2014-11-14 12:41:54 -080032
Nick Gordone98480b2017-05-24 11:23:03 -050033#include <iostream>
34#include <fstream>
akmhoque53353462014-04-22 08:43:45 -050035
akmhoque53353462014-04-22 08:43:45 -050036namespace nlsr {
37
Vince Lehman7b616582014-10-17 16:25:39 -050038template <class T>
39class ConfigurationVariable
40{
41public:
dmcoomes9f936662017-03-02 10:33:09 -060042 typedef std::function<void(T)> ConfParameterCallback;
Vince Lehman7b616582014-10-17 16:25:39 -050043 typedef boost::property_tree::ptree ConfigSection;
44
45 ConfigurationVariable(const std::string& key, const ConfParameterCallback& setter)
46 : m_key(key)
47 , m_setterCallback(setter)
48 , m_minValue(0)
49 , m_maxValue(0)
50 , m_shouldCheckRange(false)
51 , m_isRequired(true)
52 {
53 }
54
55 bool
56 parseFromConfigSection(const ConfigSection& section)
57 {
58 try {
59 T value = section.get<T>(m_key);
60
61 if (!isValidValue(value)) {
62 return false;
63 }
64
65 m_setterCallback(value);
66 return true;
67 }
68 catch (const std::exception& ex) {
69
70 if (m_isRequired) {
71 std::cerr << ex.what() << std::endl;
72 std::cerr << "Missing required configuration variable" << std::endl;
73 return false;
74 }
75 else {
76 m_setterCallback(m_defaultValue);
77 return true;
78 }
79 }
80
81 return false;
82 }
83
84 void
85 setMinAndMaxValue(T min, T max)
86 {
87 m_minValue = min;
88 m_maxValue = max;
89 m_shouldCheckRange = true;
90 }
91
92 void
93 setOptional(T defaultValue)
94 {
95 m_isRequired = false;
96 m_defaultValue = defaultValue;
97 }
98
99private:
100 void
101 printOutOfRangeError(T value)
102 {
103 std::cerr << "Invalid value for " << m_key << ": "
104 << value << ". "
105 << "Valid values: "
106 << m_minValue << " - "
107 << m_maxValue << std::endl;
108 }
109
110 bool
111 isValidValue(T value)
112 {
113 if (!m_shouldCheckRange) {
114 return true;
115 }
116 else if (value < m_minValue || value > m_maxValue)
117 {
118 printOutOfRangeError(value);
119 return false;
120 }
121
122 return true;
123 }
124
125private:
126 const std::string m_key;
127 const ConfParameterCallback m_setterCallback;
128 T m_defaultValue;
129
130 T m_minValue;
131 T m_maxValue;
132
133 bool m_shouldCheckRange;
134 bool m_isRequired;
135};
136
akmhoque157b0a42014-05-13 00:26:37 -0500137bool
akmhoqueb6450b12014-04-24 00:01:03 -0500138ConfFileProcessor::processConfFile()
akmhoque53353462014-04-22 08:43:45 -0500139{
akmhoque157b0a42014-05-13 00:26:37 -0500140 bool ret = true;
Nick Gordone98480b2017-05-24 11:23:03 -0500141 std::ifstream inputFile;
akmhoque157b0a42014-05-13 00:26:37 -0500142 inputFile.open(m_confFileName.c_str());
143 if (!inputFile.is_open()) {
Nick Gordone98480b2017-05-24 11:23:03 -0500144 std::string msg = "Failed to read configuration file: ";
akmhoque157b0a42014-05-13 00:26:37 -0500145 msg += m_confFileName;
Nick Gordone98480b2017-05-24 11:23:03 -0500146 std::cerr << msg << std::endl;
akmhoquead5fe952014-06-26 13:34:12 -0500147 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500148 }
149 ret = load(inputFile);
150 inputFile.close();
151 return ret;
152}
153
154bool
Nick Gordone98480b2017-05-24 11:23:03 -0500155ConfFileProcessor::load(std::istream& input)
akmhoque157b0a42014-05-13 00:26:37 -0500156{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700157 ConfigSection pt;
akmhoque157b0a42014-05-13 00:26:37 -0500158 bool ret = true;
159 try {
160 boost::property_tree::read_info(input, pt);
161 }
162 catch (const boost::property_tree::info_parser_error& error) {
Nick Gordone98480b2017-05-24 11:23:03 -0500163 std::stringstream msg;
akmhoque157b0a42014-05-13 00:26:37 -0500164 std::cerr << "Failed to parse configuration file " << std::endl;
165 std::cerr << m_confFileName << std::endl;
166 return false;
167 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700168
169 for (ConfigSection::const_iterator tn = pt.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500170 tn != pt.end(); ++tn) {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700171 ret = processSection(tn->first, tn->second);
akmhoque157b0a42014-05-13 00:26:37 -0500172 if (ret == false) {
173 break;
174 }
175 }
176 return ret;
177}
178
179bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700180ConfFileProcessor::processSection(const std::string& sectionName, const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500181{
182 bool ret = true;
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700183 if (sectionName == "general")
akmhoque53353462014-04-22 08:43:45 -0500184 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700185 ret = processConfSectionGeneral(section);
akmhoque157b0a42014-05-13 00:26:37 -0500186 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700187 else if (sectionName == "neighbors")
akmhoque157b0a42014-05-13 00:26:37 -0500188 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700189 ret = processConfSectionNeighbors(section);
akmhoque157b0a42014-05-13 00:26:37 -0500190 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700191 else if (sectionName == "hyperbolic")
akmhoque157b0a42014-05-13 00:26:37 -0500192 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700193 ret = processConfSectionHyperbolic(section);
akmhoque157b0a42014-05-13 00:26:37 -0500194 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700195 else if (sectionName == "fib")
akmhoque157b0a42014-05-13 00:26:37 -0500196 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700197 ret = processConfSectionFib(section);
akmhoque157b0a42014-05-13 00:26:37 -0500198 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700199 else if (sectionName == "advertising")
akmhoque157b0a42014-05-13 00:26:37 -0500200 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700201 ret = processConfSectionAdvertising(section);
akmhoque157b0a42014-05-13 00:26:37 -0500202 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700203 else if (sectionName == "security")
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700204 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700205 ret = processConfSectionSecurity(section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700206 }
akmhoque157b0a42014-05-13 00:26:37 -0500207 else
208 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700209 std::cerr << "Wrong configuration section: " << sectionName << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500210 }
211 return ret;
212}
213
214bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700215ConfFileProcessor::processConfSectionGeneral(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500216{
217 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500218 std::string network = section.get<std::string>("network");
219 std::string site = section.get<std::string>("site");
220 std::string router = section.get<std::string>("router");
akmhoque157b0a42014-05-13 00:26:37 -0500221 ndn::Name networkName(network);
222 if (!networkName.empty()) {
223 m_nlsr.getConfParameter().setNetwork(networkName);
224 }
225 else {
Nick Gordone98480b2017-05-24 11:23:03 -0500226 std::cerr << " Network can not be null or empty or in bad URI format :(!" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500227 return false;
228 }
229 ndn::Name siteName(site);
230 if (!siteName.empty()) {
231 m_nlsr.getConfParameter().setSiteName(siteName);
232 }
233 else {
Nick Gordone98480b2017-05-24 11:23:03 -0500234 std::cerr << "Site can not be null or empty or in bad URI format:( !" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500235 return false;
236 }
237 ndn::Name routerName(router);
238 if (!routerName.empty()) {
239 m_nlsr.getConfParameter().setRouterName(routerName);
240 }
241 else {
Nick Gordone98480b2017-05-24 11:23:03 -0500242 std::cerr << " Router name can not be null or empty or in bad URI format:( !" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500243 return false;
244 }
245 }
246 catch (const std::exception& ex) {
Nick Gordone98480b2017-05-24 11:23:03 -0500247 std::cerr << ex.what() << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500248 return false;
249 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700250
alvya2228c62014-12-09 10:25:11 -0600251 // lsa-refresh-time
alvy5a454952014-12-15 12:49:54 -0600252 uint32_t lsaRefreshTime = section.get<uint32_t>("lsa-refresh-time", LSA_REFRESH_TIME_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600253
254 if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
255 m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
akmhoque157b0a42014-05-13 00:26:37 -0500256 }
alvya2228c62014-12-09 10:25:11 -0600257 else {
258 std::cerr << "Wrong value for lsa-refresh-time ";
259 std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";;
260 std::cerr << LSA_REFRESH_TIME_MAX << std::endl;
261
262 return false;
263 }
264
265 // router-dead-interval
alvy5a454952014-12-15 12:49:54 -0600266 uint32_t routerDeadInterval = section.get<uint32_t>("router-dead-interval", (2*lsaRefreshTime));
alvya2228c62014-12-09 10:25:11 -0600267
268 if (routerDeadInterval > m_nlsr.getConfParameter().getLsaRefreshTime()) {
269 m_nlsr.getConfParameter().setRouterDeadInterval(routerDeadInterval);
270 }
271 else {
272 std::cerr << "Value of router-dead-interval must be larger than lsa-refresh-time" << std::endl;
273 return false;
274 }
275
276 // lsa-interest-lifetime
277 int lifetime = section.get<int>("lsa-interest-lifetime", LSA_INTEREST_LIFETIME_DEFAULT);
278
279 if (lifetime >= LSA_INTEREST_LIFETIME_MIN && lifetime <= LSA_INTEREST_LIFETIME_MAX) {
280 m_nlsr.getConfParameter().setLsaInterestLifetime(ndn::time::seconds(lifetime));
281 }
282 else {
283 std::cerr << "Wrong value for lsa-interest-timeout. "
284 << "Allowed value:" << LSA_INTEREST_LIFETIME_MIN << "-"
285 << LSA_INTEREST_LIFETIME_MAX << std::endl;
286
akmhoque157b0a42014-05-13 00:26:37 -0500287 return false;
288 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700289
alvyd5a13cd2015-01-06 16:34:38 -0600290 // log-level
Nick Gordone98480b2017-05-24 11:23:03 -0500291 std::string logLevel = section.get<std::string>("log-level", "INFO");
Vince Lehmanf99b87f2014-08-26 15:54:27 -0500292
alvyd5a13cd2015-01-06 16:34:38 -0600293 if (isValidLogLevel(logLevel)) {
294 m_nlsr.getConfParameter().setLogLevel(logLevel);
akmhoque157b0a42014-05-13 00:26:37 -0500295 }
alvyd5a13cd2015-01-06 16:34:38 -0600296 else {
297 std::cerr << "Invalid value for log-level ";
298 std::cerr << "Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERROR, NONE" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500299 return false;
300 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700301
akmhoque674b0b12014-05-20 14:33:28 -0500302 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500303 std::string logDir = section.get<std::string>("log-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500304 if (boost::filesystem::exists(logDir)) {
305 if (boost::filesystem::is_directory(logDir)) {
306 std::string testFileName=logDir+"/test.log";
Nick Gordone98480b2017-05-24 11:23:03 -0500307 std::ofstream testOutFile;
akmhoque674b0b12014-05-20 14:33:28 -0500308 testOutFile.open(testFileName.c_str());
309 if (testOutFile.is_open() && testOutFile.good()) {
310 m_nlsr.getConfParameter().setLogDir(logDir);
311 }
312 else {
313 std::cerr << "User does not have read and write permission on the directory";
314 std::cerr << std::endl;
315 return false;
316 }
317 testOutFile.close();
318 remove(testFileName.c_str());
319 }
320 else {
321 std::cerr << "Provided path is not a directory" << std::endl;
322 return false;
323 }
324 }
325 else {
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500326 std::cerr << "Provided log directory <" << logDir << "> does not exist" << std::endl;
akmhoque674b0b12014-05-20 14:33:28 -0500327 return false;
328 }
329 }
330 catch (const std::exception& ex) {
331 std::cerr << "You must configure log directory" << std::endl;
332 std::cerr << ex.what() << std::endl;
333 return false;
334 }
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500335
akmhoque674b0b12014-05-20 14:33:28 -0500336 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500337 std::string seqDir = section.get<std::string>("seq-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500338 if (boost::filesystem::exists(seqDir)) {
339 if (boost::filesystem::is_directory(seqDir)) {
340 std::string testFileName=seqDir+"/test.seq";
Nick Gordone98480b2017-05-24 11:23:03 -0500341 std::ofstream testOutFile;
akmhoque674b0b12014-05-20 14:33:28 -0500342 testOutFile.open(testFileName.c_str());
343 if (testOutFile.is_open() && testOutFile.good()) {
344 m_nlsr.getConfParameter().setSeqFileDir(seqDir);
345 }
346 else {
347 std::cerr << "User does not have read and write permission on the directory";
348 std::cerr << std::endl;
349 return false;
350 }
351 testOutFile.close();
352 remove(testFileName.c_str());
353 }
354 else {
355 std::cerr << "Provided path is not a directory" << std::endl;
356 return false;
357 }
358 }
359 else {
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500360 std::cerr << "Provided sequence directory <" << seqDir << "> does not exist" << std::endl;
akmhoque674b0b12014-05-20 14:33:28 -0500361 return false;
362 }
363 }
364 catch (const std::exception& ex) {
365 std::cerr << "You must configure sequence directory" << std::endl;
366 std::cerr << ex.what() << std::endl;
367 return false;
368 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700369
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500370 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500371 std::string log4cxxPath = section.get<std::string>("log4cxx-conf");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500372
373 if (log4cxxPath == "") {
374 std::cerr << "No value provided for log4cxx-conf" << std::endl;
375 return false;
376 }
377
378 if (boost::filesystem::exists(log4cxxPath)) {
379 m_nlsr.getConfParameter().setLog4CxxConfPath(log4cxxPath);
380 }
381 else {
382 std::cerr << "Provided path for log4cxx-conf <" << log4cxxPath
383 << "> does not exist" << std::endl;
384
385 return false;
386 }
387 }
388 catch (const std::exception& ex) {
389 // Variable is optional so default configuration will be used; continue processing file
390 }
391
akmhoque157b0a42014-05-13 00:26:37 -0500392 return true;
393}
394
395bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700396ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500397{
alvya2228c62014-12-09 10:25:11 -0600398 // hello-retries
399 int retrials = section.get<int>("hello-retries", HELLO_RETRIES_DEFAULT);
400
401 if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
402 m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
akmhoque157b0a42014-05-13 00:26:37 -0500403 }
alvya2228c62014-12-09 10:25:11 -0600404 else {
405 std::cerr << "Wrong value for hello-retries." << std::endl;
406 std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
407 std::cerr << HELLO_RETRIES_MAX << std::endl;
408
akmhoque157b0a42014-05-13 00:26:37 -0500409 return false;
410 }
alvya2228c62014-12-09 10:25:11 -0600411
412 // hello-timeout
alvy5a454952014-12-15 12:49:54 -0600413 uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600414
415 if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
416 m_nlsr.getConfParameter().setInterestResendTime(timeOut);
akmhoque157b0a42014-05-13 00:26:37 -0500417 }
alvya2228c62014-12-09 10:25:11 -0600418 else {
419 std::cerr << "Wrong value for hello-timeout. ";
420 std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
421 std::cerr << HELLO_TIMEOUT_MAX << std::endl;
422
423 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500424 }
alvya2228c62014-12-09 10:25:11 -0600425
426 // hello-interval
alvy5a454952014-12-15 12:49:54 -0600427 uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600428
429 if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
430 m_nlsr.getConfParameter().setInfoInterestInterval(interval);
akmhoque157b0a42014-05-13 00:26:37 -0500431 }
alvya2228c62014-12-09 10:25:11 -0600432 else {
433 std::cerr << "Wrong value for hello-interval. ";
434 std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
435 std::cerr << HELLO_INTERVAL_MAX << std::endl;
436
437 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500438 }
Vince Lehman7b616582014-10-17 16:25:39 -0500439
440 // Event intervals
441 // adj-lsa-build-interval
442 ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600443 std::bind(&ConfParameter::setAdjLsaBuildInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500444 &m_nlsr.getConfParameter(), _1));
445 adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX);
446 adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT);
447
448 if (!adjLsaBuildInterval.parseFromConfigSection(section)) {
449 return false;
450 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500451 // Set the retry count for fetching the FaceStatus dataset
452 ConfigurationVariable<uint32_t> faceDatasetFetchTries("face-dataset-fetch-tries",
453 std::bind(&ConfParameter::setFaceDatasetFetchTries,
454 &m_nlsr.getConfParameter(),
455 _1));
456
457 faceDatasetFetchTries.setMinAndMaxValue(FACE_DATASET_FETCH_TRIES_MIN,
458 FACE_DATASET_FETCH_TRIES_MAX);
459 faceDatasetFetchTries.setOptional(FACE_DATASET_FETCH_TRIES_DEFAULT);
460
461 if (!faceDatasetFetchTries.parseFromConfigSection(section)) {
462 return false;
463 }
464
465 // Set the interval between FaceStatus dataset fetch attempts.
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500466 ConfigurationVariable<uint32_t> faceDatasetFetchInterval("face-dataset-fetch-interval",
Nick Gordond5c1a372016-10-31 13:56:23 -0500467 bind(&ConfParameter::setFaceDatasetFetchInterval,
468 &m_nlsr.getConfParameter(),
469 _1));
470
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500471 faceDatasetFetchInterval.setMinAndMaxValue(FACE_DATASET_FETCH_INTERVAL_MIN,
472 FACE_DATASET_FETCH_INTERVAL_MAX);
473 faceDatasetFetchInterval.setOptional(FACE_DATASET_FETCH_INTERVAL_DEFAULT);
Nick Gordond5c1a372016-10-31 13:56:23 -0500474
475 if (!faceDatasetFetchInterval.parseFromConfigSection(section)) {
476 return false;
477 }
Vince Lehman7b616582014-10-17 16:25:39 -0500478
479 // first-hello-interval
480 ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600481 std::bind(&ConfParameter::setFirstHelloInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500482 &m_nlsr.getConfParameter(), _1));
483 firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
484 firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
485
486 if (!firstHelloInterval.parseFromConfigSection(section)) {
487 return false;
488 }
489
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700490 for (ConfigSection::const_iterator tn =
491 section.begin(); tn != section.end(); ++tn) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700492
Nick Gordond5c1a372016-10-31 13:56:23 -0500493 if (tn->first == "neighbor") {
akmhoque157b0a42014-05-13 00:26:37 -0500494 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700495 ConfigSection CommandAttriTree = tn->second;
akmhoque157b0a42014-05-13 00:26:37 -0500496 std::string name = CommandAttriTree.get<std::string>("name");
Nick Gordone9733ed2017-04-26 10:48:39 -0500497 std::string uriString = CommandAttriTree.get<std::string>("face-uri");
alvy2fe12872014-11-25 10:32:23 -0600498
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500499 ndn::FaceUri faceUri;
Laqin Fan54a43f02017-03-08 12:31:30 -0600500 if (! faceUri.parse(uriString)) {
501 std::cerr << "parsing failed!" << std::endl;
alvy2fe12872014-11-25 10:32:23 -0600502 return false;
503 }
504
akmhoque157b0a42014-05-13 00:26:37 -0500505 double linkCost = CommandAttriTree.get<double>("link-cost",
506 Adjacent::DEFAULT_LINK_COST);
507 ndn::Name neighborName(name);
508 if (!neighborName.empty()) {
Vince Lehmancb76ade2014-08-28 21:24:41 -0500509 Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
akmhoque157b0a42014-05-13 00:26:37 -0500510 m_nlsr.getAdjacencyList().insert(adj);
511 }
512 else {
akmhoque674b0b12014-05-20 14:33:28 -0500513 std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
akmhoque157b0a42014-05-13 00:26:37 -0500514 std::cerr << " or bad URI format" << std::endl;
akmhoque53353462014-04-22 08:43:45 -0500515 }
516 }
akmhoque157b0a42014-05-13 00:26:37 -0500517 catch (const std::exception& ex) {
518 std::cerr << ex.what() << std::endl;
519 return false;
520 }
akmhoque53353462014-04-22 08:43:45 -0500521 }
522 }
akmhoque157b0a42014-05-13 00:26:37 -0500523 return true;
akmhoque53353462014-04-22 08:43:45 -0500524}
525
akmhoque157b0a42014-05-13 00:26:37 -0500526bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700527ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500528{
alvya2228c62014-12-09 10:25:11 -0600529 // state
Nick Gordone98480b2017-05-24 11:23:03 -0500530 std::string state = section.get<std::string>("state", "off");
alvya2228c62014-12-09 10:25:11 -0600531
532 if (boost::iequals(state, "off")) {
533 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
akmhoque53353462014-04-22 08:43:45 -0500534 }
alvya2228c62014-12-09 10:25:11 -0600535 else if (boost::iequals(state, "on")) {
536 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
537 }
538 else if (state == "dry-run") {
539 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
540 }
541 else {
542 std::cerr << "Wrong format for hyperbolic state." << std::endl;
543 std::cerr << "Allowed value: off, on, dry-run" << std::endl;
544
akmhoque157b0a42014-05-13 00:26:37 -0500545 return false;
akmhoque53353462014-04-22 08:43:45 -0500546 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700547
akmhoque157b0a42014-05-13 00:26:37 -0500548 try {
Laqin Fan54a43f02017-03-08 12:31:30 -0600549 // Radius and angle(s) are mandatory configuration parameters in hyperbolic section.
550 // Even if router can have hyperbolic routing calculation off but other router
551 // in the network may use hyperbolic routing calculation for FIB generation.
552 // So each router need to advertise its hyperbolic coordinates in the network
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700553 double radius = section.get<double>("radius");
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600554 std::string angleString = section.get<std::string>("angle");
555
556 std::stringstream ss(angleString);
557 std::vector<double> angles;
558
559 double angle;
560
Laqin Fan54a43f02017-03-08 12:31:30 -0600561 while (ss >> angle) {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600562 angles.push_back(angle);
Laqin Fan54a43f02017-03-08 12:31:30 -0600563 if (ss.peek() == ',' || ss.peek() == ' ') {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600564 ss.ignore();
565 }
566 }
567
akmhoque157b0a42014-05-13 00:26:37 -0500568 if (!m_nlsr.getConfParameter().setCorR(radius)) {
569 return false;
570 }
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600571 m_nlsr.getConfParameter().setCorTheta(angles);
akmhoque53353462014-04-22 08:43:45 -0500572 }
akmhoque157b0a42014-05-13 00:26:37 -0500573 catch (const std::exception& ex) {
574 std::cerr << ex.what() << std::endl;
575 if (state == "on" || state == "dry-run") {
576 return false;
577 }
akmhoque53353462014-04-22 08:43:45 -0500578 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700579
akmhoque157b0a42014-05-13 00:26:37 -0500580 return true;
akmhoque53353462014-04-22 08:43:45 -0500581}
582
akmhoque157b0a42014-05-13 00:26:37 -0500583bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700584ConfFileProcessor::processConfSectionFib(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500585{
alvya2228c62014-12-09 10:25:11 -0600586 // max-faces-per-prefix
587 int maxFacesPerPrefix = section.get<int>("max-faces-per-prefix", MAX_FACES_PER_PREFIX_DEFAULT);
588
589 if (maxFacesPerPrefix >= MAX_FACES_PER_PREFIX_MIN &&
590 maxFacesPerPrefix <= MAX_FACES_PER_PREFIX_MAX)
591 {
592 m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -0500593 }
alvya2228c62014-12-09 10:25:11 -0600594 else {
595 std::cerr << "Wrong value for max-faces-per-prefix. ";
596 std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
597
akmhoque157b0a42014-05-13 00:26:37 -0500598 return false;
599 }
Vince Lehman7b616582014-10-17 16:25:39 -0500600
601 // routing-calc-interval
602 ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600603 std::bind(&ConfParameter::setRoutingCalcInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500604 &m_nlsr.getConfParameter(), _1));
605 routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX);
606 routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT);
607
608 if (!routingCalcInterval.parseFromConfigSection(section)) {
609 return false;
610 }
611
akmhoque157b0a42014-05-13 00:26:37 -0500612 return true;
akmhoque53353462014-04-22 08:43:45 -0500613}
614
akmhoque157b0a42014-05-13 00:26:37 -0500615bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700616ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500617{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700618 for (ConfigSection::const_iterator tn =
619 section.begin(); tn != section.end(); ++tn) {
akmhoque157b0a42014-05-13 00:26:37 -0500620 if (tn->first == "prefix") {
621 try {
622 std::string prefix = tn->second.data();
623 ndn::Name namePrefix(prefix);
624 if (!namePrefix.empty()) {
625 m_nlsr.getNamePrefixList().insert(namePrefix);
626 }
627 else {
akmhoque674b0b12014-05-20 14:33:28 -0500628 std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500629 return false;
630 }
631 }
632 catch (const std::exception& ex) {
633 std::cerr << ex.what() << std::endl;
634 return false;
635 }
akmhoque53353462014-04-22 08:43:45 -0500636 }
akmhoque53353462014-04-22 08:43:45 -0500637 }
akmhoque157b0a42014-05-13 00:26:37 -0500638 return true;
akmhoque53353462014-04-22 08:43:45 -0500639}
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700640
641bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700642ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700643{
644 ConfigSection::const_iterator it = section.begin();
645
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500646 if (it == section.end() || it->first != "validator") {
647 std::cerr << "Error: Expect validator section!" << std::endl;
648 return false;
649 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700650
651 m_nlsr.loadValidator(it->second, m_confFileName);
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500652
akmhoqued57f3672014-06-10 10:41:32 -0500653 it++;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500654 if (it != section.end() && it->first == "prefix-update-validator") {
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500655 m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700656
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500657 it++;
658 for (; it != section.end(); it++) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700659 using namespace boost::filesystem;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500660
661 if (it->first != "cert-to-publish") {
662 std::cerr << "Error: Expect cert-to-publish!" << std::endl;
663 return false;
664 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700665
666 std::string file = it->second.data();
667 path certfilePath = absolute(file, path(m_confFileName).parent_path());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500668 std::shared_ptr<ndn::security::v2::Certificate> idCert =
669 ndn::io::load<ndn::security::v2::Certificate>(certfilePath.string());
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700670
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500671 if (idCert == nullptr) {
672 std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
673 return false;
674 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700675
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500676 m_nlsr.loadCertToPublish(*idCert);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700677 }
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500678 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700679
680 return true;
681}
682
alvy2fe12872014-11-25 10:32:23 -0600683} // namespace nlsr