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