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);
106 Cs& cs = m_forwarder.
getCs();
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));