blob: 3c92e934bc1c6dc624b4bb3dcbc93463c26694a2 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, 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:
44 FaceManager(FaceTable& faceTable,
45 Dispatcher& dispatcher,
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000046 CommandAuthenticator& authenticator);
Yanbiao Li73860e32015-08-19 16:30:16 -070047
48 /**
49 * @brief Subscribe to face_system section for the config file
50 */
51 void
52 setConfigFile(ConfigFile& configFile);
53
54PUBLIC_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 Newberryb5aa7f52016-09-03 20:36:12 -070061 updateFace(const Name& topPrefix, const Interest& interest,
62 const ControlParameters& parameters,
63 const ndn::mgmt::CommandContinuation& done);
64
65 void
Yanbiao Li73860e32015-08-19 16:30:16 -070066 destroyFace(const Name& topPrefix, const Interest& interest,
67 const ControlParameters& parameters,
68 const ndn::mgmt::CommandContinuation& done);
69
Eric Newberryb5aa7f52016-09-03 20:36:12 -070070 /**
71 * \deprecated use Flags+Mask in faces/update instead
72 */
Yanbiao Li73860e32015-08-19 16:30:16 -070073 void
74 enableLocalControl(const Name& topPrefix, const Interest& interest,
75 const ControlParameters& parameters,
76 const ndn::mgmt::CommandContinuation& done);
77
Eric Newberryb5aa7f52016-09-03 20:36:12 -070078 /**
79 * \deprecated use Flags+Mask in faces/update instead
80 */
Yanbiao Li73860e32015-08-19 16:30:16 -070081 void
82 disableLocalControl(const Name& topPrefix, const Interest& interest,
83 const ControlParameters& parameters,
84 const ndn::mgmt::CommandContinuation& done);
85
86PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
87 void
Eric Newberry42602412016-08-27 09:33:18 -070088 afterCreateFaceSuccess(const ControlParameters& parameters,
Yanbiao Li73860e32015-08-19 16:30:16 -070089 const shared_ptr<Face>& newFace,
90 const ndn::mgmt::CommandContinuation& done);
91
92 void
Eric Newberry42602412016-08-27 09:33:18 -070093 afterCreateFaceFailure(uint32_t status,
94 const std::string& reason,
Yanbiao Li73860e32015-08-19 16:30:16 -070095 const ndn::mgmt::CommandContinuation& done);
96
Junxiao Shicde37ad2015-12-24 01:02:05 -070097 Face*
98 findFaceForLocalControl(const Interest& request,
99 const ControlParameters& parameters,
100 const ndn::mgmt::CommandContinuation& done);
Yanbiao Li73860e32015-08-19 16:30:16 -0700101
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700102 static void
103 setLinkServiceOptions(Face& face,
104 const ControlParameters& parameters,
105 ControlParameters& response);
106
Yanbiao Li73860e32015-08-19 16:30:16 -0700107PUBLIC_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
120private: // helpers for StatusDataset handler
121 bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000122 matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700123
Eric Newberryc64d30a2015-12-26 11:07:27 -0700124 /** \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 Shida93f1f2015-11-11 06:13:16 -0700129 /** \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 Li73860e32015-08-19 16:30:16 -0700136private: // NotificationStream
137 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700138 notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind);
Yanbiao Li73860e32015-08-19 16:30:16 -0700139
140 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700141 connectFaceStateChangeSignal(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700142
Yanbiao Li73860e32015-08-19 16:30:16 -0700143PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Junxiao Shib8590312016-12-29 21:22:25 +0000144 FaceSystem m_faceSystem; ///\todo #3904 accept FaceSystem& in constructor; don't own FaceSystem
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700145 FaceTable& m_faceTable;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700146 std::map<FaceId, signal::ScopedConnection> m_faceStateChangeConn;
Yanbiao Li73860e32015-08-19 16:30:16 -0700147
148private:
Junxiao Shiae04d342016-07-19 13:20:22 +0000149 ndn::mgmt::PostNotification m_postNotification;
Yanbiao Li73860e32015-08-19 16:30:16 -0700150 signal::ScopedConnection m_faceAddConn;
151 signal::ScopedConnection m_faceRemoveConn;
152};
153
154} // namespace nfd
155
156#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP