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 BOOST_THROW_EXCEPTION(ConfigFile::Error(
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) {
86 BOOST_THROW_EXCEPTION(ConfigFile::Error(
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();
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)) {
130 BOOST_THROW_EXCEPTION(ConfigFile::Error(
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) {
136 BOOST_THROW_EXCEPTION(ConfigFile::Error(
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)) {
149 BOOST_THROW_EXCEPTION(ConfigFile::Error(
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);
static unique_ptr< Policy > create(const std::string &policyName)
configuration file parsing utility
void ensureConfigured()
apply default configuration, if tables section was omitted in configuration file
StrategyChoice & getStrategyChoice()
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
static unique_ptr< UnsolicitedDataPolicy > create(const std::string &policyName)
void setLimit(size_t nMaxPackets)
change capacity (in number of packets)
boost::property_tree::ptree ConfigSection
a config file section
NetworkRegionTable & getNetworkRegionTable()
void setConfigFile(ConfigFile &configFile)
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
TablesConfigSection(Forwarder &forwarder)