blob: 2bcdfad8bca36e55b96714ce14fe1c5d41f12879 [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/*
Davide Pesavento2cae8ca2019-04-18 20:48:05 -04003 * Copyright (c) 2014-2019, 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"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040030#include "network-predicate.hpp"
31#include "common/config-file.hpp"
32
Junxiao Shi2d491752017-07-14 21:32:05 +000033#include <ndn-cxx/net/network-address.hpp>
34#include <ndn-cxx/net/network-interface.hpp>
35#include <ndn-cxx/net/network-monitor.hpp>
Junxiao Shib8590312016-12-29 21:22:25 +000036
37namespace nfd {
38
39class FaceTable;
Junxiao Shib8590312016-12-29 21:22:25 +000040
41namespace face {
42
Junxiao Shieef49a92018-11-10 12:19:36 +000043class NetdevBound;
Junxiao Shi38b24c72017-01-05 02:59:31 +000044class ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +000045struct ProtocolFactoryCtorParams;
Junxiao Shi38b24c72017-01-05 02:59:31 +000046
Junxiao Shib8590312016-12-29 21:22:25 +000047/** \brief entry point of the face system
48 *
Junxiao Shi38b24c72017-01-05 02:59:31 +000049 * NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy.
50 * FaceSystem class is the entry point of NFD's face system and owns ProtocolFactory objects.
Junxiao Shib8590312016-12-29 21:22:25 +000051 */
52class FaceSystem : noncopyable
53{
54public:
Junxiao Shi0ba6d642017-07-17 00:53:22 +000055 FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon);
Junxiao Shi2d491752017-07-14 21:32:05 +000056
Junxiao Shib47247d2017-01-24 15:09:16 +000057 ~FaceSystem();
58
Junxiao Shib8590312016-12-29 21:22:25 +000059 /** \return ProtocolFactory objects owned by the FaceSystem
60 */
61 std::set<const ProtocolFactory*>
62 listProtocolFactories() const;
63
Junxiao Shi38b24c72017-01-05 02:59:31 +000064 /** \return ProtocolFactory for the specified registered factory id or nullptr if not found
Junxiao Shib8590312016-12-29 21:22:25 +000065 */
66 ProtocolFactory*
Junxiao Shi38b24c72017-01-05 02:59:31 +000067 getFactoryById(const std::string& id);
68
69 /** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found
70 */
71 ProtocolFactory*
72 getFactoryByScheme(const std::string& scheme);
Junxiao Shib8590312016-12-29 21:22:25 +000073
Junxiao Shieef49a92018-11-10 12:19:36 +000074 bool
75 hasFactoryForScheme(const std::string& scheme) const;
76
Junxiao Shiea47bde2017-01-26 17:49:16 +000077 FaceTable&
78 getFaceTable()
79 {
80 return m_faceTable;
81 }
82
Junxiao Shib8590312016-12-29 21:22:25 +000083 /** \brief register handler for face_system section of NFD configuration file
84 */
85 void
86 setConfigFile(ConfigFile& configFile);
87
Eric Newberry0c841642018-01-17 15:01:00 -070088 /** \brief configuration options from "general" section
89 */
90 struct GeneralConfig
91 {
Eric Newberry17d18492018-02-10 22:50:06 -070092 bool wantCongestionMarking = true;
Eric Newberry0c841642018-01-17 15:01:00 -070093 };
94
Junxiao Shi38b24c72017-01-05 02:59:31 +000095 /** \brief context for processing a config section in ProtocolFactory
96 */
97 class ConfigContext : noncopyable
98 {
99 public:
Eric Newberry0c841642018-01-17 15:01:00 -0700100 GeneralConfig generalConfig;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000101 bool isDryRun;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000102 };
103
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000104PUBLIC_WITH_TESTS_ELSE_PRIVATE:
105 ProtocolFactoryCtorParams
106 makePFCtorParams();
107
Junxiao Shib8590312016-12-29 21:22:25 +0000108private:
109 void
110 processConfig(const ConfigSection& configSection, bool isDryRun,
111 const std::string& filename);
112
Junxiao Shib8590312016-12-29 21:22:25 +0000113PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shi38b24c72017-01-05 02:59:31 +0000114 /** \brief config section name => protocol factory
Junxiao Shi38b24c72017-01-05 02:59:31 +0000115 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000116 std::map<std::string, unique_ptr<ProtocolFactory>> m_factories;
Junxiao Shieef49a92018-11-10 12:19:36 +0000117 unique_ptr<NetdevBound> m_netdevBound;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000118
Junxiao Shib47247d2017-01-24 15:09:16 +0000119private:
Junxiao Shib8590312016-12-29 21:22:25 +0000120 /** \brief scheme => protocol factory
121 *
122 * The same protocol factory may be available under multiple schemes.
123 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000124 std::map<std::string, ProtocolFactory*> m_factoryByScheme;
Junxiao Shib8590312016-12-29 21:22:25 +0000125
126 FaceTable& m_faceTable;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000127 shared_ptr<ndn::net::NetworkMonitor> m_netmon;
Junxiao Shib8590312016-12-29 21:22:25 +0000128};
129
130} // namespace face
131
132using face::FaceSystem;
133
134} // namespace nfd
135
136#endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP