35 const Name StrategyChoiceManager::COMMAND_PREFIX =
"/localhost/nfd/strategy-choice";
37 const size_t StrategyChoiceManager::COMMAND_UNSIGNED_NCOMPS =
38 StrategyChoiceManager::COMMAND_PREFIX.
size() +
42 const size_t StrategyChoiceManager::COMMAND_SIGNED_NCOMPS =
43 StrategyChoiceManager::COMMAND_UNSIGNED_NCOMPS +
46 const Name StrategyChoiceManager::LIST_DATASET_PREFIX(
"/localhost/nfd/strategy-choice/list");
49 shared_ptr<InternalFace> face,
50 ndn::KeyChain& keyChain)
52 , m_strategyChoice(strategyChoice)
53 , m_listPublisher(strategyChoice, *m_face, LIST_DATASET_PREFIX, keyChain)
55 face->setInterestFilter(
"/localhost/nfd/strategy-choice",
68 const size_t commandNComps = command.
size();
70 if (command == LIST_DATASET_PREFIX)
72 listStrategies(request);
75 else if (commandNComps <= COMMAND_PREFIX.
size())
83 if (COMMAND_UNSIGNED_NCOMPS <= commandNComps &&
84 commandNComps < COMMAND_SIGNED_NCOMPS)
91 else if (commandNComps < COMMAND_SIGNED_NCOMPS ||
100 bind(&StrategyChoiceManager::onValidatedStrategyChoiceRequest,
this, _1),
105 StrategyChoiceManager::listStrategies(
const Interest& request)
111 StrategyChoiceManager::onValidatedStrategyChoiceRequest(
const shared_ptr<const Interest>& request)
116 const Name& command = request->getName();
128 if (verb == VERB_SET)
130 setStrategy(parameters, response);
132 else if (verb == VERB_UNSET)
134 unsetStrategy(parameters, response);
153 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: malformed");
161 if (!m_strategyChoice.
hasStrategy(selectedStrategy))
163 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: unknown-strategy: " 165 setResponse(response, 504,
"Unsupported strategy");
169 if (m_strategyChoice.
insert(prefix, selectedStrategy))
172 auto currentStrategyChoice = m_strategyChoice.
get(prefix);
173 BOOST_ASSERT(currentStrategyChoice.first);
174 parameters.
setStrategy(currentStrategyChoice.second);
179 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: not-installed");
180 setResponse(response, 405,
"Strategy not installed");
192 static const Name ROOT_PREFIX;
195 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: unset-root");
196 setResponse(response, 403,
"Cannot unset root prefix strategy");
200 NFD_LOG_DEBUG(
"strategy-choice result: FAIL reason: malformed");
represents a strategy-choice/set command
const Name & getName() const
const Name & getStrategy() const
#define NFD_LOG_DEBUG(expression)
represents the Strategy Choice table
represents parameters in a ControlCommand request or response
bool insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
void sendResponse(const Name &name, const ControlResponse &response)
represents an Interest packet
represents a strategy-choice/set command
ControlParameters & setStrategy(const Name &strategy)
std::pair< bool, Name > get(const Name &prefix) const
get strategy Name of prefix
size_t wireEncode(EncodingImpl< TAG > &encoder) const
static bool extractParameters(const Name::Component ¶meterComponent, ControlParameters &extractedParameters)
ndn::mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
void erase(const Name &prefix)
make prefix to inherit strategy from its parent
void onStrategyChoiceRequest(const Interest &request)
const Name & getName() const
void onCommandValidationFailed(const shared_ptr< const Interest > &command, const std::string &error)
size_t size() const
Get the number of components.
Name abstraction to represent an absolute name.
StrategyChoiceManager(StrategyChoice &strategyChoice, shared_ptr< InternalFace > face, ndn::KeyChain &keyChain)
bool hasStrategy(const Name &strategyName, bool isExact=false) const
determines if a strategy is installed
virtual ~StrategyChoiceManager()
Component holds a read-only name component value.
#define NFD_LOG_INIT(name)
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
void setResponse(ControlResponse &response, uint32_t code, const std::string &text)
virtual bool validateParameters(const ControlCommand &command, ControlParameters ¶meters)
const std::string STRATEGY_CHOICE_PRIVILEGE
void validate(const Interest &interest, const ndn::OnInterestValidated &onValidated, const ndn::OnInterestValidationFailed &onValidationFailed)
const Component & at(ssize_t i) const
Get component at the specified index.