Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -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 | |
| 26 | #ifndef NFD_DAEMON_NFD_HPP |
| 27 | #define NFD_DAEMON_NFD_HPP |
| 28 | |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 29 | #include "common/config-file.hpp" |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 30 | |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 31 | #include <ndn-cxx/face.hpp> |
| 32 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Junxiao Shi | 83be1da | 2017-06-30 13:37:37 +0000 | [diff] [blame] | 33 | #include <ndn-cxx/net/network-monitor.hpp> |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 34 | #include <ndn-cxx/security/key-chain.hpp> |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame^] | 35 | #include <ndn-cxx/util/scheduler.hpp> |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 36 | |
| 37 | namespace nfd { |
| 38 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 39 | class FaceTable; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 40 | class Forwarder; |
Junxiao Shi | f2bfb44 | 2018-01-05 12:34:57 +0000 | [diff] [blame] | 41 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 42 | class CommandAuthenticator; |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 43 | class ForwarderStatusManager; |
Junxiao Shi | f2bfb44 | 2018-01-05 12:34:57 +0000 | [diff] [blame] | 44 | class FaceManager; |
| 45 | class FibManager; |
| 46 | class CsManager; |
| 47 | class StrategyChoiceManager; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 48 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 49 | namespace face { |
| 50 | class Face; |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 51 | class FaceSystem; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 52 | } // namespace face |
| 53 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 54 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 55 | * \brief Class representing the NFD instance. |
| 56 | * |
| 57 | * This class is used to initialize all components of NFD. |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 58 | */ |
| 59 | class Nfd : noncopyable |
| 60 | { |
| 61 | public: |
| 62 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 63 | * \brief Create NFD instance using an absolute or relative path to a configuration file. |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 64 | */ |
| 65 | Nfd(const std::string& configFile, ndn::KeyChain& keyChain); |
| 66 | |
| 67 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 68 | * \brief Create NFD instance using a parsed ConfigSection. |
| 69 | * |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 70 | * This version of the constructor is more appropriate for integrated environments, |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 71 | * such as NS-3 or Android. |
| 72 | * |
| 73 | * \note When using this version of the constructor, error messages will show |
| 74 | * "internal://nfd.conf" when referring to configuration errors. |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 75 | */ |
| 76 | Nfd(const ConfigSection& config, ndn::KeyChain& keyChain); |
| 77 | |
| 78 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 79 | * \brief Destructor. |
Alexander Afanasyev | 2bda6f8 | 2015-02-10 14:17:19 -0800 | [diff] [blame] | 80 | */ |
| 81 | ~Nfd(); |
| 82 | |
| 83 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 84 | * \brief Perform initialization of NFD instance. |
| 85 | * |
| 86 | * After initialization, NFD can be started by invoking `getGlobalIoService().run()`. |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 87 | */ |
| 88 | void |
| 89 | initialize(); |
| 90 | |
| 91 | /** |
Davide Pesavento | 859a69e | 2019-07-13 17:10:46 -0400 | [diff] [blame] | 92 | * \brief Reload configuration file and apply updates (if any). |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 93 | */ |
| 94 | void |
| 95 | reloadConfigFile(); |
| 96 | |
| 97 | private: |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 98 | explicit |
| 99 | Nfd(ndn::KeyChain& keyChain); |
| 100 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 101 | void |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 102 | configureLogging(); |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 103 | |
| 104 | void |
| 105 | initializeManagement(); |
| 106 | |
Alexander Afanasyev | 3f41ade | 2015-06-29 18:31:22 -0700 | [diff] [blame] | 107 | void |
| 108 | reloadConfigFileFaceSection(); |
| 109 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 110 | private: |
| 111 | std::string m_configFile; |
| 112 | ConfigSection m_configSection; |
| 113 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 114 | unique_ptr<FaceTable> m_faceTable; |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 115 | unique_ptr<face::FaceSystem> m_faceSystem; |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 116 | unique_ptr<Forwarder> m_forwarder; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 117 | |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 118 | ndn::KeyChain& m_keyChain; |
| 119 | shared_ptr<face::Face> m_internalFace; |
| 120 | shared_ptr<ndn::Face> m_internalClientFace; |
| 121 | unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher; |
| 122 | shared_ptr<CommandAuthenticator> m_authenticator; |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 123 | unique_ptr<ForwarderStatusManager> m_forwarderStatusManager; |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 124 | unique_ptr<FaceManager> m_faceManager; |
| 125 | unique_ptr<FibManager> m_fibManager; |
Junxiao Shi | f2bfb44 | 2018-01-05 12:34:57 +0000 | [diff] [blame] | 126 | unique_ptr<CsManager> m_csManager; |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 127 | unique_ptr<StrategyChoiceManager> m_strategyChoiceManager; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 128 | |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 129 | shared_ptr<ndn::net::NetworkMonitor> m_netmon; |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame^] | 130 | ndn::scheduler::ScopedEventId m_reloadConfigEvent; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | } // namespace nfd |
| 134 | |
| 135 | #endif // NFD_DAEMON_NFD_HPP |