33 #include <ndn-cxx/management/nfd-face-event-notification.hpp> 34 #include <ndn-cxx/management/nfd-face-query-filter.hpp> 40 const Name FaceManager::COMMAND_PREFIX(
"/localhost/nfd/faces");
42 const size_t FaceManager::COMMAND_UNSIGNED_NCOMPS =
43 FaceManager::COMMAND_PREFIX.size() +
47 const size_t FaceManager::COMMAND_SIGNED_NCOMPS =
48 FaceManager::COMMAND_UNSIGNED_NCOMPS +
51 const FaceManager::SignedVerbAndProcessor FaceManager::SIGNED_COMMAND_VERBS[] =
53 SignedVerbAndProcessor(
55 &FaceManager::createFace
58 SignedVerbAndProcessor(
60 &FaceManager::destroyFace
63 SignedVerbAndProcessor(
65 &FaceManager::enableLocalControl
68 SignedVerbAndProcessor(
70 &FaceManager::disableLocalControl
74 const FaceManager::UnsignedVerbAndProcessor FaceManager::UNSIGNED_COMMAND_VERBS[] =
76 UnsignedVerbAndProcessor(
78 &FaceManager::listFaces
81 UnsignedVerbAndProcessor(
83 &FaceManager::ignoreUnsignedVerb
86 UnsignedVerbAndProcessor(
88 &FaceManager::listChannels
91 UnsignedVerbAndProcessor(
93 &FaceManager::listQueriedFaces
97 const Name FaceManager::FACES_LIST_DATASET_PREFIX(
"/localhost/nfd/faces/list");
98 const size_t FaceManager::FACES_LIST_DATASET_NCOMPS = FACES_LIST_DATASET_PREFIX.size();
100 const Name FaceManager::FACE_EVENTS_PREFIX(
"/localhost/nfd/faces/events");
102 const Name FaceManager::CHANNELS_LIST_DATASET_PREFIX(
"/localhost/nfd/faces/channels");
103 const size_t FaceManager::CHANNELS_LIST_DATASET_NCOMPS = CHANNELS_LIST_DATASET_PREFIX.size();
105 const Name FaceManager::FACES_QUERY_DATASET_PREFIX(
"/localhost/nfd/faces/query");
106 const size_t FaceManager::FACES_QUERY_DATASET_NCOMPS = FACES_QUERY_DATASET_PREFIX.size() + 1;
109 shared_ptr<InternalFace> face,
110 ndn::KeyChain& keyChain)
112 , m_faceTable(faceTable)
113 , m_faceAddConn(m_faceTable.onAdd.connect(bind(&
FaceManager::onAddFace, this, _1)))
114 , m_faceRemoveConn(m_faceTable.onRemove.connect(bind(&
FaceManager::onRemoveFace, this, _1)))
115 , m_faceStatusPublisher(m_faceTable, *m_face, FACES_LIST_DATASET_PREFIX, keyChain)
116 , m_channelStatusPublisher(m_factories, *m_face, CHANNELS_LIST_DATASET_PREFIX, keyChain)
117 , m_notificationStream(*m_face, FACE_EVENTS_PREFIX, keyChain)
118 , m_signedVerbDispatch(SIGNED_COMMAND_VERBS,
119 SIGNED_COMMAND_VERBS +
120 (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor)))
121 , m_unsignedVerbDispatch(UNSIGNED_COMMAND_VERBS,
122 UNSIGNED_COMMAND_VERBS +
123 (sizeof(UNSIGNED_COMMAND_VERBS) / sizeof(UnsignedVerbAndProcessor)))
126 face->setInterestFilter(
"/localhost/nfd/faces",
139 bind(&FaceManager::onConfig,
this, _1, _2, _3));
146 const std::string& filename)
148 BOOST_THROW_EXCEPTION(
Error(
"Not supported"));
155 const size_t commandNComps = command.
size();
157 if (commandNComps <= COMMAND_PREFIX.
size())
167 const auto unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb);
168 if (unsignedVerbProcessor != m_unsignedVerbDispatch.end())
171 (unsignedVerbProcessor->second)(
this, request);
173 else if (COMMAND_UNSIGNED_NCOMPS <= commandNComps &&
174 commandNComps < COMMAND_SIGNED_NCOMPS)
179 else if (commandNComps < COMMAND_SIGNED_NCOMPS ||
188 bind(&FaceManager::onValidatedFaceRequest,
this, _1),
194 FaceManager::onValidatedFaceRequest(
const shared_ptr<const Interest>& request)
196 const Name& command = request->getName();
200 SignedVerbDispatchTable::const_iterator signedVerbProcessor = m_signedVerbDispatch.find(verb);
201 if (signedVerbProcessor != m_signedVerbDispatch.end())
211 (signedVerbProcessor->second)(
this, *request, parameters);
222 FaceManager::addCreatedFaceToForwarder(
const shared_ptr<Face>& newFace)
224 m_faceTable.
add(newFace);
230 FaceManager::onCreated(
const Name& requestName,
232 const shared_ptr<Face>& newFace)
234 addCreatedFaceToForwarder(newFace);
236 parameters.
setUri(newFace->getRemoteUri().toString());
242 FaceManager::onConnectFailed(
const Name& requestName,
const std::string& reason)
249 FaceManager::createFace(
const Interest& request,
278 if (factory == m_factories.end())
286 factory->second->createFace(uri,
288 bind(&FaceManager::onCreated,
289 this, requestName, parameters, _1),
290 bind(&FaceManager::onConnectFailed,
291 this, requestName, _1));
293 catch (
const std::runtime_error& error)
295 std::string errorMessage =
"NFD error: ";
296 errorMessage += error.what();
301 catch (
const std::logic_error& error)
303 std::string errorMessage =
"NFD error: ";
304 errorMessage += error.what();
313 FaceManager::destroyFace(
const Interest& request,
325 shared_ptr<Face> target = m_faceTable.
get(parameters.
getFaceId());
326 if (static_cast<bool>(target))
336 FaceManager::onAddFace(shared_ptr<Face> face)
340 face->copyStatusTo(notification);
342 m_notificationStream.postNotification(notification);
346 FaceManager::onRemoveFace(shared_ptr<Face> face)
350 face->copyStatusTo(notification);
352 m_notificationStream.postNotification(notification);
356 FaceManager::extractLocalControlParameters(
const Interest& request,
359 shared_ptr<LocalFace>& outFace,
370 if (!static_cast<bool>(face))
376 else if (!face->isLocal())
378 NFD_LOG_DEBUG(
"command result: cannot enable local control on non-local faceid " <<
384 outFace = dynamic_pointer_cast<
LocalFace>(face);
391 FaceManager::enableLocalControl(
const Interest& request,
397 shared_ptr<LocalFace> face;
400 if (extractLocalControlParameters(request, parameters, command, face, feature))
402 face->setLocalControlHeaderFeature(feature,
true);
408 FaceManager::disableLocalControl(
const Interest& request,
412 shared_ptr<LocalFace> face;
415 if (extractLocalControlParameters(request, parameters, command, face, feature))
417 face->setLocalControlHeaderFeature(feature,
false);
423 FaceManager::listFaces(
const Interest& request)
426 const size_t commandNComps = command.
size();
428 if (commandNComps < FACES_LIST_DATASET_NCOMPS ||
429 !FACES_LIST_DATASET_PREFIX.
isPrefixOf(command))
436 m_faceStatusPublisher.
publish();
440 FaceManager::listChannels(
const Interest& request)
444 const size_t commandNComps = command.
size();
446 if (commandNComps < CHANNELS_LIST_DATASET_NCOMPS ||
447 !CHANNELS_LIST_DATASET_PREFIX.
isPrefixOf(command))
455 m_channelStatusPublisher.
publish();
459 FaceManager::listQueriedFaces(
const Interest& request)
463 const size_t queryNComps = query.
size();
465 if (queryNComps < FACES_QUERY_DATASET_NCOMPS ||
466 !FACES_QUERY_DATASET_PREFIX.
isPrefixOf(query))
476 faceFilter.
wireDecode(query[-1].blockFromValue());
486 faceQueryStatusPublisher(m_faceTable, *
m_face, query, faceFilter,
m_keyChain);
488 faceQueryStatusPublisher.
publish();
491 shared_ptr<ProtocolFactory>
492 FaceManager::findFactory(
const std::string& protocol)
495 if (factory != m_factories.end())
496 return factory->second;
498 return shared_ptr<ProtocolFactory>();
represents a faces/disable-local-control command
shared_ptr< InternalFace > m_face
FaceManager(FaceTable &faceTable, shared_ptr< InternalFace > face, ndn::KeyChain &keyChain)
void setConfigFile(ConfigFile &configFile)
Subscribe to a face management section(s) for the config file.
ControlParameters & setFaceId(uint64_t faceId)
const Name & getName() const
#define NFD_LOG_DEBUG(expression)
bool parse(const std::string &uri)
exception-safe parsing
represents parameters in a ControlCommand request or response
ndn::KeyChain & m_keyChain
represents the underlying protocol and address used by a Face
void add(shared_ptr< Face > face)
void sendResponse(const Name &name, const ControlResponse &response)
base class of NFD ControlCommand
represents a Face status change notification
represents an Interest packet
#define NFD_LOG_ERROR(expression)
FaceEventNotification & setKind(FaceEventKind kind)
ControlParameters & setUri(const std::string &uri)
represents a faces/create command
Table::const_iterator iterator
represents a faces/enable-local-control command
size_t wireEncode(EncodingImpl< TAG > &encoder) const
bool isCanonical() const
determine whether this FaceUri is in canonical form
static bool extractParameters(const Name::Component ¶meterComponent, ControlParameters &extractedParameters)
Copyright (c) 2011-2015 Regents of the University of California.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
void onFaceRequest(const Interest &request)
const std::string FACE_MANAGER_PRIVILEGE
const std::string & getScheme() const
get scheme (protocol)
void onCommandValidationFailed(const shared_ptr< const Interest > &command, const std::string &error)
uint64_t getIncomingFaceId() const
size_t size() const
Get the number of components.
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
represents Face Query Filter
void sendNack(const Name &name)
LocalControlFeature getLocalControlFeature() const
uint64_t getFaceId() const
Component holds a read-only name component value.
#define NFD_LOG_INIT(name)
#define NFD_LOG_TRACE(expression)
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
virtual bool validateParameters(const ControlCommand &command, ControlParameters ¶meters)
represents a faces/destroy command
shared_ptr< Face > get(FaceId id) const
void validate(const Interest &interest, const ndn::OnInterestValidated &onValidated, const ndn::OnInterestValidationFailed &onValidationFailed)
void wireDecode(const Block &wire)
decode FaceQueryFilter
const std::string & getUri() const
const Component & at(ssize_t i) const
Get component at the specified index.
represents an error in TLV encoding or decoding