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