blob: b7991b877885d2571c10ca13316505eca56264ae [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiea47bde2017-01-26 17:49:16 +00003 * Copyright (c) 2014-2017, 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"
Junxiao Shi25c6ce42016-09-09 13:49:59 +000031#include <ndn-cxx/mgmt/nfd/face-status.hpp>
32#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
Eric Newberry1b4ba052016-10-07 23:04:07 -070033#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070034
35namespace nfd {
36
Yanbiao Li73860e32015-08-19 16:30:16 -070037/**
38 * @brief implement the Face Management of NFD Management Protocol.
39 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
40 */
Yanbiao Lidf846e52016-01-30 21:53:47 -080041class FaceManager : public NfdManagerBase
Yanbiao Li73860e32015-08-19 16:30:16 -070042{
43public:
Junxiao Shiea47bde2017-01-26 17:49:16 +000044 FaceManager(FaceSystem& faceSystem,
45 Dispatcher& dispatcher, CommandAuthenticator& authenticator);
Yanbiao Li73860e32015-08-19 16:30:16 -070046
47 /**
48 * @brief Subscribe to face_system section for the config file
49 */
50 void
51 setConfigFile(ConfigFile& configFile);
52
53PUBLIC_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 Newberryb5aa7f52016-09-03 20:36:12 -070060 updateFace(const Name& topPrefix, const Interest& interest,
61 const ControlParameters& parameters,
62 const ndn::mgmt::CommandContinuation& done);
63
64 void
Yanbiao Li73860e32015-08-19 16:30:16 -070065 destroyFace(const Name& topPrefix, const Interest& interest,
66 const ControlParameters& parameters,
67 const ndn::mgmt::CommandContinuation& done);
68
Eric Newberryb5aa7f52016-09-03 20:36:12 -070069 /**
70 * \deprecated use Flags+Mask in faces/update instead
71 */
Yanbiao Li73860e32015-08-19 16:30:16 -070072 void
73 enableLocalControl(const Name& topPrefix, const Interest& interest,
74 const ControlParameters& parameters,
75 const ndn::mgmt::CommandContinuation& done);
76
Eric Newberryb5aa7f52016-09-03 20:36:12 -070077 /**
78 * \deprecated use Flags+Mask in faces/update instead
79 */
Yanbiao Li73860e32015-08-19 16:30:16 -070080 void
81 disableLocalControl(const Name& topPrefix, const Interest& interest,
82 const ControlParameters& parameters,
83 const ndn::mgmt::CommandContinuation& done);
84
85PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
86 void
Eric Newberry42602412016-08-27 09:33:18 -070087 afterCreateFaceSuccess(const ControlParameters& parameters,
Yanbiao Li73860e32015-08-19 16:30:16 -070088 const shared_ptr<Face>& newFace,
89 const ndn::mgmt::CommandContinuation& done);
90
91 void
Eric Newberry42602412016-08-27 09:33:18 -070092 afterCreateFaceFailure(uint32_t status,
93 const std::string& reason,
Yanbiao Li73860e32015-08-19 16:30:16 -070094 const ndn::mgmt::CommandContinuation& done);
95
Junxiao Shicde37ad2015-12-24 01:02:05 -070096 Face*
97 findFaceForLocalControl(const Interest& request,
98 const ControlParameters& parameters,
99 const ndn::mgmt::CommandContinuation& done);
Yanbiao Li73860e32015-08-19 16:30:16 -0700100
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700101 static void
102 setLinkServiceOptions(Face& face,
103 const ControlParameters& parameters,
104 ControlParameters& response);
105
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000106 static ControlParameters
107 collectFaceProperties(const Face& face);
108
Yanbiao Li73860e32015-08-19 16:30:16 -0700109PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
110 void
111 listFaces(const Name& topPrefix, const Interest& interest,
112 ndn::mgmt::StatusDatasetContext& context);
113
114 void
115 listChannels(const Name& topPrefix, const Interest& interest,
116 ndn::mgmt::StatusDatasetContext& context);
117
118 void
119 queryFaces(const Name& topPrefix, const Interest& interest,
120 ndn::mgmt::StatusDatasetContext& context);
121
122private: // helpers for StatusDataset handler
123 bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000124 matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700125
Eric Newberryc64d30a2015-12-26 11:07:27 -0700126 /** \brief get status of face, including properties and counters
127 */
128 static ndn::nfd::FaceStatus
129 collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now);
130
Junxiao Shida93f1f2015-11-11 06:13:16 -0700131 /** \brief copy face properties into traits
132 * \tparam FaceTraits either FaceStatus or FaceEventNotification
133 */
134 template<typename FaceTraits>
135 static void
136 collectFaceProperties(const Face& face, FaceTraits& traits);
137
Yanbiao Li73860e32015-08-19 16:30:16 -0700138private: // NotificationStream
139 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700140 notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind);
Yanbiao Li73860e32015-08-19 16:30:16 -0700141
142 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700143 connectFaceStateChangeSignal(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700144
Yanbiao Li73860e32015-08-19 16:30:16 -0700145PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shiea47bde2017-01-26 17:49:16 +0000146 FaceSystem& m_faceSystem;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700147 FaceTable& m_faceTable;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700148 std::map<FaceId, signal::ScopedConnection> m_faceStateChangeConn;
Yanbiao Li73860e32015-08-19 16:30:16 -0700149
150private:
Junxiao Shiae04d342016-07-19 13:20:22 +0000151 ndn::mgmt::PostNotification m_postNotification;
Yanbiao Li73860e32015-08-19 16:30:16 -0700152 signal::ScopedConnection m_faceAddConn;
153 signal::ScopedConnection m_faceRemoveConn;
154};
155
156} // namespace nfd
157
158#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP