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