Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Davide Pesavento | 1b077f6 | 2019-02-19 19:19:44 -0500 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_RIB_SERVICE_HPP |
| 27 | #define NFD_DAEMON_RIB_SERVICE_HPP |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 28 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 29 | #include "common/config-file.hpp" |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 30 | #include "mgmt/rib-manager.hpp" |
| 31 | #include "rib/fib-updater.hpp" |
| 32 | #include "rib/rib.hpp" |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 33 | |
| 34 | #include <ndn-cxx/face.hpp> |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 35 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 36 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 37 | #include <ndn-cxx/security/key-chain.hpp> |
| 38 | #include <ndn-cxx/transport/transport.hpp> |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 39 | #include <ndn-cxx/util/scheduler.hpp> |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 40 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 41 | namespace nfd::rib { |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 42 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 43 | class Readvertise; |
Alexander Afanasyev | c3ea5a7 | 2015-02-12 20:14:16 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 45 | /** |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 46 | * \brief Initializes and executes the NFD-RIB service thread. |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 47 | * |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 48 | * Only one instance of this class can be created at any time. |
Davide Pesavento | a9e1ab2 | 2023-10-02 22:10:45 -0400 | [diff] [blame] | 49 | * After initialization, NFD-RIB instance can be started by running the global io_context. |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 50 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 51 | class Service : noncopyable |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 52 | { |
| 53 | public: |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 54 | /** |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 55 | * \brief Create NFD-RIB service. |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 56 | * \param configFile absolute or relative path of configuration file |
| 57 | * \param keyChain the KeyChain |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 58 | * \throw std::logic_error Instance of rib::Service has been already constructed |
| 59 | * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 60 | */ |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 61 | Service(const std::string& configFile, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 64 | * \brief Create NFD-RIB service. |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 65 | * \param configSection parsed configuration section |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 66 | * \param keyChain the KeyChain |
| 67 | * \note This constructor overload is more appropriate for integrated environments, |
| 68 | * such as NS-3 or android. Error messages related to configuration file |
| 69 | * will use "internal://nfd.conf" as configuration filename. |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 70 | * \throw std::logic_error Instance of rib::Service has been already constructed |
| 71 | * \throw std::logic_error Instance of rib::Service is not constructed on RIB thread |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 72 | */ |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 73 | Service(const ConfigSection& configSection, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 74 | |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 75 | ~Service(); |
Alexander Afanasyev | c3ea5a7 | 2015-02-12 20:14:16 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 78 | * \brief Get a reference to the only instance of this class. |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 79 | * \throw std::logic_error No instance has been constructed |
| 80 | * \throw std::logic_error This function is invoked on a thread other than the RIB thread |
| 81 | */ |
| 82 | static Service& |
| 83 | get(); |
| 84 | |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 85 | RibManager& |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 86 | getRibManager() noexcept |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 87 | { |
| 88 | return m_ribManager; |
| 89 | } |
| 90 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 91 | private: |
Ashlesh Gawande | f84bac5 | 2018-08-27 07:39:31 +0000 | [diff] [blame] | 92 | template<typename ConfigParseFunc> |
| 93 | Service(ndn::KeyChain& keyChain, shared_ptr<ndn::Transport> localNfdTransport, |
| 94 | const ConfigParseFunc& configParse); |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 95 | |
| 96 | void |
| 97 | processConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
| 98 | |
| 99 | void |
| 100 | checkConfig(const ConfigSection& section, const std::string& filename); |
| 101 | |
| 102 | void |
| 103 | applyConfig(const ConfigSection& section, const std::string& filename); |
| 104 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 105 | private: |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 106 | static inline Service* s_instance = nullptr; |
Teng Liang | 04d5ce6 | 2018-08-06 10:20:24 +0800 | [diff] [blame] | 107 | |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 108 | ndn::KeyChain& m_keyChain; |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 109 | ndn::Face m_face; |
| 110 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 111 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 112 | Rib m_rib; |
| 113 | FibUpdater m_fibUpdater; |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 114 | unique_ptr<Readvertise> m_readvertiseNlsr; |
Yanbiao Li | f48d080 | 2018-06-01 03:00:02 -0700 | [diff] [blame] | 115 | unique_ptr<Readvertise> m_readvertisePropagation; |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 116 | ndn::mgmt::Dispatcher m_dispatcher; |
| 117 | RibManager m_ribManager; |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 120 | } // namespace nfd::rib |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 121 | |
Davide Pesavento | 1b077f6 | 2019-02-19 19:19:44 -0500 | [diff] [blame] | 122 | #endif // NFD_DAEMON_RIB_SERVICE_HPP |