management: make FaceId optional in fib/add|remove-nexthop commands
refs #1630
Change-Id: I1548d3aca7bf32b7184e1b72c00c45cdc4320d9b
diff --git a/src/management/nfd-control-command.hpp b/src/management/nfd-control-command.hpp
index 1bf0c0c..6a16a1f 100644
--- a/src/management/nfd-control-command.hpp
+++ b/src/management/nfd-control-command.hpp
@@ -321,7 +321,7 @@
{
m_requestValidator
.required(CONTROL_PARAMETER_NAME)
- .required(CONTROL_PARAMETER_FACE_ID)
+ .optional(CONTROL_PARAMETER_FACE_ID)
.optional(CONTROL_PARAMETER_COST);
m_responseValidator
.required(CONTROL_PARAMETER_NAME)
@@ -332,6 +332,9 @@
virtual void
applyDefaultsToRequest(ControlParameters& parameters) const
{
+ if (!parameters.hasFaceId()) {
+ parameters.setFaceId(0);
+ }
if (!parameters.hasCost()) {
parameters.setCost(0);
}
@@ -362,13 +365,21 @@
{
m_requestValidator
.required(CONTROL_PARAMETER_NAME)
- .required(CONTROL_PARAMETER_FACE_ID);
+ .optional(CONTROL_PARAMETER_FACE_ID);
m_responseValidator
.required(CONTROL_PARAMETER_NAME)
.required(CONTROL_PARAMETER_FACE_ID);
}
virtual void
+ applyDefaultsToRequest(ControlParameters& parameters) const
+ {
+ if (!parameters.hasFaceId()) {
+ parameters.setFaceId(0);
+ }
+ }
+
+ virtual void
validateResponse(const ControlParameters& parameters) const
{
this->ControlCommand::validateResponse(parameters);
diff --git a/tests/management/test-nfd-control-command.cpp b/tests/management/test-nfd-control-command.cpp
index 6487cd8..7b92657 100644
--- a/tests/management/test-nfd-control-command.cpp
+++ b/tests/management/test-nfd-control-command.cpp
@@ -128,6 +128,12 @@
command.applyDefaultsToRequest(p1);
BOOST_REQUIRE(p1.hasCost());
BOOST_CHECK_EQUAL(p1.getCost(), 0);
+
+ p1.unsetFaceId();
+ BOOST_CHECK_NO_THROW(command.validateRequest(p1));
+ command.applyDefaultsToRequest(p1);
+ BOOST_REQUIRE(p1.hasFaceId());
+ BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
}
BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
@@ -146,6 +152,12 @@
.setFaceId(0);
BOOST_CHECK_NO_THROW(command.validateRequest(p2));
BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
+
+ p1.unsetFaceId();
+ BOOST_CHECK_NO_THROW(command.validateRequest(p1));
+ command.applyDefaultsToRequest(p1);
+ BOOST_REQUIRE(p1.hasFaceId());
+ BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
}
BOOST_AUTO_TEST_CASE(StrategyChoiceSet)