blob: bf07beefd779a4cadd2ad9a66ed59363c852404a [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 * \author Minsheng Zhang <mzhang4@memphis.edu>
22 *
23 **/
akmhoque53353462014-04-22 08:43:45 -050024#include <iostream>
25#include <fstream>
akmhoque157b0a42014-05-13 00:26:37 -050026#include <boost/algorithm/string.hpp>
27#include <boost/property_tree/info_parser.hpp>
28#include <boost/property_tree/ptree.hpp>
akmhoque674b0b12014-05-20 14:33:28 -050029#include <boost/filesystem.hpp>
akmhoque53353462014-04-22 08:43:45 -050030
akmhoque157b0a42014-05-13 00:26:37 -050031#include <ndn-cxx/name.hpp>
32
akmhoque53353462014-04-22 08:43:45 -050033#include "conf-parameter.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050034#include "conf-file-processor.hpp"
akmhoque53353462014-04-22 08:43:45 -050035#include "adjacent.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050036#include "utility/name-helper.hpp"
akmhoque53353462014-04-22 08:43:45 -050037
akmhoque53353462014-04-22 08:43:45 -050038namespace nlsr {
39
40using namespace std;
41
Vince Lehman7b616582014-10-17 16:25:39 -050042template <class T>
43class ConfigurationVariable
44{
45public:
46 typedef ndn::function<void(T)> ConfParameterCallback;
47 typedef boost::property_tree::ptree ConfigSection;
48
49 ConfigurationVariable(const std::string& key, const ConfParameterCallback& setter)
50 : m_key(key)
51 , m_setterCallback(setter)
52 , m_minValue(0)
53 , m_maxValue(0)
54 , m_shouldCheckRange(false)
55 , m_isRequired(true)
56 {
57 }
58
59 bool
60 parseFromConfigSection(const ConfigSection& section)
61 {
62 try {
63 T value = section.get<T>(m_key);
64
65 if (!isValidValue(value)) {
66 return false;
67 }
68
69 m_setterCallback(value);
70 return true;
71 }
72 catch (const std::exception& ex) {
73
74 if (m_isRequired) {
75 std::cerr << ex.what() << std::endl;
76 std::cerr << "Missing required configuration variable" << std::endl;
77 return false;
78 }
79 else {
80 m_setterCallback(m_defaultValue);
81 return true;
82 }
83 }
84
85 return false;
86 }
87
88 void
89 setMinAndMaxValue(T min, T max)
90 {
91 m_minValue = min;
92 m_maxValue = max;
93 m_shouldCheckRange = true;
94 }
95
96 void
97 setOptional(T defaultValue)
98 {
99 m_isRequired = false;
100 m_defaultValue = defaultValue;
101 }
102
103private:
104 void
105 printOutOfRangeError(T value)
106 {
107 std::cerr << "Invalid value for " << m_key << ": "
108 << value << ". "
109 << "Valid values: "
110 << m_minValue << " - "
111 << m_maxValue << std::endl;
112 }
113
114 bool
115 isValidValue(T value)
116 {
117 if (!m_shouldCheckRange) {
118 return true;
119 }
120 else if (value < m_minValue || value > m_maxValue)
121 {
122 printOutOfRangeError(value);
123 return false;
124 }
125
126 return true;
127 }
128
129private:
130 const std::string m_key;
131 const ConfParameterCallback m_setterCallback;
132 T m_defaultValue;
133
134 T m_minValue;
135 T m_maxValue;
136
137 bool m_shouldCheckRange;
138 bool m_isRequired;
139};
140
akmhoque157b0a42014-05-13 00:26:37 -0500141bool
akmhoqueb6450b12014-04-24 00:01:03 -0500142ConfFileProcessor::processConfFile()
akmhoque53353462014-04-22 08:43:45 -0500143{
akmhoque157b0a42014-05-13 00:26:37 -0500144 bool ret = true;
145 ifstream inputFile;
146 inputFile.open(m_confFileName.c_str());
147 if (!inputFile.is_open()) {
148 string msg = "Failed to read configuration file: ";
149 msg += m_confFileName;
150 cerr << msg << endl;
akmhoquead5fe952014-06-26 13:34:12 -0500151 return false;
akmhoque157b0a42014-05-13 00:26:37 -0500152 }
153 ret = load(inputFile);
154 inputFile.close();
155 return ret;
156}
157
158bool
159ConfFileProcessor::load(istream& input)
160{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700161 ConfigSection pt;
akmhoque157b0a42014-05-13 00:26:37 -0500162 bool ret = true;
163 try {
164 boost::property_tree::read_info(input, pt);
165 }
166 catch (const boost::property_tree::info_parser_error& error) {
167 stringstream msg;
168 std::cerr << "Failed to parse configuration file " << std::endl;
169 std::cerr << m_confFileName << std::endl;
170 return false;
171 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700172
173 for (ConfigSection::const_iterator tn = pt.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500174 tn != pt.end(); ++tn) {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700175 ret = processSection(tn->first, tn->second);
akmhoque157b0a42014-05-13 00:26:37 -0500176 if (ret == false) {
177 break;
178 }
179 }
180 return ret;
181}
182
183bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700184ConfFileProcessor::processSection(const std::string& sectionName, const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500185{
186 bool ret = true;
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700187 if (sectionName == "general")
akmhoque53353462014-04-22 08:43:45 -0500188 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700189 ret = processConfSectionGeneral(section);
akmhoque157b0a42014-05-13 00:26:37 -0500190 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700191 else if (sectionName == "neighbors")
akmhoque157b0a42014-05-13 00:26:37 -0500192 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700193 ret = processConfSectionNeighbors(section);
akmhoque157b0a42014-05-13 00:26:37 -0500194 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700195 else if (sectionName == "hyperbolic")
akmhoque157b0a42014-05-13 00:26:37 -0500196 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700197 ret = processConfSectionHyperbolic(section);
akmhoque157b0a42014-05-13 00:26:37 -0500198 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700199 else if (sectionName == "fib")
akmhoque157b0a42014-05-13 00:26:37 -0500200 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700201 ret = processConfSectionFib(section);
akmhoque157b0a42014-05-13 00:26:37 -0500202 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700203 else if (sectionName == "advertising")
akmhoque157b0a42014-05-13 00:26:37 -0500204 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700205 ret = processConfSectionAdvertising(section);
akmhoque157b0a42014-05-13 00:26:37 -0500206 }
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700207 else if (sectionName == "security")
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700208 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700209 ret = processConfSectionSecurity(section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700210 }
akmhoque157b0a42014-05-13 00:26:37 -0500211 else
212 {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700213 std::cerr << "Wrong configuration section: " << sectionName << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500214 }
215 return ret;
216}
217
218bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700219ConfFileProcessor::processConfSectionGeneral(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500220{
221 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700222 std::string network = section.get<string>("network");
223 std::string site = section.get<string>("site");
224 std::string router = section.get<string>("router");
akmhoque157b0a42014-05-13 00:26:37 -0500225 ndn::Name networkName(network);
226 if (!networkName.empty()) {
227 m_nlsr.getConfParameter().setNetwork(networkName);
228 }
229 else {
230 cerr << " Network can not be null or empty or in bad URI format :(!" << endl;
231 return false;
232 }
233 ndn::Name siteName(site);
234 if (!siteName.empty()) {
235 m_nlsr.getConfParameter().setSiteName(siteName);
236 }
237 else {
238 cerr << "Site can not be null or empty or in bad URI format:( !" << endl;
239 return false;
240 }
241 ndn::Name routerName(router);
242 if (!routerName.empty()) {
243 m_nlsr.getConfParameter().setRouterName(routerName);
244 }
245 else {
246 cerr << " Router name can not be null or empty or in bad URI format:( !" << endl;
247 return false;
248 }
249 }
250 catch (const std::exception& ex) {
251 cerr << ex.what() << endl;
252 return false;
253 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700254
akmhoque157b0a42014-05-13 00:26:37 -0500255 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700256 int32_t lsaRefreshTime = section.get<int32_t>("lsa-refresh-time");
akmhoque157b0a42014-05-13 00:26:37 -0500257 if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN &&
258 lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
259 m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
260 }
261 else {
262 std::cerr << "Wrong value for lsa-refresh-time ";
263 std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";;
264 std::cerr << LSA_REFRESH_TIME_MAX << std::endl;
265 return false;
266 }
267 }
268 catch (const std::exception& ex) {
269 std::cerr << ex.what() << std::endl;
270 return false;
271 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700272
akmhoque157b0a42014-05-13 00:26:37 -0500273 try {
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700274 int lifetime = section.get<int>("lsa-interest-lifetime");
275 if (lifetime >= LSA_INTEREST_LIFETIME_MIN && lifetime <= LSA_INTEREST_LIFETIME_MAX) {
276 m_nlsr.getConfParameter().setLsaInterestLifetime(ndn::time::seconds(lifetime));
277 }
278 else {
279 std::cerr << "Wrong value for lsa-interest-timeout. "
280 << "Allowed value:" << LSA_INTEREST_LIFETIME_MIN << "-"
281 << LSA_INTEREST_LIFETIME_MAX << std::endl;
282 return false;
283 }
284 }
285 catch (const std::exception& ex) {
286 std::cerr << ex.what() << std::endl;
287 // return false;
288 }
289
290 try {
Vince Lehmanf99b87f2014-08-26 15:54:27 -0500291
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700292 std::string logLevel = section.get<string>("log-level");
Vince Lehmanf99b87f2014-08-26 15:54:27 -0500293
294 if (isValidLogLevel(logLevel)) {
akmhoque157b0a42014-05-13 00:26:37 -0500295 m_nlsr.getConfParameter().setLogLevel(logLevel);
296 }
297 else {
Vince Lehmanf99b87f2014-08-26 15:54:27 -0500298 std::cerr << "Invalid value for log-level ";
299 std::cerr << "Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERROR, NONE" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500300 return false;
301 }
302 }
303 catch (const std::exception& ex) {
304 std::cerr << ex.what() << std::endl;
305 return false;
306 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700307
akmhoque674b0b12014-05-20 14:33:28 -0500308 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700309 std::string logDir = section.get<string>("log-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500310 if (boost::filesystem::exists(logDir)) {
311 if (boost::filesystem::is_directory(logDir)) {
312 std::string testFileName=logDir+"/test.log";
313 ofstream testOutFile;
314 testOutFile.open(testFileName.c_str());
315 if (testOutFile.is_open() && testOutFile.good()) {
316 m_nlsr.getConfParameter().setLogDir(logDir);
317 }
318 else {
319 std::cerr << "User does not have read and write permission on the directory";
320 std::cerr << std::endl;
321 return false;
322 }
323 testOutFile.close();
324 remove(testFileName.c_str());
325 }
326 else {
327 std::cerr << "Provided path is not a directory" << std::endl;
328 return false;
329 }
330 }
331 else {
332 std::cerr << "Log directory provided does not exists" << std::endl;
333 return false;
334 }
335 }
336 catch (const std::exception& ex) {
337 std::cerr << "You must configure log directory" << std::endl;
338 std::cerr << ex.what() << std::endl;
339 return false;
340 }
341 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700342 std::string seqDir = section.get<string>("seq-dir");
akmhoque674b0b12014-05-20 14:33:28 -0500343 if (boost::filesystem::exists(seqDir)) {
344 if (boost::filesystem::is_directory(seqDir)) {
345 std::string testFileName=seqDir+"/test.seq";
346 ofstream testOutFile;
347 testOutFile.open(testFileName.c_str());
348 if (testOutFile.is_open() && testOutFile.good()) {
349 m_nlsr.getConfParameter().setSeqFileDir(seqDir);
350 }
351 else {
352 std::cerr << "User does not have read and write permission on the directory";
353 std::cerr << std::endl;
354 return false;
355 }
356 testOutFile.close();
357 remove(testFileName.c_str());
358 }
359 else {
360 std::cerr << "Provided path is not a directory" << std::endl;
361 return false;
362 }
363 }
364 else {
365 std::cerr << "Seq directory provided does not exists" << std::endl;
366 return false;
367 }
368 }
369 catch (const std::exception& ex) {
370 std::cerr << "You must configure sequence directory" << std::endl;
371 std::cerr << ex.what() << std::endl;
372 return false;
373 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700374
akmhoque157b0a42014-05-13 00:26:37 -0500375 return true;
376}
377
378bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700379ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section)
akmhoque157b0a42014-05-13 00:26:37 -0500380{
381 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700382 int retrials = section.get<int>("hello-retries");
akmhoque157b0a42014-05-13 00:26:37 -0500383 if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) {
384 m_nlsr.getConfParameter().setInterestRetryNumber(retrials);
385 }
386 else {
387 std::cerr << "Wrong value for hello-retries. ";
388 std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-";
389 std::cerr << HELLO_RETRIES_MAX << std::endl;
390 return false;
391 }
392 }
393 catch (const std::exception& ex) {
394 std::cerr << ex.what() << std::endl;
395 return false;
396 }
397 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700398 int timeOut = section.get<int>("hello-timeout");
akmhoque157b0a42014-05-13 00:26:37 -0500399 if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
400 m_nlsr.getConfParameter().setInterestResendTime(timeOut);
401 }
402 else {
403 std::cerr << "Wrong value for hello-timeout. ";
404 std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-";
405 std::cerr << HELLO_TIMEOUT_MAX << std::endl;
406 return false;
407 }
408 }
409 catch (const std::exception& ex) {
410 std::cerr << ex.what() << std::endl;
411 }
412 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700413 int interval = section.get<int>("hello-interval");
akmhoque157b0a42014-05-13 00:26:37 -0500414 if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
415 m_nlsr.getConfParameter().setInfoInterestInterval(interval);
416 }
417 else {
418 std::cerr << "Wrong value for hello-interval. ";
419 std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-";
420 std::cerr << HELLO_INTERVAL_MAX << std::endl;
421 return false;
422 }
423 }
424 catch (const std::exception& ex) {
425 std::cerr << ex.what() << std::endl;
426 }
Vince Lehman7b616582014-10-17 16:25:39 -0500427
428 // Event intervals
429 // adj-lsa-build-interval
430 ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval",
431 bind(&ConfParameter::setAdjLsaBuildInterval,
432 &m_nlsr.getConfParameter(), _1));
433 adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX);
434 adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT);
435
436 if (!adjLsaBuildInterval.parseFromConfigSection(section)) {
437 return false;
438 }
439
440 // first-hello-interval
441 ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval",
442 bind(&ConfParameter::setFirstHelloInterval,
443 &m_nlsr.getConfParameter(), _1));
444 firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX);
445 firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT);
446
447 if (!firstHelloInterval.parseFromConfigSection(section)) {
448 return false;
449 }
450
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700451 for (ConfigSection::const_iterator tn =
452 section.begin(); tn != section.end(); ++tn) {
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700453
akmhoque157b0a42014-05-13 00:26:37 -0500454 if (tn->first == "neighbor")
akmhoque53353462014-04-22 08:43:45 -0500455 {
akmhoque157b0a42014-05-13 00:26:37 -0500456 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700457 ConfigSection CommandAttriTree = tn->second;
akmhoque157b0a42014-05-13 00:26:37 -0500458 std::string name = CommandAttriTree.get<std::string>("name");
459 std::string faceUri = CommandAttriTree.get<std::string>("face-uri");
460 double linkCost = CommandAttriTree.get<double>("link-cost",
461 Adjacent::DEFAULT_LINK_COST);
462 ndn::Name neighborName(name);
463 if (!neighborName.empty()) {
Vince Lehmancb76ade2014-08-28 21:24:41 -0500464 Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
akmhoque157b0a42014-05-13 00:26:37 -0500465 m_nlsr.getAdjacencyList().insert(adj);
466 }
467 else {
akmhoque674b0b12014-05-20 14:33:28 -0500468 std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
akmhoque157b0a42014-05-13 00:26:37 -0500469 std::cerr << " or bad URI format" << std::endl;
akmhoque53353462014-04-22 08:43:45 -0500470 }
471 }
akmhoque157b0a42014-05-13 00:26:37 -0500472 catch (const std::exception& ex) {
473 std::cerr << ex.what() << std::endl;
474 return false;
475 }
akmhoque53353462014-04-22 08:43:45 -0500476 }
477 }
akmhoque157b0a42014-05-13 00:26:37 -0500478 return true;
akmhoque53353462014-04-22 08:43:45 -0500479}
480
akmhoque157b0a42014-05-13 00:26:37 -0500481bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700482ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500483{
akmhoque157b0a42014-05-13 00:26:37 -0500484 std::string state;
485 try {
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700486 state= section.get<string>("state","off");
akmhoque157b0a42014-05-13 00:26:37 -0500487 if (boost::iequals(state, "off")) {
488 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF);
489 }
490 else if (boost::iequals(state, "on")) {
491 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON);
492 }
493 else if (state == "dry-run") {
494 m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
495 }
496 else {
497 std::cerr << "Wrong format for hyperbolic state." << std::endl;
498 std::cerr << "Allowed value: off, on, dry-run" << std::endl;
499 return false;
500 }
akmhoque53353462014-04-22 08:43:45 -0500501 }
akmhoque157b0a42014-05-13 00:26:37 -0500502 catch (const std::exception& ex) {
503 std::cerr << ex.what() << std::endl;
504 return false;
akmhoque53353462014-04-22 08:43:45 -0500505 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700506
akmhoque157b0a42014-05-13 00:26:37 -0500507 try {
508 /* Radius and angle is mandatory configuration parameter in hyperbolic section.
509 * Even if router can have hyperbolic routing calculation off but other router
510 * in the network may use hyperbolic routing calculation for FIB generation.
511 * So each router need to advertise its hyperbolic coordinates in the network
512 */
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700513 double radius = section.get<double>("radius");
514 double angle = section.get<double>("angle");
akmhoque157b0a42014-05-13 00:26:37 -0500515 if (!m_nlsr.getConfParameter().setCorR(radius)) {
516 return false;
517 }
518 m_nlsr.getConfParameter().setCorTheta(angle);
akmhoque53353462014-04-22 08:43:45 -0500519 }
akmhoque157b0a42014-05-13 00:26:37 -0500520 catch (const std::exception& ex) {
521 std::cerr << ex.what() << std::endl;
522 if (state == "on" || state == "dry-run") {
523 return false;
524 }
akmhoque53353462014-04-22 08:43:45 -0500525 }
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700526
akmhoque157b0a42014-05-13 00:26:37 -0500527 return true;
akmhoque53353462014-04-22 08:43:45 -0500528}
529
akmhoque157b0a42014-05-13 00:26:37 -0500530bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700531ConfFileProcessor::processConfSectionFib(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500532{
akmhoque157b0a42014-05-13 00:26:37 -0500533 try {
534 int maxFacesPerPrefixNumber =
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700535 section.get<int>("max-faces-per-prefix");
akmhoque157b0a42014-05-13 00:26:37 -0500536 if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN &&
537 maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX)
akmhoque53353462014-04-22 08:43:45 -0500538 {
akmhoque157b0a42014-05-13 00:26:37 -0500539 m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber);
akmhoque53353462014-04-22 08:43:45 -0500540 }
akmhoque157b0a42014-05-13 00:26:37 -0500541 else {
542 std::cerr << "Wrong value for max-faces-per-prefix. ";
akmhoque157b0a42014-05-13 00:26:37 -0500543 std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl;
544 return false;
akmhoque53353462014-04-22 08:43:45 -0500545 }
akmhoque53353462014-04-22 08:43:45 -0500546 }
akmhoque157b0a42014-05-13 00:26:37 -0500547 catch (const std::exception& ex) {
548 cerr << ex.what() << endl;
549 return false;
550 }
Vince Lehman7b616582014-10-17 16:25:39 -0500551
552 // routing-calc-interval
553 ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval",
554 bind(&ConfParameter::setRoutingCalcInterval,
555 &m_nlsr.getConfParameter(), _1));
556 routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX);
557 routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT);
558
559 if (!routingCalcInterval.parseFromConfigSection(section)) {
560 return false;
561 }
562
akmhoque157b0a42014-05-13 00:26:37 -0500563 return true;
akmhoque53353462014-04-22 08:43:45 -0500564}
565
akmhoque157b0a42014-05-13 00:26:37 -0500566bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700567ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section)
akmhoque53353462014-04-22 08:43:45 -0500568{
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700569 for (ConfigSection::const_iterator tn =
570 section.begin(); tn != section.end(); ++tn) {
akmhoque157b0a42014-05-13 00:26:37 -0500571 if (tn->first == "prefix") {
572 try {
573 std::string prefix = tn->second.data();
574 ndn::Name namePrefix(prefix);
575 if (!namePrefix.empty()) {
576 m_nlsr.getNamePrefixList().insert(namePrefix);
577 }
578 else {
akmhoque674b0b12014-05-20 14:33:28 -0500579 std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
akmhoque157b0a42014-05-13 00:26:37 -0500580 return false;
581 }
582 }
583 catch (const std::exception& ex) {
584 std::cerr << ex.what() << std::endl;
585 return false;
586 }
akmhoque53353462014-04-22 08:43:45 -0500587 }
akmhoque53353462014-04-22 08:43:45 -0500588 }
akmhoque157b0a42014-05-13 00:26:37 -0500589 return true;
akmhoque53353462014-04-22 08:43:45 -0500590}
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700591
592bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700593ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700594{
595 ConfigSection::const_iterator it = section.begin();
596
597 if (it == section.end() || it->first != "validator")
598 {
599 std::cerr << "Error: Expect validator section!" << std::endl;
600 return false;
601 }
602
603 m_nlsr.loadValidator(it->second, m_confFileName);
akmhoqued57f3672014-06-10 10:41:32 -0500604 it++;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700605
606 for (; it != section.end(); it++)
607 {
608 using namespace boost::filesystem;
609 if (it->first != "cert-to-publish")
610 {
611 std::cerr << "Error: Expect cert-to-publish!" << std::endl;
612 return false;
613 }
614
615 std::string file = it->second.data();
616 path certfilePath = absolute(file, path(m_confFileName).parent_path());
617 ndn::shared_ptr<ndn::IdentityCertificate> idCert =
618 ndn::io::load<ndn::IdentityCertificate>(certfilePath.string());
619
620 if (!static_cast<bool>(idCert))
621 {
622 std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl;
623 return false;
624 }
625
626 m_nlsr.loadCertToPublish(idCert);
627 }
628
629 return true;
630}
631
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700632} // namespace nlsr