36 const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
47 , m_strategyChoice(strategyChoice)
49 , m_networkRegionTable(networkRegionTable)
50 , m_areTablesConfigured(false)
59 bind(&TablesConfigSection::processConfig,
this, _1, _2, _3));
66 if (m_areTablesConfigured) {
70 NFD_LOG_INFO(
"Setting CS max packets to " << DEFAULT_CS_MAX_PACKETS);
71 m_cs.
setLimit(DEFAULT_CS_MAX_PACKETS);
73 m_areTablesConfigured =
true;
77 TablesConfigSection::processConfig(
const ConfigSection& configSection,
79 const std::string& filename)
100 size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
102 boost::optional<const ConfigSection&> csMaxPacketsNode =
103 configSection.get_child_optional(
"cs_max_packets");
105 if (csMaxPacketsNode) {
106 boost::optional<size_t> valCsMaxPackets =
107 configSection.get_optional<
size_t>(
"cs_max_packets");
109 if (!valCsMaxPackets) {
110 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Invalid value for option \"cs_max_packets\"" 111 " in \"tables\" section"));
114 nCsMaxPackets = *valCsMaxPackets;
117 boost::optional<const ConfigSection&> strategyChoiceSection =
118 configSection.get_child_optional(
"strategy_choice");
120 if (strategyChoiceSection) {
121 processStrategyChoiceSection(*strategyChoiceSection, isDryRun);
124 boost::optional<const ConfigSection&> networkRegionSection =
125 configSection.get_child_optional(
"network_region");
127 if (networkRegionSection) {
128 processNetworkRegionSection(*networkRegionSection, isDryRun);
132 NFD_LOG_INFO(
"Setting CS max packets to " << nCsMaxPackets);
135 m_areTablesConfigured =
true;
140 TablesConfigSection::processStrategyChoiceSection(
const ConfigSection& configSection,
151 std::map<Name, Name> choices;
153 for (
const auto& prefixAndStrategy : configSection) {
154 const Name prefix(prefixAndStrategy.first);
155 if (choices.find(prefix) != choices.end()) {
156 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Duplicate strategy choice for prefix \"" +
157 prefix.
toUri() +
"\" in \"strategy_choice\" " 161 const std::string strategyString(prefixAndStrategy.second.get_value<std::string>());
162 if (strategyString.empty()) {
163 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Invalid strategy choice \"\" for prefix \"" +
164 prefix.
toUri() +
"\" in \"strategy_choice\" " 168 const Name strategyName(strategyString);
171 strategyName.
toUri() +
"\" for prefix \"" +
172 prefix.
toUri() +
"\" in \"strategy_choice\" " 176 choices[prefix] = strategyName;
180 for (
const auto& prefixAndStrategy : choices) {
181 if (!isDryRun && !m_strategyChoice.
insert(prefixAndStrategy.first, prefixAndStrategy.second)) {
183 prefixAndStrategy.second.toUri() +
"\" for " 184 "prefix \"" + prefixAndStrategy.first.toUri() +
185 "\" in \"strategy_choicev\""));
191 TablesConfigSection::processNetworkRegionSection(
const ConfigSection& configSection,
201 m_networkRegionTable.clear();
204 for (
const auto& pair : configSection) {
205 const Name region(pair.first);
208 m_networkRegionTable.insert(region);
std::string toUri() const
Encode this name as a URI.
void ensureTablesAreConfigured()
represents the Strategy Choice table
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
stores a collection of producer region names
represents the Measurements table
represents the Interest Table
#define NFD_LOG_INFO(expression)
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.
represents the ContentStore
#define NFD_LOG_INIT(name)
void setConfigFile(ConfigFile &configFile)
TablesConfigSection(Cs &cs, Pit &pit, Fib &fib, StrategyChoice &strategyChoice, Measurements &measurements, NetworkRegionTable &networkRegionTable)