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