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