blob: 6f05b0f586602a9e9be6384c03848e46d7b1a90f [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry2642cd22017-07-13 21:34:53 -04002/*
Davide Pesaventocfb1a312018-03-01 01:30:56 -05003 * Copyright (c) 2014-2018, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -07004 * 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 Lidf846e52016-01-30 21:53:47 -080029#include "nfd-manager-base.hpp"
Junxiao Shib8590312016-12-29 21:22:25 +000030#include "face/face-system.hpp"
Davide Pesaventocfb1a312018-03-01 01:30:56 -050031
Junxiao Shi25c6ce42016-09-09 13:49:59 +000032#include <ndn-cxx/mgmt/nfd/face-status.hpp>
33#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
Eric Newberry1b4ba052016-10-07 23:04:07 -070034#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070035
36namespace nfd {
37
Yanbiao Li73860e32015-08-19 16:30:16 -070038/**
39 * @brief implement the Face Management of NFD Management Protocol.
Alexander Afanasyev635bf202017-03-09 21:57:34 +000040 * @sa https://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
Yanbiao Li73860e32015-08-19 16:30:16 -070041 */
Yanbiao Lidf846e52016-01-30 21:53:47 -080042class FaceManager : public NfdManagerBase
Yanbiao Li73860e32015-08-19 16:30:16 -070043{
44public:
Junxiao Shiea47bde2017-01-26 17:49:16 +000045 FaceManager(FaceSystem& faceSystem,
Davide Pesaventocfb1a312018-03-01 01:30:56 -050046 Dispatcher& dispatcher,
47 CommandAuthenticator& authenticator);
Yanbiao Li73860e32015-08-19 16:30:16 -070048
49PUBLIC_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 Newberryb5aa7f52016-09-03 20:36:12 -070056 updateFace(const Name& topPrefix, const Interest& interest,
57 const ControlParameters& parameters,
58 const ndn::mgmt::CommandContinuation& done);
59
60 void
Yanbiao Li73860e32015-08-19 16:30:16 -070061 destroyFace(const Name& topPrefix, const Interest& interest,
62 const ControlParameters& parameters,
63 const ndn::mgmt::CommandContinuation& done);
64
Yanbiao Li73860e32015-08-19 16:30:16 -070065PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
66 void
Eric Newberry42602412016-08-27 09:33:18 -070067 afterCreateFaceSuccess(const ControlParameters& parameters,
Yanbiao Li73860e32015-08-19 16:30:16 -070068 const shared_ptr<Face>& newFace,
69 const ndn::mgmt::CommandContinuation& done);
70
71 void
Eric Newberry42602412016-08-27 09:33:18 -070072 afterCreateFaceFailure(uint32_t status,
73 const std::string& reason,
Yanbiao Li73860e32015-08-19 16:30:16 -070074 const ndn::mgmt::CommandContinuation& done);
75
Eric Newberryb5aa7f52016-09-03 20:36:12 -070076 static void
77 setLinkServiceOptions(Face& face,
Eric Newberry2642cd22017-07-13 21:34:53 -040078 const ControlParameters& parameters);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070079
Yanbiao Li58ba3f92017-02-15 14:27:18 +000080 static ControlParameters
Junxiao Shi1cce2a32017-05-02 02:39:55 +000081 collectFaceProperties(const Face& face, bool wantUris);
Yanbiao Li58ba3f92017-02-15 14:27:18 +000082
Yanbiao Li73860e32015-08-19 16:30:16 -070083PUBLIC_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
96private: // helpers for StatusDataset handler
97 bool
Junxiao Shib84e6742016-07-19 13:16:22 +000098 matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -070099
Eric Newberryc64d30a2015-12-26 11:07:27 -0700100 /** \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 Shida93f1f2015-11-11 06:13:16 -0700105 /** \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 Li73860e32015-08-19 16:30:16 -0700112private: // NotificationStream
113 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700114 notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind);
Yanbiao Li73860e32015-08-19 16:30:16 -0700115
116 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700117 connectFaceStateChangeSignal(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700118
Davide Pesaventob5eee202017-09-21 23:59:22 -0400119private:
Junxiao Shiea47bde2017-01-26 17:49:16 +0000120 FaceSystem& m_faceSystem;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700121 FaceTable& m_faceTable;
Davide Pesaventob5eee202017-09-21 23:59:22 -0400122
123PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Eric Newberry1b4ba052016-10-07 23:04:07 -0700124 std::map<FaceId, signal::ScopedConnection> m_faceStateChangeConn;
Yanbiao Li73860e32015-08-19 16:30:16 -0700125
126private:
Junxiao Shiae04d342016-07-19 13:20:22 +0000127 ndn::mgmt::PostNotification m_postNotification;
Yanbiao Li73860e32015-08-19 16:30:16 -0700128 signal::ScopedConnection m_faceAddConn;
129 signal::ScopedConnection m_faceRemoveConn;
130};
131
132} // namespace nfd
133
134#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP