blob: e93ef351a6a4502b9f4c64937f839b895f2429a3 [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
akmhoque674b0b12014-05-20 14:33:28 -0500290 try {
Nick Gordone98480b2017-05-24 11:23:03 -0500291 std::string seqDir = section.get<std::string>("seq-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500292 if (boost::filesystem::exists(seqDir)) {
293 if (boost::filesystem::is_directory(seqDir)) {
294 std::string testFileName=seqDir+"/test.seq";
Nick Gordone98480b2017-05-24 11:23:03 -0500295 std::ofstream testOutFile;
akmhoque674b0b12014-05-20 14:33:28 -0500296 testOutFile.open(testFileName.c_str());
297 if (testOutFile.is_open() && testOutFile.good()) {
298 m_nlsr.getConfParameter().setSeqFileDir(seqDir);
299 }
300 else {
301 std::cerr << "User does not have read and write permission on the directory";
302 std::cerr << std::endl;
303 return false;
304 }
305 testOutFile.close();
306 remove(testFileName.c_str());
307 }
308 else {
309 std::cerr << "Provided path is not a directory" << std::endl;
310 return false;
311 }
312 }
313 else {
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500314 std::cerr << "Provided sequence directory <" << seqDir << "> does not exist" << std::endl;
akmhoque674b0b12014-05-20 14:33:28 -0500315 return false;
316 }
317 }
318 catch (const std::exception& ex) {
319 std::cerr << "You must configure sequence directory" << std::endl;
320 std::cerr << ex.what() << std::endl;
321 return false;
322 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700323
akmhoque157b0a42014-05-13 00:26:37 -0500324 return true;
325}
326
327bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700328ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500329{
alvya2228c62014-12-09 10:25:11 -0600330 // hello-retries
331 int retrials = section.get<int>("hello-retries", HELLO_RETRIES_DEFAULT);
332
333 if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
334 m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
akmhoque157b0a42014-05-13 00:26:37 -0500335 }
alvya2228c62014-12-09 10:25:11 -0600336 else {
337 std::cerr << "Wrong value for hello-retries." << std::endl;
338 std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
339 std::cerr << HELLO_RETRIES_MAX << std::endl;
340
akmhoque157b0a42014-05-13 00:26:37 -0500341 return false;
342 }
alvya2228c62014-12-09 10:25:11 -0600343
344 // hello-timeout
alvy5a454952014-12-15 12:49:54 -0600345 uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600346
347 if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
348 m_nlsr.getConfParameter().setInterestResendTime(timeOut);
akmhoque157b0a42014-05-13 00:26:37 -0500349 }
alvya2228c62014-12-09 10:25:11 -0600350 else {
351 std::cerr << "Wrong value for hello-timeout. ";
352 std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
353 std::cerr << HELLO_TIMEOUT_MAX << std::endl;
354
355 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500356 }
alvya2228c62014-12-09 10:25:11 -0600357
358 // hello-interval
alvy5a454952014-12-15 12:49:54 -0600359 uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT);
alvya2228c62014-12-09 10:25:11 -0600360
361 if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
362 m_nlsr.getConfParameter().setInfoInterestInterval(interval);
akmhoque157b0a42014-05-13 00:26:37 -0500363 }
alvya2228c62014-12-09 10:25:11 -0600364 else {
365 std::cerr << "Wrong value for hello-interval. ";
366 std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
367 std::cerr << HELLO_INTERVAL_MAX << std::endl;
368
369 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500370 }
Vince Lehman7b616582014-10-17 16:25:39 -0500371
372 // Event intervals
373 // adj-lsa-build-interval
374 ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600375 std::bind(&ConfParameter::setAdjLsaBuildInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500376 &m_nlsr.getConfParameter(), _1));
377 adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX);
378 adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT);
379
380 if (!adjLsaBuildInterval.parseFromConfigSection(section)) {
381 return false;
382 }
Nick Gordond5c1a372016-10-31 13:56:23 -0500383 // Set the retry count for fetching the FaceStatus dataset
384 ConfigurationVariable<uint32_t> faceDatasetFetchTries("face-dataset-fetch-tries",
385 std::bind(&ConfParameter::setFaceDatasetFetchTries,
386 &m_nlsr.getConfParameter(),
387 _1));
388
389 faceDatasetFetchTries.setMinAndMaxValue(FACE_DATASET_FETCH_TRIES_MIN,
390 FACE_DATASET_FETCH_TRIES_MAX);
391 faceDatasetFetchTries.setOptional(FACE_DATASET_FETCH_TRIES_DEFAULT);
392
393 if (!faceDatasetFetchTries.parseFromConfigSection(section)) {
394 return false;
395 }
396
397 // Set the interval between FaceStatus dataset fetch attempts.
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500398 ConfigurationVariable<uint32_t> faceDatasetFetchInterval("face-dataset-fetch-interval",
Nick Gordond5c1a372016-10-31 13:56:23 -0500399 bind(&ConfParameter::setFaceDatasetFetchInterval,
400 &m_nlsr.getConfParameter(),
401 _1));
402
Ashlesh Gawande3909aa12017-07-28 16:01:35 -0500403 faceDatasetFetchInterval.setMinAndMaxValue(FACE_DATASET_FETCH_INTERVAL_MIN,
404 FACE_DATASET_FETCH_INTERVAL_MAX);
405 faceDatasetFetchInterval.setOptional(FACE_DATASET_FETCH_INTERVAL_DEFAULT);
Nick Gordond5c1a372016-10-31 13:56:23 -0500406
407 if (!faceDatasetFetchInterval.parseFromConfigSection(section)) {
408 return false;
409 }
Vince Lehman7b616582014-10-17 16:25:39 -0500410
411 // first-hello-interval
412 ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600413 std::bind(&ConfParameter::setFirstHelloInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500414 &m_nlsr.getConfParameter(), _1));
415 firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
416 firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
417
418 if (!firstHelloInterval.parseFromConfigSection(section)) {
419 return false;
420 }
421
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700422 for (ConfigSection::const_iterator tn =
423 section.begin(); tn != section.end(); ++tn) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700424
Nick Gordond5c1a372016-10-31 13:56:23 -0500425 if (tn->first == "neighbor") {
akmhoque157b0a42014-05-13 00:26:37 -0500426 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700427 ConfigSection CommandAttriTree = tn->second;
akmhoque157b0a42014-05-13 00:26:37 -0500428 std::string name = CommandAttriTree.get<std::string>("name");
Nick Gordone9733ed2017-04-26 10:48:39 -0500429 std::string uriString = CommandAttriTree.get<std::string>("face-uri");
alvy2fe12872014-11-25 10:32:23 -0600430
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500431 ndn::FaceUri faceUri;
Laqin Fan54a43f02017-03-08 12:31:30 -0600432 if (! faceUri.parse(uriString)) {
433 std::cerr << "parsing failed!" << std::endl;
alvy2fe12872014-11-25 10:32:23 -0600434 return false;
435 }
436
akmhoque157b0a42014-05-13 00:26:37 -0500437 double linkCost = CommandAttriTree.get<double>("link-cost",
438 Adjacent::DEFAULT_LINK_COST);
439 ndn::Name neighborName(name);
440 if (!neighborName.empty()) {
Vince Lehmancb76ade2014-08-28 21:24:41 -0500441 Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
akmhoque157b0a42014-05-13 00:26:37 -0500442 m_nlsr.getAdjacencyList().insert(adj);
443 }
444 else {
akmhoque674b0b12014-05-20 14:33:28 -0500445 std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
akmhoque157b0a42014-05-13 00:26:37 -0500446 std::cerr << " or bad URI format" << std::endl;
akmhoque53353462014-04-22 08:43:45 -0500447 }
448 }
akmhoque157b0a42014-05-13 00:26:37 -0500449 catch (const std::exception& ex) {
450 std::cerr << ex.what() << std::endl;
451 return false;
452 }
akmhoque53353462014-04-22 08:43:45 -0500453 }
454 }
akmhoque157b0a42014-05-13 00:26:37 -0500455 return true;
akmhoque53353462014-04-22 08:43:45 -0500456}
457
akmhoque157b0a42014-05-13 00:26:37 -0500458bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700459ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500460{
alvya2228c62014-12-09 10:25:11 -0600461 // state
Nick Gordone98480b2017-05-24 11:23:03 -0500462 std::string state = section.get<std::string>("state", "off");
alvya2228c62014-12-09 10:25:11 -0600463
464 if (boost::iequals(state, "off")) {
465 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
akmhoque53353462014-04-22 08:43:45 -0500466 }
alvya2228c62014-12-09 10:25:11 -0600467 else if (boost::iequals(state, "on")) {
468 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
469 }
470 else if (state == "dry-run") {
471 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
472 }
473 else {
474 std::cerr << "Wrong format for hyperbolic state." << std::endl;
475 std::cerr << "Allowed value: off, on, dry-run" << std::endl;
476
akmhoque157b0a42014-05-13 00:26:37 -0500477 return false;
akmhoque53353462014-04-22 08:43:45 -0500478 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700479
akmhoque157b0a42014-05-13 00:26:37 -0500480 try {
Laqin Fan54a43f02017-03-08 12:31:30 -0600481 // Radius and angle(s) are mandatory configuration parameters in hyperbolic section.
482 // Even if router can have hyperbolic routing calculation off but other router
483 // in the network may use hyperbolic routing calculation for FIB generation.
484 // So each router need to advertise its hyperbolic coordinates in the network
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700485 double radius = section.get<double>("radius");
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600486 std::string angleString = section.get<std::string>("angle");
487
488 std::stringstream ss(angleString);
489 std::vector<double> angles;
490
491 double angle;
492
Laqin Fan54a43f02017-03-08 12:31:30 -0600493 while (ss >> angle) {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600494 angles.push_back(angle);
Laqin Fan54a43f02017-03-08 12:31:30 -0600495 if (ss.peek() == ',' || ss.peek() == ' ') {
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600496 ss.ignore();
497 }
498 }
499
akmhoque157b0a42014-05-13 00:26:37 -0500500 if (!m_nlsr.getConfParameter().setCorR(radius)) {
501 return false;
502 }
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600503 m_nlsr.getConfParameter().setCorTheta(angles);
akmhoque53353462014-04-22 08:43:45 -0500504 }
akmhoque157b0a42014-05-13 00:26:37 -0500505 catch (const std::exception& ex) {
506 std::cerr << ex.what() << std::endl;
507 if (state == "on" || state == "dry-run") {
508 return false;
509 }
akmhoque53353462014-04-22 08:43:45 -0500510 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700511
akmhoque157b0a42014-05-13 00:26:37 -0500512 return true;
akmhoque53353462014-04-22 08:43:45 -0500513}
514
akmhoque157b0a42014-05-13 00:26:37 -0500515bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700516ConfFileProcessor::processConfSectionFib(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500517{
alvya2228c62014-12-09 10:25:11 -0600518 // max-faces-per-prefix
519 int maxFacesPerPrefix = section.get<int>("max-faces-per-prefix", MAX_FACES_PER_PREFIX_DEFAULT);
520
521 if (maxFacesPerPrefix >= MAX_FACES_PER_PREFIX_MIN &&
522 maxFacesPerPrefix <= MAX_FACES_PER_PREFIX_MAX)
523 {
524 m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -0500525 }
alvya2228c62014-12-09 10:25:11 -0600526 else {
527 std::cerr << "Wrong value for max-faces-per-prefix. ";
528 std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
529
akmhoque157b0a42014-05-13 00:26:37 -0500530 return false;
531 }
Vince Lehman7b616582014-10-17 16:25:39 -0500532
533 // routing-calc-interval
534 ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval",
dmcoomes9f936662017-03-02 10:33:09 -0600535 std::bind(&ConfParameter::setRoutingCalcInterval,
Vince Lehman7b616582014-10-17 16:25:39 -0500536 &m_nlsr.getConfParameter(), _1));
537 routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX);
538 routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT);
539
540 if (!routingCalcInterval.parseFromConfigSection(section)) {
541 return false;
542 }
543
akmhoque157b0a42014-05-13 00:26:37 -0500544 return true;
akmhoque53353462014-04-22 08:43:45 -0500545}
546
akmhoque157b0a42014-05-13 00:26:37 -0500547bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700548ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500549{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700550 for (ConfigSection::const_iterator tn =
551 section.begin(); tn != section.end(); ++tn) {
akmhoque157b0a42014-05-13 00:26:37 -0500552 if (tn->first == "prefix") {
553 try {
554 std::string prefix = tn->second.data();
555 ndn::Name namePrefix(prefix);
556 if (!namePrefix.empty()) {
557 m_nlsr.getNamePrefixList().insert(namePrefix);
558 }
559 else {
akmhoque674b0b12014-05-20 14:33:28 -0500560 std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500561 return false;
562 }
563 }
564 catch (const std::exception& ex) {
565 std::cerr << ex.what() << std::endl;
566 return false;
567 }
akmhoque53353462014-04-22 08:43:45 -0500568 }
akmhoque53353462014-04-22 08:43:45 -0500569 }
akmhoque157b0a42014-05-13 00:26:37 -0500570 return true;
akmhoque53353462014-04-22 08:43:45 -0500571}
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700572
573bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700574ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700575{
576 ConfigSection::const_iterator it = section.begin();
577
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500578 if (it == section.end() || it->first != "validator") {
579 std::cerr << "Error: Expect validator section!" << std::endl;
580 return false;
581 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700582
583 m_nlsr.loadValidator(it->second, m_confFileName);
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500584
akmhoqued57f3672014-06-10 10:41:32 -0500585 it++;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500586 if (it != section.end() && it->first == "prefix-update-validator") {
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500587 m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700588
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500589 it++;
590 for (; it != section.end(); it++) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700591 using namespace boost::filesystem;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500592
593 if (it->first != "cert-to-publish") {
594 std::cerr << "Error: Expect cert-to-publish!" << std::endl;
595 return false;
596 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700597
598 std::string file = it->second.data();
599 path certfilePath = absolute(file, path(m_confFileName).parent_path());
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500600 std::shared_ptr<ndn::security::v2::Certificate> idCert =
601 ndn::io::load<ndn::security::v2::Certificate>(certfilePath.string());
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700602
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500603 if (idCert == nullptr) {
604 std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
605 return false;
606 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700607
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500608 m_nlsr.loadCertToPublish(*idCert);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700609 }
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500610 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700611
612 return true;
613}
614
alvy2fe12872014-11-25 10:32:23 -0600615} // namespace nlsr