36 const size_t TablesConfigSection::DEFAULT_CS_MAX_PACKETS = 65536;
46 , m_strategyChoice(strategyChoice)
48 , m_areTablesConfigured(false)
57 bind(&TablesConfigSection::onConfig,
this, _1, _2, _3));
64 if (m_areTablesConfigured)
69 NFD_LOG_INFO(
"Setting CS max packets to " << DEFAULT_CS_MAX_PACKETS);
70 m_cs.
setLimit(DEFAULT_CS_MAX_PACKETS);
72 m_areTablesConfigured =
true;
76 TablesConfigSection::onConfig(
const ConfigSection& configSection,
78 const std::string& filename)
93 size_t nCsMaxPackets = DEFAULT_CS_MAX_PACKETS;
95 boost::optional<const ConfigSection&> csMaxPacketsNode =
96 configSection.get_child_optional(
"cs_max_packets");
100 boost::optional<size_t> valCsMaxPackets =
101 configSection.get_optional<
size_t>(
"cs_max_packets");
103 if (!valCsMaxPackets)
106 " in \"tables\" section");
109 nCsMaxPackets = *valCsMaxPackets;
112 boost::optional<const ConfigSection&> strategyChoiceSection =
113 configSection.get_child_optional(
"strategy_choice");
115 if (strategyChoiceSection)
117 processSectionStrategyChoice(*strategyChoiceSection, isDryRun);
122 NFD_LOG_INFO(
"Setting CS max packets to " << nCsMaxPackets);
125 m_areTablesConfigured =
true;
130 TablesConfigSection::processSectionStrategyChoice(
const ConfigSection& configSection,
141 std::map<Name, Name> choices;
143 for (
const auto& prefixAndStrategy : configSection)
145 const Name prefix(prefixAndStrategy.first);
146 if (choices.find(prefix) != choices.end())
148 throw ConfigFile::Error(
"Duplicate strategy choice for prefix \"" +
149 prefix.toUri() +
"\" in \"strategy_choice\" section");
152 const std::string strategyString(prefixAndStrategy.second.get_value<std::string>());
153 if (strategyString.empty())
155 throw ConfigFile::Error(
"Invalid strategy choice \"\" for prefix \"" +
156 prefix.toUri() +
"\" in \"strategy_choice\" section");
159 const Name strategyName(strategyString);
162 throw ConfigFile::Error(
"Invalid strategy choice \"" +
163 strategyName.toUri() +
"\" for prefix \"" +
164 prefix.toUri() +
"\" in \"strategy_choice\" section");
167 choices[prefix] = strategyName;
171 for (
const auto& prefixAndStrategy : choices)
173 if (!isDryRun && !m_strategyChoice.
insert(prefixAndStrategy.first, prefixAndStrategy.second))
175 throw ConfigFile::Error(
"Failed to set strategy \"" +
176 prefixAndStrategy.second.toUri() +
"\" for prefix \"" +
177 prefixAndStrategy.first.toUri() +
"\" in \"strategy_choicev\"");
TablesConfigSection(Cs &cs, Pit &pit, Fib &fib, StrategyChoice &strategyChoice, Measurements &measurements)
void ensureTablesAreConfigured()
represents the Strategy Choice table
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
represents the Interest Table
#define NFD_LOG_INFO(expression)
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
boost::property_tree::ptree ConfigSection
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
#define NFD_LOG_INIT(name)
void setConfigFile(ConfigFile &configFile)
void setLimit(size_t nMaxPackets)
sets maximum allowed size of Content Store (in packets)