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