blob: 094f2884d6df59806492927cbe42ce030e9afe6b [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 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>
Junxiao Shicde37ad2015-12-24 01:02:05 -070032#include "face/face.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070033
34namespace nfd {
35
36class FaceTable;
37class NetworkInterfaceInfo;
38class ProtocolFactory;
39
40/**
41 * @brief implement the Face Management of NFD Management Protocol.
42 * @sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
43 */
Yanbiao Lidf846e52016-01-30 21:53:47 -080044class FaceManager : public NfdManagerBase
Yanbiao Li73860e32015-08-19 16:30:16 -070045{
46public:
47 FaceManager(FaceTable& faceTable,
48 Dispatcher& dispatcher,
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000049 CommandAuthenticator& authenticator);
Yanbiao Li73860e32015-08-19 16:30:16 -070050
51 /**
52 * @brief Subscribe to face_system section for the config file
53 */
54 void
55 setConfigFile(ConfigFile& configFile);
56
57PUBLIC_WITH_TESTS_ELSE_PRIVATE: // ControlCommand
58 void
59 createFace(const Name& topPrefix, const Interest& interest,
60 const ControlParameters& parameters,
61 const ndn::mgmt::CommandContinuation& done);
62
63 void
64 destroyFace(const Name& topPrefix, const Interest& interest,
65 const ControlParameters& parameters,
66 const ndn::mgmt::CommandContinuation& done);
67
68 void
69 enableLocalControl(const Name& topPrefix, const Interest& interest,
70 const ControlParameters& parameters,
71 const ndn::mgmt::CommandContinuation& done);
72
73 void
74 disableLocalControl(const Name& topPrefix, const Interest& interest,
75 const ControlParameters& parameters,
76 const ndn::mgmt::CommandContinuation& done);
77
78PUBLIC_WITH_TESTS_ELSE_PRIVATE: // helpers for ControlCommand
79 void
Eric Newberry42602412016-08-27 09:33:18 -070080 afterCreateFaceSuccess(const ControlParameters& parameters,
Yanbiao Li73860e32015-08-19 16:30:16 -070081 const shared_ptr<Face>& newFace,
82 const ndn::mgmt::CommandContinuation& done);
83
84 void
Eric Newberry42602412016-08-27 09:33:18 -070085 afterCreateFaceFailure(uint32_t status,
86 const std::string& reason,
Yanbiao Li73860e32015-08-19 16:30:16 -070087 const ndn::mgmt::CommandContinuation& done);
88
Junxiao Shicde37ad2015-12-24 01:02:05 -070089 Face*
90 findFaceForLocalControl(const Interest& request,
91 const ControlParameters& parameters,
92 const ndn::mgmt::CommandContinuation& done);
Yanbiao Li73860e32015-08-19 16:30:16 -070093
94PUBLIC_WITH_TESTS_ELSE_PRIVATE: // StatusDataset
95 void
96 listFaces(const Name& topPrefix, const Interest& interest,
97 ndn::mgmt::StatusDatasetContext& context);
98
99 void
100 listChannels(const Name& topPrefix, const Interest& interest,
101 ndn::mgmt::StatusDatasetContext& context);
102
103 void
104 queryFaces(const Name& topPrefix, const Interest& interest,
105 ndn::mgmt::StatusDatasetContext& context);
106
107private: // helpers for StatusDataset handler
108 bool
Junxiao Shib84e6742016-07-19 13:16:22 +0000109 matchFilter(const ndn::nfd::FaceQueryFilter& filter, const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700110
Eric Newberryc64d30a2015-12-26 11:07:27 -0700111 /** \brief get status of face, including properties and counters
112 */
113 static ndn::nfd::FaceStatus
114 collectFaceStatus(const Face& face, const time::steady_clock::TimePoint& now);
115
Junxiao Shida93f1f2015-11-11 06:13:16 -0700116 /** \brief copy face properties into traits
117 * \tparam FaceTraits either FaceStatus or FaceEventNotification
118 */
119 template<typename FaceTraits>
120 static void
121 collectFaceProperties(const Face& face, FaceTraits& traits);
122
Yanbiao Li73860e32015-08-19 16:30:16 -0700123private: // NotificationStream
124 void
Junxiao Shiae04d342016-07-19 13:20:22 +0000125 notifyAddFace(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700126
127 void
Junxiao Shiae04d342016-07-19 13:20:22 +0000128 notifyRemoveFace(const Face& face);
Yanbiao Li73860e32015-08-19 16:30:16 -0700129
130private: // configuration
131 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200132 processConfig(const ConfigSection& configSection, bool isDryRun,
133 const std::string& filename);
Yanbiao Li73860e32015-08-19 16:30:16 -0700134
135 void
136 processSectionUnix(const ConfigSection& configSection, bool isDryRun);
137
138 void
139 processSectionTcp(const ConfigSection& configSection, bool isDryRun);
140
141 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200142 processSectionUdp(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700143 const std::vector<NetworkInterfaceInfo>& nicList);
144
145 void
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200146 processSectionEther(const ConfigSection& configSection, bool isDryRun,
Yanbiao Li73860e32015-08-19 16:30:16 -0700147 const std::vector<NetworkInterfaceInfo>& nicList);
148
149 void
150 processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
151
Yanbiao Li73860e32015-08-19 16:30:16 -0700152PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento1d7e7af2015-10-10 23:54:08 +0200153 std::map<std::string /*protocol*/, shared_ptr<ProtocolFactory>> m_factories;
Yanbiao Li73860e32015-08-19 16:30:16 -0700154
155private:
156 FaceTable& m_faceTable;
Junxiao Shiae04d342016-07-19 13:20:22 +0000157 ndn::mgmt::PostNotification m_postNotification;
Yanbiao Li73860e32015-08-19 16:30:16 -0700158 signal::ScopedConnection m_faceAddConn;
159 signal::ScopedConnection m_faceRemoveConn;
160};
161
162} // namespace nfd
163
164#endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP