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