30 #include <ndn-cxx/lp/tags.hpp> 31 #include <ndn-cxx/mgmt/nfd/face-status.hpp> 32 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> 39 const Name RibManager::LOCAL_HOST_TOP_PREFIX =
"/localhost/nfd";
40 const Name RibManager::LOCAL_HOP_TOP_PREFIX =
"/localhop/nfd";
41 const std::string RibManager::MGMT_MODULE_NAME =
"rib";
42 const Name RibManager::FACES_LIST_DATASET_PREFIX =
"/localhost/nfd/faces/list";
43 const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
50 , m_keyChain(keyChain)
51 , m_nfdController(m_face, m_keyChain)
52 , m_faceMonitor(m_face)
53 , m_localhostValidator(m_face)
54 , m_localhopValidator(m_face)
55 , m_isLocalhopEnabled(false)
56 , m_prefixPropagator(m_nfdController, m_keyChain, m_rib)
57 , m_fibUpdater(m_rib, m_nfdController)
58 , m_addTopPrefix([&dispatcher] (const
Name& topPrefix) {
62 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
63 bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
64 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
65 bind(&RibManager::unregisterEntry,
this, _2, _3, _4, _5));
78 registerTopPrefix(LOCAL_HOST_TOP_PREFIX);
80 if (m_isLocalhopEnabled) {
81 registerTopPrefix(LOCAL_HOP_TOP_PREFIX);
84 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
85 m_faceMonitor.
onNotification.connect(bind(&RibManager::onNotification,
this, _1));
86 m_faceMonitor.
start();
88 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
97 bind(&RibManager::onEnableLocalFieldsSuccess,
this),
98 bind(&RibManager::onEnableLocalFieldsError,
this, _1));
105 bind(&RibManager::onConfig,
this, _1, _2, _3));
117 NFD_LOG_DEBUG(
"RIB update failed for " << update <<
" (code: " << code
118 <<
", error: " << error <<
")");
121 scheduleActiveFaceFetch(time::seconds(1));
127 const std::string& filename)
129 bool isAutoPrefixPropagatorEnabled =
false;
131 for (
const auto& item : configSection) {
132 if (item.first ==
"localhost_security") {
133 m_localhostValidator.
load(item.second, filename);
135 else if (item.first ==
"localhop_security") {
136 m_localhopValidator.
load(item.second, filename);
137 m_isLocalhopEnabled =
true;
139 else if (item.first ==
"auto_prefix_propagate") {
141 isAutoPrefixPropagatorEnabled =
true;
148 m_prefixPropagator.
enable();
151 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized rib property: " + item.first));
155 if (!isAutoPrefixPropagatorEnabled) {
161 RibManager::registerTopPrefix(
const Name& topPrefix)
166 .setName(
Name(topPrefix).append(MGMT_MODULE_NAME))
168 bind(&RibManager::onCommandPrefixAddNextHopSuccess,
this, cref(topPrefix), _1),
169 bind(&RibManager::onCommandPrefixAddNextHopError,
this, cref(topPrefix), _1));
172 m_addTopPrefix(topPrefix);
176 RibManager::registerEntry(
const Name& topPrefix,
const Interest& interest,
180 setFaceForSelfRegistration(interest, parameters);
201 " with EventId: " << eventId);
207 route.
expires = time::steady_clock::TimePoint::max();
211 <<
" origin=" << route.
origin 212 <<
" cost=" << route.
cost);
223 m_registeredFaces.insert(route.
faceId);
227 RibManager::unregisterEntry(
const Name& topPrefix,
const Interest& interest,
231 setFaceForSelfRegistration(interest, parameters);
241 <<
" origin=" << route.
origin);
254 RibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
257 for (
auto&& ribTableEntry : m_rib) {
258 const auto& ribEntry = *ribTableEntry.second;
261 for (
auto&& route : ribEntry) {
268 if (route.expires < time::steady_clock::TimePoint::max()) {
276 record.
setName(ribEntry.getName());
286 bool isSelfRegistration = (parameters.
getFaceId() == 0);
287 if (isSelfRegistration) {
292 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
293 parameters.
setFaceId(*incomingFaceIdTag);
298 RibManager::makeAuthorization(
const std::string& verb)
300 return [
this] (
const Name& prefix,
const Interest& interest,
304 BOOST_ASSERT(params !=
nullptr);
306 BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
309 m_localhostValidator : m_localhopValidator;
317 RibManager::fetchActiveFaces()
322 bind(&RibManager::removeInvalidFaces,
this, _1),
323 bind(&RibManager::onFetchActiveFacesFailure,
this, _1, _2),
328 RibManager::onFetchActiveFacesFailure(uint32_t code,
const std::string& reason)
330 NFD_LOG_DEBUG(
"Face Status Dataset request failure " << code <<
" " << reason);
331 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
335 RibManager::onFaceDestroyedEvent(uint64_t faceId)
338 m_registeredFaces.erase(faceId);
342 RibManager::scheduleActiveFaceFetch(
const time::seconds& timeToWait)
347 bind(&RibManager::fetchActiveFaces,
this));
351 RibManager::removeInvalidFaces(
const std::vector<ndn::nfd::FaceStatus>& activeFaces)
355 FaceIdSet activeFaceIds;
357 activeFaceIds.insert(item.getFaceId());
362 for (
auto&& faceId : m_registeredFaces) {
363 if (activeFaceIds.count(faceId) == 0) {
367 bind(&RibManager::onFaceDestroyedEvent,
this, faceId));
372 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
384 bind(&RibManager::onFaceDestroyedEvent,
this, notification.
getFaceId()));
389 RibManager::onCommandPrefixAddNextHopSuccess(
const Name& prefix,
398 route.expires = time::steady_clock::TimePoint::max();
401 m_rib.
insert(prefix, route);
403 m_registeredFaces.insert(route.faceId);
407 RibManager::onCommandPrefixAddNextHopError(
const Name&
name,
410 BOOST_THROW_EXCEPTION(
Error(
"Error in setting interest filter (" + name.
toUri() +
415 RibManager::onEnableLocalFieldsSuccess()
423 BOOST_THROW_EXCEPTION(
Error(
"Couldn't enable local fields (code: " +
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
uint64_t getFlags() const
ControlParameters & setFaceId(uint64_t faceId)
void validate(const Data &data, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed)
Validate Data and call either onValidated or onValidationFailed.
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
std::string toUri() const
Encode this name as a URI.
shared_ptr< T > getTag() const
get a tag item
void load(const std::string &filename)
represents a fib/add-nexthop command
void setExpirationEvent(const scheduler::EventId eid)
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
time::steady_clock::TimePoint expires
void cancel(const EventId &eventId)
cancel a scheduled event
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
The validator which can be set up via a configuration file.
reply with a ControlResponse where StatusCode is 403
configuration file parsing utility
size_t wireEncode(EncodingImpl< TAG > &encoder) const
The packet signing interface.
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
RibManager(Dispatcher &dispatcher, ndn::Face &face, ndn::KeyChain &keyChain)
RibEntry & setName(const Name &prefix)
represents a Face status change notification
represents an Interest packet
#define NFD_LOG_DEBUG(expression)
std::function< void(RejectReply act)> RejectContinuation
a function to be called if authorization is rejected
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
void start()
start or resume receiving notifications
Data abstraction for Route.
void disable()
disable automatic prefix propagation
void onRibUpdateSuccess(const RibUpdate &update)
Route & setFaceId(uint64_t faceId)
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
#define NFD_LOG_INFO(expression)
Route & setExpirationPeriod(const time::milliseconds &expirationPeriod)
Route & setFlags(uint64_t flags)
set route inheritance flags
uint64_t getOrigin() const
provides a tag type for simple types
std::shared_ptr< ns3::EventId > EventId
#define NFD_LOG_TRACE(expression)
const Name & getName() const
ndn::mgmt::ControlResponse ControlResponse
void insert(const Name &prefix, const Route &route)
contains options for ControlCommand execution
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
RibUpdate & setAction(Action action)
void loadConfig(const ConfigSection &configSection)
load the "auto_prefix_propagate" section from config file
represents a route for a name prefix
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
bool hasExpirationPeriod() const
FaceEventKind getKind() const
boost::property_tree::ptree ConfigSection
Name abstraction to represent an absolute name.
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
RibEntry & addRoute(const Route &route)
void enable()
enable automatic prefix propagation
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
const time::milliseconds & getExpirationPeriod() const
RibUpdate & setName(const Name &name)
void onRouteExpiration(const Name &prefix, const Route &route)
void append(const Block &block)
append a Block to the response
Route & setCost(uint64_t cost)
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 & setOrigin(uint64_t origin)
set Origin
bit that controls whether local fields are enabled on a face
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)
void onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
Data abstraction for RIB entry.
void setConfigFile(ConfigFile &configFile)