Skip to content

Commit

Permalink
update: use NFD RIB control command definitions from ndn-cxx
Browse files Browse the repository at this point in the history
And make validateParameters() static

Change-Id: I981bf3c8d5ba7b2ef7ef8292de5ec54bb7cc0c3b
  • Loading branch information
Pesa committed Jan 2, 2025
1 parent b071654 commit 384327d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 164 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Named Data Link State Routing Protocol (NLSR)'
copyright = 'Copyright © 2014-2024 Named Data Networking Project.'
copyright = 'Copyright © 2014-2025 Named Data Networking Project.'
author = 'Named Data Networking Project'

# The short X.Y version.
Expand Down
18 changes: 8 additions & 10 deletions src/update/manager-base.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-2022, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -22,16 +22,14 @@
#ifndef NLSR_MANAGER_BASE_HPP
#define NLSR_MANAGER_BASE_HPP

#include "lsdb.hpp"
#include "name-prefix-list.hpp"
#include "test-access-control.hpp"
#include "lsdb.hpp"
#include "nfd-rib-commands.hpp"
#include "prefix-update-commands.hpp"

#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/mgmt/nfd/control-command.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>

Expand All @@ -56,19 +54,19 @@ class ManagerBase : boost::noncopyable
using std::runtime_error::runtime_error;
};

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

protected:
/*! \brief generate the relative prefix for a handler by appending the verb name to the module name
/*! \brief Generate the relative prefix for a handler by appending the verb name to the module name.
*/
ndn::PartialName
makeRelPrefix(const std::string& verb) const;

PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/*! \brief validate the parameters for a given command
*/
/*! \brief Validate the parameters for a given command.
*/
template<typename T>
bool
static bool
validateParameters(const ndn::mgmt::ControlParameters& parameters)
{
const auto* castParams = dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters);
Expand Down
12 changes: 5 additions & 7 deletions src/update/nfd-rib-command-processor.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-2021, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -21,8 +21,7 @@

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

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

NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
NamePrefixList& namePrefixList,
Expand All @@ -31,14 +30,13 @@ NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher
{
m_dispatcher.addControlCommand<ndn::nfd::ControlParameters>(makeRelPrefix("register"),
ndn::mgmt::makeAcceptAllAuthorization(),
std::bind(&NfdRibCommandProcessor::validateParameters<NfdRibRegisterCommand>, this, _1),
[] (const auto& p) { return validateParameters<ndn::nfd::RibRegisterCommand>(p); },
std::bind(&NfdRibCommandProcessor::advertiseAndInsertPrefix, this, _1, _2, _3, _4));

m_dispatcher.addControlCommand<ndn::nfd::ControlParameters>(makeRelPrefix("unregister"),
ndn::mgmt::makeAcceptAllAuthorization(),
std::bind(&NfdRibCommandProcessor::validateParameters<NfdRibUnregisterCommand>, this, _1),
[] (const auto& p) { return validateParameters<ndn::nfd::RibUnregisterCommand>(p); },
std::bind(&NfdRibCommandProcessor::withdrawAndRemovePrefix, this, _1, _2, _3, _4));
}

} // namespace update
} // namespace nlsr
} // namespace nlsr::update
23 changes: 8 additions & 15 deletions src/update/nfd-rib-command-processor.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,20 +17,14 @@
*
* 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/>.
**/
*/

#ifndef UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
#define UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
#ifndef NLSR_UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
#define NLSR_UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP

#include "manager-base.hpp"
#include "route/fib.hpp"
#include "nfd-rib-commands.hpp"

#include <ndn-cxx/encoding/tlv-nfd.hpp>


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

class NfdRibCommandProcessor : public CommandManagerBase
{
Expand All @@ -40,7 +34,6 @@ class NfdRibCommandProcessor : public CommandManagerBase
Lsdb& lsdb);
};

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

#endif // UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
#endif // NLSR_UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
42 changes: 0 additions & 42 deletions src/update/nfd-rib-commands.cpp

This file was deleted.

60 changes: 0 additions & 60 deletions src/update/nfd-rib-commands.hpp

This file was deleted.

16 changes: 6 additions & 10 deletions src/update/prefix-update-processor.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-2022, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -23,16 +23,15 @@
#include "logger.hpp"
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "prefix-update-commands.hpp"

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

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

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

INIT_LOGGER(update.PrefixUpdateProcessor);

Expand Down Expand Up @@ -67,14 +66,12 @@ PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,

m_dispatcher.addControlCommand<ndn::nfd::ControlParameters>(makeRelPrefix("advertise"),
makeAuthorization(),
std::bind(&PrefixUpdateProcessor::validateParameters<AdvertisePrefixCommand>,
this, _1),
[] (const auto& p) { return validateParameters<AdvertisePrefixCommand>(p); },
std::bind(&PrefixUpdateProcessor::advertiseAndInsertPrefix, this, _1, _2, _3, _4));

m_dispatcher.addControlCommand<ndn::nfd::ControlParameters>(makeRelPrefix("withdraw"),
makeAuthorization(),
std::bind(&PrefixUpdateProcessor::validateParameters<WithdrawPrefixCommand>,
this, _1),
[] (const auto& p) { return validateParameters<WithdrawPrefixCommand>(p); },
std::bind(&PrefixUpdateProcessor::withdrawAndRemovePrefix, this, _1, _2, _3, _4));
}

Expand Down Expand Up @@ -193,5 +190,4 @@ PrefixUpdateProcessor::afterWithdraw(const ndn::Name& prefix)
return addOrDeletePrefix(prefix, false);
}

} // namespace update
} // namespace nlsr
} // namespace nlsr::update
9 changes: 3 additions & 6 deletions src/update/prefix-update-processor.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-2022, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -23,14 +23,12 @@
#define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP

#include "manager-base.hpp"
#include "prefix-update-commands.hpp"

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

#include <boost/property_tree/ptree.hpp>

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

using ConfigSection = boost::property_tree::ptree;

Expand Down Expand Up @@ -93,7 +91,6 @@ class PrefixUpdateProcessor : public CommandManagerBase
const std::string& m_confFileNameDynamic;
};

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

#endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
18 changes: 5 additions & 13 deletions tests/update/test-nfd-rib-command-processor.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-2024, The University of Memphis,
* Copyright (c) 2014-2025, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
Expand All @@ -20,7 +20,6 @@
*/

#include "update/nfd-rib-command-processor.hpp"
#include "adjacency-list.hpp"
#include "conf-parameter.hpp"
#include "nlsr.hpp"

Expand Down Expand Up @@ -98,8 +97,8 @@ class NfdRibCommandProcessorFixture : public IoKeyChainFixture
};

using Commands = boost::mp11::mp_list<
update::NfdRibRegisterCommand,
update::NfdRibUnregisterCommand
ndn::nfd::RibRegisterCommand,
ndn::nfd::RibUnregisterCommand
>;

BOOST_FIXTURE_TEST_SUITE(TestNfdRibCommandProcessor, NfdRibCommandProcessorFixture)
Expand All @@ -115,16 +114,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersSuccess, NfdRibCommand, Commands
BOOST_AUTO_TEST_CASE_TEMPLATE(ValidateParametersFailure, NfdRibCommand, Commands)
{
ndn::nfd::ControlParameters parameters;
parameters.setName("/test/prefixA").setCost(10);
parameters.setName("/test/prefixA").setMtu(500);

bool wasValidated = true;
try {
processor.validateParameters<NfdRibCommand>(parameters);
}
catch (...) {
wasValidated = false;
}
BOOST_CHECK(!wasValidated);
BOOST_CHECK_THROW(processor.validateParameters<NfdRibCommand>(parameters), std::invalid_argument);
}

BOOST_AUTO_TEST_CASE(OnReceiveInterestRegisterCommand)
Expand Down

0 comments on commit 384327d

Please sign in to comment.