55 , m_keyChain(keyChain)
56 , m_nfdController(nfdController)
57 , m_dispatcher(dispatcher)
59 , m_localhostValidator(face)
60 , m_localhopValidator(make_unique<
ndn::
security::CertificateFetcherDirectFetch>(face))
61 , m_paValidator(make_unique<
ndn::
security::CertificateFetcherDirectFetch>(face))
62 , m_isLocalhopEnabled(false)
64 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
65 std::bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
66 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
67 std::bind(&RibManager::unregisterEntry,
this, _2, _3, _4, _5));
75 m_localhostValidator.
load(section, filename);
81 m_localhopValidator.
load(section, filename);
82 m_isLocalhopEnabled =
true;
88 m_isLocalhopEnabled =
false;
94 m_paValidator.
load(section, filename);
100 registerTopPrefix(LOCALHOST_TOP_PREFIX);
102 if (m_isLocalhopEnabled) {
106 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
107 m_faceMonitor.
onNotification.connect([
this] (
const auto& notif) { onNotification(notif); });
108 m_faceMonitor.
start();
110 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
123 " " + res.getText() +
")"));
128 RibManager::beginAddRoute(
const Name&
name,
Route route, optional<time::nanoseconds> expires,
129 const std::function<
void(RibUpdateResult)>&
done)
138 if (expires && *expires <= 0_s) {
140 return done(RibUpdateResult::EXPIRED);
144 " origin=" << route.
origin <<
" cost=" << route.
cost);
156 beginRibUpdate(update,
done);
160 RibManager::beginRemoveRoute(
const Name& name,
const Route& route,
161 const std::function<
void(RibUpdateResult)>&
done)
164 " origin=" << route.
origin);
170 beginRibUpdate(update,
done);
174 RibManager::beginRibUpdate(
const RibUpdate& update,
175 const std::function<
void(RibUpdateResult)>&
done)
180 done(RibUpdateResult::OK);
182 [=] (uint32_t code,
const std::string& error) {
183 NFD_LOG_DEBUG(
"RIB update failed for " << update <<
" (" << code <<
" " << error <<
")");
186 scheduleActiveFaceFetch(1_s);
188 done(RibUpdateResult::ERROR);
193 RibManager::registerTopPrefix(
const Name& topPrefix)
200 NFD_LOG_DEBUG(
"Successfully registered " << topPrefix <<
" with NFD");
204 route.
faceId = res.getFaceId();
208 m_rib.
insert(topPrefix, route);
212 to_string(res.getCode()) +
" " + res.getText() +
")"));
230 setFaceForSelfRegistration(interest, parameters);
241 optional<time::nanoseconds> expires;
247 beginAddRoute(parameters.
getName(),
std::move(route), expires, [] (RibUpdateResult) {});
251 RibManager::unregisterEntry(
const Name&,
const Interest& interest,
255 setFaceForSelfRegistration(interest, parameters);
264 beginRemoveRoute(parameters.
getName(), route, [] (RibUpdateResult) {});
268 RibManager::listEntries(
const Name&,
const Interest& interest,
272 for (
const auto& kv : m_rib) {
295 bool isSelfRegistration = (parameters.
getFaceId() == 0);
296 if (isSelfRegistration) {
301 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
302 parameters.
setFaceId(*incomingFaceIdTag);
307 RibManager::makeAuthorization(
const std::string&)
313 BOOST_ASSERT(params !=
nullptr);
317 auto& validator = prefix == LOCALHOST_TOP_PREFIX ? m_localhostValidator : m_localhopValidator;
318 validator.validate(interest,
319 [&interest, accept] (
auto&&...) { extractRequester(interest, accept); },
331 return os <<
"ERROR";
333 return os <<
"VALIDATION_FAILURE";
335 return os <<
"EXPIRED";
337 return os <<
"NOT_FOUND";
339 NDN_THROW(std::invalid_argument(
"Unknown SlAnnounceResult"));
343 RibManager::getSlAnnounceResultFromRibUpdateResult(RibUpdateResult r)
346 case RibUpdateResult::OK:
348 case RibUpdateResult::ERROR:
350 case RibUpdateResult::EXPIRED:
362 m_paValidator.validate(*pa.
getData(),
364 Route route(pa, faceId);
367 [=] (RibUpdateResult ribRes) {
368 auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
373 [=] (
const Data&, ndn::security::ValidationError err) {
375 " validation error: " << err);
386 routeQuery.
faceId = faceId;
391 NFD_LOG_DEBUG(
"slRenew " << name <<
" " << faceId <<
": not found");
396 Route route = *oldRoute;
398 beginAddRoute(routeName, route,
nullopt,
399 [=] (RibUpdateResult ribRes) {
400 auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
401 NFD_LOG_INFO(
"slRenew " << name <<
" " << faceId <<
": " << res <<
" " << routeName);
409 shared_ptr<rib::RibEntry> entry;
410 auto exactMatch = m_rib.
find(name);
411 if (exactMatch != m_rib.
end()) {
412 entry = exactMatch->second;
417 if (entry ==
nullptr) {
421 auto pa = entry->getPrefixAnnouncement();
422 pa.toData(m_keyChain);
427 RibManager::fetchActiveFaces()
432 std::bind(&RibManager::removeInvalidFaces,
this, _1),
433 std::bind(&RibManager::onFetchActiveFacesFailure,
this, _1, _2),
438 RibManager::onFetchActiveFacesFailure(uint32_t code,
const std::string& reason)
440 NFD_LOG_DEBUG(
"Face Status Dataset request failure " << code <<
" " << reason);
441 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
445 RibManager::scheduleActiveFaceFetch(
const time::seconds& timeToWait)
447 m_activeFaceFetchEvent =
getScheduler().schedule(timeToWait, [
this] { fetchActiveFaces(); });
451 RibManager::removeInvalidFaces(
const std::vector<ndn::nfd::FaceStatus>& activeFaces)
455 std::set<uint64_t> activeFaceIds;
456 for (
const auto& faceStatus : activeFaces) {
457 activeFaceIds.insert(faceStatus.getFaceId());
462 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
void beginRemoveFailedFaces(const std::set< uint64_t > &activeFaceIds)
void start()
start or resume receiving notifications
RibUpdate & setRoute(const Route &route)
boost::chrono::seconds seconds
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name & prefix
uint64_t getFlags() const
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...
Copyright (c) 2011-2015 Regents of the University of California.
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 the Routing Information Base
shared_ptr< T > getTag() const
get a tag item
void load(const std::string &filename)
represents a fib/add-nexthop command
std::underlying_type_t< ndn::nfd::RouteFlags > flags
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
#define NFD_LOG_INIT(name)
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name const Interest const ControlParameters const ndn::mgmt::CommandContinuation done
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands. ...
std::string to_string(const T &val)
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
static time_point now() noexcept
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.
Route * findLongestPrefix(const Name &prefix, const Route &route) const
reply with a ControlResponse where StatusCode is 403
Route & setFlags(uint64_t flags)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
const_iterator find(const Name &prefix) const
const RouteList & getRoutes() const
Route & setOrigin(RouteOrigin origin)
the announcement cannot be verified against the trust schema
void setExpirationEvent(const scheduler::EventId &eid)
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
represents a Face status change notification
RibManager(rib::Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher)
Represents an Interest packet.
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
represents a route in a RibEntry
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
const Name & getName() const
A prefix announcement object that represents an application's intent of registering a prefix toward i...
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
the announcement has expired
provides a tag type for simple types
optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
optional< time::steady_clock::time_point > expires
const Name & getName() const
const_iterator end() const
ndn::nfd::RouteOrigin origin
route does not exist (slRenew only)
void insert(const Name &prefix, const Route &route)
std::ostream & operator<<(std::ostream &os, const Network &network)
mgmt::ControlResponse ControlResponse
void enableLocalhop(const ConfigSection §ion, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix...
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
static const std::string MGMT_MODULE_NAME
void end()
Finalizes the response successfully after appending zero or more blocks.
RibUpdate & setAction(Action action)
Represents a RIB entry, which contains one or more Routes with the same prefix.
represents a route for a name prefix
shared_ptr< RibEntry > findParent(const Name &prefix) const
Provide a communication channel with local or remote NDN forwarder.
void post(const std::function< void()> &callback)
void addTopPrefix(const Name &prefix, bool wantRegister=true, const security::SigningInfo &signingInfo=security::SigningInfo())
add a top-level prefix
NFD Management protocol client.
bool hasExpirationPeriod() const
FaceEventKind getKind() const
RouteOrigin getOrigin() const
RibEntry & addRoute(const Route &route)
const Name & getAnnouncedName() const
Return announced name.
RIB and FIB have been updated.
time::steady_clock::time_point annExpires
Expiration time of the prefix announcement.
boost::property_tree::ptree ConfigSection
a config file section
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const ndn::mgmt::AcceptContinuation & accept
Implements the RIB Management of NFD Management Protocol.
Represents an absolute name.
static const time::seconds ACTIVE_FACE_FETCH_INTERVAL
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
base class for a struct that contains ControlCommand parameters
uint64_t getFaceId() const
represents a faces/update command
size_t size() const
Returns the number of components.
void append(span< const uint8_t > bytes)
Appends a sequence of bytes to the response.
const time::milliseconds & getExpirationPeriod() const
RibUpdate & setName(const Name &name)
void onRouteExpiration(const Name &prefix, const Route &route)
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED const Name const Interest const ControlParameters & parameters
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
#define NDN_CXX_UNREACHABLE
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
Route & setFaceId(uint64_t faceId)
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
static const Name LOCALHOP_TOP_PREFIX
represents a faces/list dataset
void applyPaConfig(const ConfigSection §ion, const std::string &filename)
Apply prefix_announcement_validation configuration.
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
const optional< Data > & getData() const
Get the Data representing the prefix announcement, if available.
Provides a context for generating the response to a StatusDataset request.
void slFindAnn(const Name &name, const SlFindAnnCallback &cb) const
Retrieve an outgoing prefix announcement for self-learning strategy.
uint64_t getFaceId() const
void registerWithNfd()
Start accepting commands and dataset requests.
Represents a Data packet.
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
whether local fields are enabled on a face
RibEntry & setName(const Name &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)
represents an item in NFD RIB dataset
const nullopt_t nullopt((nullopt_t::init()))
void applyLocalhostConfig(const ConfigSection §ion, const std::string &filename)
Apply localhost_security configuration.
boost::chrono::nanoseconds nanoseconds
static const Name LOCALHOST_TOP_PREFIX
boost::chrono::milliseconds milliseconds