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