blob: 164df0476a873e450a235658c4eeb52662284580 [file] [log] [blame]
Steve DiBenedettoabe9e972014-02-20 15:37:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * Copyright (c) 2014, 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
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070025
26#include "face-manager.hpp"
27
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060028#include "core/logger.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070029#include "core/config-file.hpp"
Alexander Afanasyevdc889712014-12-20 19:57:36 -080030#include "face/protocol-factory.hpp"
31#include "fw/face-table.hpp"
Wentao Shang53df1632014-04-21 12:01:32 -070032
Alexander Afanasyev4a771362014-04-24 21:29:33 -070033#include <ndn-cxx/management/nfd-face-event-notification.hpp>
Chengyu Fan320d2332014-10-29 16:40:33 -060034#include <ndn-cxx/management/nfd-face-query-filter.hpp>
Davide Pesavento52a18f92014-04-10 00:55:01 +020035
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070036namespace nfd {
37
38NFD_LOG_INIT("FaceManager");
39
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060040const Name FaceManager::COMMAND_PREFIX("/localhost/nfd/faces");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070041
42const size_t FaceManager::COMMAND_UNSIGNED_NCOMPS =
43 FaceManager::COMMAND_PREFIX.size() +
44 1 + // verb
Steve DiBenedetto7564d972014-03-24 14:28:46 -060045 1; // verb parameters
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070046
47const size_t FaceManager::COMMAND_SIGNED_NCOMPS =
48 FaceManager::COMMAND_UNSIGNED_NCOMPS +
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070049 4; // (timestamp, nonce, signed info tlv, signature tlv)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070050
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060051const FaceManager::SignedVerbAndProcessor FaceManager::SIGNED_COMMAND_VERBS[] =
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070052 {
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060053 SignedVerbAndProcessor(
Steve DiBenedetto7564d972014-03-24 14:28:46 -060054 Name::Component("create"),
55 &FaceManager::createFace
56 ),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070057
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060058 SignedVerbAndProcessor(
Steve DiBenedetto7564d972014-03-24 14:28:46 -060059 Name::Component("destroy"),
60 &FaceManager::destroyFace
61 ),
62
63 SignedVerbAndProcessor(
64 Name::Component("enable-local-control"),
65 &FaceManager::enableLocalControl
66 ),
67
68 SignedVerbAndProcessor(
69 Name::Component("disable-local-control"),
70 &FaceManager::disableLocalControl
71 ),
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070072 };
73
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060074const FaceManager::UnsignedVerbAndProcessor FaceManager::UNSIGNED_COMMAND_VERBS[] =
75 {
76 UnsignedVerbAndProcessor(
77 Name::Component("list"),
78 &FaceManager::listFaces
79 ),
Steve DiBenedettofbb40a82014-03-11 19:40:15 -060080
81 UnsignedVerbAndProcessor(
82 Name::Component("events"),
83 &FaceManager::ignoreUnsignedVerb
84 ),
Steve DiBenedettoef04f272014-06-04 14:28:31 -060085
86 UnsignedVerbAndProcessor(
87 Name::Component("channels"),
88 &FaceManager::listChannels
89 ),
Chengyu Fan320d2332014-10-29 16:40:33 -060090
91 UnsignedVerbAndProcessor(
92 Name::Component("query"),
93 &FaceManager::listQueriedFaces
94 ),
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060095 };
96
Steve DiBenedettoef04f272014-06-04 14:28:31 -060097const Name FaceManager::FACES_LIST_DATASET_PREFIX("/localhost/nfd/faces/list");
98const size_t FaceManager::FACES_LIST_DATASET_NCOMPS = FACES_LIST_DATASET_PREFIX.size();
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060099
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600100const Name FaceManager::FACE_EVENTS_PREFIX("/localhost/nfd/faces/events");
101
102const Name FaceManager::CHANNELS_LIST_DATASET_PREFIX("/localhost/nfd/faces/channels");
103const size_t FaceManager::CHANNELS_LIST_DATASET_NCOMPS = CHANNELS_LIST_DATASET_PREFIX.size();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700104
Chengyu Fan320d2332014-10-29 16:40:33 -0600105const Name FaceManager::FACES_QUERY_DATASET_PREFIX("/localhost/nfd/faces/query");
106const size_t FaceManager::FACES_QUERY_DATASET_NCOMPS = FACES_QUERY_DATASET_PREFIX.size() + 1;
107
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700108FaceManager::FaceManager(FaceTable& faceTable,
Vince Lehman5144f822014-07-23 15:12:56 -0700109 shared_ptr<InternalFace> face,
110 ndn::KeyChain& keyChain)
111 : ManagerBase(face, FACE_MANAGER_PRIVILEGE, keyChain)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700112 , m_faceTable(faceTable)
Junxiao Shi1e064172014-12-14 19:37:46 -0700113 , m_faceAddConn(m_faceTable.onAdd.connect(bind(&FaceManager::onAddFace, this, _1)))
114 , m_faceRemoveConn(m_faceTable.onRemove.connect(bind(&FaceManager::onRemoveFace, this, _1)))
Vince Lehman5144f822014-07-23 15:12:56 -0700115 , m_faceStatusPublisher(m_faceTable, *m_face, FACES_LIST_DATASET_PREFIX, keyChain)
116 , m_channelStatusPublisher(m_factories, *m_face, CHANNELS_LIST_DATASET_PREFIX, keyChain)
Junxiao Shi15b12e72014-08-09 19:56:24 -0700117 , m_notificationStream(*m_face, FACE_EVENTS_PREFIX, keyChain)
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600118 , m_signedVerbDispatch(SIGNED_COMMAND_VERBS,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600119 SIGNED_COMMAND_VERBS +
120 (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor)))
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600121 , m_unsignedVerbDispatch(UNSIGNED_COMMAND_VERBS,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600122 UNSIGNED_COMMAND_VERBS +
123 (sizeof(UNSIGNED_COMMAND_VERBS) / sizeof(UnsignedVerbAndProcessor)))
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600124
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700125{
126 face->setInterestFilter("/localhost/nfd/faces",
127 bind(&FaceManager::onFaceRequest, this, _2));
128}
129
Steve DiBenedetto4aca99c2014-03-11 11:27:54 -0600130FaceManager::~FaceManager()
131{
132
133}
134
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700135void
136FaceManager::setConfigFile(ConfigFile& configFile)
137{
138 configFile.addSectionHandler("face_system",
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -0600139 bind(&FaceManager::onConfig, this, _1, _2, _3));
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700140}
141
142
143void
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -0600144FaceManager::onConfig(const ConfigSection& configSection,
145 bool isDryRun,
146 const std::string& filename)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700147{
Alexander Afanasyevdc889712014-12-20 19:57:36 -0800148 throw Error("Not supported");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700149}
150
151void
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700152FaceManager::onFaceRequest(const Interest& request)
153{
154 const Name& command = request.getName();
155 const size_t commandNComps = command.size();
156
Steve DiBenedettocd4ee5f2014-12-08 16:09:11 -0700157 if (commandNComps <= COMMAND_PREFIX.size())
158 {
159 // command is too short to have a verb
160 NFD_LOG_DEBUG("command result: malformed");
161 sendResponse(command, 400, "Malformed command");
162 return;
163 }
164
165 const Name::Component& verb = command.at(COMMAND_PREFIX.size());
166
167 const auto unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600168 if (unsignedVerbProcessor != m_unsignedVerbDispatch.end())
169 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700170 NFD_LOG_DEBUG("command result: processing verb: " << verb);
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700171 (unsignedVerbProcessor->second)(this, request);
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600172 }
173 else if (COMMAND_UNSIGNED_NCOMPS <= commandNComps &&
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600174 commandNComps < COMMAND_SIGNED_NCOMPS)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700175 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700176 NFD_LOG_DEBUG("command result: unsigned verb: " << command);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700177 sendResponse(command, 401, "Signature required");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700178 }
179 else if (commandNComps < COMMAND_SIGNED_NCOMPS ||
180 !COMMAND_PREFIX.isPrefixOf(command))
181 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700182 NFD_LOG_DEBUG("command result: malformed");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700183 sendResponse(command, 400, "Malformed command");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700184 }
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600185 else
186 {
187 validate(request,
188 bind(&FaceManager::onValidatedFaceRequest, this, _1),
189 bind(&ManagerBase::onCommandValidationFailed, this, _1, _2));
190 }
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700191}
192
193void
194FaceManager::onValidatedFaceRequest(const shared_ptr<const Interest>& request)
195{
196 const Name& command = request->getName();
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600197 const Name::Component& verb = command[COMMAND_PREFIX.size()];
198 const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1];
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700199
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600200 SignedVerbDispatchTable::const_iterator signedVerbProcessor = m_signedVerbDispatch.find(verb);
201 if (signedVerbProcessor != m_signedVerbDispatch.end())
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700202 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600203 ControlParameters parameters;
204 if (!extractParameters(parameterComponent, parameters))
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700205 {
206 sendResponse(command, 400, "Malformed command");
207 return;
208 }
209
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700210 NFD_LOG_DEBUG("command result: processing verb: " << verb);
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600211 (signedVerbProcessor->second)(this, *request, parameters);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700212 }
213 else
214 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700215 NFD_LOG_DEBUG("command result: unsupported verb: " << verb);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700216 sendResponse(command, 501, "Unsupported command");
217 }
218
219}
220
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700221void
Alexander Afanasyevbbe3f0c2014-03-23 11:44:01 -0700222FaceManager::addCreatedFaceToForwarder(const shared_ptr<Face>& newFace)
223{
224 m_faceTable.add(newFace);
225
Junxiao Shi6e694322014-04-03 10:27:13 -0700226 //NFD_LOG_DEBUG("Created face " << newFace->getRemoteUri() << " ID " << newFace->getId());
Alexander Afanasyevbbe3f0c2014-03-23 11:44:01 -0700227}
228
229void
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700230FaceManager::onCreated(const Name& requestName,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600231 ControlParameters& parameters,
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700232 const shared_ptr<Face>& newFace)
233{
Alexander Afanasyevbbe3f0c2014-03-23 11:44:01 -0700234 addCreatedFaceToForwarder(newFace);
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600235 parameters.setFaceId(newFace->getId());
Steve DiBenedetto25999282014-05-22 15:25:12 -0600236 parameters.setUri(newFace->getRemoteUri().toString());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700237
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600238 sendResponse(requestName, 200, "Success", parameters.wireEncode());
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700239}
240
241void
242FaceManager::onConnectFailed(const Name& requestName, const std::string& reason)
243{
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700244 NFD_LOG_DEBUG("Failed to create face: " << reason);
Steve DiBenedettoca53ac62014-03-27 19:58:40 -0600245 sendResponse(requestName, 408, reason);
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700246}
247
248void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600249FaceManager::createFace(const Interest& request,
250 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700251{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600252 const Name& requestName = request.getName();
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600253 ndn::nfd::FaceCreateCommand command;
254
255 if (!validateParameters(command, parameters))
256 {
257 sendResponse(requestName, 400, "Malformed command");
Steve DiBenedettoca53ac62014-03-27 19:58:40 -0600258 NFD_LOG_TRACE("invalid control parameters URI");
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600259 return;
260 }
261
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700262 FaceUri uri;
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600263 if (!uri.parse(parameters.getUri()))
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700264 {
265 sendResponse(requestName, 400, "Malformed command");
Steve DiBenedettoca53ac62014-03-27 19:58:40 -0600266 NFD_LOG_TRACE("failed to parse URI");
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700267 return;
268 }
269
Chengyu Fanb94af7c2014-12-17 11:46:47 +0800270 if (!uri.isCanonical())
271 {
272 sendResponse(requestName, 400, "Non-canonical URI");
273 NFD_LOG_TRACE("received non-canonical URI");
274 return;
275 }
276
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700277 FactoryMap::iterator factory = m_factories.find(uri.getScheme());
278 if (factory == m_factories.end())
279 {
280 sendResponse(requestName, 501, "Unsupported protocol");
281 return;
282 }
283
Steve DiBenedettoca53ac62014-03-27 19:58:40 -0600284 try
285 {
286 factory->second->createFace(uri,
287 bind(&FaceManager::onCreated,
288 this, requestName, parameters, _1),
289 bind(&FaceManager::onConnectFailed,
290 this, requestName, _1));
291 }
292 catch (const std::runtime_error& error)
293 {
294 std::string errorMessage = "NFD error: ";
295 errorMessage += error.what();
296
297 NFD_LOG_ERROR(errorMessage);
298 sendResponse(requestName, 500, errorMessage);
299 }
300 catch (const std::logic_error& error)
301 {
302 std::string errorMessage = "NFD error: ";
303 errorMessage += error.what();
304
305 NFD_LOG_ERROR(errorMessage);
306 sendResponse(requestName, 500, errorMessage);
307 }
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700308}
309
310
311void
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600312FaceManager::destroyFace(const Interest& request,
313 ControlParameters& parameters)
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700314{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600315 const Name& requestName = request.getName();
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600316 ndn::nfd::FaceDestroyCommand command;
317
318 if (!validateParameters(command, parameters))
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600319 {
320 sendResponse(requestName, 400, "Malformed command");
321 return;
322 }
323
324 shared_ptr<Face> target = m_faceTable.get(parameters.getFaceId());
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600325 if (static_cast<bool>(target))
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700326 {
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700327 target->close();
328 }
Steve DiBenedettoba749052014-03-22 19:54:53 -0600329
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600330 sendResponse(requestName, 200, "Success", parameters.wireEncode());
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600331
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700332}
333
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600334void
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600335FaceManager::onAddFace(shared_ptr<Face> face)
336{
Junxiao Shi6e694322014-04-03 10:27:13 -0700337 ndn::nfd::FaceEventNotification notification;
Chengyu Fanf9c2bb12014-10-06 11:52:44 -0600338 notification.setKind(ndn::nfd::FACE_EVENT_CREATED);
339 face->copyStatusTo(notification);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600340
Junxiao Shi6e694322014-04-03 10:27:13 -0700341 m_notificationStream.postNotification(notification);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600342}
343
344void
345FaceManager::onRemoveFace(shared_ptr<Face> face)
346{
Junxiao Shi6e694322014-04-03 10:27:13 -0700347 ndn::nfd::FaceEventNotification notification;
Chengyu Fanf9c2bb12014-10-06 11:52:44 -0600348 notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED);
349 face->copyStatusTo(notification);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600350
Junxiao Shi6e694322014-04-03 10:27:13 -0700351 m_notificationStream.postNotification(notification);
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600352}
353
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600354bool
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600355FaceManager::extractLocalControlParameters(const Interest& request,
356 ControlParameters& parameters,
357 ControlCommand& command,
358 shared_ptr<LocalFace>& outFace,
359 LocalControlFeature& outFeature)
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600360{
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600361 if (!validateParameters(command, parameters))
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600362 {
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600363 sendResponse(request.getName(), 400, "Malformed command");
364 return false;
365 }
366
367 shared_ptr<Face> face = m_faceTable.get(request.getIncomingFaceId());
368
369 if (!static_cast<bool>(face))
370 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700371 NFD_LOG_DEBUG("command result: faceid " << request.getIncomingFaceId() << " not found");
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600372 sendResponse(request.getName(), 410, "Face not found");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600373 return false;
374 }
375 else if (!face->isLocal())
376 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700377 NFD_LOG_DEBUG("command result: cannot enable local control on non-local faceid " <<
378 face->getId());
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600379 sendResponse(request.getName(), 412, "Face is non-local");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600380 return false;
381 }
382
383 outFace = dynamic_pointer_cast<LocalFace>(face);
384 outFeature = static_cast<LocalControlFeature>(parameters.getLocalControlFeature());
385
386 return true;
387}
388
389void
390FaceManager::enableLocalControl(const Interest& request,
391 ControlParameters& parameters)
392{
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600393 ndn::nfd::FaceEnableLocalControlCommand command;
394
395
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600396 shared_ptr<LocalFace> face;
397 LocalControlFeature feature;
398
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600399 if (extractLocalControlParameters(request, parameters, command, face, feature))
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600400 {
401 face->setLocalControlHeaderFeature(feature, true);
402 sendResponse(request.getName(), 200, "Success", parameters.wireEncode());
403 }
404}
405
406void
407FaceManager::disableLocalControl(const Interest& request,
408 ControlParameters& parameters)
409{
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600410 ndn::nfd::FaceDisableLocalControlCommand command;
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600411 shared_ptr<LocalFace> face;
412 LocalControlFeature feature;
413
Steve DiBenedetto51d242a2014-03-31 13:46:43 -0600414 if (extractLocalControlParameters(request, parameters, command, face, feature))
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600415 {
416 face->setLocalControlHeaderFeature(feature, false);
417 sendResponse(request.getName(), 200, "Success", parameters.wireEncode());
418 }
419}
420
Steve DiBenedettofbb40a82014-03-11 19:40:15 -0600421void
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600422FaceManager::listFaces(const Interest& request)
423{
424 const Name& command = request.getName();
425 const size_t commandNComps = command.size();
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700426
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600427 if (commandNComps < FACES_LIST_DATASET_NCOMPS ||
428 !FACES_LIST_DATASET_PREFIX.isPrefixOf(command))
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600429 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700430 NFD_LOG_DEBUG("command result: malformed");
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600431 sendResponse(command, 400, "Malformed command");
432 return;
433 }
434
Steve DiBenedettoef04f272014-06-04 14:28:31 -0600435 m_faceStatusPublisher.publish();
436}
437
438void
439FaceManager::listChannels(const Interest& request)
440{
441 NFD_LOG_DEBUG("in listChannels");
442 const Name& command = request.getName();
443 const size_t commandNComps = command.size();
444
445 if (commandNComps < CHANNELS_LIST_DATASET_NCOMPS ||
446 !CHANNELS_LIST_DATASET_PREFIX.isPrefixOf(command))
447 {
448 NFD_LOG_DEBUG("command result: malformed");
449 sendResponse(command, 400, "Malformed command");
450 return;
451 }
452
453 NFD_LOG_DEBUG("publishing");
454 m_channelStatusPublisher.publish();
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -0600455}
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700456
Chengyu Fan320d2332014-10-29 16:40:33 -0600457void
458FaceManager::listQueriedFaces(const Interest& request)
459{
460 NFD_LOG_DEBUG("in listQueriedFaces");
461 const Name& query = request.getName();
462 const size_t queryNComps = query.size();
463
464 if (queryNComps < FACES_QUERY_DATASET_NCOMPS ||
465 !FACES_QUERY_DATASET_PREFIX.isPrefixOf(query))
466 {
467 NFD_LOG_DEBUG("query result: malformed");
Chengyu Fanab205c22014-11-18 10:58:41 -0700468 sendNack(query);
Chengyu Fan320d2332014-10-29 16:40:33 -0600469 return;
470 }
471
472 ndn::nfd::FaceQueryFilter faceFilter;
473 try
474 {
475 faceFilter.wireDecode(query[-1].blockFromValue());
476 }
477 catch (tlv::Error&)
478 {
479 NFD_LOG_DEBUG("query result: malformed filter");
Chengyu Fanab205c22014-11-18 10:58:41 -0700480 sendNack(query);
Chengyu Fan320d2332014-10-29 16:40:33 -0600481 return;
482 }
483
484 FaceQueryStatusPublisher
485 faceQueryStatusPublisher(m_faceTable, *m_face, query, faceFilter, m_keyChain);
486
487 faceQueryStatusPublisher.publish();
488}
489
Alexander Afanasyev5959b012014-06-02 19:18:12 +0300490shared_ptr<ProtocolFactory>
491FaceManager::findFactory(const std::string& protocol)
492{
493 FactoryMap::iterator factory = m_factories.find(protocol);
494 if (factory != m_factories.end())
495 return factory->second;
496 else
497 return shared_ptr<ProtocolFactory>();
498}
499
Steve DiBenedettoabe9e972014-02-20 15:37:04 -0700500} // namespace nfd