Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [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_MGMT_FACE_MANAGER_HPP |
| 27 | #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP |
| 28 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 29 | #include "nfd-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> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 32 | #include "face/face.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | |
| 36 | class FaceTable; |
| 37 | class NetworkInterfaceInfo; |
| 38 | class ProtocolFactory; |
| 39 | |
| 40 | /** |
| 41 | * @brief implement the Face Management of NFD Management Protocol. |
| 42 | * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt |
| 43 | */ |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 44 | class FaceManager : public NfdManagerBase |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | FaceManager(FaceTable& faceTable, |
| 48 | Dispatcher& dispatcher, |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 49 | CommandAuthenticator& authenticator); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * @brief Subscribe to face_system section for the config file |
| 53 | */ |
| 54 | void |
| 55 | setConfigFile(ConfigFile& configFile); |
| 56 | |
| 57 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand |
| 58 | void |
| 59 | createFace(const Name& topPrefix, const Interest& interest, |
| 60 | const ControlParameters& parameters, |
| 61 | const ndn::mgmt::CommandContinuation& done); |
| 62 | |
| 63 | void |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 64 | updateFace(const Name& topPrefix, const Interest& interest, |
| 65 | const ControlParameters& parameters, |
| 66 | const ndn::mgmt::CommandContinuation& done); |
| 67 | |
| 68 | void |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 69 | destroyFace(const Name& topPrefix, const Interest& interest, |
| 70 | const ControlParameters& parameters, |
| 71 | const ndn::mgmt::CommandContinuation& done); |
| 72 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 73 | /** |
| 74 | * \deprecated use Flags+Mask in faces/update instead |
| 75 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 76 | void |
| 77 | enableLocalControl(const Name& topPrefix, const Interest& interest, |
| 78 | const ControlParameters& parameters, |
| 79 | const ndn::mgmt::CommandContinuation& done); |
| 80 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 81 | /** |
| 82 | * \deprecated use Flags+Mask in faces/update instead |
| 83 | */ |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 84 | void |
| 85 | disableLocalControl(const Name& topPrefix, const Interest& interest, |
| 86 | const ControlParameters& parameters, |
| 87 | const ndn::mgmt::CommandContinuation& done); |
| 88 | |
| 89 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand |
| 90 | void |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 91 | afterCreateFaceSuccess(const ControlParameters& parameters, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 92 | const shared_ptr<Face>& newFace, |
| 93 | const ndn::mgmt::CommandContinuation& done); |
| 94 | |
| 95 | void |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 96 | afterCreateFaceFailure(uint32_t status, |
| 97 | const std::string& reason, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 98 | const ndn::mgmt::CommandContinuation& done); |
| 99 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 100 | Face* |
| 101 | findFaceForLocalControl(const Interest& request, |
| 102 | const ControlParameters& parameters, |
| 103 | const ndn::mgmt::CommandContinuation& done); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 104 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 105 | static void |
| 106 | setLinkServiceOptions(Face& face, |
| 107 | const ControlParameters& parameters, |
| 108 | ControlParameters& response); |
| 109 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 110 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset |
| 111 | void |
| 112 | listFaces(const Name& topPrefix, const Interest& interest, |
| 113 | ndn::mgmt::StatusDatasetContext& context); |
| 114 | |
| 115 | void |
| 116 | listChannels(const Name& topPrefix, const Interest& interest, |
| 117 | ndn::mgmt::StatusDatasetContext& context); |
| 118 | |
| 119 | void |
| 120 | queryFaces(const Name& topPrefix, const Interest& interest, |
| 121 | ndn::mgmt::StatusDatasetContext& context); |
| 122 | |
| 123 | private: // helpers for StatusDataset handler |
| 124 | bool |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 125 | matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 126 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 127 | /** \brief get status of face, including properties and counters |
| 128 | */ |
| 129 | static ndn::nfd::FaceStatus |
| 130 | collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now); |
| 131 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 132 | /** \brief copy face properties into traits |
| 133 | * \tparam FaceTraits either FaceStatus or FaceEventNotification |
| 134 | */ |
| 135 | template<typename FaceTraits> |
| 136 | static void |
| 137 | collectFaceProperties(const Face& face, FaceTraits& traits); |
| 138 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 139 | private: // NotificationStream |
| 140 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 141 | notifyAddFace(const Face& face); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 142 | |
| 143 | void |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 144 | notifyRemoveFace(const Face& face); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 145 | |
| 146 | private: // configuration |
| 147 | void |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 148 | processConfig(const ConfigSection& configSection, bool isDryRun, |
| 149 | const std::string& filename); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 150 | |
| 151 | void |
| 152 | processSectionUnix(const ConfigSection& configSection, bool isDryRun); |
| 153 | |
| 154 | void |
| 155 | processSectionTcp(const ConfigSection& configSection, bool isDryRun); |
| 156 | |
| 157 | void |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 158 | processSectionUdp(const ConfigSection& configSection, bool isDryRun, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 159 | const std::vector<NetworkInterfaceInfo>& nicList); |
| 160 | |
| 161 | void |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 162 | processSectionEther(const ConfigSection& configSection, bool isDryRun, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 163 | const std::vector<NetworkInterfaceInfo>& nicList); |
| 164 | |
| 165 | void |
| 166 | processSectionWebSocket(const ConfigSection& configSection, bool isDryRun); |
| 167 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 168 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Davide Pesavento | 1d7e7af | 2015-10-10 23:54:08 +0200 | [diff] [blame] | 169 | std::map<std::string /*protocol*/, shared_ptr<ProtocolFactory>> m_factories; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 170 | FaceTable& m_faceTable; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 171 | |
| 172 | private: |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 173 | ndn::mgmt::PostNotification m_postNotification; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 174 | signal::ScopedConnection m_faceAddConn; |
| 175 | signal::ScopedConnection m_faceRemoveConn; |
| 176 | }; |
| 177 | |
| 178 | } // namespace nfd |
| 179 | |
| 180 | #endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP |