Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California, |
| 4 | * 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 |
| 10 | * |
| 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 | |
| 26 | #include "tables-config-section.hpp" |
| 27 | |
| 28 | #include "common.hpp" |
| 29 | #include "core/logger.hpp" |
| 30 | #include "core/config-file.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | NFD_LOG_INIT("TablesConfigSection"); |
| 35 | |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame^] | 36 | const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536; |
| 37 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 38 | TablesConfigSection::TablesConfigSection(Cs& cs, |
| 39 | Pit& pit, |
| 40 | Fib& fib, |
| 41 | StrategyChoice& strategyChoice, |
| 42 | Measurements& measurements) |
| 43 | : m_cs(cs) |
| 44 | // , m_pit(pit) |
| 45 | // , m_fib(fib) |
| 46 | // , m_strategyChoice(strategyChoice) |
| 47 | // , m_measurements(measurements) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame^] | 48 | , m_areTablesConfigured(false) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 49 | { |
| 50 | |
| 51 | } |
| 52 | |
| 53 | void |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame^] | 54 | TablesConfigSection::setConfigFile(ConfigFile& configFile) |
| 55 | { |
| 56 | configFile.addSectionHandler("tables", |
| 57 | bind(&TablesConfigSection::onConfig, this, _1, _2, _3)); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void |
| 62 | TablesConfigSection::ensureTablesAreConfigured() |
| 63 | { |
| 64 | if (m_areTablesConfigured) |
| 65 | { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | NFD_LOG_INFO("Setting CS max packets to " << DEFAULT_CS_MAX_PACKETS); |
| 70 | m_cs.setLimit(DEFAULT_CS_MAX_PACKETS); |
| 71 | } |
| 72 | |
| 73 | void |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 74 | TablesConfigSection::onConfig(const ConfigSection& configSection, |
| 75 | bool isDryRun, |
| 76 | const std::string& filename) |
| 77 | { |
| 78 | // tables |
| 79 | // { |
| 80 | // cs_max_packets 65536 |
| 81 | // } |
| 82 | |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame^] | 83 | size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS; |
| 84 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 85 | boost::optional<const ConfigSection&> csMaxPacketsNode = |
| 86 | configSection.get_child_optional("cs_max_packets"); |
| 87 | |
| 88 | if (csMaxPacketsNode) |
| 89 | { |
| 90 | boost::optional<size_t> valCsMaxPackets = |
| 91 | configSection.get_optional<size_t>("cs_max_packets"); |
| 92 | |
| 93 | if (!valCsMaxPackets) |
| 94 | { |
| 95 | throw ConfigFile::Error("Invalid value for option \"cs_max_packets\"" |
| 96 | " in \"tables\" section"); |
| 97 | } |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 98 | |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame^] | 99 | nCsMaxPackets = *valCsMaxPackets; |
| 100 | } |
| 101 | |
| 102 | if (!isDryRun) |
| 103 | { |
| 104 | NFD_LOG_INFO("Setting CS max packets to " << nCsMaxPackets); |
| 105 | |
| 106 | m_cs.setLimit(nCsMaxPackets); |
| 107 | m_areTablesConfigured = true; |
| 108 | } |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | } // namespace nfd |