47 , m_faceSystem(faceSystem)
48 , m_faceTable(faceSystem.getFaceTable())
51 registerCommandHandler<ndn::nfd::FaceCreateCommand>(
"create", bind(&FaceManager::createFace,
this, _4, _5));
52 registerCommandHandler<ndn::nfd::FaceUpdateCommand>(
"update", bind(&FaceManager::updateFace,
this, _3, _4, _5));
53 registerCommandHandler<ndn::nfd::FaceDestroyCommand>(
"destroy", bind(&FaceManager::destroyFace,
this, _4, _5));
62 m_faceAddConn = m_faceTable.
afterAdd.connect([
this] (
const Face& face) {
63 connectFaceStateChangeSignal(face);
66 m_faceRemoveConn = m_faceTable.
beforeRemove.connect([
this] (
const Face& face) {
88 optional<FaceUri> localUri;
98 if (!localUri->isCanonical()) {
99 NFD_LOG_TRACE(
"received non-canonical local URI: " << localUri->toString());
106 if (factory ==
nullptr) {
112 face::FaceParams faceParams;
120 if (parameters.
hasMtu()) {
121 faceParams.mtu = parameters.
getMtu();
131 factory->createFace({remoteUri, localUri, faceParams},
132 [
this, parameters, done] (
const auto& face) {
133 this->afterCreateFaceSuccess(face, parameters, done);
135 [done] (uint32_t status,
const std::string& reason) {
140 catch (
const std::runtime_error& error) {
142 done(
ControlResponse(500,
"Face creation failed due to internal error"));
145 catch (
const std::logic_error& error) {
147 done(
ControlResponse(500,
"Face creation failed due to internal error"));
157 BOOST_ASSERT(transport !=
nullptr);
159 if (transport->getMtu() > 0) {
174 auto linkService = dynamic_cast<face::GenericLinkService*>(face.
getLinkService());
175 if (linkService !=
nullptr) {
176 const auto& options = linkService->getOptions();
200 FaceManager::afterCreateFaceSuccess(
const shared_ptr<Face>& face,
205 NFD_LOG_TRACE(
"Attempted to create duplicate face of " << face->getId());
207 done(
ControlResponse(409,
"Face with remote URI already exists").setBody(response.wireEncode()));
218 m_faceTable.
add(face);
227 auto linkService = dynamic_cast<face::GenericLinkService*>(face.
getLinkService());
228 if (linkService ==
nullptr) {
231 auto options = linkService->getOptions();
250 linkService->setOptions(options);
254 FaceManager::updateFace(
const Interest& interest,
258 FaceId faceId = parameters.getFaceId();
261 if (incomingFaceIdTag ==
nullptr) {
263 done(
ControlResponse(404,
"No FaceId specified and IncomingFaceId not available"));
266 faceId = *incomingFaceIdTag;
269 Face* face = m_faceTable.
get(faceId);
270 if (face ==
nullptr) {
278 bool areParamsValid =
true;
283 NFD_LOG_TRACE(
"received request to enable local fields on non-local face");
284 areParamsValid =
false;
290 if (parameters.hasFacePersistency()) {
291 auto persistency = parameters.getFacePersistency();
292 if (!face->getTransport()->canChangePersistencyTo(persistency)) {
293 NFD_LOG_TRACE(
"cannot change face persistency to " << persistency);
294 areParamsValid =
false;
295 response.setFacePersistency(persistency);
299 if (!areParamsValid) {
300 done(
ControlResponse(409,
"Invalid properties specified").setBody(response.wireEncode()));
305 if (parameters.hasFacePersistency()) {
306 face->setPersistency(parameters.getFacePersistency());
319 Face* face = m_faceTable.
get(parameters.getFaceId());
320 if (face !=
nullptr) {
331 to.setFaceId(face.
getId())
338 auto linkService = dynamic_cast<face::GenericLinkService*>(face.
getLinkService());
339 if (linkService !=
nullptr) {
340 const auto& options = linkService->getOptions();
354 if (expirationTime != time::steady_clock::TimePoint::max()) {
356 time::duration_cast<time::milliseconds>(expirationTime - now)));
359 auto linkService = dynamic_cast<face::GenericLinkService*>(face.
getLinkService());
360 if (linkService !=
nullptr) {
361 const auto& options = linkService->getOptions();
385 for (
const auto& face : m_faceTable) {
396 for (
const auto* factory : factories) {
397 for (
const auto& channel : factory->getChannels()) {
449 FaceManager::queryFaces(
const Interest& interest,
454 faceFilter.
wireDecode(interest.getName()[-1].blockFromValue());
456 catch (
const tlv::Error& e) {
462 for (
const auto& face : m_faceTable) {
478 m_postNotification(notification.
wireEncode());
482 FaceManager::connectFaceStateChangeSignal(
const Face& face)
486 FaceId faceId = face.getId();
487 m_faceStateChangeConn[faceId] = face.afterStateChange.connect(
489 if (newState == FaceState::UP) {
492 else if (newState == FaceState::DOWN) {
495 else if (newState == FaceState::CLOSED) {
497 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
ControlParameters & setFaceId(uint64_t faceId)
const std::string & getLocalUri() const
static void updateLinkServiceOptions(Face &face, const ControlParameters ¶meters)
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
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
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
Transport * getTransport() const
FaceEventNotification & setKind(FaceEventKind kind)
std::set< const ProtocolFactory * > listProtocolFactories() const
FaceUri getLocalUri() const
FaceUri getRemoteUri() const
LinkService * getLinkService() 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)
time::steady_clock::TimePoint getExpirationTime() const
provides a tag type for simple types
FaceStatus & setNInInterests(uint64_t nInInterests)
FacePersistency getFacePersistency() const
FaceStatus & setNInBytes(uint64_t nInBytes)
static ndn::nfd::FaceStatus makeFaceStatus(const Face &face, const time::steady_clock::TimePoint &now)
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)
mgmt::ControlResponse ControlResponse
whether the link reliability feature is enabled on a face
FaceStatus & setNInNacks(uint64_t nInNacks)
ndn::nfd::LinkType getLinkType() const
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
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()
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
ndn::nfd::FaceScope getScope() const
represents the underlying protocol and address used by a Face
static bool matchFilter(const ndn::nfd::FaceQueryFilter &filter, const Face &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.
ndn::nfd::FacePersistency getPersistency() const
FaceStatus & setNOutNacks(uint64_t nOutNacks)
ControlParameters & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
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
void close()
request the face to be closed
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)
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
set a bit in Flags
const FaceId INVALID_FACEID
indicates an invalid FaceId
implement the Face Management of NFD Management Protocol.
const FaceCounters & getCounters() const
static ControlParameters makeUpdateFaceResponse(const Face &face)
static void copyFaceProperties(const Face &face, T &to)
face went DOWN (from UP state)
FaceStatus & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
size_t wireEncode(EncodingImpl< TAG > &encoder) const
ChannelStatus & setLocalUri(const std::string localUri)