blob: bca770236c0a24280237841c354d278e482d6a26 [file] [log] [blame]
Junxiao Shib8590312016-12-29 21:22:25 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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.hpp"
32#include "core/network-interface-predicate.hpp"
Junxiao Shib8590312016-12-29 21:22:25 +000033
34namespace nfd {
35
36class FaceTable;
Junxiao Shib8590312016-12-29 21:22:25 +000037
38namespace face {
39
Junxiao Shi38b24c72017-01-05 02:59:31 +000040class ProtocolFactory;
41
Junxiao Shib8590312016-12-29 21:22:25 +000042/** \brief entry point of the face system
43 *
Junxiao Shi38b24c72017-01-05 02:59:31 +000044 * NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy.
45 * FaceSystem class is the entry point of NFD's face system and owns ProtocolFactory objects.
Junxiao Shib8590312016-12-29 21:22:25 +000046 */
47class FaceSystem : noncopyable
48{
49public:
50 explicit
51 FaceSystem(FaceTable& faceTable);
52
Junxiao Shib47247d2017-01-24 15:09:16 +000053 ~FaceSystem();
54
Junxiao Shib8590312016-12-29 21:22:25 +000055 /** \return ProtocolFactory objects owned by the FaceSystem
56 */
57 std::set<const ProtocolFactory*>
58 listProtocolFactories() const;
59
Junxiao Shi38b24c72017-01-05 02:59:31 +000060 /** \return ProtocolFactory for the specified registered factory id or nullptr if not found
Junxiao Shib8590312016-12-29 21:22:25 +000061 */
62 ProtocolFactory*
Junxiao Shi38b24c72017-01-05 02:59:31 +000063 getFactoryById(const std::string& id);
64
65 /** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found
66 */
67 ProtocolFactory*
68 getFactoryByScheme(const std::string& scheme);
Junxiao Shib8590312016-12-29 21:22:25 +000069
70 /** \brief register handler for face_system section of NFD configuration file
71 */
72 void
73 setConfigFile(ConfigFile& configFile);
74
Junxiao Shi38b24c72017-01-05 02:59:31 +000075 /** \brief context for processing a config section in ProtocolFactory
76 */
77 class ConfigContext : noncopyable
78 {
79 public:
80 const std::vector<NetworkInterfaceInfo>&
Junxiao Shi7003c602017-01-10 13:35:28 +000081 listNetifs() const
Junxiao Shi38b24c72017-01-05 02:59:31 +000082 {
Junxiao Shi7003c602017-01-10 13:35:28 +000083 ///\todo get netifs from NetworkMonitor
84 return m_netifs;
Junxiao Shi38b24c72017-01-05 02:59:31 +000085 }
86
87 public:
88 bool isDryRun;
89 FaceCreatedCallback addFace;
90 ///\todo add NetworkMonitor
91
92 private:
Junxiao Shi7003c602017-01-10 13:35:28 +000093 std::vector<NetworkInterfaceInfo> m_netifs;
Junxiao Shi38b24c72017-01-05 02:59:31 +000094
95 friend class FaceSystem;
96 };
97
Junxiao Shib8590312016-12-29 21:22:25 +000098private:
99 void
100 processConfig(const ConfigSection& configSection, bool isDryRun,
101 const std::string& filename);
102
Junxiao Shib8590312016-12-29 21:22:25 +0000103PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shi38b24c72017-01-05 02:59:31 +0000104 /** \brief config section name => protocol factory
Junxiao Shi38b24c72017-01-05 02:59:31 +0000105 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000106 std::map<std::string, unique_ptr<ProtocolFactory>> m_factories;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000107
Junxiao Shib47247d2017-01-24 15:09:16 +0000108private:
Junxiao Shib8590312016-12-29 21:22:25 +0000109 /** \brief scheme => protocol factory
110 *
111 * The same protocol factory may be available under multiple schemes.
112 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000113 std::map<std::string, ProtocolFactory*> m_factoryByScheme;
Junxiao Shib8590312016-12-29 21:22:25 +0000114
115 FaceTable& m_faceTable;
116};
117
118} // namespace face
119
120using face::FaceSystem;
121
122} // namespace nfd
123
124#endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP