blob: da217b28d782d9e02874c1cb3db5c33e2005e610 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
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
29#include "manager-base.hpp"
30#include "face/local-face.hpp"
31#include <ndn-cxx/management/nfd-face-query-filter.hpp>
32
33namespace nfd {
34
35class FaceTable;
36class NetworkInterfaceInfo;
37class ProtocolFactory;
38
Junxiao Shi40cb61c2015-09-23 18:36:45 -070039namespace face {
40class LpFace;
41} // namespace face
42
Yanbiao Li73860e32015-08-19 16:30:16 -070043/**
44 * @brief implement the Face Management of NFD Management Protocol.
45 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
46 */
47class FaceManager : public ManagerBase
48{
49public:
50 FaceManager(FaceTable& faceTable,
51 Dispatcher& dispatcher,
52 CommandValidator& validator);
53
54 /**
55 * @brief Subscribe to face_system section for the config file
56 */
57 void
58 setConfigFile(ConfigFile& configFile);
59
60PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand
61 void
62 createFace(const Name& topPrefix, const Interest& interest,
63 const ControlParameters& parameters,
64 const ndn::mgmt::CommandContinuation& done);
65
66 void
67 destroyFace(const Name& topPrefix, const Interest& interest,
68 const ControlParameters& parameters,
69 const ndn::mgmt::CommandContinuation& done);
70
71 void
72 enableLocalControl(const Name& topPrefix, const Interest& interest,
73 const ControlParameters& parameters,
74 const ndn::mgmt::CommandContinuation& done);
75
76 void
77 disableLocalControl(const Name& topPrefix, const Interest& interest,
78 const ControlParameters& parameters,
79 const ndn::mgmt::CommandContinuation& done);
80
81PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
82 void
83 afterCreateFaceSuccess(ControlParameters& parameters,
84 const shared_ptr<Face>& newFace,
85 const ndn::mgmt::CommandContinuation& done);
86
87 void
88 afterCreateFaceFailure(const std::string& reason,
89 const ndn::mgmt::CommandContinuation& done);
90
91 struct ExtractLocalControlParametersResult
92 {
93 bool isValid;
94 shared_ptr<LocalFace> face;
Junxiao Shi40cb61c2015-09-23 18:36:45 -070095 face::LpFace* lpFace;
Yanbiao Li73860e32015-08-19 16:30:16 -070096 LocalControlFeature feature;
97 };
98
99 ExtractLocalControlParametersResult
100 extractLocalControlParameters(const Interest& request,
101 const ControlParameters& parameters,
102 const ndn::mgmt::CommandContinuation& done);
103
104PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
105 void
106 listFaces(const Name& topPrefix, const Interest& interest,
107 ndn::mgmt::StatusDatasetContext& context);
108
109 void
110 listChannels(const Name& topPrefix, const Interest& interest,
111 ndn::mgmt::StatusDatasetContext& context);
112
113 void
114 queryFaces(const Name& topPrefix, const Interest& interest,
115 ndn::mgmt::StatusDatasetContext& context);
116
117private: // helpers for StatusDataset handler
118 bool
119 doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr<Face> face);
120
Junxiao Shida93f1f2015-11-11 06:13:16 -0700121 /** \brief copy face properties into traits
122 * \tparam FaceTraits either FaceStatus or FaceEventNotification
123 */
124 template<typename FaceTraits>
125 static void
126 collectFaceProperties(const Face& face, FaceTraits& traits);
127
128 /** \brief copy face counters into FaceStatus
129 */
130 static void
131 collectFaceCounters(const Face& face, ndn::nfd::FaceStatus& status);
132
Yanbiao Li73860e32015-08-19 16:30:16 -0700133private: // NotificationStream
134 void
135 afterFaceAdded(shared_ptr<Face> face,
136 const ndn::mgmt::PostNotification& post);
137
138 void
139 afterFaceRemoved(shared_ptr<Face> face,
140 const ndn::mgmt::PostNotification& post);
141
142private: // configuration
143 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200144 processConfig(const ConfigSection& configSection, bool isDryRun,
145 const std::string& filename);
Yanbiao Li73860e32015-08-19 16:30:16 -0700146
147 void
148 processSectionUnix(const ConfigSection& configSection, bool isDryRun);
149
150 void
151 processSectionTcp(const ConfigSection& configSection, bool isDryRun);
152
153 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200154 processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700155 const std::vector<NetworkInterfaceInfo>& nicList);
156
157 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200158 processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700159 const std::vector<NetworkInterfaceInfo>& nicList);
160
161 void
162 processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
163
Yanbiao Li73860e32015-08-19 16:30:16 -0700164PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200165 std::map<std::string /*protocol*/, shared_ptr<ProtocolFactory>> m_factories;
Yanbiao Li73860e32015-08-19 16:30:16 -0700166
167private:
168 FaceTable& m_faceTable;
169 signal::ScopedConnection m_faceAddConn;
170 signal::ScopedConnection m_faceRemoveConn;
171};
172
173} // namespace nfd
174
175#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP