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));
53 m_forwarder.
getCs().setLimit(DEFAULT_CS_MAX_PACKETS);
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) {
76 "Unknown cs_policy \"" + policyName +
"\" in \"tables\" section"));
80 unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
81 OptionalConfigSection unsolicitedDataPolicyNode = section.get_child_optional(
"cs_unsolicited_policy");
82 if (unsolicitedDataPolicyNode) {
83 std::string policyName = unsolicitedDataPolicyNode->get_value<std::string>();
85 if (unsolicitedDataPolicy ==
nullptr) {
87 "Unknown cs_unsolicited_policy \"" + policyName +
"\" in \"tables\" section"));
91 unsolicitedDataPolicy = make_unique<fw::DefaultUnsolicitedDataPolicy>();
95 if (strategyChoiceSection) {
96 processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
100 if (networkRegionSection) {
101 processNetworkRegionSection(*networkRegionSection, isDryRun);
108 Cs& cs = m_forwarder.
getCs();
109 cs.setLimit(nCsMaxPackets);
110 if (cs.size() == 0 && csPolicy !=
nullptr) {
111 cs.setPolicy(std::move(csPolicy));
116 m_isConfigured =
true;
120 TablesConfigSection::processStrategyChoiceSection(
const ConfigSection& section,
bool isDryRun)
124 std::map<Name, Name> choices;
125 for (
const auto& prefixAndStrategy : section) {
126 Name prefix(prefixAndStrategy.first);
127 Name strategy(prefixAndStrategy.second.get_value<std::string>());
129 if (!Strategy::canCreate(strategy)) {
131 "Unknown strategy \"" + prefixAndStrategy.second.get_value<std::string>() +
132 "\" for prefix \"" + prefix.toUri() +
"\" in \"strategy_choice\" section"));
135 if (!choices.emplace(prefix, strategy).second) {
137 "Duplicate strategy choice for prefix \"" + prefix.toUri() +
138 "\" in \"strategy_choice\" section"));
147 for (
const auto& prefixAndStrategy : choices) {
148 if (!sc.insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
150 "Failed to set strategy \"" + prefixAndStrategy.second.toUri() +
"\" for " 151 "prefix \"" + prefixAndStrategy.first.toUri() +
"\" in \"strategy_choicev\""));
158 TablesConfigSection::processNetworkRegionSection(
const ConfigSection& section,
bool isDryRun)
166 for (
const auto& pair : section) {
167 Name region(pair.first);
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
configuration file parsing utility
StrategyChoice & getStrategyChoice()
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
static unique_ptr< Policy > create(const std::string &policyName)
TablesConfigSection(Forwarder &forwarder)
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
stores a collection of producer region names
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
void setConfigFile(ConfigFile &configFile)
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
boost::property_tree::ptree ConfigSection
a config file section
represents a forwarding strategy
NetworkRegionTable & getNetworkRegionTable()