36 : m_forwarder(forwarder)
37 , m_isConfigured(false)
45 processConfig(std::forward<decltype(args)>(args)...);
60 m_isConfigured =
true;
64 TablesConfigSection::processConfig(
const ConfigSection& section,
bool isDryRun,
const std::string&)
68 if (csMaxPacketsNode) {
69 nCsMaxPackets = ConfigFile::parseNumber<size_t>(*csMaxPacketsNode,
"cs_max_packets",
"tables");
72 unique_ptr<cs::Policy> csPolicy;
75 std::string policyName = csPolicyNode->get_value<std::string>();
77 if (csPolicy ==
nullptr) {
78 NDN_THROW(ConfigFile::Error(
"Unknown cs_policy '" + policyName +
"' in section 'tables'"));
82 unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
83 OptionalConfigSection unsolicitedDataPolicyNode = section.get_child_optional(
"cs_unsolicited_policy");
84 if (unsolicitedDataPolicyNode) {
85 std::string policyName = unsolicitedDataPolicyNode->get_value<std::string>();
87 if (unsolicitedDataPolicy ==
nullptr) {
88 NDN_THROW(ConfigFile::Error(
"Unknown cs_unsolicited_policy '" + policyName +
"' in section 'tables'"));
92 unsolicitedDataPolicy = make_unique<fw::DefaultUnsolicitedDataPolicy>();
96 if (strategyChoiceSection) {
97 processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
101 if (networkRegionSection) {
102 processNetworkRegionSection(*networkRegionSection, isDryRun);
109 Cs& cs = m_forwarder.
getCs();
111 if (cs.size() == 0 && csPolicy !=
nullptr) {
112 cs.setPolicy(std::move(csPolicy));
117 m_isConfigured =
true;
121 TablesConfigSection::processStrategyChoiceSection(
const ConfigSection& section,
bool isDryRun)
123 std::map<Name, Name> choices;
124 for (
const auto& prefixAndStrategy : section) {
125 Name prefix(prefixAndStrategy.first);
126 Name strategy(prefixAndStrategy.second.get_value<std::string>());
129 NDN_THROW(ConfigFile::Error(
"Unknown strategy '" + prefixAndStrategy.second.get_value<std::string>() +
130 "' for prefix '" + prefix.toUri() +
"' in section 'strategy_choice'"));
133 if (!choices.try_emplace(prefix, std::move(strategy)).second) {
134 NDN_THROW(ConfigFile::Error(
"Duplicate strategy choice for prefix '" + prefix.toUri() +
135 "' in section 'strategy_choice'"));
144 for (
const auto& prefixAndStrategy : choices) {
145 if (!sc.insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
146 NDN_THROW(ConfigFile::Error(
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));
Configuration file parsing utility.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
Setup notification of configuration file sections.
Main class of NFD's forwarding engine.
NetworkRegionTable & getNetworkRegionTable() noexcept
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy) noexcept
StrategyChoice & getStrategyChoice() noexcept
void setConfigFile(ConfigFile &configFile)
TablesConfigSection(Forwarder &forwarder)
void ensureConfigured()
Apply default configuration, if tables section was omitted in configuration file.
void setLimit(size_t nMaxPackets)
Change capacity (in number of packets).
static unique_ptr< Policy > create(const std::string &policyName)
Returns a cs::Policy identified by policyName, or nullptr if policyName is unknown.
static bool canCreate(const Name &instanceName)
Returns whether a strategy instance can be created from instanceName.
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
boost::optional< const ConfigSection & > OptionalConfigSection
An optional configuration file section.
boost::property_tree::ptree ConfigSection
A configuration file section.
constexpr size_t DEFAULT_CS_MAX_PACKETS