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