blob: 6441ee7679944f4cb3dafe10578076f19fb803ee [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 Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, 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
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040029#include "common/config-file.hpp"
30
Junxiao Shi2d491752017-07-14 21:32:05 +000031#include <ndn-cxx/net/network-address.hpp>
32#include <ndn-cxx/net/network-interface.hpp>
33#include <ndn-cxx/net/network-monitor.hpp>
Junxiao Shib8590312016-12-29 21:22:25 +000034
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050035#include <map>
36#include <set>
37
Junxiao Shib8590312016-12-29 21:22:25 +000038namespace nfd {
39
40class FaceTable;
Junxiao Shib8590312016-12-29 21:22:25 +000041
42namespace face {
43
Junxiao Shieef49a92018-11-10 12:19:36 +000044class NetdevBound;
Junxiao Shi38b24c72017-01-05 02:59:31 +000045class ProtocolFactory;
Junxiao Shi0ba6d642017-07-17 00:53:22 +000046struct ProtocolFactoryCtorParams;
Junxiao Shi38b24c72017-01-05 02:59:31 +000047
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040048/**
49 * \brief Entry point of NFD's face system.
Junxiao Shib8590312016-12-29 21:22:25 +000050 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040051 * NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy.
52 * The FaceSystem class is the entry point of the face system and owns all ProtocolFactory objects.
Junxiao Shib8590312016-12-29 21:22:25 +000053 */
54class FaceSystem : noncopyable
55{
56public:
Junxiao Shi0ba6d642017-07-17 00:53:22 +000057 FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon);
Junxiao Shi2d491752017-07-14 21:32:05 +000058
Junxiao Shib47247d2017-01-24 15:09:16 +000059 ~FaceSystem();
60
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040061 /**
62 * \brief Returns all ProtocolFactory objects owned by the face system.
Junxiao Shib8590312016-12-29 21:22:25 +000063 */
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040064 [[nodiscard]] std::set<const ProtocolFactory*>
Junxiao Shib8590312016-12-29 21:22:25 +000065 listProtocolFactories() const;
66
Davide Pesaventoc5a9f812023-10-17 18:01:52 -040067 /**
68 * \return ProtocolFactory for the specified registered factory id or nullptr if not found.
Junxiao Shib8590312016-12-29 21:22:25 +000069 */
70 ProtocolFactory*
Davide Pesaventoc5a9f812023-10-17 18:01:52 -040071 getFactoryById(const std::string& id) const;
Junxiao Shi38b24c72017-01-05 02:59:31 +000072
Davide Pesaventoc5a9f812023-10-17 18:01:52 -040073 /**
74 * \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found.
Junxiao Shi38b24c72017-01-05 02:59:31 +000075 */
76 ProtocolFactory*
Davide Pesaventoc5a9f812023-10-17 18:01:52 -040077 getFactoryByScheme(const std::string& scheme) const;
Junxiao Shib8590312016-12-29 21:22:25 +000078
Junxiao Shieef49a92018-11-10 12:19:36 +000079 bool
80 hasFactoryForScheme(const std::string& scheme) const;
81
Junxiao Shiea47bde2017-01-26 17:49:16 +000082 FaceTable&
83 getFaceTable()
84 {
85 return m_faceTable;
86 }
87
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040088 /** \brief Register handler for the `face_system` section of NFD's configuration file.
Junxiao Shib8590312016-12-29 21:22:25 +000089 */
90 void
91 setConfigFile(ConfigFile& configFile);
92
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040093 /** \brief Configuration options from `general` section.
Eric Newberry0c841642018-01-17 15:01:00 -070094 */
95 struct GeneralConfig
96 {
Eric Newberry17d18492018-02-10 22:50:06 -070097 bool wantCongestionMarking = true;
Eric Newberry0c841642018-01-17 15:01:00 -070098 };
99
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400100 /** \brief Context for processing a config section in ProtocolFactory.
Junxiao Shi38b24c72017-01-05 02:59:31 +0000101 */
102 class ConfigContext : noncopyable
103 {
104 public:
Eric Newberry0c841642018-01-17 15:01:00 -0700105 GeneralConfig generalConfig;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000106 bool isDryRun;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000107 };
108
Davide Pesavento264af772021-02-09 21:48:24 -0500109NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000110 ProtocolFactoryCtorParams
111 makePFCtorParams();
112
Junxiao Shib8590312016-12-29 21:22:25 +0000113private:
114 void
115 processConfig(const ConfigSection& configSection, bool isDryRun,
116 const std::string& filename);
117
Davide Pesavento264af772021-02-09 21:48:24 -0500118NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400119 /** \brief Config section name => protocol factory.
Junxiao Shi38b24c72017-01-05 02:59:31 +0000120 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000121 std::map<std::string, unique_ptr<ProtocolFactory>> m_factories;
Junxiao Shieef49a92018-11-10 12:19:36 +0000122 unique_ptr<NetdevBound> m_netdevBound;
Junxiao Shi38b24c72017-01-05 02:59:31 +0000123
Junxiao Shib47247d2017-01-24 15:09:16 +0000124private:
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400125 /** \brief Scheme => protocol factory.
Junxiao Shib8590312016-12-29 21:22:25 +0000126 *
127 * The same protocol factory may be available under multiple schemes.
128 */
Junxiao Shib47247d2017-01-24 15:09:16 +0000129 std::map<std::string, ProtocolFactory*> m_factoryByScheme;
Junxiao Shib8590312016-12-29 21:22:25 +0000130
131 FaceTable& m_faceTable;
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000132 shared_ptr<ndn::net::NetworkMonitor> m_netmon;
Junxiao Shib8590312016-12-29 21:22:25 +0000133};
134
135} // namespace face
136
137using face::FaceSystem;
138
139} // namespace nfd
140
141#endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP