34 #include <ndn-cxx/lp/tags.hpp> 35 #include <ndn-cxx/mgmt/nfd/control-command.hpp> 36 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> 37 #include <ndn-cxx/mgmt/nfd/control-response.hpp> 38 #include <ndn-cxx/mgmt/nfd/face-status.hpp> 39 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> 46 const Name RibManager::LOCAL_HOST_TOP_PREFIX =
"/localhost/nfd";
47 const Name RibManager::LOCAL_HOP_TOP_PREFIX =
"/localhop/nfd";
48 const std::string RibManager::MGMT_MODULE_NAME =
"rib";
49 const Name RibManager::FACES_LIST_DATASET_PREFIX =
"/localhost/nfd/faces/list";
50 const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
51 const Name RibManager::READVERTISE_NLSR_PREFIX =
"/localhost/nlsr";
58 , m_keyChain(keyChain)
59 , m_nfdController(m_face, m_keyChain)
60 , m_faceMonitor(m_face)
61 , m_localhostValidator(m_face)
62 , m_localhopValidator(m_face)
63 , m_isLocalhopEnabled(false)
64 , m_prefixPropagator(m_nfdController, m_keyChain, m_rib)
65 , m_fibUpdater(m_rib, m_nfdController)
66 , m_addTopPrefix([&dispatcher] (const
Name& topPrefix) {
70 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
71 bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
72 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
73 bind(&RibManager::unregisterEntry,
this, _2, _3, _4, _5));
83 registerTopPrefix(LOCAL_HOST_TOP_PREFIX);
85 if (m_isLocalhopEnabled) {
86 registerTopPrefix(LOCAL_HOP_TOP_PREFIX);
89 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
90 m_faceMonitor.
onNotification.connect(bind(&RibManager::onNotification,
this, _1));
91 m_faceMonitor.
start();
93 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
102 bind(&RibManager::onEnableLocalFieldsSuccess,
this),
103 bind(&RibManager::onEnableLocalFieldsError,
this, _1));
110 bind(&RibManager::onConfig,
this, _1, _2, _3));
122 NFD_LOG_DEBUG(
"RIB update failed for " << update <<
" (code: " << code
123 <<
", error: " << error <<
")");
126 scheduleActiveFaceFetch(time::seconds(1));
132 const std::string& filename)
134 bool isAutoPrefixPropagatorEnabled =
false;
135 bool wantReadvertiseToNlsr =
false;
137 for (
const auto& item : configSection) {
138 if (item.first ==
"localhost_security") {
139 m_localhostValidator.load(item.second, filename);
141 else if (item.first ==
"localhop_security") {
142 m_localhopValidator.load(item.second, filename);
143 m_isLocalhopEnabled =
true;
145 else if (item.first ==
"auto_prefix_propagate") {
147 isAutoPrefixPropagatorEnabled =
true;
154 m_prefixPropagator.
enable();
156 else if (item.first ==
"readvertise_nlsr") {
160 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized rib property: " + item.first));
164 if (!isAutoPrefixPropagatorEnabled) {
168 if (wantReadvertiseToNlsr && m_readvertiseNlsr ==
nullptr) {
172 make_unique<ClientToNlsrReadvertisePolicy>(),
173 make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib)));
175 else if (!wantReadvertiseToNlsr && m_readvertiseNlsr !=
nullptr) {
177 m_readvertiseNlsr.reset();
182 RibManager::registerTopPrefix(
const Name& topPrefix)
187 .setName(
Name(topPrefix).append(MGMT_MODULE_NAME))
189 bind(&RibManager::onCommandPrefixAddNextHopSuccess,
this, cref(topPrefix), _1),
190 bind(&RibManager::onCommandPrefixAddNextHopError,
this, cref(topPrefix), _1));
193 m_addTopPrefix(topPrefix);
197 RibManager::registerEntry(
const Name& topPrefix,
const Interest& interest,
201 setFaceForSelfRegistration(interest, parameters);
221 " with EventId: " << eventId);
231 <<
" origin=" << route.
origin 232 <<
" cost=" << route.
cost);
243 m_registeredFaces.insert(route.
faceId);
247 RibManager::unregisterEntry(
const Name& topPrefix,
const Interest& interest,
251 setFaceForSelfRegistration(interest, parameters);
261 <<
" origin=" << route.
origin);
274 RibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
278 for (
const auto& kv : m_rib) {
301 bool isSelfRegistration = (parameters.
getFaceId() == 0);
302 if (isSelfRegistration) {
307 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
308 parameters.
setFaceId(*incomingFaceIdTag);
313 RibManager::makeAuthorization(
const std::string& verb)
315 return [
this] (
const Name& prefix,
const Interest& interest,
319 BOOST_ASSERT(params !=
nullptr);
321 BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
323 ndn::ValidatorConfig& validator = prefix == LOCAL_HOST_TOP_PREFIX ?
324 m_localhostValidator : m_localhopValidator;
325 validator.validate(interest,
332 RibManager::fetchActiveFaces()
337 bind(&RibManager::removeInvalidFaces,
this, _1),
338 bind(&RibManager::onFetchActiveFacesFailure,
this, _1, _2),
343 RibManager::onFetchActiveFacesFailure(uint32_t code,
const std::string& reason)
345 NFD_LOG_DEBUG(
"Face Status Dataset request failure " << code <<
" " << reason);
346 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
350 RibManager::onFaceDestroyedEvent(uint64_t faceId)
353 m_registeredFaces.erase(faceId);
357 RibManager::scheduleActiveFaceFetch(
const time::seconds& timeToWait)
359 m_activeFaceFetchEvent =
scheduler::schedule(timeToWait, [
this] { this->fetchActiveFaces(); });
363 RibManager::removeInvalidFaces(
const std::vector<ndn::nfd::FaceStatus>& activeFaces)
367 FaceIdSet activeFaceIds;
368 for (
const auto& faceStatus : activeFaces) {
369 activeFaceIds.insert(faceStatus.getFaceId());
374 for (
auto faceId : m_registeredFaces) {
375 if (activeFaceIds.count(faceId) == 0) {
377 scheduler::schedule(time::seconds(0), [
this, faceId] { this->onFaceDestroyedEvent(faceId); });
382 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
394 bind(&RibManager::onFaceDestroyedEvent,
this, notification.
getFaceId()));
399 RibManager::onCommandPrefixAddNextHopSuccess(
const Name& prefix,
411 m_rib.
insert(prefix, route);
413 m_registeredFaces.insert(route.faceId);
417 RibManager::onCommandPrefixAddNextHopError(
const Name&
name,
420 BOOST_THROW_EXCEPTION(
Error(
"Error in setting interest filter (" + name.
toUri() +
425 RibManager::onEnableLocalFieldsSuccess()
433 BOOST_THROW_EXCEPTION(
Error(
"Couldn't enable local fields (code: " +
void start()
start or resume receiving notifications
constexpr nullopt_t nullopt
uint64_t getFlags() const
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
ControlParameters & setFaceId(uint64_t faceId)
a collection of common functions shared by all NFD managers and RIB manager, such as communicating wi...
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
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
Accept any value the remote endpoint offers.
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
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
std::underlying_type< ndn::nfd::RouteFlags >::type flags
Route & setOrigin(RouteOrigin origin)
RibManager(Dispatcher &dispatcher, ndn::Face &face, ndn::KeyChain &keyChain)
represents a Face status change notification
bool hasExpirationPeriod() const
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
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)
ndn::optional< time::steady_clock::TimePoint > expires
Route & setCost(uint64_t cost)
const std::string & getText() const
provides a tag type for simple types
std::shared_ptr< ns3::EventId > EventId
std::string toUri() const
Get URI representation of the name.
#define NFD_LOG_TRACE(expression)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
ndn::nfd::RouteOrigin origin
void insert(const Name &prefix, const Route &route)
RouteOrigin getOrigin() const
mgmt::ControlResponse ControlResponse
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)
represents a RIB entry, which contains one or more Routes with the same prefix
const RouteList & getRoutes() const
void loadConfig(const ConfigSection &configSection)
load the "auto_prefix_propagate" section from config file
represents a route for a name prefix
const Name & getName() const
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
uint64_t getFaceId() const
RibEntry & addRoute(const Route &route)
boost::property_tree::ptree ConfigSection
a config file section
Represents an absolute name.
const Name & getName() const
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
represents a faces/update command
uint64_t getFaceId() const
void enable()
enable automatic prefix propagation
const time::milliseconds & getExpirationPeriod() const
FaceEventKind getKind() const
RibUpdate & setName(const Name &name)
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
shared_ptr< T > getTag() const
get a tag item
represents a faces/list dataset
std::string to_string(const V &v)
provides a context for generating response to a StatusDataset request
#define NFD_LOG_INIT(name)
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
controls 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)
void onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
represents an item in NFD RIB dataset
void setConfigFile(ConfigFile &configFile)