mgmt: tables.cs_unsolicited_policy config option
This commit introduces tests/check-typeid.hpp which provides
unit testing tools to validate runtime type information.
refs #2181
Change-Id: I987c9875517001ea82878cbe2646839a03ad54f3
diff --git a/tests/daemon/mgmt/tables-config-section.t.cpp b/tests/daemon/mgmt/tables-config-section.t.cpp
index d87c6e6..139d61c 100644
--- a/tests/daemon/mgmt/tables-config-section.t.cpp
+++ b/tests/daemon/mgmt/tables-config-section.t.cpp
@@ -27,6 +27,7 @@
#include "fw/forwarder.hpp"
#include "tests/test-common.hpp"
+#include "tests/check-typeid.hpp"
#include "../fw/dummy-strategy.hpp"
#include "../fw/install-strategy.hpp"
@@ -35,205 +36,248 @@
class TablesConfigSectionFixture : protected BaseFixture
{
-public:
-
+protected:
TablesConfigSectionFixture()
- : m_cs(m_forwarder.getCs())
- , m_pit(m_forwarder.getPit())
- , m_fib(m_forwarder.getFib())
- , m_strategyChoice(m_forwarder.getStrategyChoice())
- , m_measurements(m_forwarder.getMeasurements())
- , m_networkRegionTable(m_forwarder.getNetworkRegionTable())
- , m_tablesConfig(m_forwarder)
+ : cs(forwarder.getCs())
+ , strategyChoice(forwarder.getStrategyChoice())
+ , networkRegionTable(forwarder.getNetworkRegionTable())
+ , tablesConfig(forwarder)
{
- m_tablesConfig.setConfigFile(m_config);
}
void
- runConfig(const std::string& CONFIG, bool isDryRun)
+ runConfig(const std::string& config, bool isDryRun)
{
- m_config.parse(CONFIG, isDryRun, "dummy-config");
+ ConfigFile cf;
+ tablesConfig.setConfigFile(cf);
+ cf.parse(config, isDryRun, "dummy-config");
}
protected:
- Forwarder m_forwarder;
+ Forwarder forwarder;
+ Cs& cs;
+ StrategyChoice& strategyChoice;
+ NetworkRegionTable& networkRegionTable;
- Cs& m_cs;
- Pit& m_pit;
- Fib& m_fib;
- StrategyChoice& m_strategyChoice;
- Measurements& m_measurements;
- NetworkRegionTable& m_networkRegionTable;
-
- TablesConfigSection m_tablesConfig;
- ConfigFile m_config;
+ TablesConfigSection tablesConfig;
};
-BOOST_FIXTURE_TEST_SUITE(Mgmt, TablesConfigSectionFixture)
-BOOST_AUTO_TEST_SUITE(TestTablesConfigSection)
+BOOST_AUTO_TEST_SUITE(Mgmt)
+BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
-BOOST_AUTO_TEST_CASE(ConfigureTablesWithDefaults)
+BOOST_AUTO_TEST_SUITE(CsMaxPackets)
+
+BOOST_AUTO_TEST_CASE(NoSection)
{
- const size_t initialLimit = m_cs.getLimit();
+ const size_t initialLimit = cs.getLimit();
- m_tablesConfig.ensureConfigured();
- BOOST_CHECK_NE(initialLimit, m_cs.getLimit());
+ tablesConfig.ensureConfigured();
+ BOOST_CHECK_NE(cs.getLimit(), initialLimit);
}
-BOOST_AUTO_TEST_CASE(EmptyTablesSection)
+BOOST_AUTO_TEST_CASE(Default)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ }
+ )CONFIG";
- const size_t nCsMaxPackets = m_cs.getLimit();
+ const size_t initialLimit = cs.getLimit();
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
- BOOST_CHECK_EQUAL(m_cs.getLimit(), nCsMaxPackets);
+ BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
- BOOST_CHECK_NE(m_cs.getLimit(), nCsMaxPackets);
-
- const size_t defaultLimit = m_cs.getLimit();
-
- m_tablesConfig.ensureConfigured();
- BOOST_CHECK_EQUAL(defaultLimit, m_cs.getLimit());
+ BOOST_CHECK_NE(cs.getLimit(), initialLimit);
}
-BOOST_AUTO_TEST_CASE(MissingTablesSection)
+BOOST_AUTO_TEST_CASE(Valid)
{
- const std::string CONFIG =
- "not_tables\n"
- "{\n"
- " some_other_field 0\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ cs_max_packets 101
+ }
+ )CONFIG";
- ConfigFile passiveConfig(&ConfigFile::ignoreUnknownSection);
-
- const size_t initialLimit = m_cs.getLimit();
-
- passiveConfig.parse(CONFIG, true, "dummy-config");
- BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit());
-
- passiveConfig.parse(CONFIG, false, "dummy-config");
- BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit());
-
- m_tablesConfig.ensureConfigured();
- BOOST_CHECK_NE(initialLimit, m_cs.getLimit());
-}
-
-BOOST_AUTO_TEST_SUITE(Cs)
-
-BOOST_AUTO_TEST_CASE(ValidCsMaxPackets)
-{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " cs_max_packets 101\n"
- "}\n";
-
- BOOST_REQUIRE_NE(m_cs.getLimit(), 101);
+ BOOST_REQUIRE_NE(cs.getLimit(), 101);
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
- BOOST_CHECK_NE(m_cs.getLimit(), 101);
+ BOOST_CHECK_NE(cs.getLimit(), 101);
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
- BOOST_CHECK_EQUAL(m_cs.getLimit(), 101);
+ BOOST_CHECK_EQUAL(cs.getLimit(), 101);
- m_tablesConfig.ensureConfigured();
- BOOST_CHECK_EQUAL(m_cs.getLimit(), 101);
+ tablesConfig.ensureConfigured();
+ BOOST_CHECK_EQUAL(cs.getLimit(), 101);
}
-BOOST_AUTO_TEST_CASE(MissingValueCsMaxPackets)
+BOOST_AUTO_TEST_CASE(MissingValue)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " cs_max_packets\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ cs_max_packets
+ }
+ )CONFIG";
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
}
-BOOST_AUTO_TEST_CASE(InvalidValueCsMaxPackets)
+BOOST_AUTO_TEST_CASE(InvalidValue)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " cs_max_packets invalid\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ cs_max_packets invalid
+ }
+ )CONFIG";
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
}
-BOOST_AUTO_TEST_SUITE_END() // Cs
+BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
-BOOST_AUTO_TEST_SUITE(ConfigStrategy)
+class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
+{
+protected:
+ class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
+ {
+ };
+
+ CsUnsolicitedPolicyFixture()
+ {
+ forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
+
+BOOST_AUTO_TEST_CASE(NoSection)
+{
+ tablesConfig.ensureConfigured();
+
+ fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
+ NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
+}
+
+BOOST_AUTO_TEST_CASE(Default)
+{
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ }
+ )CONFIG";
+
+ BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
+ fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
+ NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
+
+ BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
+ currentPolicy = &forwarder.getUnsolicitedDataPolicy();
+ NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
+}
+
+BOOST_AUTO_TEST_CASE(Known)
+{
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ cs_unsolicited_policy admit-all
+ }
+ )CONFIG";
+
+ BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
+ fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
+ NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
+
+ BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
+ currentPolicy = &forwarder.getUnsolicitedDataPolicy();
+ NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
+}
+
+BOOST_AUTO_TEST_CASE(Unknown)
+{
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ cs_unsolicited_policy unknown
+ }
+ )CONFIG";
+
+ BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
+ BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
+
+BOOST_AUTO_TEST_SUITE(StrategyChoice)
BOOST_AUTO_TEST_CASE(Unversioned)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " strategy_choice\n"
- " {\n"
- " / /localhost/nfd/strategy/test-strategy-a\n"
- " /a /localhost/nfd/strategy/test-strategy-b\n"
- " }\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ / /localhost/nfd/strategy/test-strategy-a
+ /a /localhost/nfd/strategy/test-strategy-b
+ }
+ }
+ )CONFIG";
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
{
- fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
+ fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
- fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
+ fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
}
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
{
- fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
+ fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
- fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
+ fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
}
}
BOOST_AUTO_TEST_CASE(Versioned)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- "strategy_choice\n"
- "{\n"
- " /test/latest /localhost/nfd/strategy/test-strategy-a\n"
- " /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01\n"
- "}\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ /test/latest /localhost/nfd/strategy/test-strategy-a
+ /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01
+ }
+ }
+ )CONFIG";
-
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01");
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02");
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
{
- fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
+ fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
BOOST_REQUIRE_NE(testLatestStrategy.getName(),
"/localhost/nfd/strategy/test-strategy-a/%FD%01");
BOOST_REQUIRE_NE(testLatestStrategy.getName(),
"/localhost/nfd/strategy/test-strategy-a/%FD%02");
- fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
+ fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
BOOST_REQUIRE_NE(testOldStrategy.getName(),
"/localhost/nfd/strategy/test-strategy-a/%FD%01");
BOOST_REQUIRE_NE(testOldStrategy.getName(),
@@ -242,11 +286,11 @@
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
{
- fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
+ fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(),
"/localhost/nfd/strategy/test-strategy-a/%FD%02");
- fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
+ fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
BOOST_REQUIRE_EQUAL(testOldStrategy.getName(),
"/localhost/nfd/strategy/test-strategy-a/%FD%01");
}
@@ -254,15 +298,15 @@
BOOST_AUTO_TEST_CASE(NonExisting)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " strategy_choice\n"
- " {\n"
- " / /localhost/nfd/strategy/test-doesnotexist\n"
- " }\n"
- "}\n";
-
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ / /localhost/nfd/strategy/test-doesnotexist
+ }
+ }
+ )CONFIG";
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
@@ -270,17 +314,17 @@
BOOST_AUTO_TEST_CASE(MissingPrefix)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " strategy_choice\n"
- " {\n"
- " /localhost/nfd/strategy/test-strategy-a\n"
- " }\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ /localhost/nfd/strategy/test-strategy-a
+ }
+ }
+ )CONFIG";
-
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
@@ -288,19 +332,20 @@
BOOST_AUTO_TEST_CASE(Duplicate)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " strategy_choice\n"
- " {\n"
- " / /localhost/nfd/strategy/test-strategy-a\n"
- " /a /localhost/nfd/strategy/test-strategy-b\n"
- " / /localhost/nfd/strategy/test-strategy-b\n"
- " }\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ strategy_choice
+ {
+ / /localhost/nfd/strategy/test-strategy-a
+ /a /localhost/nfd/strategy/test-strategy-b
+ / /localhost/nfd/strategy/test-strategy-b
+ }
+ }
+ )CONFIG";
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
- install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
+ install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
@@ -312,61 +357,65 @@
BOOST_AUTO_TEST_CASE(Basic)
{
- const std::string CONFIG =
- "tables\n"
- "{\n"
- " network_region\n"
- " {\n"
- " /test/regionA\n"
- " /test/regionB/component\n"
- " }\n"
- "}\n";
+ const std::string CONFIG = R"CONFIG(
+ tables
+ {
+ network_region
+ {
+ /test/regionA
+ /test/regionB/component
+ }
+ }
+ )CONFIG";
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
- BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 0);
+ BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
- BOOST_CHECK(m_networkRegionTable.find("/test/regionA") == m_networkRegionTable.end());
- BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") == m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
- BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 2);
+ BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
- BOOST_CHECK(m_networkRegionTable.find("/test/regionA") != m_networkRegionTable.end());
- BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") != m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
}
BOOST_AUTO_TEST_CASE(Reload)
{
- const std::string CONFIG1 =
- "tables\n"
- "{\n"
- " network_region\n"
- " {\n"
- " /some/region\n"
- " }\n"
- "}\n";
+ const std::string CONFIG1 = R"CONFIG(
+ tables
+ {
+ network_region
+ {
+ /some/region
+ }
+ }
+ )CONFIG";
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
- BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
- BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
- const std::string CONFIG2 =
- "tables\n"
- "{\n"
- " network_region\n"
- " {\n"
- " /different/region\n"
- " }\n"
- "}\n";
+ const std::string CONFIG2 = R"CONFIG(
+ tables
+ {
+ network_region
+ {
+ /different/region
+ }
+ }
+ )CONFIG";
+
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
- BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
- BOOST_CHECK(m_networkRegionTable.find("/different/region") == m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
- BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
- BOOST_CHECK(m_networkRegionTable.find("/different/region") != m_networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
+ BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
}
BOOST_AUTO_TEST_SUITE_END() // NetworkRegion