mgmt: use strategy registry in TablesConfigSection
refs #3868
Change-Id: I3500505f11d8dbfa37bb57c283bd4847ab0f11e5
diff --git a/daemon/mgmt/tables-config-section.cpp b/daemon/mgmt/tables-config-section.cpp
index 7d355d0..fcd0916 100644
--- a/daemon/mgmt/tables-config-section.cpp
+++ b/daemon/mgmt/tables-config-section.cpp
@@ -24,6 +24,7 @@
*/
#include "tables-config-section.hpp"
+#include "fw/strategy.hpp"
namespace nfd {
@@ -120,15 +121,14 @@
void
TablesConfigSection::processStrategyChoiceSection(const ConfigSection& section, bool isDryRun)
{
- StrategyChoice& sc = m_forwarder.getStrategyChoice();
+ using fw::Strategy;
std::map<Name, Name> choices;
-
for (const auto& prefixAndStrategy : section) {
Name prefix(prefixAndStrategy.first);
Name strategy(prefixAndStrategy.second.get_value<std::string>());
- if (!sc.hasStrategy(strategy)) {
+ if (!Strategy::canCreate(strategy)) {
BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unknown strategy \"" + prefixAndStrategy.second.get_value<std::string>() +
"\" for prefix \"" + prefix.toUri() + "\" in \"strategy_choice\" section"));
@@ -145,6 +145,7 @@
return;
}
+ StrategyChoice& sc = m_forwarder.getStrategyChoice();
for (const auto& prefixAndStrategy : choices) {
if (!sc.insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
BOOST_THROW_EXCEPTION(ConfigFile::Error(
@@ -152,6 +153,7 @@
"prefix \"" + prefixAndStrategy.first.toUri() + "\" in \"strategy_choicev\""));
}
}
+ ///\todo redesign so that strategy parameter errors can be catched during dry-run
}
void
diff --git a/tests/daemon/mgmt/tables-config-section.t.cpp b/tests/daemon/mgmt/tables-config-section.t.cpp
index c0edbab..32aab40 100644
--- a/tests/daemon/mgmt/tables-config-section.t.cpp
+++ b/tests/daemon/mgmt/tables-config-section.t.cpp
@@ -393,6 +393,22 @@
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
}
+BOOST_AUTO_TEST_CASE(UnacceptableParameters)
+{
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ / /localhost/nfd/strategy/best-route/%FD%01/param
+ }
+ }
+ )CONFIG";
+
+ BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
+ BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
+}
+
BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
BOOST_AUTO_TEST_SUITE(NetworkRegion)