blob: b61e7a8bb33a1b3eeadd8066e6f3a253aaa561f3 [file] [log] [blame]
Junxiao Shib8590312016-12-29 21:22:25 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi2d491752017-07-14 21:32:05 +00002/*
Junxiao Shi38b24c72017-01-05 02:59:31 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shib8590312016-12-29 21:22:25 +00004 * 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_FACE_FACE_SYSTEM_HPP
27#define NFD_DAEMON_FACE_FACE_SYSTEM_HPP
28
Junxiao Shi38b24c72017-01-05 02:59:31 +000029#include "channel.hpp"
Junxiao Shib8590312016-12-29 21:22:25 +000030#include "core/config-file.hpp"
Junxiao Shi38b24c72017-01-05 02:59:31 +000031#include "core/network-interface-predicate.hpp"
Junxiao Shi2d491752017-07-14 21:32:05 +000032#include <ndn-cxx/net/network-address.hpp>
33#include <ndn-cxx/net/network-interface.hpp>
34#include <ndn-cxx/net/network-monitor.hpp>
Junxiao Shib8590312016-12-29 21:22:25 +000035
36namespace nfd {
37
38class FaceTable;
Junxiao Shib8590312016-12-29 21:22:25 +000039
40namespace face {
41
Junxiao Shi38b24c72017-01-05 02:59:31 +000042class ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +000043struct ProtocolFactoryCtorParams;
Junxiao Shi38b24c72017-01-05 02:59:31 +000044
Junxiao Shib8590312016-12-29 21:22:25 +000045/** \brief entry point of the face system
46 *
Junxiao Shi38b24c72017-01-05 02:59:31 +000047 * NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy.
48 * FaceSystem class is the entry point of NFD's face system and owns ProtocolFactory objects.
Junxiao Shib8590312016-12-29 21:22:25 +000049 */
50class FaceSystem : noncopyable
51{
52public:
Junxiao Shi0ba6d642017-07-17 00:53:22 +000053 FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon);
Junxiao Shi2d491752017-07-14 21:32:05 +000054
55 DEPRECATED(
Junxiao Shib8590312016-12-29 21:22:25 +000056 explicit
Junxiao Shi2d491752017-07-14 21:32:05 +000057 FaceSystem(FaceTable& faceTable));
Junxiao Shib8590312016-12-29 21:22:25 +000058
Junxiao Shib47247d2017-01-24 15:09:16 +000059 ~FaceSystem();
60
Junxiao Shib8590312016-12-29 21:22:25 +000061 /** \return ProtocolFactory objects owned by the FaceSystem
62 */
63 std::set<const ProtocolFactory*>
64 listProtocolFactories() const;
65
Junxiao Shi38b24c72017-01-05 02:59:31 +000066 /** \return ProtocolFactory for the specified registered factory id or nullptr if not found
Junxiao Shib8590312016-12-29 21:22:25 +000067 */
68 ProtocolFactory*
Junxiao Shi38b24c72017-01-05 02:59:31 +000069 getFactoryById(const std::string& id);
70
71 /** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found
72 */
73 ProtocolFactory*
74 getFactoryByScheme(const std::string& scheme);
Junxiao Shib8590312016-12-29 21:22:25 +000075
Junxiao Shiea47bde2017-01-26 17:49:16 +000076 FaceTable&
77 getFaceTable()
78 {
79 return m_faceTable;
80 }
81
Junxiao Shib8590312016-12-29 21:22:25 +000082 /** \brief register handler for face_system section of NFD configuration file
83 */
84 void
85 setConfigFile(ConfigFile& configFile);
86
Junxiao Shi38b24c72017-01-05 02:59:31 +000087 /** \brief context for processing a config section in ProtocolFactory
88 */
89 class ConfigContext : noncopyable
90 {
91 public:
Junxiao Shi38b24c72017-01-05 02:59:31 +000092 bool isDryRun;
Junxiao Shi38b24c72017-01-05 02:59:31 +000093 };
94
Junxiao Shi0ba6d642017-07-17 00:53:22 +000095PUBLIC_WITH_TESTS_ELSE_PRIVATE:
96 ProtocolFactoryCtorParams
97 makePFCtorParams();
98
Junxiao Shib8590312016-12-29 21:22:25 +000099private:
100 void
101 processConfig(const ConfigSection& configSection, bool isDryRun,
102 const std::string& filename);
103
Junxiao Shib8590312016-12-29 21:22:25 +0000104PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shi38b24c72017-01-05 02:59:31 +0000105 /** \brief config section name => protocol factory
Junxiao Shi38b24c72017-01-05 02:59:31 +0000106 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000107 std::map<std::string, unique_ptr<ProtocolFactory>> m_factories;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000108
Junxiao Shib47247d2017-01-24 15:09:16 +0000109private:
Junxiao Shib8590312016-12-29 21:22:25 +0000110 /** \brief scheme => protocol factory
111 *
112 * The same protocol factory may be available under multiple schemes.
113 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000114 std::map<std::string, ProtocolFactory*> m_factoryByScheme;
Junxiao Shib8590312016-12-29 21:22:25 +0000115
116 FaceTable& m_faceTable;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000117
118 shared_ptr<ndn::net::NetworkMonitor> m_netmon;
Junxiao Shib8590312016-12-29 21:22:25 +0000119};
120
121} // namespace face
122
123using face::FaceSystem;
124
125} // namespace nfd
126
127#endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP