blob: d388221306752ced633abfe7050f02f57d82e175 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
dmcoomescf8d0ed2017-02-21 11:39:01 -06003 * Copyright (c) 2014-2018, 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
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -0600290 uint32_t syncInterestLifetime = section.get<uint32_t>("sync-interest-lifetime", SYNC_INTEREST_LIFETIME_DEFAULT);
291 if (syncInterestLifetime >= SYNC_INTEREST_LIFETIME_MIN &&
292 syncInterestLifetime <= SYNC_INTEREST_LIFETIME_MAX) {
293 m_nlsr.getConfParameter().setSyncInterestLifetime(syncInterestLifetime);
294 }
295 else {
296 std::cerr << "Wrong value for sync-interest-lifetime. "
297 << "Allowed value:" << SYNC_INTEREST_LIFETIME_MIN << "-"
298 << SYNC_INTEREST_LIFETIME_MAX << std::endl;
299
300 return false;
301 }
302
akmhoque674b0b12014-05-20 14:33:28 -0500303 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500304 std::string seqDir = section.get<std::string>("seq-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500305 if (boost::filesystem::exists(seqDir)) {
306 if (boost::filesystem::is_directory(seqDir)) {
307 std::string testFileName=seqDir+"/test.seq";
Nick Gordone98480b2017-05-24 11:23:03 -0500308 std::ofstream testOutFile;
akmhoque674b0b12014-05-20 14:33:28 -0500309 testOutFile.open(testFileName.c_str());
310 if (testOutFile.is_open() && testOutFile.good()) {
311 m_nlsr.getConfParameter().setSeqFileDir(seqDir);
312 }
313 else {
314 std::cerr << "User does not have read and write permission on the directory";
315 std::cerr << std::endl;
316 return false;
317 }
318 testOutFile.close();
319 remove(testFileName.c_str());
320 }
321 else {
322 std::cerr << "Provided path is not a directory" << std::endl;
323 return false;
324 }
325 }
326 else {
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500327 std::cerr << "Provided sequence directory <" << seqDir << "> does not exist" << std::endl;
akmhoque674b0b12014-05-20 14:33:28 -0500328 return false;
329 }
330 }
331 catch (const std::exception& ex) {
332 std::cerr << "You must configure sequence directory" << std::endl;
333 std::cerr << ex.what() << std::endl;
334 return false;
335 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700336
akmhoque157b0a42014-05-13 00:26:37 -0500337 return true;
338}
339
340bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700341ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500342{
alvya2228c62014-12-09 10:25:11 -0600343 // hello-retries
344 int retrials = section.get<int>("hello-retries", HELLO_RETRIES_DEFAULT);
345
346 if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
347 m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
akmhoque157b0a42014-05-13 00:26:37 -0500348 }
alvya2228c62014-12-09 10:25:11 -0600349 else {
350 std::cerr << "Wrong value for hello-retries." << std::endl;
351 std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
352 std::cerr << HELLO_RETRIES_MAX << std::endl;
353
akmhoque157b0a42014-05-13 00:26:37 -0500354 return false;
355 }
alvya2228c62014-12-09 10:25:11 -0600356
357 // hello-timeout
alvy5a454952014-12-15 12:49:54 -0600358 uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600359
360 if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
361 m_nlsr.getConfParameter().setInterestResendTime(timeOut);
akmhoque157b0a42014-05-13 00:26:37 -0500362 }
alvya2228c62014-12-09 10:25:11 -0600363 else {
364 std::cerr << "Wrong value for hello-timeout. ";
365 std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
366 std::cerr << HELLO_TIMEOUT_MAX << std::endl;
367
368 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500369 }
alvya2228c62014-12-09 10:25:11 -0600370
371 // hello-interval
alvy5a454952014-12-15 12:49:54 -0600372 uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600373
374 if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
375 m_nlsr.getConfParameter().setInfoInterestInterval(interval);
akmhoque157b0a42014-05-13 00:26:37 -0500376 }
alvya2228c62014-12-09 10:25:11 -0600377 else {
378 std::cerr << "Wrong value for hello-interval. ";
379 std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
380 std::cerr << HELLO_INTERVAL_MAX << std::endl;
381
382 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500383 }
Vince Lehman7b616582014-10-17 16:25:39 -0500384
385 // Event intervals
386 // adj-lsa-build-interval
387 ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600388 std::bind(&ConfParameter::setAdjLsaBuildInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500389 &m_nlsr.getConfParameter(), _1));
390 adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX);
391 adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT);
392
393 if (!adjLsaBuildInterval.parseFromConfigSection(section)) {
394 return false;
395 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500396 // Set the retry count for fetching the FaceStatus dataset
397 ConfigurationVariable<uint32_t> faceDatasetFetchTries("face-dataset-fetch-tries",
398 std::bind(&ConfParameter::setFaceDatasetFetchTries,
399 &m_nlsr.getConfParameter(),
400 _1));
401
402 faceDatasetFetchTries.setMinAndMaxValue(FACE_DATASET_FETCH_TRIES_MIN,
403 FACE_DATASET_FETCH_TRIES_MAX);
404 faceDatasetFetchTries.setOptional(FACE_DATASET_FETCH_TRIES_DEFAULT);
405
406 if (!faceDatasetFetchTries.parseFromConfigSection(section)) {
407 return false;
408 }
409
410 // Set the interval between FaceStatus dataset fetch attempts.
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500411 ConfigurationVariable<uint32_t> faceDatasetFetchInterval("face-dataset-fetch-interval",
Nick Gordond5c1a372016-10-31 13:56:23 -0500412 bind(&ConfParameter::setFaceDatasetFetchInterval,
413 &m_nlsr.getConfParameter(),
414 _1));
415
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500416 faceDatasetFetchInterval.setMinAndMaxValue(FACE_DATASET_FETCH_INTERVAL_MIN,
417 FACE_DATASET_FETCH_INTERVAL_MAX);
418 faceDatasetFetchInterval.setOptional(FACE_DATASET_FETCH_INTERVAL_DEFAULT);
Nick Gordond5c1a372016-10-31 13:56:23 -0500419
420 if (!faceDatasetFetchInterval.parseFromConfigSection(section)) {
421 return false;
422 }
Vince Lehman7b616582014-10-17 16:25:39 -0500423
424 // first-hello-interval
425 ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600426 std::bind(&ConfParameter::setFirstHelloInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500427 &m_nlsr.getConfParameter(), _1));
428 firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
429 firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
430
431 if (!firstHelloInterval.parseFromConfigSection(section)) {
432 return false;
433 }
434
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700435 for (ConfigSection::const_iterator tn =
436 section.begin(); tn != section.end(); ++tn) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700437
Nick Gordond5c1a372016-10-31 13:56:23 -0500438 if (tn->first == "neighbor") {
akmhoque157b0a42014-05-13 00:26:37 -0500439 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700440 ConfigSection CommandAttriTree = tn->second;
akmhoque157b0a42014-05-13 00:26:37 -0500441 std::string name = CommandAttriTree.get<std::string>("name");
Nick Gordone9733ed2017-04-26 10:48:39 -0500442 std::string uriString = CommandAttriTree.get<std::string>("face-uri");
alvy2fe12872014-11-25 10:32:23 -0600443
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500444 ndn::FaceUri faceUri;
Laqin Fan54a43f02017-03-08 12:31:30 -0600445 if (! faceUri.parse(uriString)) {
446 std::cerr << "parsing failed!" << std::endl;
alvy2fe12872014-11-25 10:32:23 -0600447 return false;
448 }
449
akmhoque157b0a42014-05-13 00:26:37 -0500450 double linkCost = CommandAttriTree.get<double>("link-cost",
451 Adjacent::DEFAULT_LINK_COST);
452 ndn::Name neighborName(name);
453 if (!neighborName.empty()) {
Vince Lehmancb76ade2014-08-28 21:24:41 -0500454 Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
akmhoque157b0a42014-05-13 00:26:37 -0500455 m_nlsr.getAdjacencyList().insert(adj);
456 }
457 else {
akmhoque674b0b12014-05-20 14:33:28 -0500458 std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
akmhoque157b0a42014-05-13 00:26:37 -0500459 std::cerr << " or bad URI format" << std::endl;
akmhoque53353462014-04-22 08:43:45 -0500460 }
461 }
akmhoque157b0a42014-05-13 00:26:37 -0500462 catch (const std::exception& ex) {
463 std::cerr << ex.what() << std::endl;
464 return false;
465 }
akmhoque53353462014-04-22 08:43:45 -0500466 }
467 }
akmhoque157b0a42014-05-13 00:26:37 -0500468 return true;
akmhoque53353462014-04-22 08:43:45 -0500469}
470
akmhoque157b0a42014-05-13 00:26:37 -0500471bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700472ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500473{
alvya2228c62014-12-09 10:25:11 -0600474 // state
Nick Gordone98480b2017-05-24 11:23:03 -0500475 std::string state = section.get<std::string>("state", "off");
alvya2228c62014-12-09 10:25:11 -0600476
477 if (boost::iequals(state, "off")) {
478 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
akmhoque53353462014-04-22 08:43:45 -0500479 }
alvya2228c62014-12-09 10:25:11 -0600480 else if (boost::iequals(state, "on")) {
481 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
482 }
483 else if (state == "dry-run") {
484 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
485 }
486 else {
487 std::cerr << "Wrong format for hyperbolic state." << std::endl;
488 std::cerr << "Allowed value: off, on, dry-run" << std::endl;
489
akmhoque157b0a42014-05-13 00:26:37 -0500490 return false;
akmhoque53353462014-04-22 08:43:45 -0500491 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700492
akmhoque157b0a42014-05-13 00:26:37 -0500493 try {
Laqin Fan54a43f02017-03-08 12:31:30 -0600494 // Radius and angle(s) are mandatory configuration parameters in hyperbolic section.
495 // Even if router can have hyperbolic routing calculation off but other router
496 // in the network may use hyperbolic routing calculation for FIB generation.
497 // So each router need to advertise its hyperbolic coordinates in the network
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700498 double radius = section.get<double>("radius");
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600499 std::string angleString = section.get<std::string>("angle");
500
501 std::stringstream ss(angleString);
502 std::vector<double> angles;
503
504 double angle;
505
Laqin Fan54a43f02017-03-08 12:31:30 -0600506 while (ss >> angle) {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600507 angles.push_back(angle);
Laqin Fan54a43f02017-03-08 12:31:30 -0600508 if (ss.peek() == ',' || ss.peek() == ' ') {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600509 ss.ignore();
510 }
511 }
512
akmhoque157b0a42014-05-13 00:26:37 -0500513 if (!m_nlsr.getConfParameter().setCorR(radius)) {
514 return false;
515 }
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600516 m_nlsr.getConfParameter().setCorTheta(angles);
akmhoque53353462014-04-22 08:43:45 -0500517 }
akmhoque157b0a42014-05-13 00:26:37 -0500518 catch (const std::exception& ex) {
519 std::cerr << ex.what() << std::endl;
520 if (state == "on" || state == "dry-run") {
521 return false;
522 }
akmhoque53353462014-04-22 08:43:45 -0500523 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700524
akmhoque157b0a42014-05-13 00:26:37 -0500525 return true;
akmhoque53353462014-04-22 08:43:45 -0500526}
527
akmhoque157b0a42014-05-13 00:26:37 -0500528bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700529ConfFileProcessor::processConfSectionFib(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500530{
alvya2228c62014-12-09 10:25:11 -0600531 // max-faces-per-prefix
532 int maxFacesPerPrefix = section.get<int>("max-faces-per-prefix", MAX_FACES_PER_PREFIX_DEFAULT);
533
534 if (maxFacesPerPrefix >= MAX_FACES_PER_PREFIX_MIN &&
535 maxFacesPerPrefix <= MAX_FACES_PER_PREFIX_MAX)
536 {
537 m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -0500538 }
alvya2228c62014-12-09 10:25:11 -0600539 else {
540 std::cerr << "Wrong value for max-faces-per-prefix. ";
541 std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
542
akmhoque157b0a42014-05-13 00:26:37 -0500543 return false;
544 }
Vince Lehman7b616582014-10-17 16:25:39 -0500545
546 // routing-calc-interval
547 ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600548 std::bind(&ConfParameter::setRoutingCalcInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500549 &m_nlsr.getConfParameter(), _1));
550 routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX);
551 routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT);
552
553 if (!routingCalcInterval.parseFromConfigSection(section)) {
554 return false;
555 }
556
akmhoque157b0a42014-05-13 00:26:37 -0500557 return true;
akmhoque53353462014-04-22 08:43:45 -0500558}
559
akmhoque157b0a42014-05-13 00:26:37 -0500560bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700561ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500562{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700563 for (ConfigSection::const_iterator tn =
564 section.begin(); tn != section.end(); ++tn) {
akmhoque157b0a42014-05-13 00:26:37 -0500565 if (tn->first == "prefix") {
566 try {
567 std::string prefix = tn->second.data();
568 ndn::Name namePrefix(prefix);
569 if (!namePrefix.empty()) {
570 m_nlsr.getNamePrefixList().insert(namePrefix);
571 }
572 else {
akmhoque674b0b12014-05-20 14:33:28 -0500573 std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500574 return false;
575 }
576 }
577 catch (const std::exception& ex) {
578 std::cerr << ex.what() << std::endl;
579 return false;
580 }
akmhoque53353462014-04-22 08:43:45 -0500581 }
akmhoque53353462014-04-22 08:43:45 -0500582 }
akmhoque157b0a42014-05-13 00:26:37 -0500583 return true;
akmhoque53353462014-04-22 08:43:45 -0500584}
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700585
586bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700587ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700588{
589 ConfigSection::const_iterator it = section.begin();
590
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500591 if (it == section.end() || it->first != "validator") {
592 std::cerr << "Error: Expect validator section!" << std::endl;
593 return false;
594 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700595
596 m_nlsr.loadValidator(it->second, m_confFileName);
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500597
akmhoqued57f3672014-06-10 10:41:32 -0500598 it++;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500599 if (it != section.end() && it->first == "prefix-update-validator") {
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500600 m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700601
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500602 it++;
603 for (; it != section.end(); it++) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700604 using namespace boost::filesystem;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500605
606 if (it->first != "cert-to-publish") {
607 std::cerr << "Error: Expect cert-to-publish!" << std::endl;
608 return false;
609 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700610
611 std::string file = it->second.data();
612 path certfilePath = absolute(file, path(m_confFileName).parent_path());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500613 std::shared_ptr<ndn::security::v2::Certificate> idCert =
614 ndn::io::load<ndn::security::v2::Certificate>(certfilePath.string());
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700615
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500616 if (idCert == nullptr) {
617 std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
618 return false;
619 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700620
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500621 m_nlsr.loadCertToPublish(*idCert);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700622 }
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500623 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700624
625 return true;
626}
627
alvy2fe12872014-11-25 10:32:23 -0600628} // namespace nlsr