Skip to content

Commit

Permalink
mgmt: adapt to API changes in ndn-cxx ControlCommand and Dispatcher
Browse files Browse the repository at this point in the history
Change-Id: Iabedb5d6bbe34883c21015c8d74f68e9ba2a7f58
  • Loading branch information
Pesa committed Jan 3, 2025
1 parent 384327d commit d2610dc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
18 changes: 9 additions & 9 deletions src/route/fib.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
Expand All @@ -24,6 +24,8 @@
#include "logger.hpp"
#include "nexthop-list.hpp"

#include <ndn-cxx/mgmt/nfd/control-command.hpp>

#include <algorithm>
#include <cmath>
#include <map>
Expand Down Expand Up @@ -198,8 +200,7 @@ Fib::registerPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri,
NLSR_LOG_DEBUG("Registering prefix: " << faceParameters.getName() << " faceUri: " << faceUri);
m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
std::bind(&Fib::onRegistrationSuccess, this, _1, faceUri),
std::bind(&Fib::onRegistrationFailure, this, _1,
faceParameters, faceUri, times));
std::bind(&Fib::onRegistrationFailure, this, _1, faceParameters, faceUri, times));
}
else {
NLSR_LOG_WARN("Error: No Face Id for face uri: " << faceUri);
Expand Down Expand Up @@ -264,8 +265,8 @@ Fib::unregisterPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri)
" Face Id: " << commandSuccessResult.getFaceId());
},
[] (const ndn::nfd::ControlResponse& response) {
NLSR_LOG_DEBUG("Failed in unregistering name" << ": " << response.getText() <<
" (code: " << response.getCode() << ")");
NLSR_LOG_DEBUG("Failed in unregistering name: " << response.getText() <<
" (code " << response.getCode() << ")");
});
}
}
Expand All @@ -279,9 +280,8 @@ Fib::setStrategy(const ndn::Name& name, const ndn::Name& strategy, uint32_t coun
.setStrategy(strategy);

m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
std::bind(&Fib::onSetStrategySuccess, this, _1),
std::bind(&Fib::onSetStrategyFailure, this, _1,
parameters, count));
std::bind(&Fib::onSetStrategySuccess, this, _1),
std::bind(&Fib::onSetStrategyFailure, this, _1, parameters, count));
}

void
Expand All @@ -292,7 +292,7 @@ Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResul
}

void
Fib::onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
Fib::onSetStrategyFailure(const ndn::nfd::ControlResponse&,
const ndn::nfd::ControlParameters& parameters,
uint32_t count)
{
Expand Down
12 changes: 5 additions & 7 deletions src/update/manager-base.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand Down Expand Up @@ -53,11 +53,10 @@ CommandManagerBase::CommandManagerBase(ndn::mgmt::Dispatcher& dispatcher,
void
CommandManagerBase::advertiseAndInsertPrefix(const ndn::Name& prefix,
const ndn::Interest& interest,
const ndn::mgmt::ControlParameters& parameters,
const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
{
const ndn::nfd::ControlParameters& castParams =
static_cast<const ndn::nfd::ControlParameters&>(parameters);
const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);

// Only build a Name LSA if the added name is new
if (m_namePrefixList.insert(castParams.getName())) {
Expand Down Expand Up @@ -95,11 +94,10 @@ CommandManagerBase::advertiseAndInsertPrefix(const ndn::Name& prefix,
void
CommandManagerBase::withdrawAndRemovePrefix(const ndn::Name& prefix,
const ndn::Interest& interest,
const ndn::mgmt::ControlParameters& parameters,
const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
{
const ndn::nfd::ControlParameters& castParams =
static_cast<const ndn::nfd::ControlParameters&>(parameters);
const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);

// Only build a Name LSA if the added name is new
if (m_namePrefixList.erase(castParams.getName())) {
Expand Down
16 changes: 6 additions & 10 deletions src/update/manager-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,14 @@ class ManagerBase : boost::noncopyable
PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/*! \brief Validate the parameters for a given command.
*/
template<typename T>
template<typename Command>
static bool
validateParameters(const ndn::mgmt::ControlParameters& parameters)
validateParameters(const ndn::mgmt::ControlParametersBase& parameters)
{
const auto* castParams = dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters);
BOOST_ASSERT(castParams != nullptr);

T command;
try {
command.validateRequest(*castParams);
Command::validateRequest(dynamic_cast<const ndn::nfd::ControlParameters&>(parameters));
}
catch (const ndn::nfd::ControlCommand::ArgumentError&) {
catch (const ndn::nfd::ArgumentError&) {
throw;
}
catch (const std::exception& e) {
Expand Down Expand Up @@ -110,7 +106,7 @@ class CommandManagerBase : public ManagerBase
void
advertiseAndInsertPrefix(const ndn::Name& prefix,
const ndn::Interest& interest,
const ndn::mgmt::ControlParameters& parameters,
const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done);

/*! \brief remove desired name prefix from the advertised name prefix list
Expand All @@ -119,7 +115,7 @@ class CommandManagerBase : public ManagerBase
void
withdrawAndRemovePrefix(const ndn::Name& prefix,
const ndn::Interest& interest,
const ndn::mgmt::ControlParameters& parameters,
const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done);

/*! \brief save an advertised prefix to the nlsr configuration file
Expand Down
53 changes: 24 additions & 29 deletions src/update/prefix-update-commands.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2019, The University of Memphis,
/*
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -17,33 +17,28 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/

#include "prefix-update-commands.hpp"

namespace nlsr {
namespace update {

WithdrawPrefixCommand::WithdrawPrefixCommand()
: ControlCommand("nlsr", "withdraw")
{
m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);

m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
m_responseValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
}

AdvertisePrefixCommand::AdvertisePrefixCommand()
: ControlCommand("nlsr", "advertise")
{
m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);

m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
m_responseValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);

}

} // namespace update
} // namespace nlsr
namespace nlsr::update {

const AdvertisePrefixCommand::RequestFormat AdvertisePrefixCommand::s_requestFormat =
RequestFormat()
.required(ndn::nfd::CONTROL_PARAMETER_NAME)
.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
const AdvertisePrefixCommand::ResponseFormat AdvertisePrefixCommand::s_responseFormat =
ResponseFormat()
.required(ndn::nfd::CONTROL_PARAMETER_NAME)
.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);

const WithdrawPrefixCommand::RequestFormat WithdrawPrefixCommand::s_requestFormat =
RequestFormat()
.required(ndn::nfd::CONTROL_PARAMETER_NAME)
.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
const WithdrawPrefixCommand::ResponseFormat WithdrawPrefixCommand::s_responseFormat =
ResponseFormat()
.required(ndn::nfd::CONTROL_PARAMETER_NAME)
.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);

} // namespace nlsr::update
24 changes: 10 additions & 14 deletions src/update/prefix-update-commands.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, The University of Memphis,
/*
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -17,10 +17,10 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/

/*! \file
* Define parameters for commands to manipulate advertised name prefixes
* Define parameters for commands to manipulate advertised name prefixes.
*
* These classes serve to define what parameters are required for
* Prefix Update commands. We assume these commands are secure because
Expand All @@ -36,22 +36,18 @@

#include <ndn-cxx/mgmt/nfd/control-command.hpp>

namespace nlsr {
namespace update {
namespace nlsr::update {

class WithdrawPrefixCommand : public ndn::nfd::ControlCommand
class AdvertisePrefixCommand : public ndn::nfd::ControlCommand<AdvertisePrefixCommand>
{
public:
WithdrawPrefixCommand();
NDN_CXX_CONTROL_COMMAND(AdvertisePrefixCommand, "nlsr", "advertise");
};

class AdvertisePrefixCommand : public ndn::nfd::ControlCommand
class WithdrawPrefixCommand : public ndn::nfd::ControlCommand<WithdrawPrefixCommand>
{
public:
AdvertisePrefixCommand();
NDN_CXX_CONTROL_COMMAND(WithdrawPrefixCommand, "nlsr", "withdraw");
};

} // namespace update
} // namespace nlsr
} // namespace nlsr::update

#endif // NLSR_UPDATE_PREFIX_UPDATE_COMMANDS_HPP
2 changes: 1 addition & 1 deletion src/update/prefix-update-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ndn::mgmt::Authorization
PrefixUpdateProcessor::makeAuthorization()
{
return [=] (const ndn::Name& prefix, const ndn::Interest& interest,
const ndn::mgmt::ControlParameters* params,
const ndn::mgmt::ControlParametersBase* params,
const ndn::mgmt::AcceptContinuation& accept,
const ndn::mgmt::RejectContinuation& reject) {
m_validator.validate(interest,
Expand Down

0 comments on commit d2610dc

Please sign in to comment.