31 const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
34 : m_forwarder(forwarder)
35 , m_isConfigured(false)
43 bind(&TablesConfigSection::processConfig,
this, _1, _2));
57 m_isConfigured =
true;
61 TablesConfigSection::processConfig(
const ConfigSection& section,
bool isDryRun)
63 size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
65 if (csMaxPacketsNode) {
66 nCsMaxPackets = ConfigFile::parseNumber<size_t>(*csMaxPacketsNode,
"cs_max_packets",
"tables");
69 unique_ptr<cs::Policy> csPolicy;
72 std::string policyName = csPolicyNode->get_value<std::string>();
74 if (csPolicy ==
nullptr) {
75 NDN_THROW(
ConfigFile::Error(
"Unknown cs_policy '" + policyName +
"' in section 'tables'"));
79 unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
80 OptionalConfigSection unsolicitedDataPolicyNode = section.get_child_optional(
"cs_unsolicited_policy");
81 if (unsolicitedDataPolicyNode) {
82 std::string policyName = unsolicitedDataPolicyNode->get_value<std::string>();
84 if (unsolicitedDataPolicy ==
nullptr) {
85 NDN_THROW(
ConfigFile::Error(
"Unknown cs_unsolicited_policy '" + policyName +
"' in section 'tables'"));
89 unsolicitedDataPolicy = make_unique<fw::DefaultUnsolicitedDataPolicy>();
93 if (strategyChoiceSection) {
94 processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
98 if (networkRegionSection) {
99 processNetworkRegionSection(*networkRegionSection, isDryRun);
108 if (cs.
size() == 0 && csPolicy !=
nullptr) {
114 m_isConfigured =
true;
118 TablesConfigSection::processStrategyChoiceSection(
const ConfigSection& section,
bool isDryRun)
122 std::map<Name, Name> choices;
123 for (
const auto& prefixAndStrategy : section) {
124 Name prefix(prefixAndStrategy.first);
125 Name strategy(prefixAndStrategy.second.get_value<std::string>());
127 if (!Strategy::canCreate(strategy)) {
129 "Unknown strategy '" + prefixAndStrategy.second.get_value<std::string>() +
130 "' for prefix '" + prefix.toUri() +
"' in section 'strategy_choice'"));
133 if (!choices.emplace(prefix, strategy).second) {
135 "Duplicate strategy choice for prefix '" + prefix.toUri() +
"' in section 'strategy_choice'"));
144 for (
const auto& prefixAndStrategy : choices) {
145 if (!sc.
insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
147 "Failed to set strategy '" + prefixAndStrategy.second.toUri() +
"' for prefix '" +
148 prefixAndStrategy.first.toUri() +
"' in section 'strategy_choice'"));
155 TablesConfigSection::processNetworkRegionSection(
const ConfigSection& section,
bool isDryRun)
163 for (
const auto& pair : section) {
164 nrt.insert(Name(pair.first));
Main class of NFD's forwarding engine.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
configuration file parsing utility
Represents the Strategy Choice table.
InsertResult insert(const Name &prefix, const Name &strategyName)
Set strategy of prefix to be strategyName.
StrategyChoice & getStrategyChoice()
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
static unique_ptr< Policy > create(const std::string &policyName)
TablesConfigSection(Forwarder &forwarder)
implements the Content Store
boost::property_tree::ptree ConfigSection
a config file section
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void ensureConfigured()
apply default configuration, if tables section was omitted in configuration file
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
void setConfigFile(ConfigFile &configFile)
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
size_t size() const
get number of stored packets
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Represents a forwarding strategy.
NetworkRegionTable & getNetworkRegionTable()