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)
105 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Invalid value for option \"cs_max_packets\"" 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);
124 m_cs.setLimit(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 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Duplicate strategy choice for prefix \"" +
149 prefix.
toUri() +
"\" in \"strategy_choice\" " 153 const std::string strategyString(prefixAndStrategy.second.get_value<std::string>());
154 if (strategyString.empty())
156 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Invalid strategy choice \"\" for prefix \"" +
157 prefix.
toUri() +
"\" in \"strategy_choice\" " 161 const Name strategyName(strategyString);
165 strategyName.
toUri() +
"\" for prefix \"" +
166 prefix.
toUri() +
"\" in \"strategy_choice\" " 170 choices[prefix] = strategyName;
174 for (
const auto& prefixAndStrategy : choices)
176 if (!isDryRun && !m_strategyChoice.
insert(prefixAndStrategy.first, prefixAndStrategy.second))
179 prefixAndStrategy.second.toUri() +
"\" for " 180 "prefix \"" + prefixAndStrategy.first.toUri() +
181 "\" 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 Measurements table
represents the Interest Table
std::string toUri() const
Encode this name as a URI.
#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
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
#define NFD_LOG_INIT(name)
void setConfigFile(ConfigFile &configFile)