30 const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
33 : m_forwarder(forwarder)
34 , m_isConfigured(false)
42 bind(&TablesConfigSection::processConfig,
this, _1, _2));
55 m_isConfigured =
true;
59 TablesConfigSection::processConfig(
const ConfigSection& section,
bool isDryRun)
61 typedef boost::optional<const ConfigSection&> OptionalNode;
63 size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
64 OptionalNode csMaxPacketsNode = section.get_child_optional(
"cs_max_packets");
65 if (csMaxPacketsNode) {
66 nCsMaxPackets = ConfigFile::parseNumber<size_t>(*csMaxPacketsNode,
"cs_max_packets",
"tables");
69 unique_ptr<fw::UnsolicitedDataPolicy> unsolicitedDataPolicy;
70 OptionalNode unsolicitedDataPolicyNode = section.get_child_optional(
"cs_unsolicited_policy");
71 if (unsolicitedDataPolicyNode) {
72 std::string policyKey = unsolicitedDataPolicyNode->get_value<std::string>();
74 if (unsolicitedDataPolicy ==
nullptr) {
76 "Unknown cs_unsolicited_policy \"" + policyKey +
"\" in \"tables\" section"));
80 unsolicitedDataPolicy = make_unique<fw::DefaultUnsolicitedDataPolicy>();
83 OptionalNode strategyChoiceSection = section.get_child_optional(
"strategy_choice");
84 if (strategyChoiceSection) {
85 processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
88 OptionalNode networkRegionSection = section.get_child_optional(
"network_region");
89 if (networkRegionSection) {
90 processNetworkRegionSection(*networkRegionSection, isDryRun);
101 m_isConfigured =
true;
105 TablesConfigSection::processStrategyChoiceSection(
const ConfigSection& section,
bool isDryRun)
109 std::map<Name, Name> choices;
111 for (
const auto& prefixAndStrategy : section) {
112 Name prefix(prefixAndStrategy.first);
113 Name strategy(prefixAndStrategy.second.get_value<std::string>());
117 "Unknown strategy \"" + prefixAndStrategy.second.get_value<std::string>() +
118 "\" for prefix \"" + prefix.
toUri() +
"\" in \"strategy_choice\" section"));
121 if (!choices.emplace(prefix, strategy).second) {
123 "Duplicate strategy choice for prefix \"" + prefix.
toUri() +
124 "\" in \"strategy_choice\" section"));
132 for (
const auto& prefixAndStrategy : choices) {
133 if (!sc.
insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
135 "Failed to set strategy \"" + prefixAndStrategy.second.toUri() +
"\" for " 136 "prefix \"" + prefixAndStrategy.first.toUri() +
"\" in \"strategy_choicev\""));
142 TablesConfigSection::processNetworkRegionSection(
const ConfigSection& section,
bool isDryRun)
150 for (
const auto& pair : section) {
151 Name region(pair.first);
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
std::string toUri() const
Encode this name as a URI.
configuration file parsing utility
void ensureConfigured()
apply default configuration, if tables section was omitted in configuration file
stores a collection of producer region names
StrategyChoice & getStrategyChoice()
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
represents the Strategy Choice table
NetworkRegionTable & getNetworkRegionTable()
void setConfigFile(ConfigFile &configFile)
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &key)
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
TablesConfigSection(Forwarder &forwarder)