blob: 1f0918a060521783cd24e7f13a1f3ae71b6f956d [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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 Gordond0a7df32017-05-30 16:44:34 -050024#include "nlsr.hpp"
25
akmhoque157b0a42014-05-13 00:26:37 -050026#include <boost/smart_ptr/shared_ptr.hpp>
27#include <boost/property_tree/ptree.hpp>
akmhoquefdbddb12014-05-02 18:35:19 -050028#include <boost/cstdint.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050029
akmhoque53353462014-04-22 08:43:45 -050030namespace nlsr {
akmhoqueb6450b12014-04-24 00:01:03 -050031
Nick Gordond0a7df32017-05-30 16:44:34 -050032/*! \brief A class containing methods to parse an NLSR configuration file
33 *
34 * This class contains methods to parse an NLSR configuration file and
35 * set all the parameters in NLSR to the received values. There are
36 * defaults for any unconfigured settings.
37 *
38 * This is currently called by the wrapper class NlsrRunner to
39 * populate the NLSR object with its configuration before NLSR is
40 * started.
41 *
42 * \sa nlsr::ConfParameter
43 * \sa NlsrRunner::run
44 */
akmhoque53353462014-04-22 08:43:45 -050045class ConfFileProcessor
46{
47public:
akmhoquefdbddb12014-05-02 18:35:19 -050048 ConfFileProcessor(Nlsr& nlsr, const std::string& cfile)
akmhoqueb6450b12014-04-24 00:01:03 -050049 : m_confFileName(cfile)
50 , m_nlsr(nlsr)
akmhoque53353462014-04-22 08:43:45 -050051 {
52 }
53
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:
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070065 typedef boost::property_tree::ptree ConfigSection;
66
Nick Gordond0a7df32017-05-30 16:44:34 -050067 /*! \brief Parse the configuration file into a tree and process the nodes.
68 *
69 * Reads the configuration file as a property tree, and then iterates
70 * over them, attempting to parse each node. The nodes themselves
71 * are passed to another function that determines what kind of
72 * section it is and handles it appropriately. On any error in
73 * reading the file, return false.
74 *
75 * \return Whether configuration was successful.
76 */
akmhoque157b0a42014-05-13 00:26:37 -050077 bool
78 load(std::istream& input);
akmhoque53353462014-04-22 08:43:45 -050079
Nick Gordond0a7df32017-05-30 16:44:34 -050080 /*! \brief A dispatcher-like function to send configuration tree nodes to the right subfunction.
81 */
akmhoque157b0a42014-05-13 00:26:37 -050082 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070083 processSection(const std::string& sectionName, const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050084
Nick Gordond0a7df32017-05-30 16:44:34 -050085 /*! \brief Parse general options, including router name, logging directory, LSA refresh.
86 */
akmhoque157b0a42014-05-13 00:26:37 -050087 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070088 processConfSectionGeneral(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050089
Nick Gordond0a7df32017-05-30 16:44:34 -050090 /*! \brief Configure options relating to neighbor configuration and detection.
91 *
92 * Parse options that control NLSR's behavior about neighbors. Such
93 * things include how many hello interests are sent and what their
94 * timeout is, as well as parsing neighbor specifications. Neighbor
95 * Face URIs are parsed and confirmed as valid here by ndn-cxx.
96 */
akmhoque157b0a42014-05-13 00:26:37 -050097 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -070098 processConfSectionNeighbors(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -050099
Nick Gordond0a7df32017-05-30 16:44:34 -0500100 /*! \brief Set the state of hyperbolic routing: off, on, dry-run.
101 */
akmhoque157b0a42014-05-13 00:26:37 -0500102 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700103 processConfSectionHyperbolic(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500104
Nick Gordond0a7df32017-05-30 16:44:34 -0500105 /*! \brief Set options for the FIB: nexthops per prefix, routing calculation interval.
106 */
akmhoque157b0a42014-05-13 00:26:37 -0500107 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700108 processConfSectionFib(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500109
Nick Gordond0a7df32017-05-30 16:44:34 -0500110 /*! \brief Set prefixes that NLSR is supposed to advertise immediately.
111 */
akmhoque157b0a42014-05-13 00:26:37 -0500112 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700113 processConfSectionAdvertising(const ConfigSection& section);
akmhoque53353462014-04-22 08:43:45 -0500114
Nick Gordond0a7df32017-05-30 16:44:34 -0500115 /*! \brief Parse and set rules for the validator.
116 *
117 * This section parses and sets rules for the validators, which
118 * control what criteria Interest and Data need to follow to be
119 * considered valid by this NLSR.
120 */
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700121 bool
Alexander Afanasyev8388ec62014-08-16 18:38:57 -0700122 processConfSectionSecurity(const ConfigSection& section);
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700123
akmhoque53353462014-04-22 08:43:45 -0500124private:
Nick Gordond0a7df32017-05-30 16:44:34 -0500125 /*! m_confFileName The full path of the configuration file to parse. */
akmhoquefdbddb12014-05-02 18:35:19 -0500126 std::string m_confFileName;
Nick Gordond0a7df32017-05-30 16:44:34 -0500127 /*! m_nlsr The NLSR object to configure upon successful parsing. */
akmhoqueb6450b12014-04-24 00:01:03 -0500128 Nlsr& m_nlsr;
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