31 #include <boost/logic/tribool.hpp> 33 #include <ndn-cxx/lp/tags.hpp> 34 #include <ndn-cxx/mgmt/nfd/channel-status.hpp> 44 , m_faceSystem(faceSystem)
45 , m_faceTable(faceSystem.getFaceTable())
48 registerCommandHandler<ndn::nfd::FaceCreateCommand>(
"create",
49 bind(&FaceManager::createFace,
this, _2, _3, _4, _5));
51 registerCommandHandler<ndn::nfd::FaceUpdateCommand>(
"update",
52 bind(&FaceManager::updateFace,
this, _2, _3, _4, _5));
54 registerCommandHandler<ndn::nfd::FaceDestroyCommand>(
"destroy",
55 bind(&FaceManager::destroyFace,
this, _2, _3, _4, _5));
65 connectFaceStateChangeSignal(
face);
74 FaceManager::createFace(
const Name& topPrefix,
const Interest& interest,
91 optional<FaceUri> localUri;
101 if (!localUri->isCanonical()) {
102 NFD_LOG_TRACE(
"received non-canonical local URI: " << localUri->toString());
109 if (factory ==
nullptr) {
115 face::FaceParams faceParams;
131 factory->createFace({remoteUri, localUri, faceParams},
132 bind(&FaceManager::afterCreateFaceSuccess,
this, parameters, _1, done),
133 bind(&FaceManager::afterCreateFaceFailure,
this, _1, _2, done));
135 catch (
const std::runtime_error& error) {
137 done(
ControlResponse(500,
"Face creation failed due to internal error"));
140 catch (
const std::logic_error& error) {
142 done(
ControlResponse(500,
"Face creation failed due to internal error"));
149 const shared_ptr<Face>&
face,
156 done(
ControlResponse(409,
"Face with remote URI already exists").setBody(response.wireEncode()));
174 FaceManager::afterCreateFaceFailure(uint32_t status,
175 const std::string& reason,
184 FaceManager::updateFace(
const Name& topPrefix,
const Interest& interest,
188 FaceId faceId = parameters.getFaceId();
192 if (incomingFaceIdTag ==
nullptr) {
194 done(
ControlResponse(404,
"No FaceId specified and IncomingFaceId not available"));
197 faceId = *incomingFaceIdTag;
202 if (
face ==
nullptr) {
210 bool areParamsValid =
true;
215 NFD_LOG_TRACE(
"received request to enable local fields on non-local face");
216 areParamsValid =
false;
222 if (parameters.hasFacePersistency()) {
223 auto persistency = parameters.getFacePersistency();
224 if (!
face->getTransport()->canChangePersistencyTo(persistency)) {
225 NFD_LOG_TRACE(
"cannot change face persistency to " << persistency);
226 areParamsValid =
false;
227 response.setFacePersistency(persistency);
231 if (!areParamsValid) {
232 done(
ControlResponse(409,
"Invalid properties specified").setBody(response.wireEncode()));
237 if (parameters.hasFacePersistency()) {
238 face->setPersistency(parameters.getFacePersistency());
240 setLinkServiceOptions(*
face, parameters);
243 response = collectFaceProperties(*
face,
false);
249 FaceManager::destroyFace(
const Name& topPrefix,
const Interest& interest,
253 Face*
face = m_faceTable.
get(parameters.getFaceId());
254 if (
face !=
nullptr) {
262 FaceManager::setLinkServiceOptions(
Face&
face,
266 BOOST_ASSERT(linkService !=
nullptr);
268 auto options = linkService->getOptions();
279 if (parameters.hasBaseCongestionMarkingInterval()) {
280 options.baseCongestionMarkingInterval = parameters.getBaseCongestionMarkingInterval();
282 if (parameters.hasDefaultCongestionThreshold()) {
283 options.defaultCongestionThreshold = parameters.getDefaultCongestionThreshold();
285 linkService->setOptions(options);
289 FaceManager::collectFaceProperties(
const Face&
face,
bool wantUris)
292 BOOST_ASSERT(linkService !=
nullptr);
293 auto options = linkService->getOptions();
296 params.setFaceId(
face.getId())
297 .setFacePersistency(
face.getPersistency())
298 .setBaseCongestionMarkingInterval(options.baseCongestionMarkingInterval)
299 .setDefaultCongestionThreshold(options.defaultCongestionThreshold)
304 params.setUri(
face.getRemoteUri().toString())
305 .setLocalUri(
face.getLocalUri().toString());
311 FaceManager::listFaces(
const Name& topPrefix,
const Interest& interest,
315 for (
const Face&
face : m_faceTable) {
323 FaceManager::listChannels(
const Name& topPrefix,
const Interest& interest,
327 for (
const auto* factory : factories) {
328 for (
const auto& channel : factory->getChannels()) {
338 FaceManager::queryFaces(
const Name& topPrefix,
const Interest& interest,
342 const Name& query = interest.getName();
344 faceFilter.
wireDecode(query[-1].blockFromValue());
346 catch (
const tlv::Error& e) {
352 for (
const Face&
face : m_faceTable) {
353 if (!matchFilter(faceFilter,
face)) {
410 collectFaceProperties(
face, status);
413 if (expirationTime != time::steady_clock::TimePoint::max()) {
415 time::duration_cast<time::milliseconds>(expirationTime - now)));
420 if (linkService !=
nullptr) {
421 auto linkServiceOptions = linkService->getOptions();
426 const face::FaceCounters& counters =
face.getCounters();
439 template<
typename FaceTraits>
441 FaceManager::collectFaceProperties(
const Face&
face, FaceTraits& traits)
444 .setRemoteUri(
face.getRemoteUri().toString())
445 .setLocalUri(
face.getLocalUri().toString())
446 .setFaceScope(
face.getScope())
447 .setFacePersistency(
face.getPersistency())
448 .setLinkType(
face.getLinkType());
452 if (linkService !=
nullptr) {
453 auto linkServiceOptions = linkService->getOptions();
456 linkServiceOptions.reliabilityOptions.isEnabled);
458 linkServiceOptions.allowCongestionMarking);
467 collectFaceProperties(
face, notification);
469 m_postNotification(notification.
wireEncode());
473 FaceManager::connectFaceStateChangeSignal(
const Face&
face)
478 m_faceStateChangeConn[faceId] =
face.afterStateChange.connect(
480 if (newState == FaceState::UP) {
483 else if (newState == FaceState::DOWN) {
486 else if (newState == FaceState::CLOSED) {
488 m_faceStateChangeConn.erase(faceId);
signal::Signal< FaceTable, Face & > afterAdd
fires after a face is added
LinkType getLinkType() const
bool hasFaceScope() const
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
declare the non-existence of a response
const std::string & getLocalUri() const
represents parameters in a ControlCommand request or response
time::nanoseconds getBaseCongestionMarkingInterval() const
generalization of a network interface
represents a dispatcher on server side of NFD Management protocol
static time_point now() noexcept
FaceScope getFaceScope() const
std::string toString() const
write as a string
void add(shared_ptr< Face > face)
add a face
ProtocolFactory * getFactoryByScheme(const std::string &scheme)
entry point of the face system
signal::Signal< FaceTable, Face & > beforeRemove
fires before a face is removed
represents a Face status change notification
whether congestion detection and marking is enabled on a face
const std::string & getRemoteUri() const
Represents an Interest packet.
#define NFD_LOG_DEBUG(expression)
FaceEventNotification & setKind(FaceEventKind kind)
std::set< const ProtocolFactory * > listProtocolFactories() const
bool hasRemoteUri() const
FaceStatus & setNOutBytes(uint64_t nOutBytes)
FaceStatus & setNOutInterests(uint64_t nOutInterests)
C & setFaceId(uint64_t faceId)
bool hasBaseCongestionMarkingInterval() const
Face * get(FaceId id) const
get face by FaceId
FaceStatus & setExpirationPeriod(time::milliseconds expirationPeriod)
provides a tag type for simple types
FaceStatus & setNInInterests(uint64_t nInInterests)
FacePersistency getFacePersistency() const
FaceStatus & setNInBytes(uint64_t nInBytes)
#define NFD_LOG_TRACE(expression)
#define NFD_LOG_ERROR(expression)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend FaceEventNotification to the encoder
bool hasUriScheme() const
mgmt::ControlResponse ControlResponse
whether the link reliability feature is enabled on a face
FaceStatus & setNInNacks(uint64_t nInNacks)
Copyright (c) 2011-2015 Regents of the University of California.
FaceManager(FaceSystem &faceSystem, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
TransportState FaceState
indicates the state of a face
bool parse(const std::string &uri)
exception-safe parsing
uint64_t getFaceId() const
FaceStatus & setNOutData(uint64_t nOutData)
const std::string & getLocalUri() const
void end()
end the response successfully after appending zero or more blocks
face went UP (from DOWN state)
uint64_t getDefaultCongestionThreshold() const
get default congestion threshold (measured in bytes)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend FaceStatus to the encoder
represents an item in NFD Face dataset
Represents an absolute name.
represents the underlying protocol and address used by a Face
bool hasFlagBit(size_t bit) const
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
represents Face Query Filter
const std::string & getUri() const
const std::string & getScheme() const
get scheme (protocol)
FaceStatus & setBaseCongestionMarkingInterval(time::nanoseconds interval)
provides ControlCommand authorization according to NFD configuration file
FaceStatus & setNOutNacks(uint64_t nOutNacks)
bool hasDefaultCongestionThreshold() const
void append(const Block &block)
append a Block to the response
represents an item in NFD Channel dataset
bool getFlagBit(size_t bit) const
FaceStatus & setNInData(uint64_t nInData)
ndn::mgmt::PostNotification registerNotificationStream(const std::string &verb)
const std::string & getUriScheme() const
provides a context for generating response to a StatusDataset request
FacePersistency getFacePersistency() const
uint64_t FaceId
identifies a face
bool isCanonical() const
determine whether this FaceUri is in canonical form
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
#define NFD_LOG_INIT(name)
bool hasFacePersistency() const
whether local fields are enabled on a face
void wireDecode(const Block &wire)
decode FaceQueryFilter
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
const FaceId INVALID_FACEID
indicates an invalid FaceId
face went DOWN (from UP state)
FaceStatus & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
ChannelStatus & setLocalUri(const std::string localUri)