diff --git a/docs/conf.py b/docs/conf.py index 8e1f755..77cf00b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/src/update/manager-base.hpp b/src/update/manager-base.hpp index 557a015..db6ef62 100644 --- a/src/update/manager-base.hpp +++ b/src/update/manager-base.hpp @@ -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. * @@ -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 #include -#include #include +#include #include #include @@ -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 - bool + static bool validateParameters(const ndn::mgmt::ControlParameters& parameters) { const auto* castParams = dynamic_cast(¶meters); diff --git a/src/update/nfd-rib-command-processor.cpp b/src/update/nfd-rib-command-processor.cpp index 2570797..f4d191b 100644 --- a/src/update/nfd-rib-command-processor.cpp +++ b/src/update/nfd-rib-command-processor.cpp @@ -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. * @@ -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, @@ -31,14 +30,13 @@ NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher { m_dispatcher.addControlCommand(makeRelPrefix("register"), ndn::mgmt::makeAcceptAllAuthorization(), - std::bind(&NfdRibCommandProcessor::validateParameters, this, _1), + [] (const auto& p) { return validateParameters(p); }, std::bind(&NfdRibCommandProcessor::advertiseAndInsertPrefix, this, _1, _2, _3, _4)); m_dispatcher.addControlCommand(makeRelPrefix("unregister"), ndn::mgmt::makeAcceptAllAuthorization(), - std::bind(&NfdRibCommandProcessor::validateParameters, this, _1), + [] (const auto& p) { return validateParameters(p); }, std::bind(&NfdRibCommandProcessor::withdrawAndRemovePrefix, this, _1, _2, _3, _4)); } -} // namespace update -} // namespace nlsr +} // namespace nlsr::update diff --git a/src/update/nfd-rib-command-processor.hpp b/src/update/nfd-rib-command-processor.hpp index 4b6ca5c..351e375 100644 --- a/src/update/nfd-rib-command-processor.hpp +++ b/src/update/nfd-rib-command-processor.hpp @@ -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. * @@ -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 . - **/ + */ -#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 - - -namespace nlsr { -namespace update { +namespace nlsr::update { class NfdRibCommandProcessor : public CommandManagerBase { @@ -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 diff --git a/src/update/nfd-rib-commands.cpp b/src/update/nfd-rib-commands.cpp deleted file mode 100644 index fd2c2af..0000000 --- a/src/update/nfd-rib-commands.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2017, The University of Memphis, - * Regents of the University of California, - * Arizona Board of Regents. - * - * This file is part of NLSR (Named-data Link State Routing). - * See AUTHORS.md for complete list of NLSR authors and contributors. - * - * NLSR is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * NLSR, e.g., in COPYING.md file. If not, see . - **/ - -#include "nfd-rib-commands.hpp" - -namespace nlsr { -namespace update { - -NfdRibRegisterCommand::NfdRibRegisterCommand() - : ControlCommand("nlsr", "register") -{ - m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME); - m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_ORIGIN); -} - -NfdRibUnregisterCommand::NfdRibUnregisterCommand() - : ControlCommand("nlsr", "unregister") -{ - m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME); - m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_ORIGIN); -} - -} // namespace update -} // namespace nlsr diff --git a/src/update/nfd-rib-commands.hpp b/src/update/nfd-rib-commands.hpp deleted file mode 100644 index b259b7e..0000000 --- a/src/update/nfd-rib-commands.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2017, The University of Memphis, - * Regents of the University of California, - * Arizona Board of Regents. - * - * This file is part of NLSR (Named-data Link State Routing). - * See AUTHORS.md for complete list of NLSR authors and contributors. - * - * NLSR is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * NLSR, e.g., in COPYING.md file. If not, see . - **/ - -/*! \file - * Define parameters for NFD RIB commands - * - * When validating an NFD RIB command, NLSR is only concerned with the - * name in the command. However, a request is rejected if it has - * unsolicited fields, so the origin, which is set by NFD's RIB, must - * be considered optional. We consider these to be secure because they - * are currently only received over the localhost prefix. These serve - * to support NFD RIB to NLSR route readvertising. - * - * \sa NfdRibCommandProcessor - * \sa nlsr::Nlsr::LOCALHOST_PREFIX - * \sa nlsr::Nlsr::getDispatcher - */ - -#ifndef UPDATE_NFD_RIB_COMMANDS_HPP -#define UPDATE_NFD_RIB_COMMANDS_HPP - -#include - -namespace nlsr { -namespace update { - -class NfdRibRegisterCommand : public ndn::nfd::ControlCommand -{ -public: - NfdRibRegisterCommand(); -}; - -class NfdRibUnregisterCommand : public ndn::nfd::ControlCommand -{ -public: - NfdRibUnregisterCommand(); -}; - -} // namespace update -} // namespace nlsr - -#endif // UPDATE_NFD_RIB_COMMANDS_HPP diff --git a/src/update/prefix-update-processor.cpp b/src/update/prefix-update-processor.cpp index c36b408..6edfae7 100644 --- a/src/update/prefix-update-processor.cpp +++ b/src/update/prefix-update-processor.cpp @@ -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. * @@ -23,16 +23,15 @@ #include "logger.hpp" #include "lsdb.hpp" #include "nlsr.hpp" +#include "prefix-update-commands.hpp" #include #include #include -#include #include -namespace nlsr { -namespace update { +namespace nlsr::update { INIT_LOGGER(update.PrefixUpdateProcessor); @@ -67,14 +66,12 @@ PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher, m_dispatcher.addControlCommand(makeRelPrefix("advertise"), makeAuthorization(), - std::bind(&PrefixUpdateProcessor::validateParameters, - this, _1), + [] (const auto& p) { return validateParameters(p); }, std::bind(&PrefixUpdateProcessor::advertiseAndInsertPrefix, this, _1, _2, _3, _4)); m_dispatcher.addControlCommand(makeRelPrefix("withdraw"), makeAuthorization(), - std::bind(&PrefixUpdateProcessor::validateParameters, - this, _1), + [] (const auto& p) { return validateParameters(p); }, std::bind(&PrefixUpdateProcessor::withdrawAndRemovePrefix, this, _1, _2, _3, _4)); } @@ -193,5 +190,4 @@ PrefixUpdateProcessor::afterWithdraw(const ndn::Name& prefix) return addOrDeletePrefix(prefix, false); } -} // namespace update -} // namespace nlsr +} // namespace nlsr::update diff --git a/src/update/prefix-update-processor.hpp b/src/update/prefix-update-processor.hpp index 1864d0f..9230f0b 100644 --- a/src/update/prefix-update-processor.hpp +++ b/src/update/prefix-update-processor.hpp @@ -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. * @@ -23,14 +23,12 @@ #define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP #include "manager-base.hpp" -#include "prefix-update-commands.hpp" #include #include -namespace nlsr { -namespace update { +namespace nlsr::update { using ConfigSection = boost::property_tree::ptree; @@ -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 diff --git a/tests/update/test-nfd-rib-command-processor.cpp b/tests/update/test-nfd-rib-command-processor.cpp index 17106dc..371610f 100644 --- a/tests/update/test-nfd-rib-command-processor.cpp +++ b/tests/update/test-nfd-rib-command-processor.cpp @@ -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. * @@ -20,7 +20,6 @@ */ #include "update/nfd-rib-command-processor.hpp" -#include "adjacency-list.hpp" #include "conf-parameter.hpp" #include "nlsr.hpp" @@ -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) @@ -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(parameters); - } - catch (...) { - wasValidated = false; - } - BOOST_CHECK(!wasValidated); + BOOST_CHECK_THROW(processor.validateParameters(parameters), std::invalid_argument); } BOOST_AUTO_TEST_CASE(OnReceiveInterestRegisterCommand)