blob: f551b7893f8ec06fa3a4daf00e7ffe78df7bbe50 [file] [log] [blame]
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -07002/*
Davide Pesavento412c9822021-07-02 00:21:05 -04003 * Copyright (c) 2014-2021, Regents of the University of California,
Vince Lehman63ab1bb2015-09-04 17:06:58 -05004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040026#ifndef NFD_DAEMON_MGMT_TABLES_CONFIG_SECTION_HPP
27#define NFD_DAEMON_MGMT_TABLES_CONFIG_SECTION_HPP
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060028
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040029#include "common/config-file.hpp"
Junxiao Shi0cc125c2016-08-25 21:50:04 +000030#include "fw/forwarder.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060031
32namespace nfd {
33
Junxiao Shi0cc125c2016-08-25 21:50:04 +000034/** \brief handles 'tables' config section
Vince Lehman63ab1bb2015-09-04 17:06:58 -050035 *
Junxiao Shi0cc125c2016-08-25 21:50:04 +000036 * This class recognizes a config section that looks like
37 * \code{.unparsed}
38 * tables
39 * {
40 * cs_max_packets 65536
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -070041 * cs_policy lru
Junxiao Shi9685cc52016-08-29 12:47:05 +000042 * cs_unsolicited_policy drop-all
43 *
Junxiao Shi0cc125c2016-08-25 21:50:04 +000044 * strategy_choice
45 * {
46 * / /localhost/nfd/strategy/best-route
47 * /localhost /localhost/nfd/strategy/multicast
48 * /localhost/nfd /localhost/nfd/strategy/best-route
49 * /ndn/broadcast /localhost/nfd/strategy/multicast
50 * }
51 *
52 * network_region
53 * {
54 * /example/region1
55 * /example/region2
56 * }
57 * }
58 * \endcode
Junxiao Shi9685cc52016-08-29 12:47:05 +000059 *
60 * During a configuration reload,
Junxiao Shib4a5acd2016-12-07 19:59:18 +000061 * \li cs_max_packets, cs_policy, and cs_unsolicited_policy are applied;
Junxiao Shi9685cc52016-08-29 12:47:05 +000062 * defaults are used if an option is omitted.
63 * \li strategy_choice entries are inserted, but old entries are not deleted.
64 * \li network_region is applied; it's kept unchanged if the section is omitted.
65 *
66 * It's necessary to call \p ensureConfigured() after initial configuration and
67 * configuration reload, so that the correct defaults are applied in case
68 * tables section is omitted.
Vince Lehman63ab1bb2015-09-04 17:06:58 -050069 */
Junxiao Shi0cc125c2016-08-25 21:50:04 +000070class TablesConfigSection : noncopyable
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060071{
72public:
Junxiao Shi0cc125c2016-08-25 21:50:04 +000073 explicit
74 TablesConfigSection(Forwarder& forwarder);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060075
76 void
77 setConfigFile(ConfigFile& configFile);
78
Junxiao Shi0cc125c2016-08-25 21:50:04 +000079 /** \brief apply default configuration, if tables section was omitted in configuration file
80 */
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060081 void
Junxiao Shi0cc125c2016-08-25 21:50:04 +000082 ensureConfigured();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060083
84private:
Junxiao Shi0cc125c2016-08-25 21:50:04 +000085 void
Davide Pesavento412c9822021-07-02 00:21:05 -040086 processConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060087
88 void
Junxiao Shi0cc125c2016-08-25 21:50:04 +000089 processStrategyChoiceSection(const ConfigSection& section, bool isDryRun);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060090
Steve DiBenedettoc0640f52014-11-03 15:55:43 -070091 void
Junxiao Shi0cc125c2016-08-25 21:50:04 +000092 processNetworkRegionSection(const ConfigSection& section, bool isDryRun);
Vince Lehman63ab1bb2015-09-04 17:06:58 -050093
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060094private:
Junxiao Shi0cc125c2016-08-25 21:50:04 +000095 Forwarder& m_forwarder;
Junxiao Shi0cc125c2016-08-25 21:50:04 +000096 bool m_isConfigured;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060097};
98
99} // namespace nfd
100
Davide Pesavento2cae8ca2019-04-18 20:48:05 -0400101#endif // NFD_DAEMON_MGMT_TABLES_CONFIG_SECTION_HPP