44 , m_isUpdateInProgress(false)
55 m_fibUpdater = updater;
61 return m_rib.find(prefix);
67 RibTable::const_iterator ribIt = m_rib.find(prefix);
70 if (ribIt != m_rib.end()) {
71 shared_ptr<RibEntry> entry = ribIt->second;
75 if (routeIt != entry->end()) {
89 if (ribIt != m_rib.end()) {
90 shared_ptr<RibEntry> entry(ribIt->second);
94 if (routeIt == entry->end()) {
96 entry->insertRoute(route);
100 m_faceMap[route.
faceId].push_back(entry);
105 if (static_cast<bool>(routeIt->getExpirationEvent())) {
106 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " 114 routeIt->flags = route.
flags;
115 routeIt->cost = route.
cost;
116 routeIt->expires = route.
expires;
121 shared_ptr<RibEntry> entry(make_shared<RibEntry>(
RibEntry()));
123 m_rib[prefix] = entry;
126 entry->setName(prefix);
127 entry->insertRoute(route);
130 shared_ptr<RibEntry> parent =
findParent(prefix);
133 if (parent !=
nullptr) {
134 parent->addChild(entry);
139 for (
const auto& child : children) {
140 if (child->getParent() == parent) {
142 if (parent !=
nullptr) {
143 parent->removeChild(child);
146 entry->addChild(child);
151 m_faceMap[route.
faceId].push_back(entry);
159 Rib::erase(
const Name& prefix,
const Route& route)
164 if (ribIt != m_rib.end()) {
165 shared_ptr<RibEntry> entry(ribIt->second);
169 if (routeIt != entry->end()) {
170 entry->eraseRoute(routeIt);
174 if (!entry->hasFaceId(route.
faceId)) {
175 m_faceMap[route.
faceId].remove(entry);
179 if (entry->getRoutes().size() == 0) {
202 for (
int i = prefix.
size() - 1; i >= 0; i--) {
203 RibTable::const_iterator it = m_rib.find(prefix.
getPrefix(i));
205 if (it != m_rib.end()) {
210 return shared_ptr<RibEntry>();
213 std::list<shared_ptr<RibEntry> >
216 std::list<shared_ptr<RibEntry> > children;
218 RibTable::const_iterator it = m_rib.find(prefix);
220 if (it != m_rib.end()) {
222 for (; it != m_rib.end(); ++it) {
224 children.push_back((it->second));
235 std::list<shared_ptr<RibEntry>>
238 std::list<shared_ptr<RibEntry>> children;
240 for (std::pair<
Name, shared_ptr<RibEntry>> pair : m_rib) {
242 children.push_back(pair.second);
253 if (it == m_rib.end()) {
257 shared_ptr<RibEntry> entry(it->second);
259 shared_ptr<RibEntry> parent = entry->getParent();
262 if (parent !=
nullptr) {
263 parent->removeChild(entry);
266 for (
auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
267 shared_ptr<RibEntry> child = *childIt;
273 entry->removeChild(child);
276 if (parent !=
nullptr) {
277 parent->addChild(child);
290 Rib::getAncestorRoutes(
const RibEntry& entry)
const 294 shared_ptr<RibEntry> parent = entry.
getParent();
296 while (parent !=
nullptr) {
297 for (
const Route& route : parent->getRoutes()) {
299 ancestorRoutes.insert(route);
303 if (parent->hasCapture()) {
307 parent = parent->getParent();
310 return ancestorRoutes;
314 Rib::getAncestorRoutes(
const Name&
name)
const 318 shared_ptr<RibEntry> parent =
findParent(name);
320 while (parent !=
nullptr) {
321 for (
const Route& route : parent->getRoutes()) {
323 ancestorRoutes.insert(route);
327 if (parent->hasCapture()) {
331 parent = parent->getParent();
334 return ancestorRoutes;
342 BOOST_ASSERT(m_fibUpdater !=
nullptr);
344 addUpdateToQueue(update, onSuccess, onFailure);
346 sendBatchFromQueue();
352 for (
const auto& nameAndRoute : findRoutesWithFaceId(faceId)) {
358 addUpdateToQueue(update,
nullptr,
nullptr);
361 sendBatchFromQueue();
365 Rib::addUpdateToQueue(
const RibUpdate& update,
372 UpdateQueueItem item{batch, onSuccess, onFailure};
373 m_updateBatches.push_back(std::move(item));
377 Rib::sendBatchFromQueue()
379 if (m_updateBatches.empty() || m_isUpdateInProgress) {
383 m_isUpdateInProgress =
true;
385 UpdateQueueItem item = std::move(m_updateBatches.front());
386 m_updateBatches.pop_front();
391 BOOST_ASSERT(batch.
size() == 1);
398 batch, _1, managerSuccessCallback),
400 managerFailureCallback, _1, _2));
402 if (m_onSendBatchFromQueue !=
nullptr) {
403 m_onSendBatchFromQueue(batch);
425 modifyInheritedRoutes(inheritedRoutes);
427 m_isUpdateInProgress =
false;
429 if (onSuccess !=
nullptr) {
434 sendBatchFromQueue();
439 uint32_t code,
const std::string& error)
441 m_isUpdateInProgress =
false;
443 if (onFailure !=
nullptr) {
444 onFailure(code, error);
448 sendBatchFromQueue();
452 Rib::modifyInheritedRoutes(
const RibUpdateList& inheritedRoutes)
454 for (
const RibUpdate& update : inheritedRoutes) {
457 BOOST_ASSERT(ribIt != m_rib.end());
458 shared_ptr<RibEntry> entry(ribIt->second);
462 entry->addInheritedRoute(update.
getRoute());
465 entry->removeInheritedRoute(update.
getRoute());
473 std::list<Rib::NameAndRoute>
474 Rib::findRoutesWithFaceId(uint64_t faceId)
476 std::list<NameAndRoute> routes;
481 if (lookupIt == m_faceMap.end()) {
488 for (
const shared_ptr<RibEntry>& entry : ribEntries) {
490 for (
const Route& route : *entry) {
491 if (route.
faceId == faceId) {
492 routes.push_back(NameAndRoute(entry->getName(), route));
503 for (
const auto& item : rib) {
504 os << item.second <<
"\n";
RibUpdate & setRoute(const Route &route)
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
shared_ptr< RibEntry > getParent() const
const scheduler::EventId & getExpirationEvent() const
#define NFD_LOG_DEBUG(expression)
const Route & getRoute() const
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
time::steady_clock::TimePoint expires
void cancel(const EventId &eventId)
cancel a scheduled event
void add(const RibUpdate &update)
static bool sortRoutes(const Route &lhs, const Route &rhs)
represents a collection of RibUpdates to be applied to a single FaceId
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
const_iterator find(const Name &prefix) const
bool isChildInherit() const
computes FibUpdates based on updates to the RIB and sends them to NFD
void onFibUpdateSuccess(const RibUpdateBatch &batch, const RibUpdateList &inheritedRoutes, const Rib::UpdateSuccessCallback &onSuccess)
RouteList::iterator iterator
function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
std::set< Route, RouteComparePredicate > RouteSet
Table::const_iterator iterator
function< void()> UpdateSuccessCallback
std::list< shared_ptr< RibEntry > > RibEntryList
const Name & getName() const
std::list< RibUpdate > RibUpdateList
void insert(const Name &prefix, const Route &route)
Copyright (c) 2011-2015 Regents of the University of California.
RibEntry
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
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
Name abstraction to represent an absolute name.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
RibTable::const_iterator const_iterator
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
size_t size() const
Get the number of components.
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
#define NFD_LOG_INIT(name)
RibUpdate & setName(const Name &name)
#define NFD_LOG_TRACE(expression)
void onRouteExpiration(const Name &prefix, const Route &route)
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
An update triggered by a face destruction notification.
void computeAndSendFibUpdates(const RibUpdateBatch &batch, const FibUpdateSuccessCallback &onSuccess, const FibUpdateFailureCallback &onFailure)
computes FibUpdates using the provided RibUpdateBatch and then sends the updates to NFD's FIB ...
void setFibUpdater(FibUpdater *updater)