Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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_MGMT_FACE_MANAGER_HPP |
| 27 | #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP |
| 28 | |
| 29 | #include "manager-base.hpp" |
| 30 | #include "face/local-face.hpp" |
| 31 | #include <ndn-cxx/management/nfd-face-query-filter.hpp> |
| 32 | |
| 33 | namespace nfd { |
| 34 | |
| 35 | class FaceTable; |
| 36 | class NetworkInterfaceInfo; |
| 37 | class ProtocolFactory; |
| 38 | |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame^] | 39 | namespace face { |
| 40 | class LpFace; |
| 41 | } // namespace face |
| 42 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 43 | /** |
| 44 | * @brief implement the Face Management of NFD Management Protocol. |
| 45 | * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt |
| 46 | */ |
| 47 | class FaceManager : public ManagerBase |
| 48 | { |
| 49 | public: |
| 50 | FaceManager(FaceTable& faceTable, |
| 51 | Dispatcher& dispatcher, |
| 52 | CommandValidator& validator); |
| 53 | |
| 54 | /** |
| 55 | * @brief Subscribe to face_system section for the config file |
| 56 | */ |
| 57 | void |
| 58 | setConfigFile(ConfigFile& configFile); |
| 59 | |
| 60 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand |
| 61 | void |
| 62 | createFace(const Name& topPrefix, const Interest& interest, |
| 63 | const ControlParameters& parameters, |
| 64 | const ndn::mgmt::CommandContinuation& done); |
| 65 | |
| 66 | void |
| 67 | destroyFace(const Name& topPrefix, const Interest& interest, |
| 68 | const ControlParameters& parameters, |
| 69 | const ndn::mgmt::CommandContinuation& done); |
| 70 | |
| 71 | void |
| 72 | enableLocalControl(const Name& topPrefix, const Interest& interest, |
| 73 | const ControlParameters& parameters, |
| 74 | const ndn::mgmt::CommandContinuation& done); |
| 75 | |
| 76 | void |
| 77 | disableLocalControl(const Name& topPrefix, const Interest& interest, |
| 78 | const ControlParameters& parameters, |
| 79 | const ndn::mgmt::CommandContinuation& done); |
| 80 | |
| 81 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand |
| 82 | void |
| 83 | afterCreateFaceSuccess(ControlParameters& parameters, |
| 84 | const shared_ptr<Face>& newFace, |
| 85 | const ndn::mgmt::CommandContinuation& done); |
| 86 | |
| 87 | void |
| 88 | afterCreateFaceFailure(const std::string& reason, |
| 89 | const ndn::mgmt::CommandContinuation& done); |
| 90 | |
| 91 | struct ExtractLocalControlParametersResult |
| 92 | { |
| 93 | bool isValid; |
| 94 | shared_ptr<LocalFace> face; |
Junxiao Shi | 40cb61c | 2015-09-23 18:36:45 -0700 | [diff] [blame^] | 95 | face::LpFace* lpFace; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 96 | LocalControlFeature feature; |
| 97 | }; |
| 98 | |
| 99 | ExtractLocalControlParametersResult |
| 100 | extractLocalControlParameters(const Interest& request, |
| 101 | const ControlParameters& parameters, |
| 102 | const ndn::mgmt::CommandContinuation& done); |
| 103 | |
| 104 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset |
| 105 | void |
| 106 | listFaces(const Name& topPrefix, const Interest& interest, |
| 107 | ndn::mgmt::StatusDatasetContext& context); |
| 108 | |
| 109 | void |
| 110 | listChannels(const Name& topPrefix, const Interest& interest, |
| 111 | ndn::mgmt::StatusDatasetContext& context); |
| 112 | |
| 113 | void |
| 114 | queryFaces(const Name& topPrefix, const Interest& interest, |
| 115 | ndn::mgmt::StatusDatasetContext& context); |
| 116 | |
| 117 | private: // helpers for StatusDataset handler |
| 118 | bool |
| 119 | doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr<Face> face); |
| 120 | |
| 121 | private: // NotificationStream |
| 122 | void |
| 123 | afterFaceAdded(shared_ptr<Face> face, |
| 124 | const ndn::mgmt::PostNotification& post); |
| 125 | |
| 126 | void |
| 127 | afterFaceRemoved(shared_ptr<Face> face, |
| 128 | const ndn::mgmt::PostNotification& post); |
| 129 | |
| 130 | private: // configuration |
| 131 | void |
| 132 | processConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename); |
| 133 | |
| 134 | void |
| 135 | processSectionUnix(const ConfigSection& configSection, bool isDryRun); |
| 136 | |
| 137 | void |
| 138 | processSectionTcp(const ConfigSection& configSection, bool isDryRun); |
| 139 | |
| 140 | void |
| 141 | processSectionUdp(const ConfigSection& configSection, |
| 142 | bool isDryRun, |
| 143 | const std::vector<NetworkInterfaceInfo>& nicList); |
| 144 | |
| 145 | void |
| 146 | processSectionEther(const ConfigSection& configSection, |
| 147 | bool isDryRun, |
| 148 | const std::vector<NetworkInterfaceInfo>& nicList); |
| 149 | |
| 150 | void |
| 151 | processSectionWebSocket(const ConfigSection& configSection, bool isDryRun); |
| 152 | |
| 153 | private: // helpers for configuration |
| 154 | void |
| 155 | addCreatedFaceToForwarder(shared_ptr<Face> newFace); |
| 156 | |
| 157 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 158 | typedef std::map<std::string/*protocol*/, shared_ptr<ProtocolFactory>> FactoryMap; |
| 159 | FactoryMap m_factories; |
| 160 | |
| 161 | private: |
| 162 | FaceTable& m_faceTable; |
| 163 | signal::ScopedConnection m_faceAddConn; |
| 164 | signal::ScopedConnection m_faceRemoveConn; |
| 165 | }; |
| 166 | |
| 167 | } // namespace nfd |
| 168 | |
| 169 | #endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP |