35 #include <ndn-cxx/lp/tags.hpp> 36 #include <ndn-cxx/mgmt/nfd/control-command.hpp> 37 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> 38 #include <ndn-cxx/mgmt/nfd/control-response.hpp> 39 #include <ndn-cxx/mgmt/nfd/face-status.hpp> 40 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> 47 const Name RibManager::LOCAL_HOST_TOP_PREFIX =
"/localhost/nfd";
48 const Name RibManager::LOCAL_HOP_TOP_PREFIX =
"/localhop/nfd";
49 const std::string RibManager::MGMT_MODULE_NAME =
"rib";
50 const Name RibManager::FACES_LIST_DATASET_PREFIX =
"/localhost/nfd/faces/list";
51 const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
52 const Name RibManager::READVERTISE_NLSR_PREFIX =
"/localhost/nlsr";
59 , m_keyChain(keyChain)
60 , m_nfdController(m_face, m_keyChain)
61 , m_faceMonitor(m_face)
62 , m_localhostValidator(m_face)
63 , m_localhopValidator(m_face)
64 , m_isLocalhopEnabled(false)
65 , m_prefixPropagator(m_nfdController, m_keyChain, m_rib)
66 , m_fibUpdater(m_rib, m_nfdController)
67 , m_addTopPrefix([&dispatcher] (const
Name& topPrefix) {
71 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
72 bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
73 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
74 bind(&RibManager::unregisterEntry,
this, _2, _3, _4, _5));
76 registerStatusDatasetHandler(
"list", bind(&RibManager::listEntries,
this, _1, _2, _3));
84 registerTopPrefix(LOCAL_HOST_TOP_PREFIX);
86 if (m_isLocalhopEnabled) {
87 registerTopPrefix(LOCAL_HOP_TOP_PREFIX);
90 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
91 m_faceMonitor.
onNotification.connect(bind(&RibManager::onNotification,
this, _1));
92 m_faceMonitor.
start();
94 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
103 bind(&RibManager::onEnableLocalFieldsSuccess,
this),
104 bind(&RibManager::onEnableLocalFieldsError,
this, _1));
111 bind(&RibManager::onConfig,
this, _1, _2, _3));
123 NFD_LOG_DEBUG(
"RIB update failed for " << update <<
" (code: " << code
124 <<
", error: " << error <<
")");
127 scheduleActiveFaceFetch(time::seconds(1));
133 const std::string& filename)
135 bool isAutoPrefixPropagatorEnabled =
false;
136 bool wantReadvertiseToNlsr =
false;
138 for (
const auto& item : configSection) {
139 if (item.first ==
"localhost_security") {
140 m_localhostValidator.
load(item.second, filename);
142 else if (item.first ==
"localhop_security") {
143 m_localhopValidator.
load(item.second, filename);
144 m_isLocalhopEnabled =
true;
146 else if (item.first ==
"auto_prefix_propagate") {
148 isAutoPrefixPropagatorEnabled =
true;
155 m_prefixPropagator.
enable();
157 else if (item.first ==
"readvertise_nlsr") {
161 BOOST_THROW_EXCEPTION(Error(
"Unrecognized rib property: " + item.first));
165 if (!isAutoPrefixPropagatorEnabled) {
169 if (wantReadvertiseToNlsr && m_readvertiseNlsr ==
nullptr) {
173 make_unique<ClientToNlsrReadvertisePolicy>(),
174 make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib)));
176 else if (!wantReadvertiseToNlsr && m_readvertiseNlsr !=
nullptr) {
178 m_readvertiseNlsr.reset();
183 RibManager::registerTopPrefix(
const Name& topPrefix)
188 .setName(
Name(topPrefix).append(MGMT_MODULE_NAME))
190 bind(&RibManager::onCommandPrefixAddNextHopSuccess,
this, cref(topPrefix), _1),
191 bind(&RibManager::onCommandPrefixAddNextHopError,
this, cref(topPrefix), _1));
194 m_addTopPrefix(topPrefix);
198 RibManager::registerEntry(
const Name& topPrefix,
const Interest& interest,
208 setFaceForSelfRegistration(interest, parameters);
211 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
214 route.faceId = parameters.getFaceId();
215 route.origin = parameters.getOrigin();
216 route.cost = parameters.getCost();
217 route.flags = parameters.getFlags();
219 if (parameters.hasExpirationPeriod() &&
220 parameters.getExpirationPeriod() != time::milliseconds::max()) {
227 NFD_LOG_TRACE(
"Scheduled unregistration at: " << *route.expires <<
228 " with EventId: " << eventId);
231 route.setExpirationEvent(eventId);
237 NFD_LOG_INFO(
"Adding route " << parameters.getName() <<
" nexthop=" << route.faceId
238 <<
" origin=" << route.origin
239 <<
" cost=" << route.cost);
243 .setName(parameters.getName())
250 m_registeredFaces.insert(route.faceId);
254 RibManager::unregisterEntry(
const Name& topPrefix,
const Interest& interest,
258 setFaceForSelfRegistration(interest, parameters);
261 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
264 route.faceId = parameters.getFaceId();
265 route.origin = parameters.getOrigin();
267 NFD_LOG_INFO(
"Removing route " << parameters.getName() <<
" nexthop=" << route.faceId
268 <<
" origin=" << route.origin);
272 .setName(parameters.getName())
281 RibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
285 for (
const auto& kv : m_rib) {
289 for (
const Route& route : entry.getRoutes()) {
308 bool isSelfRegistration = (parameters.getFaceId() == 0);
309 if (isSelfRegistration) {
314 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
315 parameters.setFaceId(*incomingFaceIdTag);
320 RibManager::makeAuthorization(
const std::string& verb)
322 return [
this] (
const Name& prefix,
const Interest& interest,
326 BOOST_ASSERT(params !=
nullptr);
328 BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
331 m_localhostValidator : m_localhopValidator;
339 RibManager::fetchActiveFaces()
344 bind(&RibManager::removeInvalidFaces,
this, _1),
345 bind(&RibManager::onFetchActiveFacesFailure,
this, _1, _2),
350 RibManager::onFetchActiveFacesFailure(uint32_t code,
const std::string& reason)
352 NFD_LOG_DEBUG(
"Face Status Dataset request failure " << code <<
" " << reason);
353 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
357 RibManager::onFaceDestroyedEvent(uint64_t faceId)
359 m_rib.beginRemoveFace(faceId);
360 m_registeredFaces.erase(faceId);
364 RibManager::scheduleActiveFaceFetch(
const time::seconds& timeToWait)
366 m_activeFaceFetchEvent =
scheduler::schedule(timeToWait, [
this] { this->fetchActiveFaces(); });
370 RibManager::removeInvalidFaces(
const std::vector<ndn::nfd::FaceStatus>& activeFaces)
374 FaceIdSet activeFaceIds;
375 for (
const auto& faceStatus : activeFaces) {
376 activeFaceIds.insert(faceStatus.getFaceId());
381 for (
auto faceId : m_registeredFaces) {
382 if (activeFaceIds.count(faceId) == 0) {
384 scheduler::schedule(time::seconds(0), [
this, faceId] { this->onFaceDestroyedEvent(faceId); });
389 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
401 bind(&RibManager::onFaceDestroyedEvent,
this, notification.
getFaceId()));
406 RibManager::onCommandPrefixAddNextHopSuccess(
const Name& prefix,
409 NFD_LOG_DEBUG(
"Successfully registered " + prefix.toUri() +
" with NFD");
418 m_rib.insert(prefix, route);
420 m_registeredFaces.insert(route.faceId);
424 RibManager::onCommandPrefixAddNextHopError(
const Name&
name,
427 BOOST_THROW_EXCEPTION(Error(
"Error in setting interest filter (" +
name.toUri() +
432 RibManager::onEnableLocalFieldsSuccess()
440 BOOST_THROW_EXCEPTION(Error(
"Couldn't enable local fields (code: " +
void start()
start or resume receiving notifications
constexpr nullopt_t nullopt
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
RibEntry
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
void load(const std::string &filename)
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
represents a fib/add-nexthop command
The interface of signing key management.
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
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
configuration file parsing utility
Route & setFlags(uint64_t flags)
std::enable_if< std::is_default_constructible< Dataset >::value >::type fetch(const std::function< void(typename Dataset::ResultType)> &onSuccess, const DatasetFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start dataset fetching
Route & setOrigin(RouteOrigin origin)
RibManager(Dispatcher &dispatcher, ndn::Face &face, ndn::KeyChain &keyChain)
represents a Face status change notification
#define NFD_LOG_DEBUG(expression)
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
represents a route in a RibEntry
void disable()
disable automatic prefix propagation
void onRibUpdateSuccess(const RibUpdate &update)
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
#define NFD_LOG_INFO(expression)
Route & setCost(uint64_t cost)
provides a tag type for simple types
std::shared_ptr< ns3::EventId > EventId
#define NFD_LOG_TRACE(expression)
mgmt::ControlResponse ControlResponse
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.
void addSectionHandler(const std::string §ionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
size_t wireEncode(EncodingImpl< TAG > &block) const
void end()
end the response successfully after appending zero or more blocks
void loadConfig(const ConfigSection &configSection)
load the "auto_prefix_propagate" section from config file
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
FaceEventKind getKind() const
RibEntry & addRoute(const Route &route)
boost::property_tree::ptree ConfigSection
a config file section
Represents an absolute name.
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
uint64_t getFaceId() const
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 enable()
enable automatic prefix propagation
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
void onRouteExpiration(const Name &prefix, const Route &route)
Route & setFaceId(uint64_t faceId)
void append(const Block &block)
append a Block to the response
const std::string & getText() const
represents a faces/list dataset
std::string to_string(const V &v)
provides a context for generating response to a StatusDataset request
uint64_t getFaceId() const
#define NFD_LOG_INIT(name)
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 onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
represents an item in NFD RIB dataset
void setConfigFile(ConfigFile &configFile)