mgmt,main: configure tables with defaults when missing config section/values
refs: #1743
Change-Id: Id0c24bd2b2e86df763892d194f9c04777a369d0c
diff --git a/daemon/mgmt/tables-config-section.cpp b/daemon/mgmt/tables-config-section.cpp
index 0efa02d..124a2d3 100644
--- a/daemon/mgmt/tables-config-section.cpp
+++ b/daemon/mgmt/tables-config-section.cpp
@@ -33,6 +33,8 @@
NFD_LOG_INIT("TablesConfigSection");
+const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
+
TablesConfigSection::TablesConfigSection(Cs& cs,
Pit& pit,
Fib& fib,
@@ -43,11 +45,32 @@
// , m_fib(fib)
// , m_strategyChoice(strategyChoice)
// , m_measurements(measurements)
+ , m_areTablesConfigured(false)
{
}
void
+TablesConfigSection::setConfigFile(ConfigFile& configFile)
+{
+ configFile.addSectionHandler("tables",
+ bind(&TablesConfigSection::onConfig, this, _1, _2, _3));
+}
+
+
+void
+TablesConfigSection::ensureTablesAreConfigured()
+{
+ if (m_areTablesConfigured)
+ {
+ return;
+ }
+
+ NFD_LOG_INFO("Setting CS max packets to " << DEFAULT_CS_MAX_PACKETS);
+ m_cs.setLimit(DEFAULT_CS_MAX_PACKETS);
+}
+
+void
TablesConfigSection::onConfig(const ConfigSection& configSection,
bool isDryRun,
const std::string& filename)
@@ -57,6 +80,8 @@
// cs_max_packets 65536
// }
+ size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
+
boost::optional<const ConfigSection&> csMaxPacketsNode =
configSection.get_child_optional("cs_max_packets");
@@ -70,18 +95,17 @@
throw ConfigFile::Error("Invalid value for option \"cs_max_packets\""
" in \"tables\" section");
}
- else if (!isDryRun)
- {
- m_cs.setLimit(*valCsMaxPackets);
- }
- }
-}
-void
-TablesConfigSection::setConfigFile(ConfigFile& configFile)
-{
- configFile.addSectionHandler("tables",
- bind(&TablesConfigSection::onConfig, this, _1, _2, _3));
+ nCsMaxPackets = *valCsMaxPackets;
+ }
+
+ if (!isDryRun)
+ {
+ NFD_LOG_INFO("Setting CS max packets to " << nCsMaxPackets);
+
+ m_cs.setLimit(nCsMaxPackets);
+ m_areTablesConfigured = true;
+ }
}
} // namespace nfd