blob: c4a2c48d5cf135b7b8ed038c01065cdb8b36a467 [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 Shi25c6ce42016-09-09 13:49:59 +000030#include <ndn-cxx/mgmt/nfd/face-status.hpp>
31#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
Eric Newberry1b4ba052016-10-07 23:04:07 -070032#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
Junxiao Shicde37ad2015-12-24 01:02:05 -070033#include "face/face.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070034
35namespace nfd {
36
37class FaceTable;
38class NetworkInterfaceInfo;
39class ProtocolFactory;
40
41/**
42 * @brief implement the Face Management of NFD Management Protocol.
43 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
44 */
Yanbiao Lidf846e52016-01-30 21:53:47 -080045class FaceManager : public NfdManagerBase
Yanbiao Li73860e32015-08-19 16:30:16 -070046{
47public:
48 FaceManager(FaceTable& faceTable,
49 Dispatcher& dispatcher,
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000050 CommandAuthenticator& authenticator);
Yanbiao Li73860e32015-08-19 16:30:16 -070051
52 /**
53 * @brief Subscribe to face_system section for the config file
54 */
55 void
56 setConfigFile(ConfigFile& configFile);
57
58PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand
59 void
60 createFace(const Name& topPrefix, const Interest& interest,
61 const ControlParameters& parameters,
62 const ndn::mgmt::CommandContinuation& done);
63
64 void
Eric Newberryb5aa7f52016-09-03 20:36:12 -070065 updateFace(const Name& topPrefix, const Interest& interest,
66 const ControlParameters& parameters,
67 const ndn::mgmt::CommandContinuation& done);
68
69 void
Yanbiao Li73860e32015-08-19 16:30:16 -070070 destroyFace(const Name& topPrefix, const Interest& interest,
71 const ControlParameters& parameters,
72 const ndn::mgmt::CommandContinuation& done);
73
Eric Newberryb5aa7f52016-09-03 20:36:12 -070074 /**
75 * \deprecated use Flags+Mask in faces/update instead
76 */
Yanbiao Li73860e32015-08-19 16:30:16 -070077 void
78 enableLocalControl(const Name& topPrefix, const Interest& interest,
79 const ControlParameters& parameters,
80 const ndn::mgmt::CommandContinuation& done);
81
Eric Newberryb5aa7f52016-09-03 20:36:12 -070082 /**
83 * \deprecated use Flags+Mask in faces/update instead
84 */
Yanbiao Li73860e32015-08-19 16:30:16 -070085 void
86 disableLocalControl(const Name& topPrefix, const Interest& interest,
87 const ControlParameters& parameters,
88 const ndn::mgmt::CommandContinuation& done);
89
90PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
91 void
Eric Newberry42602412016-08-27 09:33:18 -070092 afterCreateFaceSuccess(const ControlParameters& parameters,
Yanbiao Li73860e32015-08-19 16:30:16 -070093 const shared_ptr<Face>& newFace,
94 const ndn::mgmt::CommandContinuation& done);
95
96 void
Eric Newberry42602412016-08-27 09:33:18 -070097 afterCreateFaceFailure(uint32_t status,
98 const std::string& reason,
Yanbiao Li73860e32015-08-19 16:30:16 -070099 const ndn::mgmt::CommandContinuation& done);
100
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101 Face*
102 findFaceForLocalControl(const Interest& request,
103 const ControlParameters& parameters,
104 const ndn::mgmt::CommandContinuation& done);
Yanbiao Li73860e32015-08-19 16:30:16 -0700105
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700106 static void
107 setLinkServiceOptions(Face& face,
108 const ControlParameters& parameters,
109 ControlParameters& response);
110
Yanbiao Li73860e32015-08-19 16:30:16 -0700111PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
112 void
113 listFaces(const Name& topPrefix, const Interest& interest,
114 ndn::mgmt::StatusDatasetContext& context);
115
116 void
117 listChannels(const Name& topPrefix, const Interest& interest,
118 ndn::mgmt::StatusDatasetContext& context);
119
120 void
121 queryFaces(const Name& topPrefix, const Interest& interest,
122 ndn::mgmt::StatusDatasetContext& context);
123
124private: // helpers for StatusDataset handler
125 bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000126 matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700127
Eric Newberryc64d30a2015-12-26 11:07:27 -0700128 /** \brief get status of face, including properties and counters
129 */
130 static ndn::nfd::FaceStatus
131 collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now);
132
Junxiao Shida93f1f2015-11-11 06:13:16 -0700133 /** \brief copy face properties into traits
134 * \tparam FaceTraits either FaceStatus or FaceEventNotification
135 */
136 template<typename FaceTraits>
137 static void
138 collectFaceProperties(const Face& face, FaceTraits& traits);
139
Yanbiao Li73860e32015-08-19 16:30:16 -0700140private: // NotificationStream
141 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700142 notifyFaceEvent(const Face& face, ndn::nfd::FaceEventKind kind);
Yanbiao Li73860e32015-08-19 16:30:16 -0700143
144 void
Eric Newberry1b4ba052016-10-07 23:04:07 -0700145 connectFaceStateChangeSignal(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700146
147private: // configuration
148 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200149 processConfig(const ConfigSection& configSection, bool isDryRun,
150 const std::string& filename);
Yanbiao Li73860e32015-08-19 16:30:16 -0700151
152 void
153 processSectionUnix(const ConfigSection& configSection, bool isDryRun);
154
155 void
156 processSectionTcp(const ConfigSection& configSection, bool isDryRun);
157
158 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200159 processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700160 const std::vector<NetworkInterfaceInfo>& nicList);
161
162 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200163 processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700164 const std::vector<NetworkInterfaceInfo>& nicList);
165
166 void
167 processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
168
Yanbiao Li73860e32015-08-19 16:30:16 -0700169PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200170 std::map<std::string /*protocol*/, shared_ptr<ProtocolFactory>> m_factories;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700171 FaceTable& m_faceTable;
Eric Newberry1b4ba052016-10-07 23:04:07 -0700172 std::map<FaceId, signal::ScopedConnection> m_faceStateChangeConn;
Yanbiao Li73860e32015-08-19 16:30:16 -0700173
174private:
Junxiao Shiae04d342016-07-19 13:20:22 +0000175 ndn::mgmt::PostNotification m_postNotification;
Yanbiao Li73860e32015-08-19 16:30:16 -0700176 signal::ScopedConnection m_faceAddConn;
177 signal::ScopedConnection m_faceRemoveConn;
178};
179
180} // namespace nfd
181
182#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP