46 , m_faceSystem(faceSystem)
47 , m_faceTable(faceSystem.getFaceTable())
50 registerCommandHandler<ndn::nfd::FaceCreateCommand>(
"create",
51 std::bind(&FaceManager::createFace,
this, _4, _5));
52 registerCommandHandler<ndn::nfd::FaceUpdateCommand>(
"update",
53 std::bind(&FaceManager::updateFace,
this, _3, _4, _5));
54 registerCommandHandler<ndn::nfd::FaceDestroyCommand>(
"destroy",
55 std::bind(&FaceManager::destroyFace,
this, _4, _5));
64 m_faceAddConn = m_faceTable.
afterAdd.connect([
this] (
const Face& face) {
65 connectFaceStateChangeSignal(face);
68 m_faceRemoveConn = m_faceTable.
beforeRemove.connect([
this] (
const Face& face) {
90 optional<FaceUri> localUri;
100 if (!localUri->isCanonical()) {
101 NFD_LOG_TRACE(
"received non-canonical local URI: " << localUri->toString());
108 if (factory ==
nullptr) {
122 if (parameters.
hasMtu()) {
124 faceParams.
mtu = std::min<uint64_t>(std::numeric_limits<ssize_t>::max(), parameters.
getMtu());
134 factory->
createFace({remoteUri, localUri, faceParams},
136 this->afterCreateFaceSuccess(face, parameters, done);
138 [
done] (uint32_t status,
const std::string& reason) {
143 catch (
const std::runtime_error& error) {
148 catch (
const std::logic_error& error) {
159 if (face.getMtu() >= 0) {
172 .setFacePersistency(face.getPersistency());
176 if (linkService !=
nullptr) {
177 const auto& options = linkService->getOptions();
192 params.
setUri(face.getRemoteUri().toString())
193 .setLocalUri(face.getLocalUri().toString());
199 FaceManager::afterCreateFaceSuccess(
const shared_ptr<Face>& face,
204 NFD_LOG_TRACE(
"Attempted to create duplicate face of " << face->getId());
206 done(
ControlResponse(409,
"Face with remote URI already exists").setBody(response.wireEncode()));
217 m_faceTable.
add(face);
227 if (linkService ==
nullptr) {
230 auto options = linkService->getOptions();
249 if (parameters.
hasMtu()) {
251 options.overrideMtu = std::min<uint64_t>(std::numeric_limits<ssize_t>::max(), parameters.
getMtu());
254 linkService->setOptions(options);
265 if (incomingFaceIdTag ==
nullptr) {
270 faceId = *incomingFaceIdTag;
273 Face* face = m_faceTable.
get(faceId);
274 if (face ==
nullptr) {
282 bool areParamsValid =
true;
287 NFD_LOG_TRACE(
"received request to enable local fields on non-local face");
288 areParamsValid =
false;
296 if (!face->getTransport()->canChangePersistencyTo(persistency)) {
297 NFD_LOG_TRACE(
"cannot change face persistency to " << persistency);
298 areParamsValid =
false;
304 if (parameters.
hasMtu()) {
305 auto mtu = parameters.
getMtu();
307 auto actualMtu = std::min<uint64_t>(std::numeric_limits<ssize_t>::max(), mtu);
309 if (linkService ==
nullptr || !linkService->canOverrideMtuTo(actualMtu)) {
311 areParamsValid =
false;
316 if (!areParamsValid) {
337 if (face !=
nullptr) {
348 to.setFaceId(face.getId())
349 .setRemoteUri(face.getRemoteUri().toString())
350 .setLocalUri(face.getLocalUri().toString())
351 .setFaceScope(face.getScope())
352 .setFacePersistency(face.getPersistency())
353 .setLinkType(face.getLinkType());
356 if (linkService !=
nullptr) {
357 const auto& options = linkService->getOptions();
370 auto expirationTime = face.getExpirationTime();
371 if (expirationTime != time::steady_clock::time_point::max()) {
373 time::duration_cast<time::milliseconds>(expirationTime - now)));
377 if (linkService !=
nullptr) {
378 const auto& options = linkService->getOptions();
385 const auto& counters = face.getCounters();
402 for (
const auto& face : m_faceTable) {
413 for (
const auto* factory : factories) {
414 for (
const auto& channel : factory->getChannels()) {
427 filter.
getFaceId() !=
static_cast<uint64_t
>(face.getId())) {
432 filter.
getUriScheme() != face.getRemoteUri().getScheme() &&
433 filter.
getUriScheme() != face.getLocalUri().getScheme()) {
438 filter.
getRemoteUri() != face.getRemoteUri().toString()) {
443 filter.
getLocalUri() != face.getLocalUri().toString()) {
466 FaceManager::queryFaces(
const Interest& interest,
479 for (
const auto& face : m_faceTable) {
495 m_postNotification(notification.
wireEncode());
499 FaceManager::connectFaceStateChangeSignal(
const Face& face)
503 FaceId faceId = face.getId();
504 m_faceStateChangeConn[faceId] = face.afterStateChange.connect(
506 if (newState == FaceState::UP) {
509 else if (newState == FaceState::DOWN) {
512 else if (newState == FaceState::CLOSED) {
514 m_faceStateChangeConn.erase(faceId);
LinkType getLinkType() const
bool hasFaceScope() const
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
Rejects the request.
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name const Interest & interest
ControlParameters & setFaceId(uint64_t faceId)
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
optional< uint64_t > defaultCongestionThreshold
shared_ptr< T > getTag() const
get a tag item
const std::string & getLocalUri() const
#define NFD_LOG_INIT(name)
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name const Interest const ControlParameters const ndn::mgmt::CommandContinuation done
static void updateLinkServiceOptions(Face &face, const ControlParameters ¶meters)
boost::logic::tribool wantCongestionMarking
represents parameters in a ControlCommand request or response
time::nanoseconds getBaseCongestionMarkingInterval() const
represents a dispatcher on server side of NFD Management protocol
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
static time_point now() noexcept
ControlParameters & setMtu(uint64_t mtu)
set MTU (measured in bytes)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
boost::chrono::time_point< steady_clock > time_point
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)
ndn::nfd::FacePersistency persistency
entry point of the face system
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.
FaceEventNotification & setKind(FaceEventKind kind)
std::set< const ProtocolFactory * > listProtocolFactories() const
bool hasRemoteUri() const
FaceStatus & setNOutBytes(uint64_t nOutBytes)
FaceStatus & setNOutInterests(uint64_t nOutInterests)
bool hasBaseCongestionMarkingInterval() const
ControlParameters & setUri(const std::string &uri)
Face * get(FaceId id) const
get face by FaceId
FaceStatus & setExpirationPeriod(time::milliseconds expirationPeriod)
signal::Signal< FaceTable, Face > beforeRemove
Fires immediately before a face is removed.
provides a tag type for simple types
FaceStatus & setNInInterests(uint64_t nInInterests)
FacePersistency getFacePersistency() const
FaceStatus & setNInBytes(uint64_t nInBytes)
Provides support for an underlying protocol.
uint64_t getMtu() const
get MTU (measured in bytes)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend FaceEventNotification to the encoder
bool hasUriScheme() const
static ControlParameters makeCreateFaceResponse(const Face &face)
optional< time::nanoseconds > baseCongestionMarkingInterval
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)
ControlParameters & setBaseCongestionMarkingInterval(time::nanoseconds interval)
TransportState FaceState
indicates the state of a face
NDN_CXX_NODISCARD bool parse(const std::string &uri)
exception-safe parsing
uint64_t getFaceId() const
static void copyMtu(const Face &face, T &to)
FaceStatus & setNOutData(uint64_t nOutData)
const std::string & getLocalUri() const
void end()
Finalizes 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 the underlying protocol and address used by a Face
static bool matchFilter(const ndn::nfd::FaceQueryFilter &filter, const Face &face)
static ndn::nfd::FaceStatus makeFaceStatus(const Face &face, const time::steady_clock::time_point &now)
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
uint64_t getFaceId() const
const std::string & getUri() const
const std::string & getScheme() const
get scheme (protocol)
void append(span< const uint8_t > bytes)
Appends a sequence of bytes to the response.
FaceStatus & setBaseCongestionMarkingInterval(time::nanoseconds interval)
Provides ControlCommand authorization according to NFD configuration file.
bool hasFacePersistency() const
const Name & getName() const noexcept
ControlParameters & setFacePersistency(FacePersistency persistency)
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name const Interest const ControlParameters & parameters
FaceStatus & setNOutNacks(uint64_t nOutNacks)
ControlParameters & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
bool hasDefaultCongestionThreshold() const
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 the response to a StatusDataset request.
FacePersistency getFacePersistency() const
bool isCanonical() const
determine whether this FaceUri is in canonical form
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)
void createFace(const CreateFaceRequest &req, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure)
Create a unicast face.
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
set a bit in Flags
uint64_t FaceId
Identifies a face.
const FaceId INVALID_FACEID
indicates an invalid FaceId
Implements the Face Management of NFD Management Protocol.
static ControlParameters makeUpdateFaceResponse(const Face &face)
static void copyFaceProperties(const Face &face, T &to)
represents an error in TLV encoding or decoding
face went DOWN (from UP state)
Parameters used to set Transport properties or LinkService options on a newly created face...
FaceStatus & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
ChannelStatus & setLocalUri(const std::string localUri)
signal::Signal< FaceTable, Face > afterAdd
Fires immediately after a face is added.