blob: 8e90a73d23d0da454b443ff2ed1d58bb89f5b39f [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"
Junxiao Shi0de23a22015-12-03 20:07:02 +000030#include <ndn-cxx/management/nfd-face-status.hpp>
Yanbiao Li73860e32015-08-19 16:30:16 -070031#include <ndn-cxx/management/nfd-face-query-filter.hpp>
32
33namespace nfd {
34
Junxiao Shi0de23a22015-12-03 20:07:02 +000035class Face;
Yanbiao Li73860e32015-08-19 16:30:16 -070036class FaceTable;
37class NetworkInterfaceInfo;
38class ProtocolFactory;
39
Junxiao Shi40cb61c2015-09-23 18:36:45 -070040namespace face {
41class LpFace;
42} // namespace face
43
Yanbiao Li73860e32015-08-19 16:30:16 -070044/**
45 * @brief implement the Face Management of NFD Management Protocol.
46 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
47 */
48class FaceManager : public ManagerBase
49{
50public:
51 FaceManager(FaceTable& faceTable,
52 Dispatcher& dispatcher,
53 CommandValidator& validator);
54
55 /**
56 * @brief Subscribe to face_system section for the config file
57 */
58 void
59 setConfigFile(ConfigFile& configFile);
60
61PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand
62 void
63 createFace(const Name& topPrefix, const Interest& interest,
64 const ControlParameters& parameters,
65 const ndn::mgmt::CommandContinuation& done);
66
67 void
68 destroyFace(const Name& topPrefix, const Interest& interest,
69 const ControlParameters& parameters,
70 const ndn::mgmt::CommandContinuation& done);
71
72 void
73 enableLocalControl(const Name& topPrefix, const Interest& interest,
74 const ControlParameters& parameters,
75 const ndn::mgmt::CommandContinuation& done);
76
77 void
78 disableLocalControl(const Name& topPrefix, const Interest& interest,
79 const ControlParameters& parameters,
80 const ndn::mgmt::CommandContinuation& done);
81
82PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
83 void
84 afterCreateFaceSuccess(ControlParameters& parameters,
85 const shared_ptr<Face>& newFace,
86 const ndn::mgmt::CommandContinuation& done);
87
88 void
89 afterCreateFaceFailure(const std::string& reason,
90 const ndn::mgmt::CommandContinuation& done);
91
92 struct ExtractLocalControlParametersResult
93 {
94 bool isValid;
Junxiao Shi40cb61c2015-09-23 18:36:45 -070095 face::LpFace* lpFace;
Yanbiao Li73860e32015-08-19 16:30:16 -070096 };
97
98 ExtractLocalControlParametersResult
99 extractLocalControlParameters(const Interest& request,
100 const ControlParameters& parameters,
101 const ndn::mgmt::CommandContinuation& done);
102
103PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
104 void
105 listFaces(const Name& topPrefix, const Interest& interest,
106 ndn::mgmt::StatusDatasetContext& context);
107
108 void
109 listChannels(const Name& topPrefix, const Interest& interest,
110 ndn::mgmt::StatusDatasetContext& context);
111
112 void
113 queryFaces(const Name& topPrefix, const Interest& interest,
114 ndn::mgmt::StatusDatasetContext& context);
115
116private: // helpers for StatusDataset handler
117 bool
118 doesMatchFilter(const ndn::nfd::FaceQueryFilter& filter, shared_ptr<Face> face);
119
Junxiao Shida93f1f2015-11-11 06:13:16 -0700120 /** \brief copy face properties into traits
121 * \tparam FaceTraits either FaceStatus or FaceEventNotification
122 */
123 template<typename FaceTraits>
124 static void
125 collectFaceProperties(const Face& face, FaceTraits& traits);
126
127 /** \brief copy face counters into FaceStatus
128 */
129 static void
130 collectFaceCounters(const Face& face, ndn::nfd::FaceStatus& status);
131
Yanbiao Li73860e32015-08-19 16:30:16 -0700132private: // NotificationStream
133 void
134 afterFaceAdded(shared_ptr<Face> face,
135 const ndn::mgmt::PostNotification& post);
136
137 void
138 afterFaceRemoved(shared_ptr<Face> face,
139 const ndn::mgmt::PostNotification& post);
140
141private: // configuration
142 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200143 processConfig(const ConfigSection& configSection, bool isDryRun,
144 const std::string& filename);
Yanbiao Li73860e32015-08-19 16:30:16 -0700145
146 void
147 processSectionUnix(const ConfigSection& configSection, bool isDryRun);
148
149 void
150 processSectionTcp(const ConfigSection& configSection, bool isDryRun);
151
152 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200153 processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700154 const std::vector<NetworkInterfaceInfo>& nicList);
155
156 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200157 processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700158 const std::vector<NetworkInterfaceInfo>& nicList);
159
160 void
161 processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
162
Yanbiao Li73860e32015-08-19 16:30:16 -0700163PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200164 std::map<std::string /*protocol*/, shared_ptr<ProtocolFactory>> m_factories;
Yanbiao Li73860e32015-08-19 16:30:16 -0700165
166private:
167 FaceTable& m_faceTable;
168 signal::ScopedConnection m_faceAddConn;
169 signal::ScopedConnection m_faceRemoveConn;
170};
171
172} // namespace nfd
173
174#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP