blob: f5283d6d61f46eabc2efd2e22a37368f8cd7c0cc [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
39/**
40 * @brief implement the Face Management of NFD Management Protocol.
41 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
42 */
43class FaceManager : public ManagerBase
44{
45public:
46 FaceManager(FaceTable& faceTable,
47 Dispatcher& dispatcher,
48 CommandValidator& validator);
49
50 /**
51 * @brief Subscribe to face_system section for the config file
52 */
53 void
54 setConfigFile(ConfigFile& configFile);
55
56PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand
57 void
58 createFace(const Name& topPrefix, const Interest& interest,
59 const ControlParameters& parameters,
60 const ndn::mgmt::CommandContinuation& done);
61
62 void
63 destroyFace(const Name& topPrefix, const Interest& interest,
64 const ControlParameters& parameters,
65 const ndn::mgmt::CommandContinuation& done);
66
67 void
68 enableLocalControl(const Name& topPrefix, const Interest& interest,
69 const ControlParameters& parameters,
70 const ndn::mgmt::CommandContinuation& done);
71
72 void
73 disableLocalControl(const Name& topPrefix, const Interest& interest,
74 const ControlParameters& parameters,
75 const ndn::mgmt::CommandContinuation& done);
76
77PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
78 void
79 afterCreateFaceSuccess(ControlParameters& parameters,
80 const shared_ptr<Face>& newFace,
81 const ndn::mgmt::CommandContinuation& done);
82
83 void
84 afterCreateFaceFailure(const std::string& reason,
85 const ndn::mgmt::CommandContinuation& done);
86
87 struct ExtractLocalControlParametersResult
88 {
89 bool isValid;
90 shared_ptr<LocalFace> face;
91 LocalControlFeature feature;
92 };
93
94 ExtractLocalControlParametersResult
95 extractLocalControlParameters(const Interest& request,
96 const ControlParameters& parameters,
97 const ndn::mgmt::CommandContinuation& done);
98
99PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
100 void
101 listFaces(const Name& topPrefix, const Interest& interest,
102 ndn::mgmt::StatusDatasetContext& context);
103
104 void
105 listChannels(const Name& topPrefix, const Interest& interest,
106 ndn::mgmt::StatusDatasetContext& context);
107
108 void
109 queryFaces(const Name& topPrefix, const Interest& interest,
110 ndn::mgmt::StatusDatasetContext& context);
111
112private: // helpers for StatusDataset handler
113 bool
114 doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr<Face> face);
115
116private: // NotificationStream
117 void
118 afterFaceAdded(shared_ptr<Face> face,
119 const ndn::mgmt::PostNotification& post);
120
121 void
122 afterFaceRemoved(shared_ptr<Face> face,
123 const ndn::mgmt::PostNotification& post);
124
125private: // configuration
126 void
127 processConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
128
129 void
130 processSectionUnix(const ConfigSection& configSection, bool isDryRun);
131
132 void
133 processSectionTcp(const ConfigSection& configSection, bool isDryRun);
134
135 void
136 processSectionUdp(const ConfigSection& configSection,
137 bool isDryRun,
138 const std::vector<NetworkInterfaceInfo>& nicList);
139
140 void
141 processSectionEther(const ConfigSection& configSection,
142 bool isDryRun,
143 const std::vector<NetworkInterfaceInfo>& nicList);
144
145 void
146 processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
147
148private: // helpers for configuration
149 void
150 addCreatedFaceToForwarder(shared_ptr<Face> newFace);
151
152PUBLIC_WITH_TESTS_ELSE_PRIVATE:
153 typedef std::map<std::string/*protocol*/, shared_ptr<ProtocolFactory>> FactoryMap;
154 FactoryMap m_factories;
155
156private:
157 FaceTable& m_faceTable;
158 signal::ScopedConnection m_faceAddConn;
159 signal::ScopedConnection m_faceRemoveConn;
160};
161
162} // namespace nfd
163
164#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP