54 , m_keyChain(keyChain)
55 , m_nfdController(nfdController)
56 , m_dispatcher(dispatcher)
57 , m_scheduler(scheduler)
59 , m_localhostValidator(face)
60 , m_localhopValidator(face)
61 , m_isLocalhopEnabled(false)
63 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
64 bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
65 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
66 bind(&RibManager::unregisterEntry,
this, _2, _3, _4, _5));
74 m_localhostValidator.
load(section, filename);
80 m_localhopValidator.
load(section, filename);
81 m_isLocalhopEnabled =
true;
87 m_isLocalhopEnabled =
false;
95 if (m_isLocalhopEnabled) {
99 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
100 m_faceMonitor.
onNotification.connect(bind(&RibManager::onNotification,
this, _1));
101 m_faceMonitor.
start();
115 BOOST_THROW_EXCEPTION(
Error(
"Couldn't enable local fields (" +
to_string(res.getCode()) +
116 " " + res.getText() +
")"));
121 RibManager::beginAddRoute(
const Name&
name,
Route route, optional<time::nanoseconds> expires,
122 const std::function<
void(RibUpdateResult)>& done)
131 if (expires && *expires <= 0_s) {
133 return done(RibUpdateResult::EXPIRED);
137 " origin=" << route.
origin <<
" cost=" << route.
cost);
145 m_registeredFaces.insert(route.
faceId);
151 beginRibUpdate(update, done);
155 RibManager::beginRemoveRoute(
const Name&
name,
const Route& route,
156 const std::function<
void(RibUpdateResult)>& done)
159 " origin=" << route.origin);
165 beginRibUpdate(update, done);
169 RibManager::beginRibUpdate(
const RibUpdate& update,
170 const std::function<
void(RibUpdateResult)>& done)
175 done(RibUpdateResult::OK);
177 [=] (uint32_t code,
const std::string& error) {
178 NFD_LOG_DEBUG(
"RIB update failed for " << update <<
" (" << code <<
" " << error <<
")");
181 scheduleActiveFaceFetch(1_s);
183 done(RibUpdateResult::ERROR);
188 RibManager::registerTopPrefix(
const Name& topPrefix)
195 NFD_LOG_DEBUG(
"Successfully registered " << topPrefix <<
" with NFD");
199 route.faceId = res.getFaceId();
203 m_rib.
insert(topPrefix, route);
205 m_registeredFaces.insert(route.faceId);
208 BOOST_THROW_EXCEPTION(Error(
"Cannot add FIB entry " + topPrefix.toUri() +
" (" +
209 to_string(res.getCode()) +
" " + res.getText() +
")"));
217 RibManager::registerEntry(
const Name& topPrefix,
const Interest& interest,
227 setFaceForSelfRegistration(interest, parameters);
230 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
233 route.faceId = parameters.getFaceId();
234 route.origin = parameters.getOrigin();
235 route.cost = parameters.getCost();
236 route.flags = parameters.getFlags();
238 optional<time::nanoseconds> expires;
239 if (parameters.hasExpirationPeriod() &&
240 parameters.getExpirationPeriod() != time::milliseconds::max()) {
241 expires = time::duration_cast<time::nanoseconds>(parameters.getExpirationPeriod());
244 beginAddRoute(parameters.getName(), std::move(route), expires, [] (RibUpdateResult) {});
248 RibManager::unregisterEntry(
const Name& topPrefix,
const Interest& interest,
252 setFaceForSelfRegistration(interest, parameters);
255 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
258 route.faceId = parameters.getFaceId();
259 route.origin = parameters.getOrigin();
261 beginRemoveRoute(parameters.getName(), route, [] (RibUpdateResult) {});
265 RibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
269 for (
const auto& kv : m_rib) {
273 for (
const Route& route : entry.getRoutes()) {
292 bool isSelfRegistration = (parameters.getFaceId() == 0);
293 if (isSelfRegistration) {
298 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
299 parameters.setFaceId(*incomingFaceIdTag);
304 RibManager::makeAuthorization(
const std::string& verb)
306 return [
this] (
const Name& prefix,
const Interest& interest,
310 BOOST_ASSERT(params !=
nullptr);
315 m_localhostValidator : m_localhopValidator;
329 return os <<
"ERROR";
331 return os <<
"VALIDATION_FAILURE";
333 return os <<
"EXPIRED";
335 return os <<
"NOT_FOUND";
337 BOOST_ASSERT_MSG(
false,
"bad SlAnnounceResult");
342 RibManager::getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r)
345 case RibUpdateResult::OK:
347 case RibUpdateResult::ERROR:
349 case RibUpdateResult::EXPIRED:
363 if (!m_isLocalhopEnabled) {
365 ": localhop_security unconfigured");
372 Route route(pa, faceId);
375 [=] (RibUpdateResult ribRes) {
376 auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
383 " validation error: " << err);
394 routeQuery.
faceId = faceId;
396 Route* oldRoute = m_rib.findLongestPrefix(
name, routeQuery);
404 Route route = *oldRoute;
406 beginAddRoute(routeName, route,
nullopt,
407 [=] (RibUpdateResult ribRes) {
408 auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
409 NFD_LOG_INFO(
"slRenew " <<
name <<
" " << faceId <<
": " << res <<
" " << routeName);
417 shared_ptr<RibEntry> entry;
418 auto exactMatch = m_rib.find(
name);
419 if (exactMatch != m_rib.end()) {
420 entry = exactMatch->second;
423 entry = m_rib.findParent(
name);
425 if (entry ==
nullptr) {
429 auto pa = entry->getPrefixAnnouncement();
430 pa.toData(m_keyChain);
435 RibManager::fetchActiveFaces()
440 bind(&RibManager::removeInvalidFaces,
this, _1),
441 bind(&RibManager::onFetchActiveFacesFailure,
this, _1, _2),
446 RibManager::onFetchActiveFacesFailure(uint32_t code,
const std::string& reason)
448 NFD_LOG_DEBUG(
"Face Status Dataset request failure " << code <<
" " << reason);
453 RibManager::onFaceDestroyedEvent(uint64_t faceId)
455 m_rib.beginRemoveFace(faceId);
456 m_registeredFaces.erase(faceId);
460 RibManager::scheduleActiveFaceFetch(
const time::seconds& timeToWait)
462 m_activeFaceFetchEvent = m_scheduler.
scheduleEvent(timeToWait, [
this] { fetchActiveFaces(); });
466 RibManager::removeInvalidFaces(
const std::vector<ndn::nfd::FaceStatus>& activeFaces)
470 FaceIdSet activeFaceIds;
471 for (
const auto& faceStatus : activeFaces) {
472 activeFaceIds.insert(faceStatus.getFaceId());
477 for (
auto faceId : m_registeredFaces) {
478 if (activeFaceIds.count(faceId) == 0) {
480 m_scheduler.
scheduleEvent(0_ns, [
this, faceId] { this->onFaceDestroyedEvent(faceId); });
void start()
start or resume receiving notifications
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
represents the Routing Information Base
void applyLocalhostConfig(const ConfigSection §ion, const std::string &filename)
Apply localhost_security configuration.
void load(const std::string &filename)
represents a fib/add-nexthop command
The interface of signing key management.
Serve commands and datasets in NFD RIB management protocol.
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
static time_point now() noexcept
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
void extractRequester(const Interest &interest, ndn::mgmt::AcceptContinuation accept)
extract a requester from a ControlCommand request
Helper for validator that uses CommandInterest + Config policy and NetworkFetcher.
reply with a ControlResponse where StatusCode is 403
Route & setFlags(uint64_t flags)
RIB and FIB have been updated.
static const time::seconds ACTIVE_FACE_FETCH_INTERVAL
Route & setOrigin(RouteOrigin origin)
represents a Face status change notification
void enableLocalhop(const ConfigSection §ion, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix.
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
represents a route in a RibEntry
optional< time::steady_clock::TimePoint > expires
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
Route & setCost(uint64_t cost)
std::enable_if_t< std::is_default_constructible< Dataset >::value > fetch(const std::function< void(typename Dataset::ResultType)> &onSuccess, const DatasetFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start dataset fetching
EventId scheduleEvent(time::nanoseconds after, const EventCallback &callback)
Schedule a one-time event after the specified delay.
A prefix announcement object that represents an application's intent of registering a prefix toward i...
provides a tag type for simple types
time::steady_clock::TimePoint annExpires
Expiration time of the prefix announcement.
optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
ndn::nfd::RouteOrigin origin
void insert(const Name &prefix, const Route &route)
mgmt::ControlResponse ControlResponse
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
contains options for ControlCommand execution
std::function< void(RejectReply reply)> RejectContinuation
a function to be called if authorization is rejected
Copyright (c) 2011-2015 Regents of the University of California.
size_t wireEncode(EncodingImpl< TAG > &block) const
the announcement has expired
route does not exist (slRenew only)
void end()
end the response successfully after appending zero or more blocks
represents a route for a name prefix
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
Provide a communication channel with local or remote NDN forwarder.
void addTopPrefix(const Name &prefix, bool wantRegister=true, const security::SigningInfo &signingInfo=security::SigningInfo())
add a top-level prefix
NFD Management protocol client.
RibManager(Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher, ndn::util::Scheduler &scheduler)
FaceEventKind getKind() const
RibEntry & addRoute(const Route &route)
const Name & getAnnouncedName() const
Return announced name.
boost::property_tree::ptree ConfigSection
a config file section
void slAnnounce(const ndn::PrefixAnnouncement &pa, uint64_t faceId, time::milliseconds maxLifetime, const SlAnnounceCallback &cb)
Insert a route by prefix announcement from self-learning strategy.
Represents an absolute name.
static const std::string MGMT_MODULE_NAME
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
void setExpirationEvent(const ndn::util::scheduler::EventId &eid)
base class for a struct that contains ControlCommand parameters
represents a faces/update command
static const int FIB_MAX_DEPTH
Maximum number of components in a FIB entry prefix.
void slFindAnn(const Name &name, const SlFindAnnCallback &cb) const
Retrieve an outgoing prefix announcement for self-learning strategy.
Validation error code and optional detailed error message.
void onRouteExpiration(const Name &prefix, const Route &route)
static const Name LOCALHOST_TOP_PREFIX
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
Route & setFaceId(uint64_t faceId)
void append(const Block &block)
append a Block to the response
represents a faces/list dataset
std::string to_string(const V &v)
const optional< Data > & getData() const
Get the Data representing the prefix announcement, if available.
provides a context for generating response to a StatusDataset request
uint64_t getFaceId() const
#define NFD_LOG_INIT(name)
void slRenew(const Name &name, uint64_t faceId, time::milliseconds maxLifetime, const SlAnnounceCallback &cb)
Renew a route created by prefix announcement from self-learning strategy.
Represents a Data packet.
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
whether local fields are enabled on a face
RibEntry & setName(const Name &prefix)
static const Name LOCALHOP_TOP_PREFIX
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
a function that performs authorization
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
the announcement cannot be verified against the trust schema
represents an item in NFD RIB dataset
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands.
const nullopt_t nullopt((nullopt_t::init()))
void registerWithNfd()
Start accepting commands and dataset requests.