Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 4 | * 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 Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 29 | #include "channel.hpp" |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 30 | #include "core/config-file.hpp" |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 31 | #include "core/network-interface-predicate.hpp" |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/net/network-address.hpp> |
| 33 | #include <ndn-cxx/net/network-interface.hpp> |
| 34 | #include <ndn-cxx/net/network-monitor.hpp> |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | |
| 38 | class FaceTable; |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 39 | |
| 40 | namespace face { |
| 41 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 42 | class ProtocolFactory; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 43 | struct ProtocolFactoryCtorParams; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 44 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 45 | /** \brief entry point of the face system |
| 46 | * |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 47 | * 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 Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 49 | */ |
| 50 | class FaceSystem : noncopyable |
| 51 | { |
| 52 | public: |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 53 | FaceSystem(FaceTable& faceTable, shared_ptr<ndn::net::NetworkMonitor> netmon); |
Junxiao Shi | 2d49175 | 2017-07-14 21:32:05 +0000 | [diff] [blame] | 54 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 55 | ~FaceSystem(); |
| 56 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 57 | /** \return ProtocolFactory objects owned by the FaceSystem |
| 58 | */ |
| 59 | std::set<const ProtocolFactory*> |
| 60 | listProtocolFactories() const; |
| 61 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 62 | /** \return ProtocolFactory for the specified registered factory id or nullptr if not found |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 63 | */ |
| 64 | ProtocolFactory* |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 65 | getFactoryById(const std::string& id); |
| 66 | |
| 67 | /** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found |
| 68 | */ |
| 69 | ProtocolFactory* |
| 70 | getFactoryByScheme(const std::string& scheme); |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 71 | |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 72 | FaceTable& |
| 73 | getFaceTable() |
| 74 | { |
| 75 | return m_faceTable; |
| 76 | } |
| 77 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 78 | /** \brief register handler for face_system section of NFD configuration file |
| 79 | */ |
| 80 | void |
| 81 | setConfigFile(ConfigFile& configFile); |
| 82 | |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 83 | /** \brief configuration options from "general" section |
| 84 | */ |
| 85 | struct GeneralConfig |
| 86 | { |
| 87 | bool wantCongestionMarking = false; |
| 88 | }; |
| 89 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 90 | /** \brief context for processing a config section in ProtocolFactory |
| 91 | */ |
| 92 | class ConfigContext : noncopyable |
| 93 | { |
| 94 | public: |
Eric Newberry | 0c84164 | 2018-01-17 15:01:00 -0700 | [diff] [blame] | 95 | GeneralConfig generalConfig; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 96 | bool isDryRun; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 99 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 100 | ProtocolFactoryCtorParams |
| 101 | makePFCtorParams(); |
| 102 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 103 | private: |
| 104 | void |
| 105 | processConfig(const ConfigSection& configSection, bool isDryRun, |
| 106 | const std::string& filename); |
| 107 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 108 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 109 | /** \brief config section name => protocol factory |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 110 | */ |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 111 | std::map<std::string, unique_ptr<ProtocolFactory>> m_factories; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 112 | |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 113 | private: |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 114 | /** \brief scheme => protocol factory |
| 115 | * |
| 116 | * The same protocol factory may be available under multiple schemes. |
| 117 | */ |
Junxiao Shi | b47247d | 2017-01-24 15:09:16 +0000 | [diff] [blame] | 118 | std::map<std::string, ProtocolFactory*> m_factoryByScheme; |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 119 | |
| 120 | FaceTable& m_faceTable; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 121 | |
| 122 | shared_ptr<ndn::net::NetworkMonitor> m_netmon; |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace face |
| 126 | |
| 127 | using face::FaceSystem; |
| 128 | |
| 129 | } // namespace nfd |
| 130 | |
| 131 | #endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP |