Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, The University of Memphis, |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 4 | * 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 Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 20 | */ |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 21 | |
| 22 | #ifndef NLSR_MANAGER_BASE_HPP |
| 23 | #define NLSR_MANAGER_BASE_HPP |
| 24 | |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 25 | #include "lsdb.hpp" |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 26 | #include "name-prefix-list.hpp" |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 27 | |
| 28 | #include <ndn-cxx/face.hpp> |
| 29 | #include <ndn-cxx/interest.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/mgmt/nfd/control-command.hpp> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/control-response.hpp> |
| 34 | |
| 35 | #include <boost/noncopyable.hpp> |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 36 | #include <optional> |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 37 | |
| 38 | namespace nlsr { |
| 39 | |
| 40 | class Lsdb; |
| 41 | |
| 42 | namespace update { |
| 43 | |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 44 | enum { PREFIX_FLAG = 1 }; |
| 45 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 46 | class ManagerBase : boost::noncopyable |
| 47 | { |
| 48 | public: |
| 49 | class Error : public std::runtime_error |
| 50 | { |
| 51 | public: |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 52 | using std::runtime_error::runtime_error; |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 55 | protected: |
Davide Pesavento | d90338d | 2021-01-07 17:50:05 -0500 | [diff] [blame] | 56 | ManagerBase(ndn::mgmt::Dispatcher& m_dispatcher, const std::string& module); |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 57 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 58 | protected: |
| 59 | ndn::mgmt::Dispatcher& m_dispatcher; |
| 60 | |
| 61 | private: |
| 62 | std::string m_module; |
| 63 | }; |
| 64 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 65 | class CommandManagerBase : public ManagerBase |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 66 | { |
| 67 | public: |
| 68 | CommandManagerBase(ndn::mgmt::Dispatcher& m_dispatcher, |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 69 | NamePrefixList& m_namePrefixList, |
| 70 | Lsdb& lsdb, |
| 71 | const std::string& module); |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 72 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 73 | virtual |
| 74 | ~CommandManagerBase() = default; |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 75 | |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 76 | /*! \brief Add desired name prefix to the advertised name prefix list |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 77 | * or insert a prefix into the FIB if parameters is valid. |
| 78 | */ |
| 79 | void |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 80 | advertiseAndInsertPrefix(const ndn::mgmt::ControlParametersBase& parameters, |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 81 | const ndn::mgmt::CommandContinuation& done); |
| 82 | |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 83 | /*! \brief Remove desired name prefix from the advertised name prefix list |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 84 | * or remove a prefix from the FIB if parameters is valid. |
| 85 | */ |
| 86 | void |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 87 | withdrawAndRemovePrefix(const ndn::mgmt::ControlParametersBase& parameters, |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 88 | const ndn::mgmt::CommandContinuation& done); |
| 89 | |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 90 | /*! \brief Save an advertised prefix to the nlsr configuration file. |
| 91 | * \return bool from the overridden function while nullopt here |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 92 | */ |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 93 | virtual std::optional<bool> |
| 94 | afterAdvertise(const ndn::Name& prefix) |
| 95 | { |
| 96 | return std::nullopt; |
| 97 | } |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 98 | |
Davide Pesavento | 968eb1a | 2025-01-07 00:46:05 -0500 | [diff] [blame^] | 99 | /*! \brief Save an advertised prefix to the nlsr configuration file. |
| 100 | * \return bool from the overridden function while nullopt here |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 101 | */ |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 102 | virtual std::optional<bool> |
| 103 | afterWithdraw(const ndn::Name& prefix) |
| 104 | { |
| 105 | return std::nullopt; |
| 106 | } |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 107 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 108 | protected: |
| 109 | NamePrefixList& m_namePrefixList; |
| 110 | Lsdb& m_lsdb; |
| 111 | }; |
| 112 | |
| 113 | } // namespace update |
| 114 | } // namespace nlsr |
| 115 | |
| 116 | #endif // NLSR_MANAGER_BASE_HPP |