akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- 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 | **/ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | #include <iostream> |
| 25 | #include <fstream> |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 26 | #include <boost/algorithm/string.hpp> |
| 27 | #include <boost/property_tree/info_parser.hpp> |
| 28 | #include <boost/property_tree/ptree.hpp> |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 29 | #include <boost/filesystem.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/name.hpp> |
| 32 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 33 | #include "conf-parameter.hpp" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 34 | #include "conf-file-processor.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | #include "adjacent.hpp" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 36 | #include "utility/name-helper.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 37 | |
| 38 | |
| 39 | namespace nlsr { |
| 40 | |
| 41 | using namespace std; |
| 42 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 43 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 44 | ConfFileProcessor::processConfFile() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 46 | bool ret = true; |
| 47 | ifstream inputFile; |
| 48 | inputFile.open(m_confFileName.c_str()); |
| 49 | if (!inputFile.is_open()) { |
| 50 | string msg = "Failed to read configuration file: "; |
| 51 | msg += m_confFileName; |
| 52 | cerr << msg << endl; |
akmhoque | ad5fe95 | 2014-06-26 13:34:12 -0500 | [diff] [blame] | 53 | return false; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 54 | } |
| 55 | ret = load(inputFile); |
| 56 | inputFile.close(); |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | bool |
| 61 | ConfFileProcessor::load(istream& input) |
| 62 | { |
| 63 | boost::property_tree::ptree pt; |
| 64 | bool ret = true; |
| 65 | try { |
| 66 | boost::property_tree::read_info(input, pt); |
| 67 | } |
| 68 | catch (const boost::property_tree::info_parser_error& error) { |
| 69 | stringstream msg; |
| 70 | std::cerr << "Failed to parse configuration file " << std::endl; |
| 71 | std::cerr << m_confFileName << std::endl; |
| 72 | return false; |
| 73 | } |
| 74 | for (boost::property_tree::ptree::const_iterator tn = pt.begin(); |
| 75 | tn != pt.end(); ++tn) { |
| 76 | std::string section = tn->first; |
| 77 | boost::property_tree::ptree SectionAttributeTree = tn ->second; |
| 78 | ret = processSection(section, SectionAttributeTree); |
| 79 | if (ret == false) { |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | bool |
| 87 | ConfFileProcessor::processSection(const std::string& section, |
| 88 | boost::property_tree::ptree SectionAttributeTree) |
| 89 | { |
| 90 | bool ret = true; |
| 91 | if (section == "general") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 92 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 93 | ret = processConfSectionGeneral(SectionAttributeTree); |
| 94 | } |
| 95 | else if (section == "neighbors") |
| 96 | { |
| 97 | ret = processConfSectionNeighbors(SectionAttributeTree); |
| 98 | } |
| 99 | else if (section == "hyperbolic") |
| 100 | { |
| 101 | ret = processConfSectionHyperbolic(SectionAttributeTree); |
| 102 | } |
| 103 | else if (section == "fib") |
| 104 | { |
| 105 | ret = processConfSectionFib(SectionAttributeTree); |
| 106 | } |
| 107 | else if (section == "advertising") |
| 108 | { |
| 109 | ret = processConfSectionAdvertising(SectionAttributeTree); |
| 110 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 111 | else if (section == "security") |
| 112 | { |
| 113 | ret = processConfSectionSecurity(SectionAttributeTree); |
| 114 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 115 | else |
| 116 | { |
| 117 | std::cerr << "Wrong configuration Command: " << section << std::endl; |
| 118 | } |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | bool |
| 123 | ConfFileProcessor::processConfSectionGeneral(boost::property_tree::ptree |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 124 | SectionAttributeTree) |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 125 | { |
| 126 | try { |
| 127 | std::string network = SectionAttributeTree.get<string>("network"); |
| 128 | std::string site = SectionAttributeTree.get<string>("site"); |
| 129 | std::string router = SectionAttributeTree.get<string>("router"); |
| 130 | ndn::Name networkName(network); |
| 131 | if (!networkName.empty()) { |
| 132 | m_nlsr.getConfParameter().setNetwork(networkName); |
| 133 | } |
| 134 | else { |
| 135 | cerr << " Network can not be null or empty or in bad URI format :(!" << endl; |
| 136 | return false; |
| 137 | } |
| 138 | ndn::Name siteName(site); |
| 139 | if (!siteName.empty()) { |
| 140 | m_nlsr.getConfParameter().setSiteName(siteName); |
| 141 | } |
| 142 | else { |
| 143 | cerr << "Site can not be null or empty or in bad URI format:( !" << endl; |
| 144 | return false; |
| 145 | } |
| 146 | ndn::Name routerName(router); |
| 147 | if (!routerName.empty()) { |
| 148 | m_nlsr.getConfParameter().setRouterName(routerName); |
| 149 | } |
| 150 | else { |
| 151 | cerr << " Router name can not be null or empty or in bad URI format:( !" << endl; |
| 152 | return false; |
| 153 | } |
| 154 | } |
| 155 | catch (const std::exception& ex) { |
| 156 | cerr << ex.what() << endl; |
| 157 | return false; |
| 158 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 159 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 160 | try { |
| 161 | int32_t lsaRefreshTime = SectionAttributeTree.get<int32_t>("lsa-refresh-time"); |
| 162 | if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && |
| 163 | lsaRefreshTime <= LSA_REFRESH_TIME_MAX) { |
| 164 | m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime); |
| 165 | } |
| 166 | else { |
| 167 | std::cerr << "Wrong value for lsa-refresh-time "; |
| 168 | std::cerr << "Allowed value: " << LSA_REFRESH_TIME_MIN << "-";; |
| 169 | std::cerr << LSA_REFRESH_TIME_MAX << std::endl; |
| 170 | return false; |
| 171 | } |
| 172 | } |
| 173 | catch (const std::exception& ex) { |
| 174 | std::cerr << ex.what() << std::endl; |
| 175 | return false; |
| 176 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 177 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 178 | try { |
| 179 | std::string logLevel = SectionAttributeTree.get<string>("log-level"); |
| 180 | if ( boost::iequals(logLevel, "info") || boost::iequals(logLevel, "debug")) { |
| 181 | m_nlsr.getConfParameter().setLogLevel(logLevel); |
| 182 | } |
| 183 | else { |
| 184 | std::cerr << "Wrong value for log-level "; |
| 185 | std::cerr << "Allowed value: INFO, DEBUG" << std::endl; |
| 186 | return false; |
| 187 | } |
| 188 | } |
| 189 | catch (const std::exception& ex) { |
| 190 | std::cerr << ex.what() << std::endl; |
| 191 | return false; |
| 192 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 193 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 194 | try { |
| 195 | std::string logDir = SectionAttributeTree.get<string>("log-dir"); |
| 196 | if (boost::filesystem::exists(logDir)) { |
| 197 | if (boost::filesystem::is_directory(logDir)) { |
| 198 | std::string testFileName=logDir+"/test.log"; |
| 199 | ofstream testOutFile; |
| 200 | testOutFile.open(testFileName.c_str()); |
| 201 | if (testOutFile.is_open() && testOutFile.good()) { |
| 202 | m_nlsr.getConfParameter().setLogDir(logDir); |
| 203 | } |
| 204 | else { |
| 205 | std::cerr << "User does not have read and write permission on the directory"; |
| 206 | std::cerr << std::endl; |
| 207 | return false; |
| 208 | } |
| 209 | testOutFile.close(); |
| 210 | remove(testFileName.c_str()); |
| 211 | } |
| 212 | else { |
| 213 | std::cerr << "Provided path is not a directory" << std::endl; |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | else { |
| 218 | std::cerr << "Log directory provided does not exists" << std::endl; |
| 219 | return false; |
| 220 | } |
| 221 | } |
| 222 | catch (const std::exception& ex) { |
| 223 | std::cerr << "You must configure log directory" << std::endl; |
| 224 | std::cerr << ex.what() << std::endl; |
| 225 | return false; |
| 226 | } |
| 227 | try { |
| 228 | std::string seqDir = SectionAttributeTree.get<string>("seq-dir"); |
| 229 | if (boost::filesystem::exists(seqDir)) { |
| 230 | if (boost::filesystem::is_directory(seqDir)) { |
| 231 | std::string testFileName=seqDir+"/test.seq"; |
| 232 | ofstream testOutFile; |
| 233 | testOutFile.open(testFileName.c_str()); |
| 234 | if (testOutFile.is_open() && testOutFile.good()) { |
| 235 | m_nlsr.getConfParameter().setSeqFileDir(seqDir); |
| 236 | } |
| 237 | else { |
| 238 | std::cerr << "User does not have read and write permission on the directory"; |
| 239 | std::cerr << std::endl; |
| 240 | return false; |
| 241 | } |
| 242 | testOutFile.close(); |
| 243 | remove(testFileName.c_str()); |
| 244 | } |
| 245 | else { |
| 246 | std::cerr << "Provided path is not a directory" << std::endl; |
| 247 | return false; |
| 248 | } |
| 249 | } |
| 250 | else { |
| 251 | std::cerr << "Seq directory provided does not exists" << std::endl; |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | catch (const std::exception& ex) { |
| 256 | std::cerr << "You must configure sequence directory" << std::endl; |
| 257 | std::cerr << ex.what() << std::endl; |
| 258 | return false; |
| 259 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 260 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 261 | return true; |
| 262 | } |
| 263 | |
| 264 | bool |
| 265 | ConfFileProcessor::processConfSectionNeighbors(boost::property_tree::ptree |
| 266 | SectionAttributeTree) |
| 267 | { |
| 268 | try { |
| 269 | int retrials = SectionAttributeTree.get<int>("hello-retries"); |
| 270 | if (retrials >= HELLO_RETRIES_MIN && retrials <= HELLO_RETRIES_MAX) { |
| 271 | m_nlsr.getConfParameter().setInterestRetryNumber(retrials); |
| 272 | } |
| 273 | else { |
| 274 | std::cerr << "Wrong value for hello-retries. "; |
| 275 | std::cerr << "Allowed value:" << HELLO_RETRIES_MIN << "-"; |
| 276 | std::cerr << HELLO_RETRIES_MAX << std::endl; |
| 277 | return false; |
| 278 | } |
| 279 | } |
| 280 | catch (const std::exception& ex) { |
| 281 | std::cerr << ex.what() << std::endl; |
| 282 | return false; |
| 283 | } |
| 284 | try { |
| 285 | int timeOut = SectionAttributeTree.get<int>("hello-timeout"); |
| 286 | if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) { |
| 287 | m_nlsr.getConfParameter().setInterestResendTime(timeOut); |
| 288 | } |
| 289 | else { |
| 290 | std::cerr << "Wrong value for hello-timeout. "; |
| 291 | std::cerr << "Allowed value:" << HELLO_TIMEOUT_MIN << "-"; |
| 292 | std::cerr << HELLO_TIMEOUT_MAX << std::endl; |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | catch (const std::exception& ex) { |
| 297 | std::cerr << ex.what() << std::endl; |
| 298 | } |
| 299 | try { |
| 300 | int interval = SectionAttributeTree.get<int>("hello-interval"); |
| 301 | if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) { |
| 302 | m_nlsr.getConfParameter().setInfoInterestInterval(interval); |
| 303 | } |
| 304 | else { |
| 305 | std::cerr << "Wrong value for hello-interval. "; |
| 306 | std::cerr << "Allowed value:" << HELLO_INTERVAL_MIN << "-"; |
| 307 | std::cerr << HELLO_INTERVAL_MAX << std::endl; |
| 308 | return false; |
| 309 | } |
| 310 | } |
| 311 | catch (const std::exception& ex) { |
| 312 | std::cerr << ex.what() << std::endl; |
| 313 | } |
| 314 | for (boost::property_tree::ptree::const_iterator tn = |
| 315 | SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) { |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 316 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 317 | if (tn->first == "neighbor") |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 318 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 319 | try { |
| 320 | boost::property_tree::ptree CommandAttriTree = tn->second; |
| 321 | std::string name = CommandAttriTree.get<std::string>("name"); |
| 322 | std::string faceUri = CommandAttriTree.get<std::string>("face-uri"); |
| 323 | double linkCost = CommandAttriTree.get<double>("link-cost", |
| 324 | Adjacent::DEFAULT_LINK_COST); |
| 325 | ndn::Name neighborName(name); |
| 326 | if (!neighborName.empty()) { |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 327 | Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0, 0); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 328 | m_nlsr.getAdjacencyList().insert(adj); |
| 329 | } |
| 330 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 331 | std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]"; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 332 | std::cerr << " or bad URI format" << std::endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 333 | } |
| 334 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 335 | catch (const std::exception& ex) { |
| 336 | std::cerr << ex.what() << std::endl; |
| 337 | return false; |
| 338 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 339 | } |
| 340 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 341 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 342 | } |
| 343 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 344 | bool |
| 345 | ConfFileProcessor::processConfSectionHyperbolic(boost::property_tree::ptree |
| 346 | SectionAttributeTree) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 347 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 348 | std::string state; |
| 349 | try { |
| 350 | state= SectionAttributeTree.get<string>("state","off"); |
| 351 | if (boost::iequals(state, "off")) { |
| 352 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_OFF); |
| 353 | } |
| 354 | else if (boost::iequals(state, "on")) { |
| 355 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_ON); |
| 356 | } |
| 357 | else if (state == "dry-run") { |
| 358 | m_nlsr.getConfParameter().setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN); |
| 359 | } |
| 360 | else { |
| 361 | std::cerr << "Wrong format for hyperbolic state." << std::endl; |
| 362 | std::cerr << "Allowed value: off, on, dry-run" << std::endl; |
| 363 | return false; |
| 364 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 365 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 366 | catch (const std::exception& ex) { |
| 367 | std::cerr << ex.what() << std::endl; |
| 368 | return false; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 369 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 370 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 371 | try { |
| 372 | /* Radius and angle is mandatory configuration parameter in hyperbolic section. |
| 373 | * Even if router can have hyperbolic routing calculation off but other router |
| 374 | * in the network may use hyperbolic routing calculation for FIB generation. |
| 375 | * So each router need to advertise its hyperbolic coordinates in the network |
| 376 | */ |
| 377 | double radius = SectionAttributeTree.get<double>("radius"); |
| 378 | double angle = SectionAttributeTree.get<double>("angle"); |
| 379 | if (!m_nlsr.getConfParameter().setCorR(radius)) { |
| 380 | return false; |
| 381 | } |
| 382 | m_nlsr.getConfParameter().setCorTheta(angle); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 383 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 384 | catch (const std::exception& ex) { |
| 385 | std::cerr << ex.what() << std::endl; |
| 386 | if (state == "on" || state == "dry-run") { |
| 387 | return false; |
| 388 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 389 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 390 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 391 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 392 | } |
| 393 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 394 | bool |
| 395 | ConfFileProcessor::processConfSectionFib(boost::property_tree::ptree |
| 396 | SectionAttributeTree) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 397 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 398 | try { |
| 399 | int maxFacesPerPrefixNumber = |
| 400 | SectionAttributeTree.get<int>("max-faces-per-prefix"); |
| 401 | if (maxFacesPerPrefixNumber >= MAX_FACES_PER_PREFIX_MIN && |
| 402 | maxFacesPerPrefixNumber <= MAX_FACES_PER_PREFIX_MAX) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 403 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 404 | m_nlsr.getConfParameter().setMaxFacesPerPrefix(maxFacesPerPrefixNumber); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 405 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 406 | else { |
| 407 | std::cerr << "Wrong value for max-faces-per-prefix. "; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 408 | std::cerr << MAX_FACES_PER_PREFIX_MIN << std::endl; |
| 409 | return false; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 410 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 411 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 412 | catch (const std::exception& ex) { |
| 413 | cerr << ex.what() << endl; |
| 414 | return false; |
| 415 | } |
| 416 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 417 | } |
| 418 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 419 | bool |
| 420 | ConfFileProcessor::processConfSectionAdvertising(boost::property_tree::ptree |
| 421 | SectionAttributeTree) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 422 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 423 | for (boost::property_tree::ptree::const_iterator tn = |
| 424 | SectionAttributeTree.begin(); tn != SectionAttributeTree.end(); ++tn) { |
| 425 | if (tn->first == "prefix") { |
| 426 | try { |
| 427 | std::string prefix = tn->second.data(); |
| 428 | ndn::Name namePrefix(prefix); |
| 429 | if (!namePrefix.empty()) { |
| 430 | m_nlsr.getNamePrefixList().insert(namePrefix); |
| 431 | } |
| 432 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 433 | std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | } |
| 437 | catch (const std::exception& ex) { |
| 438 | std::cerr << ex.what() << std::endl; |
| 439 | return false; |
| 440 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 441 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 442 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 443 | return true; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 444 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 445 | |
| 446 | bool |
| 447 | ConfFileProcessor::processConfSectionSecurity(boost::property_tree::ptree section) |
| 448 | { |
| 449 | ConfigSection::const_iterator it = section.begin(); |
| 450 | |
| 451 | if (it == section.end() || it->first != "validator") |
| 452 | { |
| 453 | std::cerr << "Error: Expect validator section!" << std::endl; |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | m_nlsr.loadValidator(it->second, m_confFileName); |
akmhoque | d57f367 | 2014-06-10 10:41:32 -0500 | [diff] [blame] | 458 | it++; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 459 | |
| 460 | for (; it != section.end(); it++) |
| 461 | { |
| 462 | using namespace boost::filesystem; |
| 463 | if (it->first != "cert-to-publish") |
| 464 | { |
| 465 | std::cerr << "Error: Expect cert-to-publish!" << std::endl; |
| 466 | return false; |
| 467 | } |
| 468 | |
| 469 | std::string file = it->second.data(); |
| 470 | path certfilePath = absolute(file, path(m_confFileName).parent_path()); |
| 471 | ndn::shared_ptr<ndn::IdentityCertificate> idCert = |
| 472 | ndn::io::load<ndn::IdentityCertificate>(certfilePath.string()); |
| 473 | |
| 474 | if (!static_cast<bool>(idCert)) |
| 475 | { |
| 476 | std::cerr << "Error: Cannot load cert-to-publish: " << file << "!" << std::endl; |
| 477 | return false; |
| 478 | } |
| 479 | |
| 480 | m_nlsr.loadCertToPublish(idCert); |
| 481 | } |
| 482 | |
| 483 | return true; |
| 484 | } |
| 485 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 486 | }//namespace NLSR |