blob: bc05937816e963534b166637c0b2d78d72a1b2d3 [file] [log] [blame]
alvy297f4162015-03-03 17:15:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento7bc3d432021-10-25 21:08:04 -04002/*
Davide Pesavento384327d2025-01-02 01:40:23 -05003 * Copyright (c) 2014-2025, The University of Memphis,
alvy297f4162015-03-03 17:15:33 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Davide Pesavento7bc3d432021-10-25 21:08:04 -040020 */
alvy297f4162015-03-03 17:15:33 -060021
dmcoomese689dd62017-03-29 11:05:12 -050022#ifndef NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
23#define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
alvy297f4162015-03-03 17:15:33 -060024
Davide Pesavento20e60a22025-01-07 01:50:10 -050025#include "command-processor.hpp"
Davide Pesavento7bc3d432021-10-25 21:08:04 -040026
alvy297f4162015-03-03 17:15:33 -060027#include <ndn-cxx/security/key-chain.hpp>
Davide Pesavento7bc3d432021-10-25 21:08:04 -040028
alvy297f4162015-03-03 17:15:33 -060029#include <boost/property_tree/ptree.hpp>
30
Davide Pesavento384327d2025-01-02 01:40:23 -050031namespace nlsr::update {
alvy297f4162015-03-03 17:15:33 -060032
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040033using ConfigSection = boost::property_tree::ptree;
alvy297f4162015-03-03 17:15:33 -060034
Davide Pesavento20e60a22025-01-07 01:50:10 -050035class PrefixUpdateProcessor : public CommandProcessor
alvy297f4162015-03-03 17:15:33 -060036{
37public:
Laqin Fan54a43f02017-03-08 12:31:30 -060038 PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
Ashlesh Gawande85998a12017-12-07 22:22:13 -060039 ndn::security::ValidatorConfig& validator,
alvy297f4162015-03-03 17:15:33 -060040 NamePrefixList& namePrefixList,
Saurab Dulal7526cee2018-01-31 18:14:10 +000041 Lsdb& lsdb, const std::string& configFileName);
Nick Gordond0a7df32017-05-30 16:44:34 -050042
43 /*! \brief Load the validator's configuration from a section of a
44 * configuration file.
45 * \sa ConfFileProcessor::processConfFile
46 * \sa ConfFileProcessor::processConfSectionSecurity
47 *
48 * Loads the state of the validator for prefix update commands by
49 * reading a section from a configuration file. This function is
50 * expecting the section to be from a Boost property tree object.
51 *
52 * \throws PrefixUpdateProcessor::Error If configuration fails to load successfully
53 */
alvy297f4162015-03-03 17:15:33 -060054 void
55 loadValidator(ConfigSection section, const std::string& filename);
56
Saurab Dulal7526cee2018-01-31 18:14:10 +000057 /*! \brief Add or delete an advertise or withdrawn prefix to the nlsr
58 * configuration file
59 */
awlane697a0ad2025-04-21 13:09:17 -050060 std::tuple<bool, std::string>
Saurab Dulal7526cee2018-01-31 18:14:10 +000061 addOrDeletePrefix(const ndn::Name& prefix, bool addPrefix);
62
awlane697a0ad2025-04-21 13:09:17 -050063 /*! \brief Save an advertised prefix to the nlsr configuration file.
64 * \return tuple {bool indicating success/failure, message string}.
65 */
66 std::tuple<bool, std::string>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040067 afterAdvertise(const ndn::Name& prefix) override;
Saurab Dulal7526cee2018-01-31 18:14:10 +000068
awlane697a0ad2025-04-21 13:09:17 -050069 /*! \brief Remove an advertised prefix from the nlsr configuration file.
70 * \return tuple {bool indicating success/failure, message string}.
71 */
72 std::tuple<bool, std::string>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040073 afterWithdraw(const ndn::Name& prefix) override;
Saurab Dulal7526cee2018-01-31 18:14:10 +000074
75 /*! \brief Check if a prefix exists in the nlsr configuration file */
76 bool
77 checkForPrefixInFile(const std::string prefix);
78
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050079 ndn::security::ValidatorConfig&
alvy297f4162015-03-03 17:15:33 -060080 getValidator()
81 {
82 return m_validator;
83 }
84
85private:
Laqin Fan54a43f02017-03-08 12:31:30 -060086 /*! \brief an authorization function for prefix-update module and verb(advertise/withdraw)
87 * accept if the verb is advertise/withdraw
88 * reject if the verb is not advertise/withdraw
89 \retval an Authorization function
90 \sa Nlsr::getDispatcher()
91 */
92 ndn::mgmt::Authorization
93 makeAuthorization();
94
95private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060096 ndn::security::ValidatorConfig& m_validator;
dulalsaurab82a34c22019-02-04 17:31:21 +000097 const std::string& m_confFileNameDynamic;
alvy297f4162015-03-03 17:15:33 -060098};
99
Davide Pesavento384327d2025-01-02 01:40:23 -0500100} // namespace nlsr::update
alvy297f4162015-03-03 17:15:33 -0600101
dmcoomese689dd62017-03-29 11:05:12 -0500102#endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP