Skip to content

Commit

Permalink
management: make FaceId optional in fib/add|remove-nexthop commands
Browse files Browse the repository at this point in the history
refs #1630

Change-Id: I1548d3aca7bf32b7184e1b72c00c45cdc4320d9b
  • Loading branch information
yoursunny committed May 20, 2014
1 parent 4671bf7 commit caac54e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/management/nfd-control-command.hpp
Expand Up @@ -321,7 +321,7 @@ class FibAddNextHopCommand : public ControlCommand
{
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)
Expand All @@ -332,6 +332,9 @@ class FibAddNextHopCommand : public ControlCommand
virtual void
applyDefaultsToRequest(ControlParameters& parameters) const
{
if (!parameters.hasFaceId()) {
parameters.setFaceId(0);
}
if (!parameters.hasCost()) {
parameters.setCost(0);
}
Expand Down Expand Up @@ -362,12 +365,20 @@ class FibRemoveNextHopCommand : public ControlCommand
{
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
{
Expand Down
12 changes: 12 additions & 0 deletions tests/management/test-nfd-control-command.cpp
Expand Up @@ -128,6 +128,12 @@ BOOST_AUTO_TEST_CASE(FibAddNextHop)
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)
Expand All @@ -146,6 +152,12 @@ BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
.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)
Expand Down

0 comments on commit caac54e

Please sign in to comment.