mgmt: tables.cs_policy config option

refs #3148

Change-Id: Icf30bbe508c1c491949d9fcb433fdfa16842d312
This commit is contained in:
Junxiao Shi committed 2016-12-07 19:59:18 +00:00
1 parent a88911105c
commit b4a5acd890
6 files changed
+79 -12

No files matched your search

+20 -4
View File
@@ -50,6 +50,7 @@ TablesConfigSection::ensureConfigured()
}
m_forwarder.getCs().setLimit(DEFAULT_CS_MAX_PACKETS);
// Don't set default cs_policy because it's already created by CS itself.
m_forwarder.setUnsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>());
m_isConfigured = true;
@@ -66,14 +67,25 @@ TablesConfigSection::processConfig(const ConfigSection& section, bool isDryRun)
nCsMaxPackets = ConfigFile::parseNumber<size_t>(*csMaxPacketsNode, "cs_max_packets", "tables");
}
unique_ptr<cs::Policy> csPolicy;
OptionalNode csPolicyNode = section.get_child_optional("cs_policy");
if (csPolicyNode) {
std::string policyName = csPolicyNode->get_value<std::string>();
csPolicy = cs::Policy::create(policyName);
if (csPolicy == nullptr) {
BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unknown cs_policy \"" + policyName + "\" in \"tables\" section"));
}
}
unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
OptionalNode unsolicitedDataPolicyNode = section.get_child_optional("cs_unsolicited_policy");
if (unsolicitedDataPolicyNode) {
std::string policyKey = unsolicitedDataPolicyNode->get_value<std::string>();
unsolicitedDataPolicy = fw::UnsolicitedDataPolicy::create(policyKey);
std::string policyName = unsolicitedDataPolicyNode->get_value<std::string>();
unsolicitedDataPolicy = fw::UnsolicitedDataPolicy::create(policyName);
if (unsolicitedDataPolicy == nullptr) {
BOOST_THROW_EXCEPTION(ConfigFile::Error(
"Unknown cs_unsolicited_policy \"" + policyKey + "\" in \"tables\" section"));
"Unknown cs_unsolicited_policy \"" + policyName + "\" in \"tables\" section"));
}
}
else {
@@ -94,7 +106,11 @@ TablesConfigSection::processConfig(const ConfigSection& section, bool isDryRun)
return;
}
m_forwarder.getCs().setLimit(nCsMaxPackets);
Cs& cs = m_forwarder.getCs();
cs.setLimit(nCsMaxPackets);
if (cs.size() == 0 && csPolicy != nullptr) {
cs.setPolicy(std::move(csPolicy));
}
m_forwarder.setUnsolicitedDataPolicy(std::move(unsolicitedDataPolicy));
+2 -2
View File
@@ -38,7 +38,7 @@ namespace nfd {
* tables
* {
* cs_max_packets 65536
*
* cs_policy priority_fifo
* cs_unsolicited_policy drop-all
*
* strategy_choice
@@ -58,7 +58,7 @@ namespace nfd {
* \endcode
*
* During a configuration reload,
* \li cs_max_packets and cs_unsolicited_policy are applied;
* \li cs_max_packets, cs_policy, and cs_unsolicited_policy are applied;
* defaults are used if an option is omitted.
* \li strategy_choice entries are inserted, but old entries are not deleted.
* \li network_region is applied; it's kept unchanged if the section is omitted.
+2 -2
View File
@@ -51,9 +51,9 @@ makeDefaultPolicy()
return Policy::create(DEFAULT_POLICY);
}
Cs::Cs(size_t nMaxPackets, unique_ptr<Policy> policy)
Cs::Cs(size_t nMaxPackets)
{
this->setPolicyImpl(std::move(policy));
this->setPolicyImpl(makeDefaultPolicy());
m_policy->setLimit(nMaxPackets);
}
+1 -4
View File
@@ -57,16 +57,13 @@
namespace nfd {
namespace cs {
unique_ptr<Policy>
makeDefaultPolicy();
/** \brief represents the ContentStore
*/
class Cs : noncopyable
{
public:
explicit
Cs(size_t nMaxPackets = 10, unique_ptr<Policy> policy = makeDefaultPolicy());
Cs(size_t nMaxPackets = 10);
/** \brief inserts a Data packet
*/
+4
View File
@@ -49,6 +49,10 @@ tables
; default is 65536, about 500MB with 8KB packet size
cs_max_packets 65536
; Set the CS replacement policy.
; Available policies are: priority_fifo, lru
cs_policy priority_fifo
; Set a policy to decide whether to cache or drop unsolicited Data.
; Available policies are: drop-all, admit-local, admit-network, admit-all
cs_unsolicited_policy drop-all
@@ -25,6 +25,8 @@
#include "mgmt/tables-config-section.hpp"
#include "fw/forwarder.hpp"
#include "table/cs-policy-lru.hpp"
#include "table/cs-policy-priority-fifo.hpp"
#include "tests/test-common.hpp"
#include "tests/check-typeid.hpp"
@@ -141,6 +143,54 @@ BOOST_AUTO_TEST_CASE(InvalidValue)
BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
BOOST_AUTO_TEST_SUITE(CsPolicy)
BOOST_AUTO_TEST_CASE(Default)
{
const std::string CONFIG = R"CONFIG(
tables
{
}
)CONFIG";
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
cs::Policy* currentPolicy = cs.getPolicy();
NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
}
BOOST_AUTO_TEST_CASE(Known)
{
const std::string CONFIG = R"CONFIG(
tables
{
cs_policy lru
}
)CONFIG";
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
cs::Policy* currentPolicy = cs.getPolicy();
NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
currentPolicy = cs.getPolicy();
NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
}
BOOST_AUTO_TEST_CASE(Unknown)
{
const std::string CONFIG = R"CONFIG(
tables
{
cs_policy unknown
}
)CONFIG";
BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
}
BOOST_AUTO_TEST_SUITE_END() // CsPolicy
class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
{
protected: