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