akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, The University of Memphis, |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 21 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 22 | #ifndef NLSR_CONF_FILE_PROCESSOR_HPP |
| 23 | #define NLSR_CONF_FILE_PROCESSOR_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 25 | #include "common.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 26 | #include "conf-parameter.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 27 | |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame^] | 28 | #include <boost/asio/io_context.hpp> |
Davide Pesavento | 22520e6 | 2021-06-08 22:16:52 -0400 | [diff] [blame] | 29 | #include <boost/property_tree/ptree.hpp> |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 30 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | namespace nlsr { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 32 | |
Ashlesh Gawande | 328fc11 | 2019-12-12 17:06:44 -0600 | [diff] [blame] | 33 | using ConfigSection = boost::property_tree::ptree; |
| 34 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 35 | /*! \brief A class containing methods to parse an NLSR configuration file |
| 36 | * |
| 37 | * This class contains methods to parse an NLSR configuration file and |
| 38 | * set all the parameters in NLSR to the received values. There are |
| 39 | * defaults for any unconfigured settings. |
| 40 | * |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 41 | * \sa nlsr::ConfParameter |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 42 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | class ConfFileProcessor |
| 44 | { |
| 45 | public: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 46 | ConfFileProcessor(ConfParameter& confParam); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 48 | /*! \brief Load and parse the configuration file, then populate NLSR. |
| 49 | * |
| 50 | * Entry-point function that chains all the necessary steps together |
| 51 | * to configure an NLSR object. |
| 52 | * |
| 53 | * \return A boolean for whether configuration was successful. |
| 54 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 55 | bool |
| 56 | processConfFile(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 57 | |
| 58 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 59 | /*! \brief Parse the configuration file into a tree and process the nodes. |
| 60 | * |
| 61 | * Reads the configuration file as a property tree, and then iterates |
| 62 | * over them, attempting to parse each node. The nodes themselves |
| 63 | * are passed to another function that determines what kind of |
| 64 | * section it is and handles it appropriately. On any error in |
| 65 | * reading the file, return false. |
| 66 | * |
| 67 | * \return Whether configuration was successful. |
| 68 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 69 | bool |
| 70 | load(std::istream& input); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 71 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 72 | /*! \brief A dispatcher-like function to send configuration tree nodes to the right subfunction. |
| 73 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 74 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 75 | processSection(const std::string& sectionName, const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 76 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 77 | /*! \brief Parse general options, including router name, LSA refresh. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 78 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 79 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 80 | processConfSectionGeneral(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 82 | /*! \brief Configure options relating to neighbor configuration and detection. |
| 83 | * |
| 84 | * Parse options that control NLSR's behavior about neighbors. Such |
| 85 | * things include how many hello interests are sent and what their |
| 86 | * timeout is, as well as parsing neighbor specifications. Neighbor |
| 87 | * Face URIs are parsed and confirmed as valid here by ndn-cxx. |
| 88 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 89 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 90 | processConfSectionNeighbors(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 92 | /*! \brief Set the state of hyperbolic routing: off, on, dry-run. |
| 93 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 94 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 95 | processConfSectionHyperbolic(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 96 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 97 | /*! \brief Set options for the FIB: nexthops per prefix, routing calculation interval. |
| 98 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 99 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 100 | processConfSectionFib(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 101 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 102 | /*! \brief Set prefixes that NLSR is supposed to advertise immediately. |
| 103 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 104 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 105 | processConfSectionAdvertising(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 107 | /*! \brief Parse and set rules for the validator. |
| 108 | * |
| 109 | * This section parses and sets rules for the validators, which |
| 110 | * control what criteria Interest and Data need to follow to be |
| 111 | * considered valid by this NLSR. |
| 112 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 113 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 114 | processConfSectionSecurity(const ConfigSection& section); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 115 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 116 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 117 | /*! m_confFileName The full path of the configuration file to parse. */ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 118 | std::string m_confFileName; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 119 | /*! m_confParam The ConfFileProcessor object to configure as parsing is done. */ |
| 120 | ConfParameter& m_confParam; |
Davide Pesavento | 5849ee7 | 2023-11-12 20:00:21 -0500 | [diff] [blame^] | 121 | /*! m_io For canonization of FaceUri. */ |
| 122 | boost::asio::io_context m_io; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 123 | }; |
| 124 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 125 | } // namespace nlsr |
Davide Pesavento | 22520e6 | 2021-06-08 22:16:52 -0400 | [diff] [blame] | 126 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 127 | #endif // NLSR_CONF_FILE_PROCESSOR_HPP |