Skip to content

Commit

Permalink
update: merge ManagerBase and CommandManagerBase
Browse files Browse the repository at this point in the history
Change-Id: Ib939d8d032ff9e6e27f51d9053d08da558fd5027
  • Loading branch information
Pesa committed Jan 15, 2025
1 parent 968eb1a commit 20e60a2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 68 deletions.
1 change: 1 addition & 0 deletions src/nlsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cstdio>
#include <unistd.h>

#include <ndn-cxx/mgmt/nfd/control-command.hpp>
#include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
#include <ndn-cxx/net/face-uri.hpp>

Expand Down
6 changes: 1 addition & 5 deletions src/nlsr.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-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 @@ -185,10 +185,6 @@ class Nlsr
DatasetInterestHandler m_datasetHandler;

private:
/*! \brief Where NLSR stores certificates it claims to be
* authoritative for. Usually the router certificate.
*/

ndn::nfd::Controller m_controller;
ndn::nfd::Controller m_faceDatasetController;

Expand Down
36 changes: 15 additions & 21 deletions src/update/manager-base.cpp → src/update/command-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,29 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/

#include "manager-base.hpp"
#include "command-processor.hpp"
#include "logger.hpp"

namespace nlsr {
namespace update {
#include <ndn-cxx/mgmt/nfd/control-response.hpp>

INIT_LOGGER(update.PrefixCommandProcessor);
namespace nlsr::update {

ManagerBase::ManagerBase(ndn::mgmt::Dispatcher& dispatcher,
const std::string& module)
: m_dispatcher(dispatcher)
, m_module(module)
{
}
INIT_LOGGER(update.CommandProcessor);

CommandManagerBase::CommandManagerBase(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixList,
Lsdb& lsdb,
const std::string& module)
: ManagerBase(dispatcher, module)
CommandProcessor::CommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixList,
Lsdb& lsdb)
: m_dispatcher(dispatcher)
, m_namePrefixList(namePrefixList)
, m_lsdb(lsdb)
{
}

CommandProcessor::~CommandProcessor() = default;

void
CommandManagerBase::advertiseAndInsertPrefix(const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
CommandProcessor::advertiseAndInsertPrefix(const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
{
const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);

Expand Down Expand Up @@ -84,8 +79,8 @@ CommandManagerBase::advertiseAndInsertPrefix(const ndn::mgmt::ControlParametersB
}

void
CommandManagerBase::withdrawAndRemovePrefix(const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
CommandProcessor::withdrawAndRemovePrefix(const ndn::mgmt::ControlParametersBase& parameters,
const ndn::mgmt::CommandContinuation& done)
{
const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);

Expand Down Expand Up @@ -121,5 +116,4 @@ CommandManagerBase::withdrawAndRemovePrefix(const ndn::mgmt::ControlParametersBa
}
}

} // namespace update
} // namespace nlsr
} // namespace nlsr::update
44 changes: 11 additions & 33 deletions src/update/manager-base.hpp → src/update/command-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,23 @@
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef NLSR_MANAGER_BASE_HPP
#define NLSR_MANAGER_BASE_HPP
#ifndef NLSR_UPDATE_COMMAND_PROCESSOR_HPP
#define NLSR_UPDATE_COMMAND_PROCESSOR_HPP

#include "lsdb.hpp"
#include "name-prefix-list.hpp"

#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/mgmt/nfd/control-command.hpp>
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
#include <ndn-cxx/mgmt/nfd/control-response.hpp>

#include <boost/noncopyable.hpp>
#include <optional>

namespace nlsr {

class Lsdb;

namespace update {
namespace nlsr::update {

enum { PREFIX_FLAG = 1 };

class ManagerBase : boost::noncopyable
class CommandProcessor : boost::noncopyable
{
public:
class Error : public std::runtime_error
Expand All @@ -52,26 +44,12 @@ class ManagerBase : boost::noncopyable
using std::runtime_error::runtime_error;
};

protected:
ManagerBase(ndn::mgmt::Dispatcher& m_dispatcher, const std::string& module);

protected:
ndn::mgmt::Dispatcher& m_dispatcher;

private:
std::string m_module;
};

class CommandManagerBase : public ManagerBase
{
public:
CommandManagerBase(ndn::mgmt::Dispatcher& m_dispatcher,
NamePrefixList& m_namePrefixList,
Lsdb& lsdb,
const std::string& module);
CommandProcessor(ndn::mgmt::Dispatcher& m_dispatcher,
NamePrefixList& m_namePrefixList,
Lsdb& lsdb);

virtual
~CommandManagerBase() = default;
~CommandProcessor() = 0;

/*! \brief Add desired name prefix to the advertised name prefix list
* or insert a prefix into the FIB if parameters is valid.
Expand Down Expand Up @@ -106,11 +84,11 @@ class CommandManagerBase : public ManagerBase
}

protected:
ndn::mgmt::Dispatcher& m_dispatcher;
NamePrefixList& m_namePrefixList;
Lsdb& m_lsdb;
};

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

#endif // NLSR_MANAGER_BASE_HPP
#endif // NLSR_UPDATE_COMMAND_PROCESSOR_HPP
6 changes: 5 additions & 1 deletion src/update/nfd-rib-command-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@

#include "nfd-rib-command-processor.hpp"

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

namespace nlsr::update {

NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixList,
Lsdb& lsdb)
: CommandManagerBase(dispatcher, namePrefixList, lsdb, "rib")
: CommandProcessor(dispatcher, namePrefixList, lsdb)
{
m_dispatcher.addControlCommand<ndn::nfd::RibRegisterCommand>(
ndn::mgmt::makeAcceptAllAuthorization(),
// the first and second arguments are ignored since the handler does not need them
std::bind(&NfdRibCommandProcessor::advertiseAndInsertPrefix, this, _3, _4));

m_dispatcher.addControlCommand<ndn::nfd::RibUnregisterCommand>(
ndn::mgmt::makeAcceptAllAuthorization(),
// the first and second arguments are ignored since the handler does not need them
std::bind(&NfdRibCommandProcessor::withdrawAndRemovePrefix, this, _3, _4));
}

Expand Down
4 changes: 2 additions & 2 deletions src/update/nfd-rib-command-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#ifndef NLSR_UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
#define NLSR_UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP

#include "manager-base.hpp"
#include "command-processor.hpp"

namespace nlsr::update {

class NfdRibCommandProcessor : public CommandManagerBase
class NfdRibCommandProcessor : public CommandProcessor
{
public:
NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
Expand Down
7 changes: 3 additions & 4 deletions src/update/prefix-update-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

#include "prefix-update-processor.hpp"
#include "logger.hpp"
#include "lsdb.hpp"
#include "prefix-update-commands.hpp"

#include <ndn-cxx/face.hpp>

#include <boost/algorithm/string.hpp>
#include <fstream>

Expand Down Expand Up @@ -55,16 +52,18 @@ PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
ndn::security::ValidatorConfig& validator,
NamePrefixList& namePrefixList,
Lsdb& lsdb, const std::string& configFileName)
: CommandManagerBase(dispatcher, namePrefixList, lsdb, "prefix-update")
: CommandProcessor(dispatcher, namePrefixList, lsdb)
, m_validator(validator)
, m_confFileNameDynamic(configFileName)
{
m_dispatcher.addControlCommand<AdvertisePrefixCommand>(
makeAuthorization(),
// the first and second arguments are ignored since the handler does not need them
std::bind(&PrefixUpdateProcessor::advertiseAndInsertPrefix, this, _3, _4));

m_dispatcher.addControlCommand<WithdrawPrefixCommand>(
makeAuthorization(),
// the first and second arguments are ignored since the handler does not need them
std::bind(&PrefixUpdateProcessor::withdrawAndRemovePrefix, this, _3, _4));
}

Expand Down
4 changes: 2 additions & 2 deletions src/update/prefix-update-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
#define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP

#include "manager-base.hpp"
#include "command-processor.hpp"

#include <ndn-cxx/security/key-chain.hpp>

Expand All @@ -32,7 +32,7 @@ namespace nlsr::update {

using ConfigSection = boost::property_tree::ptree;

class PrefixUpdateProcessor : public CommandManagerBase
class PrefixUpdateProcessor : public CommandProcessor
{
public:
PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
Expand Down

0 comments on commit 20e60a2

Please sign in to comment.