31 #include <ndn-cxx/mgmt/nfd/strategy-choice.hpp>
33 #include <boost/lexical_cast.hpp>
40 Dispatcher& dispatcher,
42 :
ManagerBase(
"strategy-choice", dispatcher, authenticator)
43 , m_table(strategyChoice)
45 registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>(
"set",
46 std::bind(&StrategyChoiceManager::setStrategy,
this, _4, _5));
47 registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>(
"unset",
48 std::bind(&StrategyChoiceManager::unsetStrategy,
this, _4, _5));
51 std::bind(&StrategyChoiceManager::listChoices,
this, _3));
55 StrategyChoiceManager::setStrategy(ControlParameters parameters,
56 const ndn::mgmt::CommandContinuation& done)
58 const Name& prefix = parameters.getName();
59 const Name& strategy = parameters.getStrategy();
63 NFD_LOG_DEBUG(
"strategy-choice/set(" << prefix <<
"," << strategy <<
"): cannot-create " << res);
64 return done(ControlResponse(res.
getStatusCode(), boost::lexical_cast<std::string>(res)));
67 NFD_LOG_DEBUG(
"strategy-choice/set(" << prefix <<
"," << strategy <<
"): OK");
68 auto [hasEntry, instanceName] = m_table.
get(prefix);
69 BOOST_ASSERT_MSG(hasEntry,
"StrategyChoice entry must exist after StrategyChoice::insert");
70 parameters.setStrategy(instanceName);
71 return done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
75 StrategyChoiceManager::unsetStrategy(ControlParameters parameters,
76 const ndn::mgmt::CommandContinuation& done)
78 const Name& prefix = parameters.getName();
81 m_table.
erase(parameters.getName());
84 done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
88 StrategyChoiceManager::listChoices(ndn::mgmt::StatusDatasetContext& context)
90 for (
const auto& i : m_table) {
91 ndn::nfd::StrategyChoice entry;
92 entry.setName(i.getPrefix())
93 .setStrategy(i.getStrategyInstanceName());
94 context.append(entry.wireEncode());
Provides ControlCommand authorization according to NFD's configuration file.
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
StrategyChoiceManager(strategy_choice::StrategyChoice &table, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
int getStatusCode() const
Get a status code for use in management command response.
Represents the Strategy Choice table.
void erase(const Name &prefix)
Make prefix to inherit strategy from its parent.
InsertResult insert(const Name &prefix, const Name &strategyName)
Set strategy of prefix to be strategyName.
std::pair< bool, Name > get(const Name &prefix) const
Get strategy Name of prefix.
#define NFD_LOG_INIT(name)