blob: 508876c962166fbbd1e1956b3c61ffe829abba2e [file] [log] [blame]
Alexander Afanasyev31c781e2015-02-09 17:39:59 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi2d491752017-07-14 21:32:05 +00002/*
Davide Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, Regents of the University of California,
Alexander Afanasyev31c781e2015-02-09 17:39:59 -08004 * 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 Pesavento2cae8ca2019-04-18 20:48:05 -040029#include "common/config-file.hpp"
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080030
Davide Pesavento859a69e2019-07-13 17:10:46 -040031#include <ndn-cxx/face.hpp>
32#include <ndn-cxx/mgmt/dispatcher.hpp>
Junxiao Shi83be1da2017-06-30 13:37:37 +000033#include <ndn-cxx/net/network-monitor.hpp>
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080034#include <ndn-cxx/security/key-chain.hpp>
35
36namespace nfd {
37
38class Forwarder;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000039class CommandAuthenticator;
Junxiao Shif2bfb442018-01-05 12:34:57 +000040
Davide Pesavento859a69e2019-07-13 17:10:46 -040041// forward-declare management modules, in the order defined in management protocol
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070042class ForwarderStatusManager;
Junxiao Shif2bfb442018-01-05 12:34:57 +000043class FaceManager;
44class FibManager;
45class CsManager;
46class StrategyChoiceManager;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080047
Junxiao Shicde37ad2015-12-24 01:02:05 -070048namespace face {
49class Face;
Junxiao Shiea47bde2017-01-26 17:49:16 +000050class FaceSystem;
Junxiao Shicde37ad2015-12-24 01:02:05 -070051} // namespace face
52
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080053/**
Davide Pesavento859a69e2019-07-13 17:10:46 -040054 * \brief Class representing the NFD instance.
55 *
56 * This class is used to initialize all components of NFD.
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080057 */
58class Nfd : noncopyable
59{
60public:
61 /**
Davide Pesavento859a69e2019-07-13 17:10:46 -040062 * \brief Create NFD instance using an absolute or relative path to a configuration file.
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080063 */
64 Nfd(const std::string& configFile, ndn::KeyChain& keyChain);
65
66 /**
Davide Pesavento859a69e2019-07-13 17:10:46 -040067 * \brief Create NFD instance using a parsed ConfigSection.
68 *
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080069 * This version of the constructor is more appropriate for integrated environments,
Davide Pesavento859a69e2019-07-13 17:10:46 -040070 * such as NS-3 or Android.
71 *
72 * \note When using this version of the constructor, error messages will show
73 * "internal://nfd.conf" when referring to configuration errors.
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080074 */
75 Nfd(const ConfigSection& config, ndn::KeyChain& keyChain);
76
77 /**
Davide Pesavento859a69e2019-07-13 17:10:46 -040078 * \brief Destructor.
Alexander Afanasyev2bda6f82015-02-10 14:17:19 -080079 */
80 ~Nfd();
81
82 /**
Davide Pesavento859a69e2019-07-13 17:10:46 -040083 * \brief Perform initialization of NFD instance.
84 *
85 * After initialization, NFD can be started by invoking `getGlobalIoService().run()`.
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080086 */
87 void
88 initialize();
89
90 /**
Davide Pesavento859a69e2019-07-13 17:10:46 -040091 * \brief Reload configuration file and apply updates (if any).
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080092 */
93 void
94 reloadConfigFile();
95
96private:
Junxiao Shi2d491752017-07-14 21:32:05 +000097 explicit
98 Nfd(ndn::KeyChain& keyChain);
99
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800100 void
Davide Pesaventoa3148082018-04-12 18:21:54 -0400101 configureLogging();
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800102
103 void
104 initializeManagement();
105
Alexander Afanasyev3f41ade2015-06-29 18:31:22 -0700106 void
107 reloadConfigFileFaceSection();
108
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800109private:
110 std::string m_configFile;
111 ConfigSection m_configSection;
112
Alexander Afanasyev2bda6f82015-02-10 14:17:19 -0800113 unique_ptr<Forwarder> m_forwarder;
Junxiao Shiea47bde2017-01-26 17:49:16 +0000114 unique_ptr<face::FaceSystem> m_faceSystem;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800115
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000116 ndn::KeyChain& m_keyChain;
117 shared_ptr<face::Face> m_internalFace;
118 shared_ptr<ndn::Face> m_internalClientFace;
119 unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
120 shared_ptr<CommandAuthenticator> m_authenticator;
Yanbiao Li7cec7ea2015-08-19 16:30:16 -0700121 unique_ptr<ForwarderStatusManager> m_forwarderStatusManager;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000122 unique_ptr<FaceManager> m_faceManager;
123 unique_ptr<FibManager> m_fibManager;
Junxiao Shif2bfb442018-01-05 12:34:57 +0000124 unique_ptr<CsManager> m_csManager;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000125 unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800126
Junxiao Shi2d491752017-07-14 21:32:05 +0000127 shared_ptr<ndn::net::NetworkMonitor> m_netmon;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000128 scheduler::ScopedEventId m_reloadConfigEvent;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800129};
130
131} // namespace nfd
132
133#endif // NFD_DAEMON_NFD_HPP