akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * 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] | 19 | **/ |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 20 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 21 | #ifndef NLSR_CONF_FILE_PROCESSOR_HPP |
| 22 | #define NLSR_CONF_FILE_PROCESSOR_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 23 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame^] | 24 | #include "common.hpp" |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 25 | #include "nlsr.hpp" |
| 26 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame^] | 27 | #include <boost/algorithm/string.hpp> |
| 28 | #include <boost/property_tree/info_parser.hpp> |
| 29 | #include <boost/filesystem.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 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 33 | /*! \brief A class containing methods to parse an NLSR configuration file |
| 34 | * |
| 35 | * This class contains methods to parse an NLSR configuration file and |
| 36 | * set all the parameters in NLSR to the received values. There are |
| 37 | * defaults for any unconfigured settings. |
| 38 | * |
| 39 | * This is currently called by the wrapper class NlsrRunner to |
| 40 | * populate the NLSR object with its configuration before NLSR is |
| 41 | * started. |
| 42 | * |
| 43 | * \sa nlsr::ConfParameter |
| 44 | * \sa NlsrRunner::run |
| 45 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | class ConfFileProcessor |
| 47 | { |
| 48 | public: |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 49 | ConfFileProcessor(Nlsr& nlsr, const std::string& cfile) |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 50 | : m_confFileName(cfile) |
| 51 | , m_nlsr(nlsr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 55 | /*! \brief Load and parse the configuration file, then populate NLSR. |
| 56 | * |
| 57 | * Entry-point function that chains all the necessary steps together |
| 58 | * to configure an NLSR object. |
| 59 | * |
| 60 | * \return A boolean for whether configuration was successful. |
| 61 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 62 | bool |
| 63 | processConfFile(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | |
| 65 | private: |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 66 | typedef boost::property_tree::ptree ConfigSection; |
| 67 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 68 | /*! \brief Parse the configuration file into a tree and process the nodes. |
| 69 | * |
| 70 | * Reads the configuration file as a property tree, and then iterates |
| 71 | * over them, attempting to parse each node. The nodes themselves |
| 72 | * are passed to another function that determines what kind of |
| 73 | * section it is and handles it appropriately. On any error in |
| 74 | * reading the file, return false. |
| 75 | * |
| 76 | * \return Whether configuration was successful. |
| 77 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 78 | bool |
| 79 | load(std::istream& input); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 81 | /*! \brief A dispatcher-like function to send configuration tree nodes to the right subfunction. |
| 82 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 83 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 84 | processSection(const std::string& sectionName, const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 86 | /*! \brief Parse general options, including router name, logging directory, LSA refresh. |
| 87 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 88 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 89 | processConfSectionGeneral(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 90 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 91 | /*! \brief Configure options relating to neighbor configuration and detection. |
| 92 | * |
| 93 | * Parse options that control NLSR's behavior about neighbors. Such |
| 94 | * things include how many hello interests are sent and what their |
| 95 | * timeout is, as well as parsing neighbor specifications. Neighbor |
| 96 | * Face URIs are parsed and confirmed as valid here by ndn-cxx. |
| 97 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 98 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 99 | processConfSectionNeighbors(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 101 | /*! \brief Set the state of hyperbolic routing: off, on, dry-run. |
| 102 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 103 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 104 | processConfSectionHyperbolic(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 106 | /*! \brief Set options for the FIB: nexthops per prefix, routing calculation interval. |
| 107 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 108 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 109 | processConfSectionFib(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 111 | /*! \brief Set prefixes that NLSR is supposed to advertise immediately. |
| 112 | */ |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 113 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 114 | processConfSectionAdvertising(const ConfigSection& section); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 115 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 116 | /*! \brief Parse and set rules for the validator. |
| 117 | * |
| 118 | * This section parses and sets rules for the validators, which |
| 119 | * control what criteria Interest and Data need to follow to be |
| 120 | * considered valid by this NLSR. |
| 121 | */ |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 122 | bool |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 123 | processConfSectionSecurity(const ConfigSection& section); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 124 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 125 | private: |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 126 | /*! m_confFileName The full path of the configuration file to parse. */ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 127 | std::string m_confFileName; |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 128 | /*! m_nlsr The NLSR object to configure upon successful parsing. */ |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 129 | Nlsr& m_nlsr; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | }; |
| 131 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 132 | } // namespace nlsr |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 133 | #endif // NLSR_CONF_FILE_PROCESSOR_HPP |