mgmt: refactor management modules to conform to NFD Management Protocol
Refactor management protocol specific option types to ControlParameters
Add control parameter field enforcement
Add missing control response "success" message bodies
Update fib management protocol response codes and behavior
Merge local control header manager into face manager
Refactor references of nfd::LocalControlHeaderFeature enum to ndn::nfd::LocalControlFeature
Remove "control-header" privilege from default configuration
refs: #1397, #1399, #1400
Change-Id: Id042daf00b3cee1f1c7fa38d2e4a4ff6d95c15c6
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index cd4dc5b..bbedd34 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -17,7 +17,7 @@
const size_t StrategyChoiceManager::COMMAND_UNSIGNED_NCOMPS =
StrategyChoiceManager::COMMAND_PREFIX.size() +
1 + // verb
- 1; // verb options
+ 1; // verb parameters
const size_t StrategyChoiceManager::COMMAND_SIGNED_NCOMPS =
StrategyChoiceManager::COMMAND_UNSIGNED_NCOMPS +
@@ -71,23 +71,24 @@
static const Name::Component VERB_UNSET("unset");
const Name& command = request->getName();
+ const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1];
- ndn::nfd::StrategyChoiceOptions options;
- if (!extractOptions(*request, options))
+ ControlParameters parameters;
+ if (!extractParameters(parameterComponent, parameters) || !parameters.hasName())
{
sendResponse(command, 400, "Malformed command");
return;
}
- const Name::Component& verb = command.get(COMMAND_PREFIX.size());
+ const Name::Component& verb = command[COMMAND_PREFIX.size()];
ControlResponse response;
if (verb == VERB_SET)
{
- setStrategy(options, response);
+ setStrategy(parameters, response);
}
else if (verb == VERB_UNSET)
{
- unsetStrategy(options, response);
+ unsetStrategy(parameters, response);
}
else
{
@@ -97,47 +98,30 @@
sendResponse(command, response);
}
-bool
-StrategyChoiceManager::extractOptions(const Interest& request,
- ndn::nfd::StrategyChoiceOptions& extractedOptions)
-{
- const Name& command = request.getName();
- const size_t optionCompIndex =
- COMMAND_PREFIX.size() + 1;
-
- try
- {
- Block rawOptions = request.getName()[optionCompIndex].blockFromValue();
- extractedOptions.wireDecode(rawOptions);
- }
- catch (const ndn::Tlv::Error& e)
- {
- NFD_LOG_INFO("Bad command option parse: " << command);
- return false;
- }
-
- NFD_LOG_DEBUG("Options parsed OK");
- return true;
-}
-
void
-StrategyChoiceManager::setStrategy(const ndn::nfd::StrategyChoiceOptions& options,
+StrategyChoiceManager::setStrategy(const ControlParameters& parameters,
ControlResponse& response)
{
- const Name& prefix = options.getName();
- const Name& selectedStrategy = options.getStrategy();
+ if (!parameters.hasStrategy())
+ {
+ setResponse(response, 400, "Malformed command");
+ return;
+ }
+
+ const Name& prefix = parameters.getName();
+ const Name& selectedStrategy = parameters.getStrategy();
if (!m_strategyChoice.hasStrategy(selectedStrategy))
{
NFD_LOG_INFO("strategy-choice result: FAIL reason: unknown-strategy: "
- << options.getStrategy());
+ << parameters.getStrategy());
setResponse(response, 504, "Unsupported strategy");
return;
}
if (m_strategyChoice.insert(prefix, selectedStrategy))
{
- setResponse(response, 200, "Success", options.wireEncode());
+ setResponse(response, 200, "Success", parameters.wireEncode());
}
else
{
@@ -146,22 +130,22 @@
}
void
-StrategyChoiceManager::unsetStrategy(const ndn::nfd::StrategyChoiceOptions& options,
+StrategyChoiceManager::unsetStrategy(const ControlParameters& parameters,
ControlResponse& response)
{
static const Name ROOT_PREFIX;
- const Name& prefix = options.getName();
+ const Name& prefix = parameters.getName();
if (prefix == ROOT_PREFIX)
{
NFD_LOG_INFO("strategy-choice result: FAIL reason: unknown-prefix: "
- << options.getName());
+ << parameters.getName());
setResponse(response, 403, "Cannot unset root prefix strategy");
return;
}
m_strategyChoice.erase(prefix);
- setResponse(response, 200, "Success", options.wireEncode());
+ setResponse(response, 200, "Success", parameters.wireEncode());
}