|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
55 , m_keyChain(keyChain)
56 , m_nfdController(nfdController)
57 , m_dispatcher(dispatcher)
59 , m_localhostValidator(face)
60 , m_localhopValidator(make_unique<
ndn::security::v2::CertificateFetcherDirectFetch>(face))
61 , m_paValidator(make_unique<
ndn::security::v2::CertificateFetcherDirectFetch>(face))
62 , m_isLocalhopEnabled(false)
64 registerCommandHandler<ndn::nfd::RibRegisterCommand>(
"register",
65 bind(&RibManager::registerEntry,
this, _2, _3, _4, _5));
66 registerCommandHandler<ndn::nfd::RibUnregisterCommand>(
"unregister",
67 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);
102 if (m_isLocalhopEnabled) {
106 NFD_LOG_INFO(
"Start monitoring face create/destroy events");
107 m_faceMonitor.
onNotification.connect(bind(&RibManager::onNotification,
this, _1));
108 m_faceMonitor.
start();
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);
211 NDN_THROW(Error(
"Cannot add FIB entry " + topPrefix.toUri() +
" (" +
212 to_string(res.getCode()) +
" " + res.getText() +
")"));
220 RibManager::registerEntry(
const Name& topPrefix,
const Interest& interest,
230 setFaceForSelfRegistration(interest, parameters);
233 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
236 route.faceId = parameters.getFaceId();
237 route.origin = parameters.getOrigin();
238 route.cost = parameters.getCost();
239 route.flags = parameters.getFlags();
241 optional<time::nanoseconds> expires;
242 if (parameters.hasExpirationPeriod() &&
243 parameters.getExpirationPeriod() != time::milliseconds::max()) {
244 expires = time::duration_cast<time::nanoseconds>(parameters.getExpirationPeriod());
247 beginAddRoute(parameters.getName(),
std::move(route), expires, [] (RibUpdateResult) {});
251 RibManager::unregisterEntry(
const Name& topPrefix,
const Interest& interest,
255 setFaceForSelfRegistration(interest, parameters);
258 done(
ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
261 route.faceId = parameters.getFaceId();
262 route.origin = parameters.getOrigin();
264 beginRemoveRoute(parameters.getName(), route, [] (RibUpdateResult) {});
268 RibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
272 for (
const auto& kv : m_rib) {
276 for (
const Route& route : entry.getRoutes()) {
295 bool isSelfRegistration = (parameters.getFaceId() == 0);
296 if (isSelfRegistration) {
301 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
302 parameters.setFaceId(*incomingFaceIdTag);
307 RibManager::makeAuthorization(
const std::string& verb)
309 return [
this] (
const Name& prefix,
const Interest& interest,
313 BOOST_ASSERT(params !=
nullptr);
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:
364 Route route(pa, faceId);
365 route.expires = std::min(route.annExpires, time::steady_clock::now() + maxLifetime);
366 beginAddRoute(pa.getAnnouncedName(), route, nullopt,
367 [=] (RibUpdateResult ribRes) {
368 auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
369 NFD_LOG_INFO(
"slAnnounce " << pa.getAnnouncedName() <<
" " << faceId <<
": " << res);
374 NFD_LOG_INFO(
"slAnnounce " << pa.getAnnouncedName() <<
" " << faceId <<
375 " validation error: " << err);
376 cb(SlAnnounceResult::VALIDATION_FAILURE);
382 RibManager::slRenew(
const Name&
name, uint64_t faceId, time::milliseconds maxLifetime,
386 routeQuery.
faceId = faceId;
388 Route* oldRoute = m_rib.findLongestPrefix(
name, routeQuery);
392 return cb(SlAnnounceResult::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;
415 entry = m_rib.findParent(
name);
417 if (entry ==
nullptr) {
421 auto pa = entry->getPrefixAnnouncement();
422 pa.toData(m_keyChain);
427 RibManager::fetchActiveFaces()
432 bind(&RibManager::removeInvalidFaces,
this, _1),
433 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);
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());
represents a faces/list dataset
const optional< Data > & getData() const
Get the Data representing the prefix announcement, if available.
represents a route in a RibEntry
ndn::nfd::RouteOrigin origin
Validation error code and optional detailed error message.
std::function< void(SlAnnounceResult res)> SlAnnounceCallback
static const Name LOCALHOST_TOP_PREFIX
void post(const std::function< void()> &callback)
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
void append(const Block &block)
append a Block to the response
Route & setCost(uint64_t cost)
@ VALIDATION_FAILURE
the announcement cannot be verified against the trust schema
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.
void start()
start or resume receiving notifications
Route & setFlags(uint64_t flags)
provides a tag type for simple types
@ FACE_EVENT_DESTROYED
face was destroyed
static time_point now() noexcept
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
void registerWithNfd()
Start accepting commands and dataset requests.
mgmt::ControlResponse ControlResponse
#define NDN_CXX_UNREACHABLE
RibManager(rib::Rib &rib, ndn::Face &face, ndn::KeyChain &keyChain, ndn::nfd::Controller &nfdController, Dispatcher &dispatcher)
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
NFD Management protocol client.
FaceEventKind getKind() const
void onRouteExpiration(const Name &prefix, const Route &route)
size_t wireEncode(EncodingImpl< TAG > &block) const
Provide a communication channel with local or remote NDN forwarder.
base class for a struct that contains ControlCommand parameters
uint64_t getFaceId() const
A prefix announcement object that represents an application's intent of registering a prefix toward i...
void enableLocalhop(const ConfigSection §ion, const std::string &filename)
Apply localhop_security configuration and allow accepting commands on /localhop/nfd/rib prefix.
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
Represents an absolute name.
represents a Face status change notification
represents a fib/add-nexthop command
represents an item in NFD RIB dataset
Copyright (c) 2011-2015 Regents of the University of California.
static const std::string MGMT_MODULE_NAME
@ OK
RIB and FIB have been updated.
@ NOT_FOUND
route does not exist (slRenew only)
void setExpirationEvent(const scheduler::EventId &eid)
void enableLocalFields()
Enable NDNLP IncomingFaceId field in order to support self-registration commands.
The interface of signing key management.
void disableLocalhop()
Disallow accepting commands on /localhop/nfd/rib prefix.
provides a context for generating response to a StatusDataset request
represents the Routing Information Base
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
void load(const std::string &filename)
static const time::seconds ACTIVE_FACE_FETCH_INTERVAL
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 insert(const Name &prefix, const Route &route)
void addTopPrefix(const Name &prefix, bool wantRegister=true, const security::SigningInfo &signingInfo=security::SigningInfo())
add a top-level prefix
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
const nullopt_t nullopt((nullopt_t::init()))
std::ostream & operator<<(std::ostream &os, const Network &network)
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
represents a faces/update command
@ EXPIRED
the announcement has expired
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
Represents a Data packet.
contains options for ControlCommand execution
Implements the RIB Management of NFD Management Protocol.
boost::property_tree::ptree ConfigSection
a config file section
static const Name LOCALHOP_TOP_PREFIX
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
RibEntry & setName(const Name &prefix)
represents parameters in a ControlCommand request or response
optional< ndn::PrefixAnnouncement > announcement
The prefix announcement that caused the creation of this route.
@ STATUS403
reply with a ControlResponse where StatusCode is 403
represents a dispatcher on server side of NFD Management protocol
std::string to_string(const T &val)
void end()
end the response successfully after appending zero or more blocks
represents a route for a name prefix
void applyLocalhostConfig(const ConfigSection §ion, const std::string &filename)
Apply localhost_security configuration.
optional< time::steady_clock::TimePoint > expires
std::function< void(RejectReply reply)> RejectContinuation
a function to be called if authorization is rejected
@ BIT_LOCAL_FIELDS_ENABLED
whether local fields are enabled on a face
time::steady_clock::TimePoint annExpires
Expiration time of the prefix announcement.
void extractRequester(const Interest &interest, ndn::mgmt::AcceptContinuation accept)
Extracts the requester from a ControlCommand request.
RibEntry & addRoute(const Route &route)
#define NFD_LOG_INIT(name)
Copyright (c) 2011-2015 Regents of the University of California.
void applyPaConfig(const ConfigSection §ion, const std::string &filename)
Apply prefix_announcement_validation configuration.
@ ROUTE_FLAG_CHILD_INHERIT
std::function< void(optional< ndn::PrefixAnnouncement >)> SlFindAnnCallback
Route & setFaceId(uint64_t faceId)
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
Route & setOrigin(RouteOrigin origin)