28 #include <ndn-cxx/mgmt/nfd/strategy-choice.hpp>
35 Dispatcher& dispatcher,
38 , m_table(strategyChoice)
40 registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>(
"set",
41 bind(&StrategyChoiceManager::setStrategy,
this, _2, _3, _4, _5));
42 registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>(
"unset",
43 bind(&StrategyChoiceManager::unsetStrategy,
this, _2, _3, _4, _5));
46 bind(&StrategyChoiceManager::listChoices,
this, _1, _2, _3));
50 StrategyChoiceManager::setStrategy(
const Name& topPrefix,
const Interest& interest,
51 ControlParameters parameters,
52 const ndn::mgmt::CommandContinuation& done)
54 const Name& prefix = parameters.getName();
55 const Name& selectedStrategy = parameters.getStrategy();
58 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: unknown-strategy: "
59 << parameters.getStrategy());
60 return done(ControlResponse(504,
"Unsupported strategy"));
63 if (m_table.
insert(prefix, selectedStrategy)) {
65 auto currentStrategyChoice = m_table.
get(prefix);
66 BOOST_ASSERT(currentStrategyChoice.first);
67 parameters.setStrategy(currentStrategyChoice.second);
68 return done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
71 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: not-installed");
72 return done(ControlResponse(405,
"Strategy not installed"));
77 StrategyChoiceManager::unsetStrategy(
const Name& topPrefix,
const Interest& interest,
78 ControlParameters parameters,
79 const ndn::mgmt::CommandContinuation& done)
81 m_table.
erase(parameters.getName());
84 done(ControlResponse(200,
"OK").setBody(parameters.wireEncode()));
88 StrategyChoiceManager::listChoices(
const Name& topPrefix,
const Interest& interest,
89 ndn::mgmt::StatusDatasetContext& context)
91 for (
auto&& i : m_table) {
92 ndn::nfd::StrategyChoice entry;
93 entry.setName(i.getPrefix()).setStrategy(i.getStrategyName());
94 context.append(entry.wireEncode());
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
#define NFD_LOG_DEBUG(expression)
provides ControlCommand authorization according to NFD configuration file
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
StrategyChoiceManager(strategy_choice::StrategyChoice &table, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
#define NFD_LOG_INIT(name)
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
void erase(const Name &prefix)
make prefix to inherit strategy from its parent