blob: f7270ba7f3e528aa2aa1c79b79790c8de6aef2ec [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
3 * Copyright (c) 2014-2020, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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 Gawande0421bc62020-05-08 20:42:19 -070020 */
Ashlesh Gawande415676b2016-12-22 00:26:23 -060021
dmcoomese689dd62017-03-29 11:05:12 -050022#ifndef NLSR_CONF_FILE_PROCESSOR_HPP
23#define NLSR_CONF_FILE_PROCESSOR_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Nick Gordone98480b2017-05-24 11:23:03 -050025#include "common.hpp"
Ashlesh Gawande85998a12017-12-07 22:22:13 -060026#include "conf-parameter.hpp"
Nick Gordond0a7df32017-05-30 16:44:34 -050027
Nick Gordone98480b2017-05-24 11:23:03 -050028#include <boost/algorithm/string.hpp>
29#include <boost/property_tree/info_parser.hpp>
30#include <boost/filesystem.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050031
akmhoque53353462014-04-22 08:43:45 -050032namespace nlsr {
akmhoqueb6450b12014-04-24 00:01:03 -050033
Ashlesh Gawande328fc112019-12-12 17:06:44 -060034namespace bf = boost::filesystem;
35using ConfigSection = boost::property_tree::ptree;
36
Nick Gordond0a7df32017-05-30 16:44:34 -050037/*! \brief A class containing methods to parse an NLSR configuration file
38 *
39 * This class contains methods to parse an NLSR configuration file and
40 * set all the parameters in NLSR to the received values. There are
41 * defaults for any unconfigured settings.
42 *
Nick Gordond0a7df32017-05-30 16:44:34 -050043 * \sa nlsr::ConfParameter
Nick Gordond0a7df32017-05-30 16:44:34 -050044 */
akmhoque53353462014-04-22 08:43:45 -050045class ConfFileProcessor
46{
47public:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060048 ConfFileProcessor(ConfParameter& confParam);
akmhoque53353462014-04-22 08:43:45 -050049
Nick Gordond0a7df32017-05-30 16:44:34 -050050 /*! \brief Load and parse the configuration file, then populate NLSR.
51 *
52 * Entry-point function that chains all the necessary steps together
53 * to configure an NLSR object.
54 *
55 * \return A boolean for whether configuration was successful.
56 */
akmhoque157b0a42014-05-13 00:26:37 -050057 bool
58 processConfFile();
akmhoque53353462014-04-22 08:43:45 -050059
60private:
Nick Gordond0a7df32017-05-30 16:44:34 -050061 /*! \brief Parse the configuration file into a tree and process the nodes.
62 *
63 * Reads the configuration file as a property tree, and then iterates
64 * over them, attempting to parse each node. The nodes themselves
65 * are passed to another function that determines what kind of
66 * section it is and handles it appropriately. On any error in
67 * reading the file, return false.
68 *
69 * \return Whether configuration was successful.
70 */
akmhoque157b0a42014-05-13 00:26:37 -050071 bool
72 load(std::istream& input);
akmhoque53353462014-04-22 08:43:45 -050073
Nick Gordond0a7df32017-05-30 16:44:34 -050074 /*! \brief A dispatcher-like function to send configuration tree nodes to the right subfunction.
75 */
akmhoque157b0a42014-05-13 00:26:37 -050076 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070077 processSection(const std::string& sectionName, const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050078
dmcoomescf8d0ed2017-02-21 11:39:01 -060079 /*! \brief Parse general options, including router name, LSA refresh.
Nick Gordond0a7df32017-05-30 16:44:34 -050080 */
akmhoque157b0a42014-05-13 00:26:37 -050081 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070082 processConfSectionGeneral(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050083
Nick Gordond0a7df32017-05-30 16:44:34 -050084 /*! \brief Configure options relating to neighbor configuration and detection.
85 *
86 * Parse options that control NLSR's behavior about neighbors. Such
87 * things include how many hello interests are sent and what their
88 * timeout is, as well as parsing neighbor specifications. Neighbor
89 * Face URIs are parsed and confirmed as valid here by ndn-cxx.
90 */
akmhoque157b0a42014-05-13 00:26:37 -050091 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070092 processConfSectionNeighbors(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050093
Nick Gordond0a7df32017-05-30 16:44:34 -050094 /*! \brief Set the state of hyperbolic routing: off, on, dry-run.
95 */
akmhoque157b0a42014-05-13 00:26:37 -050096 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070097 processConfSectionHyperbolic(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050098
Nick Gordond0a7df32017-05-30 16:44:34 -050099 /*! \brief Set options for the FIB: nexthops per prefix, routing calculation interval.
100 */
akmhoque157b0a42014-05-13 00:26:37 -0500101 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700102 processConfSectionFib(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500103
Nick Gordond0a7df32017-05-30 16:44:34 -0500104 /*! \brief Set prefixes that NLSR is supposed to advertise immediately.
105 */
akmhoque157b0a42014-05-13 00:26:37 -0500106 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700107 processConfSectionAdvertising(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500108
Nick Gordond0a7df32017-05-30 16:44:34 -0500109 /*! \brief Parse and set rules for the validator.
110 *
111 * This section parses and sets rules for the validators, which
112 * control what criteria Interest and Data need to follow to be
113 * considered valid by this NLSR.
114 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700115 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700116 processConfSectionSecurity(const ConfigSection& section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700117
akmhoque53353462014-04-22 08:43:45 -0500118private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500119 /*! m_confFileName The full path of the configuration file to parse. */
akmhoquefdbddb12014-05-02 18:35:19 -0500120 std::string m_confFileName;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600121 /*! m_confParam The ConfFileProcessor object to configure as parsing is done. */
122 ConfParameter& m_confParam;
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600123 /*! m_io For canonization of faceUri. */
124 boost::asio::io_service m_io;
akmhoque53353462014-04-22 08:43:45 -0500125};
126
Nick Gordonfad8e252016-08-11 14:21:38 -0500127} // namespace nlsr
dmcoomese689dd62017-03-29 11:05:12 -0500128#endif // NLSR_CONF_FILE_PROCESSOR_HPP