mgmt: refactor management modules to use ControlCommand
Change-Id: Icf5e10f2f2d0b95c85fd871e6484c3ed58ed6c46
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 039270f..518021a 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -587,8 +587,16 @@
ControlParameters& parameters)
{
const Name& requestName = request.getName();
+ ndn::nfd::FaceCreateCommand command;
+
+ if (!validateParameters(command, parameters))
+ {
+ sendResponse(requestName, 400, "Malformed command");
+ return;
+ }
+
FaceUri uri;
- if (!parameters.hasUri() || !uri.parse(parameters.getUri()))
+ if (!uri.parse(parameters.getUri()))
{
sendResponse(requestName, 400, "Malformed command");
return;
@@ -612,7 +620,9 @@
ControlParameters& parameters)
{
const Name& requestName = request.getName();
- if (!parameters.hasFaceId())
+ ndn::nfd::FaceDestroyCommand command;
+
+ if (!validateParameters(command, parameters))
{
sendResponse(requestName, 400, "Malformed command");
return;
@@ -625,6 +635,7 @@
}
sendResponse(requestName, 200, "Success", parameters.wireEncode());
+
}
void
@@ -653,16 +664,14 @@
bool
-FaceManager::validateLocalControlParameters(const Interest& request,
- ControlParameters& parameters,
- shared_ptr<LocalFace>& outFace,
- LocalControlFeature& outFeature)
+FaceManager::extractLocalControlParameters(const Interest& request,
+ ControlParameters& parameters,
+ ControlCommand& command,
+ shared_ptr<LocalFace>& outFace,
+ LocalControlFeature& outFeature)
{
- if (!parameters.hasLocalControlFeature() ||
- (parameters.getLocalControlFeature() != LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID &&
- parameters.getLocalControlFeature() != LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID))
+ if (!validateParameters(command, parameters))
{
- NFD_LOG_INFO("command result: malformed");
sendResponse(request.getName(), 400, "Malformed command");
return false;
}
@@ -671,14 +680,15 @@
if (!static_cast<bool>(face))
{
- NFD_LOG_INFO("command result: faceid " << parameters.getFaceId() << " not found");
- sendResponse(request.getName(), 410, "Requested face not found");
+ NFD_LOG_INFO("command result: faceid " << request.getIncomingFaceId() << " not found");
+ sendResponse(request.getName(), 410, "Face not found");
return false;
}
else if (!face->isLocal())
{
- NFD_LOG_INFO("command result: cannot enable local control on non-local faceid " << parameters.getFaceId());
- sendResponse(request.getName(), 412, "Requested face is non-local");
+ NFD_LOG_INFO("command result: cannot enable local control on non-local faceid " <<
+ face->getId());
+ sendResponse(request.getName(), 412, "Face is non-local");
return false;
}
@@ -692,10 +702,13 @@
FaceManager::enableLocalControl(const Interest& request,
ControlParameters& parameters)
{
+ ndn::nfd::FaceEnableLocalControlCommand command;
+
+
shared_ptr<LocalFace> face;
LocalControlFeature feature;
- if (validateLocalControlParameters(request, parameters, face, feature))
+ if (extractLocalControlParameters(request, parameters, command, face, feature))
{
face->setLocalControlHeaderFeature(feature, true);
sendResponse(request.getName(), 200, "Success", parameters.wireEncode());
@@ -706,10 +719,11 @@
FaceManager::disableLocalControl(const Interest& request,
ControlParameters& parameters)
{
+ ndn::nfd::FaceDisableLocalControlCommand command;
shared_ptr<LocalFace> face;
LocalControlFeature feature;
- if (validateLocalControlParameters(request, parameters, face, feature))
+ if (extractLocalControlParameters(request, parameters, command, face, feature))
{
face->setLocalControlHeaderFeature(feature, false);
sendResponse(request.getName(), 200, "Success", parameters.wireEncode());