blob: e33b50bd68ae8e7a0ff36f0c3b00339903cb4ce3 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -06003 * Copyright (c) 2014-2019, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050019 **/
Ashlesh Gawande415676b2016-12-22 00:26:23 -060020
dmcoomese689dd62017-03-29 11:05:12 -050021#ifndef NLSR_CONF_FILE_PROCESSOR_HPP
22#define NLSR_CONF_FILE_PROCESSOR_HPP
akmhoque53353462014-04-22 08:43:45 -050023
Nick Gordone98480b2017-05-24 11:23:03 -050024#include "common.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060025#include "conf-parameter.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050026
Nick Gordone98480b2017-05-24 11:23:03 -050027#include <boost/algorithm/string.hpp>
28#include <boost/property_tree/info_parser.hpp>
29#include <boost/filesystem.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050030
akmhoque53353462014-04-22 08:43:45 -050031namespace nlsr {
akmhoqueb6450b12014-04-24 00:01:03 -050032
Ashlesh Gawande328fc112019-12-12 17:06:44 -060033namespace bf = boost::filesystem;
34using ConfigSection = boost::property_tree::ptree;
35
Nick Gordond0a7df32017-05-30 16:44:34 -050036/*! \brief A class containing methods to parse an NLSR configuration file
37 *
38 * This class contains methods to parse an NLSR configuration file and
39 * set all the parameters in NLSR to the received values. There are
40 * defaults for any unconfigured settings.
41 *
42 * This is currently called by the wrapper class NlsrRunner to
43 * populate the NLSR object with its configuration before NLSR is
44 * started.
45 *
46 * \sa nlsr::ConfParameter
47 * \sa NlsrRunner::run
48 */
akmhoque53353462014-04-22 08:43:45 -050049class ConfFileProcessor
50{
51public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060052 ConfFileProcessor(ConfParameter& confParam);
akmhoque53353462014-04-22 08:43:45 -050053
Nick Gordond0a7df32017-05-30 16:44:34 -050054 /*! \brief Load and parse the configuration file, then populate NLSR.
55 *
56 * Entry-point function that chains all the necessary steps together
57 * to configure an NLSR object.
58 *
59 * \return A boolean for whether configuration was successful.
60 */
akmhoque157b0a42014-05-13 00:26:37 -050061 bool
62 processConfFile();
akmhoque53353462014-04-22 08:43:45 -050063
64private:
Nick Gordond0a7df32017-05-30 16:44:34 -050065 /*! \brief Parse the configuration file into a tree and process the nodes.
66 *
67 * Reads the configuration file as a property tree, and then iterates
68 * over them, attempting to parse each node. The nodes themselves
69 * are passed to another function that determines what kind of
70 * section it is and handles it appropriately. On any error in
71 * reading the file, return false.
72 *
73 * \return Whether configuration was successful.
74 */
akmhoque157b0a42014-05-13 00:26:37 -050075 bool
76 load(std::istream& input);
akmhoque53353462014-04-22 08:43:45 -050077
Nick Gordond0a7df32017-05-30 16:44:34 -050078 /*! \brief A dispatcher-like function to send configuration tree nodes to the right subfunction.
79 */
akmhoque157b0a42014-05-13 00:26:37 -050080 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070081 processSection(const std::string& sectionName, const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050082
dmcoomescf8d0ed2017-02-21 11:39:01 -060083 /*! \brief Parse general options, including router name, LSA refresh.
Nick Gordond0a7df32017-05-30 16:44:34 -050084 */
akmhoque157b0a42014-05-13 00:26:37 -050085 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070086 processConfSectionGeneral(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050087
Nick Gordond0a7df32017-05-30 16:44:34 -050088 /*! \brief Configure options relating to neighbor configuration and detection.
89 *
90 * Parse options that control NLSR's behavior about neighbors. Such
91 * things include how many hello interests are sent and what their
92 * timeout is, as well as parsing neighbor specifications. Neighbor
93 * Face URIs are parsed and confirmed as valid here by ndn-cxx.
94 */
akmhoque157b0a42014-05-13 00:26:37 -050095 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070096 processConfSectionNeighbors(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050097
Nick Gordond0a7df32017-05-30 16:44:34 -050098 /*! \brief Set the state of hyperbolic routing: off, on, dry-run.
99 */
akmhoque157b0a42014-05-13 00:26:37 -0500100 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700101 processConfSectionHyperbolic(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500102
Nick Gordond0a7df32017-05-30 16:44:34 -0500103 /*! \brief Set options for the FIB: nexthops per prefix, routing calculation interval.
104 */
akmhoque157b0a42014-05-13 00:26:37 -0500105 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700106 processConfSectionFib(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500107
Nick Gordond0a7df32017-05-30 16:44:34 -0500108 /*! \brief Set prefixes that NLSR is supposed to advertise immediately.
109 */
akmhoque157b0a42014-05-13 00:26:37 -0500110 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700111 processConfSectionAdvertising(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500112
Nick Gordond0a7df32017-05-30 16:44:34 -0500113 /*! \brief Parse and set rules for the validator.
114 *
115 * This section parses and sets rules for the validators, which
116 * control what criteria Interest and Data need to follow to be
117 * considered valid by this NLSR.
118 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700119 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700120 processConfSectionSecurity(const ConfigSection& section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700121
akmhoque53353462014-04-22 08:43:45 -0500122private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500123 /*! m_confFileName The full path of the configuration file to parse. */
akmhoquefdbddb12014-05-02 18:35:19 -0500124 std::string m_confFileName;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600125 /*! m_confParam The ConfFileProcessor object to configure as parsing is done. */
126 ConfParameter& m_confParam;
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600127 /*! m_io For canonization of faceUri. */
128 boost::asio::io_service m_io;
akmhoque53353462014-04-22 08:43:45 -0500129};
130
Nick Gordonfad8e252016-08-11 14:21:38 -0500131} // namespace nlsr
dmcoomese689dd62017-03-29 11:05:12 -0500132#endif // NLSR_CONF_FILE_PROCESSOR_HPP