Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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" |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 31 | |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/face-query-filter.hpp> |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 38 | /** |
| 39 | * @brief implement the Face Management of NFD Management Protocol. |
Alexander Afanasyev | 635bf20 | 2017-03-09 21:57:34 +0000 | [diff] [blame] | 40 | * @sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 41 | */ |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 42 | class FaceManager : public NfdManagerBase |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 43 | { |
| 44 | public: |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 45 | FaceManager(FaceSystem& faceSystem, |
Davide Pesavento | cfb1a31 | 2018-03-01 01:30:56 -0500 | [diff] [blame] | 46 | Dispatcher& dispatcher, |
| 47 | CommandAuthenticator& authenticator); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 48 | |
| 49 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand |
| 50 | void |
| 51 | createFace(const Name& topPrefix, const Interest& interest, |
| 52 | const ControlParameters& parameters, |
| 53 | const ndn::mgmt::CommandContinuation& done); |
| 54 | |
| 55 | void |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 56 | updateFace(const Name& topPrefix, const Interest& interest, |
| 57 | const ControlParameters& parameters, |
| 58 | const ndn::mgmt::CommandContinuation& done); |
| 59 | |
| 60 | void |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 61 | destroyFace(const Name& topPrefix, const Interest& interest, |
| 62 | const ControlParameters& parameters, |
| 63 | const ndn::mgmt::CommandContinuation& done); |
| 64 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 65 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand |
| 66 | void |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 67 | afterCreateFaceSuccess(const ControlParameters& parameters, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 68 | const shared_ptr<Face>& newFace, |
| 69 | const ndn::mgmt::CommandContinuation& done); |
| 70 | |
| 71 | void |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 72 | afterCreateFaceFailure(uint32_t status, |
| 73 | const std::string& reason, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 74 | const ndn::mgmt::CommandContinuation& done); |
| 75 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 76 | static void |
| 77 | setLinkServiceOptions(Face& face, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 78 | const ControlParameters& parameters); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 79 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 80 | static ControlParameters |
Junxiao Shi | 1cce2a3 | 2017-05-02 02:39:55 +0000 | [diff] [blame] | 81 | collectFaceProperties(const Face& face, bool wantUris); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 82 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 83 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset |
| 84 | void |
| 85 | listFaces(const Name& topPrefix, const Interest& interest, |
| 86 | ndn::mgmt::StatusDatasetContext& context); |
| 87 | |
| 88 | void |
| 89 | listChannels(const Name& topPrefix, const Interest& interest, |
| 90 | ndn::mgmt::StatusDatasetContext& context); |
| 91 | |
| 92 | void |
| 93 | queryFaces(const Name& topPrefix, const Interest& interest, |
| 94 | ndn::mgmt::StatusDatasetContext& context); |
| 95 | |
| 96 | private: // helpers for StatusDataset handler |
| 97 | bool |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 98 | matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 99 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 100 | /** \brief get status of face, including properties and counters |
| 101 | */ |
| 102 | static ndn::nfd::FaceStatus |
| 103 | collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now); |
| 104 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 105 | /** \brief copy face properties into traits |
| 106 | * \tparam FaceTraits either FaceStatus or FaceEventNotification |
| 107 | */ |
| 108 | template<typename FaceTraits> |
| 109 | static void |
| 110 | collectFaceProperties(const Face& face, FaceTraits& traits); |
| 111 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 112 | private: // NotificationStream |
| 113 | void |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 114 | notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 115 | |
| 116 | void |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 117 | connectFaceStateChangeSignal(const Face& face); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 118 | |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 119 | private: |
Junxiao Shi | ea47bde | 2017-01-26 17:49:16 +0000 | [diff] [blame] | 120 | FaceSystem& m_faceSystem; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 121 | FaceTable& m_faceTable; |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 122 | |
| 123 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Eric Newberry | 1b4ba05 | 2016-10-07 23:04:07 -0700 | [diff] [blame] | 124 | std::map<FaceId, signal::ScopedConnection> m_faceStateChangeConn; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 125 | |
| 126 | private: |
Junxiao Shi | ae04d34 | 2016-07-19 13:20:22 +0000 | [diff] [blame] | 127 | ndn::mgmt::PostNotification m_postNotification; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 128 | signal::ScopedConnection m_faceAddConn; |
| 129 | signal::ScopedConnection m_faceRemoveConn; |
| 130 | }; |
| 131 | |
| 132 | } // namespace nfd |
| 133 | |
| 134 | #endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP |