blob: 4aadc1887af791d2f9973e434723e23448e4edb9 [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/*
Junxiao Shif2bfb442018-01-05 12:34:57 +00003 * Copyright (c) 2014-2018, 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
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080029#include "core/config-file.hpp"
Alexander Afanasyev3f41ade2015-06-29 18:31:22 -070030#include "core/scheduler.hpp"
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080031
Junxiao Shi83be1da2017-06-30 13:37:37 +000032#include <ndn-cxx/net/network-monitor.hpp>
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080033#include <ndn-cxx/security/key-chain.hpp>
34
Yanbiao Li698f4fe2015-08-19 16:30:16 -070035namespace ndn {
Junxiao Shi6535f1e2015-10-08 13:02:18 -070036class Face;
Yanbiao Li698f4fe2015-08-19 16:30:16 -070037namespace mgmt {
Yanbiao Li698f4fe2015-08-19 16:30:16 -070038class Dispatcher;
Junxiao Shicde37ad2015-12-24 01:02:05 -070039} // namespace mgmt
40} // namespace ndn
Yanbiao Li698f4fe2015-08-19 16:30:16 -070041
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080042namespace nfd {
43
44class Forwarder;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000045class CommandAuthenticator;
Junxiao Shif2bfb442018-01-05 12:34:57 +000046
47// forward-declare management modules, in the order as defined in management protocol
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070048class ForwarderStatusManager;
Junxiao Shif2bfb442018-01-05 12:34:57 +000049class FaceManager;
50class FibManager;
51class CsManager;
52class StrategyChoiceManager;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080053
Junxiao Shicde37ad2015-12-24 01:02:05 -070054namespace face {
55class Face;
Junxiao Shiea47bde2017-01-26 17:49:16 +000056class FaceSystem;
Junxiao Shicde37ad2015-12-24 01:02:05 -070057} // namespace face
58
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080059/**
60 * \brief Class representing NFD instance
61 * This class can be used to initialize all components of NFD
62 */
63class Nfd : noncopyable
64{
65public:
66 /**
67 * \brief Create NFD instance using absolute or relative path to \p configFile
68 */
69 Nfd(const std::string& configFile, ndn::KeyChain& keyChain);
70
71 /**
72 * \brief Create NFD instance using a parsed ConfigSection \p config
73 * This version of the constructor is more appropriate for integrated environments,
74 * such as NS-3 or android.
75 * \note When using this version of the constructor, error messages will include
76 * "internal://nfd.conf" when referring to configuration errors.
77 */
78 Nfd(const ConfigSection& config, ndn::KeyChain& keyChain);
79
80 /**
Alexander Afanasyev2bda6f82015-02-10 14:17:19 -080081 * \brief Destructor
82 */
83 ~Nfd();
84
85 /**
Alexander Afanasyev31c781e2015-02-09 17:39:59 -080086 * \brief Perform initialization of NFD instance
87 * After initialization, NFD instance can be started by invoking run on globalIoService
88 */
89 void
90 initialize();
91
92 /**
93 * \brief Reload configuration file and apply update (if any)
94 */
95 void
96 reloadConfigFile();
97
98private:
Junxiao Shi2d491752017-07-14 21:32:05 +000099 explicit
100 Nfd(ndn::KeyChain& keyChain);
101
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800102 void
Davide Pesaventoa3148082018-04-12 18:21:54 -0400103 configureLogging();
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800104
105 void
106 initializeManagement();
107
Alexander Afanasyev3f41ade2015-06-29 18:31:22 -0700108 void
109 reloadConfigFileFaceSection();
110
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800111private:
112 std::string m_configFile;
113 ConfigSection m_configSection;
114
Alexander Afanasyev2bda6f82015-02-10 14:17:19 -0800115 unique_ptr<Forwarder> m_forwarder;
Junxiao Shiea47bde2017-01-26 17:49:16 +0000116 unique_ptr<face::FaceSystem> m_faceSystem;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800117
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000118 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 Li7cec7ea2015-08-19 16:30:16 -0700123 unique_ptr<ForwarderStatusManager> m_forwarderStatusManager;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000124 unique_ptr<FaceManager> m_faceManager;
125 unique_ptr<FibManager> m_fibManager;
Junxiao Shif2bfb442018-01-05 12:34:57 +0000126 unique_ptr<CsManager> m_csManager;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000127 unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800128
Junxiao Shi2d491752017-07-14 21:32:05 +0000129 shared_ptr<ndn::net::NetworkMonitor> m_netmon;
Junxiao Shi9ddf1b52016-08-22 03:58:55 +0000130 scheduler::ScopedEventId m_reloadConfigEvent;
Alexander Afanasyev31c781e2015-02-09 17:39:59 -0800131};
132
133} // namespace nfd
134
135#endif // NFD_DAEMON_NFD_HPP