akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 22 | #include "conf-parameter.hpp" |
| 23 | #include "conf-file-processor.hpp" |
| 24 | #include "adjacent.hpp" |
| 25 | #include "utility/name-helper.hpp" |
| 26 | #include "update/prefix-update-processor.hpp" |
| 27 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | #include <iostream> |
| 29 | #include <fstream> |
Alexander Afanasyev | b669f9c | 2014-11-14 12:41:54 -0800 | [diff] [blame] | 30 | |
| 31 | #include <ndn-cxx/name.hpp> |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 32 | #include <ndn-cxx/util/face-uri.hpp> |
Alexander Afanasyev | b669f9c | 2014-11-14 12:41:54 -0800 | [diff] [blame] | 33 | |
| 34 | // boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ... |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 35 | #include <boost/algorithm/string.hpp> |
| 36 | #include <boost/property_tree/info_parser.hpp> |
| 37 | #include <boost/property_tree/ptree.hpp> |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 38 | #include <boost/filesystem.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 40 | namespace nlsr { |
| 41 | |
| 42 | using namespace std; |
| 43 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 44 | template <class T> |
| 45 | class ConfigurationVariable |
| 46 | { |
| 47 | public: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 48 | typedef std::function<void(T)> ConfParameterCallback; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 49 | typedef boost::property_tree::ptree ConfigSection; |
| 50 | |
| 51 | ConfigurationVariable(const std::string& key, const ConfParameterCallback& setter) |
| 52 | : m_key(key) |
| 53 | , m_setterCallback(setter) |
| 54 | , m_minValue(0) |
| 55 | , m_maxValue(0) |
| 56 | , m_shouldCheckRange(false) |
| 57 | , m_isRequired(true) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | parseFromConfigSection(const ConfigSection& section) |
| 63 | { |
| 64 | try { |
| 65 | T value = section.get<T>(m_key); |
| 66 | |
| 67 | if (!isValidValue(value)) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | m_setterCallback(value); |
| 72 | return true; |
| 73 | } |
| 74 | catch (const std::exception& ex) { |
| 75 | |
| 76 | if (m_isRequired) { |
| 77 | std::cerr << ex.what() << std::endl; |
| 78 | std::cerr << "Missing required configuration variable" << std::endl; |
| 79 | return false; |
| 80 | } |
| 81 | else { |
| 82 | m_setterCallback(m_defaultValue); |
| 83 | return true; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | setMinAndMaxValue(T min, T max) |
| 92 | { |
| 93 | m_minValue = min; |
| 94 | m_maxValue = max; |
| 95 | m_shouldCheckRange = true; |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | setOptional(T defaultValue) |
| 100 | { |
| 101 | m_isRequired = false; |
| 102 | m_defaultValue = defaultValue; |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | void |
| 107 | printOutOfRangeError(T value) |
| 108 | { |
| 109 | std::cerr << "Invalid value for " << m_key << ": " |
| 110 | << value << ". " |
| 111 | << "Valid values: " |
| 112 | << m_minValue << " - " |
| 113 | << m_maxValue << std::endl; |
| 114 | } |
| 115 | |
| 116 | bool |
| 117 | isValidValue(T value) |
| 118 | { |
| 119 | if (!m_shouldCheckRange) { |
| 120 | return true; |
| 121 | } |
| 122 | else if (value < m_minValue || value > m_maxValue) |
| 123 | { |
| 124 | printOutOfRangeError(value); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | private: |
| 132 | const std::string m_key; |
| 133 | const ConfParameterCallback m_setterCallback; |
| 134 | T m_defaultValue; |
| 135 | |
| 136 | T m_minValue; |
| 137 | T m_maxValue; |
| 138 | |
| 139 | bool m_shouldCheckRange; |
| 140 | bool m_isRequired; |
| 141 | }; |
| 142 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 143 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 144 | ConfFileProcessor::processConfFile() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 146 | bool ret = true; |
| 147 | ifstream inputFile; |
| 148 | inputFile.open(m_confFileName.c_str()); |
| 149 | if (!inputFile.is_open()) { |
| 150 | string msg = "Failed to read configuration file: "; |
| 151 | msg += m_confFileName; |
| 152 | cerr << msg << endl; |
akmhoque | ad5fe95 | 2014-06-26 13:34:12 -0500 | [diff] [blame] | 153 | return false; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 154 | } |
| 155 | ret = load(inputFile); |
| 156 | inputFile.close(); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | bool |
| 161 | ConfFileProcessor::load(istream& input) |
| 162 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 163 | ConfigSection pt; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 164 | bool ret = true; |
| 165 | try { |
| 166 | boost::property_tree::read_info(input, pt); |
| 167 | } |
| 168 | catch (const boost::property_tree::info_parser_error& error) { |
| 169 | stringstream msg; |
| 170 | std::cerr << "Failed to parse configuration file " << std::endl; |
| 171 | std::cerr << m_confFileName << std::endl; |
| 172 | return false; |
| 173 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 174 | |
| 175 | for (ConfigSection::const_iterator tn = pt.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 176 | tn != pt.end(); ++tn) { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 177 | ret = processSection(tn->first, tn->second); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 178 | if (ret == false) { |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 186 | ConfFileProcessor::processSection(const std::string& sectionName, const ConfigSection& section) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 187 | { |
| 188 | bool ret = true; |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 189 | if (sectionName == "general") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 190 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 191 | ret = processConfSectionGeneral(section); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 192 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 193 | else if (sectionName == "neighbors") |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 194 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 195 | ret = processConfSectionNeighbors(section); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 196 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 197 | else if (sectionName == "hyperbolic") |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 198 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 199 | ret = processConfSectionHyperbolic(section); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 200 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 201 | else if (sectionName == "fib") |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 202 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 203 | ret = processConfSectionFib(section); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 204 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 205 | else if (sectionName == "advertising") |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 206 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 207 | ret = processConfSectionAdvertising(section); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 208 | } |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 209 | else if (sectionName == "security") |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 210 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 211 | ret = processConfSectionSecurity(section); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 212 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 213 | else |
| 214 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 215 | std::cerr << "Wrong configuration section: " << sectionName << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 216 | } |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 221 | ConfFileProcessor::processConfSectionGeneral(const ConfigSection& section) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 222 | { |
| 223 | try { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 224 | std::string network = section.get<string>("network"); |
| 225 | std::string site = section.get<string>("site"); |
| 226 | std::string router = section.get<string>("router"); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 227 | ndn::Name networkName(network); |
| 228 | if (!networkName.empty()) { |
| 229 | m_nlsr.getConfParameter().setNetwork(networkName); |
| 230 | } |
| 231 | else { |
| 232 | cerr << " Network can not be null or empty or in bad URI format :(!" << endl; |
| 233 | return false; |
| 234 | } |
| 235 | ndn::Name siteName(site); |
| 236 | if (!siteName.empty()) { |
| 237 | m_nlsr.getConfParameter().setSiteName(siteName); |
| 238 | } |
| 239 | else { |
| 240 | cerr << "Site can not be null or empty or in bad URI format:( !" << endl; |
| 241 | return false; |
| 242 | } |
| 243 | ndn::Name routerName(router); |
| 244 | if (!routerName.empty()) { |
| 245 | m_nlsr.getConfParameter().setRouterName(routerName); |
| 246 | } |
| 247 | else { |
| 248 | cerr << " Router name can not be null or empty or in bad URI format:( !" << endl; |
| 249 | return false; |
| 250 | } |
| 251 | } |
| 252 | catch (const std::exception& ex) { |
| 253 | cerr << ex.what() << endl; |
| 254 | return false; |
| 255 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 256 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 257 | // lsa-refresh-time |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 258 | uint32_t lsaRefreshTime = section.get<uint32_t>("lsa-refresh-time", LSA_REFRESH_TIME_DEFAULT); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 259 | |
| 260 | if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && lsaRefreshTime <= LSA_REFRESH_TIME_MAX) { |
| 261 | m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 262 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 263 | else { |
| 264 | std::cerr << "Wrong value for lsa-refresh-time "; |
| 265 | std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";; |
| 266 | std::cerr << LSA_REFRESH_TIME_MAX << std::endl; |
| 267 | |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | // router-dead-interval |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 272 | uint32_t routerDeadInterval = section.get<uint32_t>("router-dead-interval", (2*lsaRefreshTime)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 273 | |
| 274 | if (routerDeadInterval > m_nlsr.getConfParameter().getLsaRefreshTime()) { |
| 275 | m_nlsr.getConfParameter().setRouterDeadInterval(routerDeadInterval); |
| 276 | } |
| 277 | else { |
| 278 | std::cerr << "Value of router-dead-interval must be larger than lsa-refresh-time" << std::endl; |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | // lsa-interest-lifetime |
| 283 | int lifetime = section.get<int>("lsa-interest-lifetime", LSA_INTEREST_LIFETIME_DEFAULT); |
| 284 | |
| 285 | if (lifetime >= LSA_INTEREST_LIFETIME_MIN && lifetime <= LSA_INTEREST_LIFETIME_MAX) { |
| 286 | m_nlsr.getConfParameter().setLsaInterestLifetime(ndn::time::seconds(lifetime)); |
| 287 | } |
| 288 | else { |
| 289 | std::cerr << "Wrong value for lsa-interest-timeout. " |
| 290 | << "Allowed value:" << LSA_INTEREST_LIFETIME_MIN << "-" |
| 291 | << LSA_INTEREST_LIFETIME_MAX << std::endl; |
| 292 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 293 | return false; |
| 294 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 295 | |
alvy | d5a13cd | 2015-01-06 16:34:38 -0600 | [diff] [blame] | 296 | // log-level |
| 297 | std::string logLevel = section.get<string>("log-level", "INFO"); |
Vince Lehman | f99b87f | 2014-08-26 15:54:27 -0500 | [diff] [blame] | 298 | |
alvy | d5a13cd | 2015-01-06 16:34:38 -0600 | [diff] [blame] | 299 | if (isValidLogLevel(logLevel)) { |
| 300 | m_nlsr.getConfParameter().setLogLevel(logLevel); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 301 | } |
alvy | d5a13cd | 2015-01-06 16:34:38 -0600 | [diff] [blame] | 302 | else { |
| 303 | std::cerr << "Invalid value for log-level "; |
| 304 | std::cerr << "Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERROR, NONE" << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 305 | return false; |
| 306 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 307 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 308 | try { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 309 | std::string logDir = section.get<string>("log-dir"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 310 | 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 { |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 332 | std::cerr << "Provided log directory <" << logDir << "> does not exist" << std::endl; |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 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 | } |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 341 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 342 | try { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 343 | std::string seqDir = section.get<string>("seq-dir"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 344 | if (boost::filesystem::exists(seqDir)) { |
| 345 | if (boost::filesystem::is_directory(seqDir)) { |
| 346 | std::string testFileName=seqDir+"/test.seq"; |
| 347 | ofstream testOutFile; |
| 348 | testOutFile.open(testFileName.c_str()); |
| 349 | if (testOutFile.is_open() && testOutFile.good()) { |
| 350 | m_nlsr.getConfParameter().setSeqFileDir(seqDir); |
| 351 | } |
| 352 | else { |
| 353 | std::cerr << "User does not have read and write permission on the directory"; |
| 354 | std::cerr << std::endl; |
| 355 | return false; |
| 356 | } |
| 357 | testOutFile.close(); |
| 358 | remove(testFileName.c_str()); |
| 359 | } |
| 360 | else { |
| 361 | std::cerr << "Provided path is not a directory" << std::endl; |
| 362 | return false; |
| 363 | } |
| 364 | } |
| 365 | else { |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 366 | std::cerr << "Provided sequence directory <" << seqDir << "> does not exist" << std::endl; |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 367 | return false; |
| 368 | } |
| 369 | } |
| 370 | catch (const std::exception& ex) { |
| 371 | std::cerr << "You must configure sequence directory" << std::endl; |
| 372 | std::cerr << ex.what() << std::endl; |
| 373 | return false; |
| 374 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 375 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 376 | try { |
| 377 | std::string log4cxxPath = section.get<string>("log4cxx-conf"); |
| 378 | |
| 379 | if (log4cxxPath == "") { |
| 380 | std::cerr << "No value provided for log4cxx-conf" << std::endl; |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | if (boost::filesystem::exists(log4cxxPath)) { |
| 385 | m_nlsr.getConfParameter().setLog4CxxConfPath(log4cxxPath); |
| 386 | } |
| 387 | else { |
| 388 | std::cerr << "Provided path for log4cxx-conf <" << log4cxxPath |
| 389 | << "> does not exist" << std::endl; |
| 390 | |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | catch (const std::exception& ex) { |
| 395 | // Variable is optional so default configuration will be used; continue processing file |
| 396 | } |
| 397 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 398 | return true; |
| 399 | } |
| 400 | |
| 401 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 402 | ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 403 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 404 | // hello-retries |
| 405 | int retrials = section.get<int>("hello-retries", HELLO_RETRIES_DEFAULT); |
| 406 | |
| 407 | if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) { |
| 408 | m_nlsr.getConfParameter().setInterestRetryNumber(retrials); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 409 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 410 | else { |
| 411 | std::cerr << "Wrong value for hello-retries." << std::endl; |
| 412 | std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-"; |
| 413 | std::cerr << HELLO_RETRIES_MAX << std::endl; |
| 414 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 415 | return false; |
| 416 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 417 | |
| 418 | // hello-timeout |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 419 | uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 420 | |
| 421 | if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) { |
| 422 | m_nlsr.getConfParameter().setInterestResendTime(timeOut); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 423 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 424 | else { |
| 425 | std::cerr << "Wrong value for hello-timeout. "; |
| 426 | std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-"; |
| 427 | std::cerr << HELLO_TIMEOUT_MAX << std::endl; |
| 428 | |
| 429 | return false; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 430 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 431 | |
| 432 | // hello-interval |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 433 | uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 434 | |
| 435 | if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) { |
| 436 | m_nlsr.getConfParameter().setInfoInterestInterval(interval); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 437 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 438 | else { |
| 439 | std::cerr << "Wrong value for hello-interval. "; |
| 440 | std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-"; |
| 441 | std::cerr << HELLO_INTERVAL_MAX << std::endl; |
| 442 | |
| 443 | return false; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 444 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 445 | |
| 446 | // Event intervals |
| 447 | // adj-lsa-build-interval |
| 448 | ConfigurationVariable<uint32_t> adjLsaBuildInterval("adj-lsa-build-interval", |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 449 | std::bind(&ConfParameter::setAdjLsaBuildInterval, |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 450 | &m_nlsr.getConfParameter(), _1)); |
| 451 | adjLsaBuildInterval.setMinAndMaxValue(ADJ_LSA_BUILD_INTERVAL_MIN, ADJ_LSA_BUILD_INTERVAL_MAX); |
| 452 | adjLsaBuildInterval.setOptional(ADJ_LSA_BUILD_INTERVAL_DEFAULT); |
| 453 | |
| 454 | if (!adjLsaBuildInterval.parseFromConfigSection(section)) { |
| 455 | return false; |
| 456 | } |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 457 | // Set the retry count for fetching the FaceStatus dataset |
| 458 | ConfigurationVariable<uint32_t> faceDatasetFetchTries("face-dataset-fetch-tries", |
| 459 | std::bind(&ConfParameter::setFaceDatasetFetchTries, |
| 460 | &m_nlsr.getConfParameter(), |
| 461 | _1)); |
| 462 | |
| 463 | faceDatasetFetchTries.setMinAndMaxValue(FACE_DATASET_FETCH_TRIES_MIN, |
| 464 | FACE_DATASET_FETCH_TRIES_MAX); |
| 465 | faceDatasetFetchTries.setOptional(FACE_DATASET_FETCH_TRIES_DEFAULT); |
| 466 | |
| 467 | if (!faceDatasetFetchTries.parseFromConfigSection(section)) { |
| 468 | return false; |
| 469 | } |
| 470 | |
| 471 | // Set the interval between FaceStatus dataset fetch attempts. |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 472 | ConfigurationVariable<uint32_t> faceDatasetFetchInterval("face-dataset-fetch-interval", |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 473 | bind(&ConfParameter::setFaceDatasetFetchInterval, |
| 474 | &m_nlsr.getConfParameter(), |
| 475 | _1)); |
| 476 | |
Ashlesh Gawande | 3909aa1 | 2017-07-28 16:01:35 -0500 | [diff] [blame] | 477 | faceDatasetFetchInterval.setMinAndMaxValue(FACE_DATASET_FETCH_INTERVAL_MIN, |
| 478 | FACE_DATASET_FETCH_INTERVAL_MAX); |
| 479 | faceDatasetFetchInterval.setOptional(FACE_DATASET_FETCH_INTERVAL_DEFAULT); |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 480 | |
| 481 | if (!faceDatasetFetchInterval.parseFromConfigSection(section)) { |
| 482 | return false; |
| 483 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 484 | |
| 485 | // first-hello-interval |
| 486 | ConfigurationVariable<uint32_t> firstHelloInterval("first-hello-interval", |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 487 | std::bind(&ConfParameter::setFirstHelloInterval, |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 488 | &m_nlsr.getConfParameter(), _1)); |
| 489 | firstHelloInterval.setMinAndMaxValue(FIRST_HELLO_INTERVAL_MIN, FIRST_HELLO_INTERVAL_MAX); |
| 490 | firstHelloInterval.setOptional(FIRST_HELLO_INTERVAL_DEFAULT); |
| 491 | |
| 492 | if (!firstHelloInterval.parseFromConfigSection(section)) { |
| 493 | return false; |
| 494 | } |
| 495 | |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 496 | for (ConfigSection::const_iterator tn = |
| 497 | section.begin(); tn != section.end(); ++tn) { |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 498 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 499 | if (tn->first == "neighbor") { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 500 | try { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 501 | ConfigSection CommandAttriTree = tn->second; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 502 | std::string name = CommandAttriTree.get<std::string>("name"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 503 | std::string uriString = CommandAttriTree.get<std::string>("face-uri"); |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 504 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 505 | ndn::util::FaceUri faceUri; |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame^] | 506 | if (! faceUri.parse(uriString)) { |
| 507 | std::cerr << "parsing failed!" << std::endl; |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 511 | double linkCost = CommandAttriTree.get<double>("link-cost", |
| 512 | Adjacent::DEFAULT_LINK_COST); |
| 513 | ndn::Name neighborName(name); |
| 514 | if (!neighborName.empty()) { |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 515 | Adjacent adj(name, faceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 516 | m_nlsr.getAdjacencyList().insert(adj); |
| 517 | } |
| 518 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 519 | std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]"; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 520 | std::cerr << " or bad URI format" << std::endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 521 | } |
| 522 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 523 | catch (const std::exception& ex) { |
| 524 | std::cerr << ex.what() << std::endl; |
| 525 | return false; |
| 526 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 527 | } |
| 528 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 529 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 530 | } |
| 531 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 532 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 533 | ConfFileProcessor::processConfSectionHyperbolic(const ConfigSection& section) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 534 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 535 | // state |
| 536 | std::string state = section.get<string>("state", "off"); |
| 537 | |
| 538 | if (boost::iequals(state, "off")) { |
| 539 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 540 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 541 | else if (boost::iequals(state, "on")) { |
| 542 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 543 | } |
| 544 | else if (state == "dry-run") { |
| 545 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
| 546 | } |
| 547 | else { |
| 548 | std::cerr << "Wrong format for hyperbolic state." << std::endl; |
| 549 | std::cerr << "Allowed value: off, on, dry-run" << std::endl; |
| 550 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 551 | return false; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 552 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 553 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 554 | try { |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame^] | 555 | // Radius and angle(s) are mandatory configuration parameters in hyperbolic section. |
| 556 | // Even if router can have hyperbolic routing calculation off but other router |
| 557 | // in the network may use hyperbolic routing calculation for FIB generation. |
| 558 | // So each router need to advertise its hyperbolic coordinates in the network |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 559 | double radius = section.get<double>("radius"); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 560 | std::string angleString = section.get<std::string>("angle"); |
| 561 | |
| 562 | std::stringstream ss(angleString); |
| 563 | std::vector<double> angles; |
| 564 | |
| 565 | double angle; |
| 566 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame^] | 567 | while (ss >> angle) { |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 568 | angles.push_back(angle); |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame^] | 569 | if (ss.peek() == ',' || ss.peek() == ' ') { |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 570 | ss.ignore(); |
| 571 | } |
| 572 | } |
| 573 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 574 | if (!m_nlsr.getConfParameter().setCorR(radius)) { |
| 575 | return false; |
| 576 | } |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 577 | m_nlsr.getConfParameter().setCorTheta(angles); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 578 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 579 | catch (const std::exception& ex) { |
| 580 | std::cerr << ex.what() << std::endl; |
| 581 | if (state == "on" || state == "dry-run") { |
| 582 | return false; |
| 583 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 584 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 585 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 586 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 587 | } |
| 588 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 589 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 590 | ConfFileProcessor::processConfSectionFib(const ConfigSection& section) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 591 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 592 | // max-faces-per-prefix |
| 593 | int maxFacesPerPrefix = section.get<int>("max-faces-per-prefix", MAX_FACES_PER_PREFIX_DEFAULT); |
| 594 | |
| 595 | if (maxFacesPerPrefix >= MAX_FACES_PER_PREFIX_MIN && |
| 596 | maxFacesPerPrefix <= MAX_FACES_PER_PREFIX_MAX) |
| 597 | { |
| 598 | m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefix); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 599 | } |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 600 | else { |
| 601 | std::cerr << "Wrong value for max-faces-per-prefix. "; |
| 602 | std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl; |
| 603 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 604 | return false; |
| 605 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 606 | |
| 607 | // routing-calc-interval |
| 608 | ConfigurationVariable<uint32_t> routingCalcInterval("routing-calc-interval", |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 609 | std::bind(&ConfParameter::setRoutingCalcInterval, |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 610 | &m_nlsr.getConfParameter(), _1)); |
| 611 | routingCalcInterval.setMinAndMaxValue(ROUTING_CALC_INTERVAL_MIN, ROUTING_CALC_INTERVAL_MAX); |
| 612 | routingCalcInterval.setOptional(ROUTING_CALC_INTERVAL_DEFAULT); |
| 613 | |
| 614 | if (!routingCalcInterval.parseFromConfigSection(section)) { |
| 615 | return false; |
| 616 | } |
| 617 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 618 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 619 | } |
| 620 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 621 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 622 | ConfFileProcessor::processConfSectionAdvertising(const ConfigSection& section) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 623 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 624 | for (ConfigSection::const_iterator tn = |
| 625 | section.begin(); tn != section.end(); ++tn) { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 626 | if (tn->first == "prefix") { |
| 627 | try { |
| 628 | std::string prefix = tn->second.data(); |
| 629 | ndn::Name namePrefix(prefix); |
| 630 | if (!namePrefix.empty()) { |
| 631 | m_nlsr.getNamePrefixList().insert(namePrefix); |
| 632 | } |
| 633 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 634 | std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | } |
| 638 | catch (const std::exception& ex) { |
| 639 | std::cerr << ex.what() << std::endl; |
| 640 | return false; |
| 641 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 642 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 643 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 644 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 645 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 646 | |
| 647 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 648 | ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 649 | { |
| 650 | ConfigSection::const_iterator it = section.begin(); |
| 651 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 652 | if (it == section.end() || it->first != "validator") { |
| 653 | std::cerr << "Error: Expect validator section!" << std::endl; |
| 654 | return false; |
| 655 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 656 | |
| 657 | m_nlsr.loadValidator(it->second, m_confFileName); |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 658 | |
akmhoque | d57f367 | 2014-06-10 10:41:32 -0500 | [diff] [blame] | 659 | it++; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 660 | if (it != section.end() && it->first == "prefix-update-validator") { |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 661 | m_nlsr.getPrefixUpdateProcessor().loadValidator(it->second, m_confFileName); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 662 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 663 | it++; |
| 664 | for (; it != section.end(); it++) { |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 665 | using namespace boost::filesystem; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 666 | |
| 667 | if (it->first != "cert-to-publish") { |
| 668 | std::cerr << "Error: Expect cert-to-publish!" << std::endl; |
| 669 | return false; |
| 670 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 671 | |
| 672 | std::string file = it->second.data(); |
| 673 | path certfilePath = absolute(file, path(m_confFileName).parent_path()); |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 674 | std::shared_ptr<ndn::IdentityCertificate> idCert = |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 675 | ndn::io::load<ndn::IdentityCertificate>(certfilePath.string()); |
| 676 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 677 | if (idCert == nullptr) { |
| 678 | std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl; |
| 679 | return false; |
| 680 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 681 | |
| 682 | m_nlsr.loadCertToPublish(idCert); |
| 683 | } |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 684 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 685 | |
| 686 | return true; |
| 687 | } |
| 688 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 689 | } // namespace nlsr |