43 m_fibUpdater = updater;
49 return m_rib.find(prefix);
55 auto ribIt = m_rib.find(prefix);
58 if (ribIt != m_rib.end()) {
59 shared_ptr<RibEntry> entry = ribIt->second;
60 auto routeIt = entry->findRoute(route);
61 if (routeIt != entry->end()) {
72 Route* existingRoute =
find(prefix, route);
73 if (existingRoute ==
nullptr) {
76 existingRoute =
find(parent->getName(), route);
86 auto ribIt = m_rib.find(prefix);
89 if (ribIt != m_rib.end()) {
90 shared_ptr<RibEntry> entry(ribIt->second);
91 auto [entryIt, didInsert] = entry->insertRoute(route);
100 m_faceEntries.emplace(route.
faceId, entry);
105 if (entryIt->getExpirationEvent()) {
106 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " << *entryIt);
107 entryIt->cancelExpirationEvent();
115 auto entry = make_shared<RibEntry>();
117 m_rib[prefix] = entry;
120 entry->setName(prefix);
121 auto routeIt = entry->insertRoute(route).first;
124 shared_ptr<RibEntry> parent =
findParent(prefix);
127 if (parent !=
nullptr) {
128 parent->addChild(entry);
131 auto children = findDescendants(prefix);
132 for (
const auto& child : children) {
133 if (child->getParent() == parent) {
135 if (parent !=
nullptr) {
136 parent->removeChild(child);
138 entry->addChild(child);
143 m_faceEntries.emplace(route.
faceId, entry);
152Rib::erase(
const Name& prefix,
const Route& route)
154 auto ribIt = m_rib.find(prefix);
155 if (ribIt == m_rib.end()) {
160 shared_ptr<RibEntry> entry = ribIt->second;
161 auto routeIt = entry->findRoute(route);
163 if (routeIt != entry->end()) {
166 auto faceId = route.
faceId;
167 entry->eraseRoute(routeIt);
171 if (!entry->hasFaceId(faceId)) {
172 auto range = m_faceEntries.equal_range(faceId);
173 for (
auto it = range.first; it != range.second; ++it) {
174 if (it->second == entry) {
175 m_faceEntries.erase(it);
182 if (entry->empty()) {
198 for (
int i = prefix.size() - 1; i >= 0; i--) {
199 auto it = m_rib.find(prefix.getPrefix(i));
200 if (it != m_rib.end()) {
208std::list<shared_ptr<RibEntry>>
209Rib::findDescendants(
const Name& prefix)
const
211 std::list<shared_ptr<RibEntry>> children;
213 auto it = m_rib.find(prefix);
214 if (it != m_rib.end()) {
216 for (; it != m_rib.end(); ++it) {
217 if (prefix.isPrefixOf(it->first)) {
218 children.push_back(it->second);
229std::list<shared_ptr<RibEntry>>
230Rib::findDescendantsForNonInsertedName(
const Name& prefix)
const
232 std::list<shared_ptr<RibEntry>> children;
234 for (
const auto& [name, ribEntry] : m_rib) {
235 if (prefix.isPrefixOf(name)) {
236 children.push_back(ribEntry);
243Rib::RibTable::iterator
244Rib::eraseEntry(RibTable::iterator it)
247 if (it == m_rib.end()) {
251 shared_ptr<RibEntry> entry(it->second);
252 shared_ptr<RibEntry> parent = entry->getParent();
255 if (parent !=
nullptr) {
256 parent->removeChild(entry);
259 for (
auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
260 shared_ptr<RibEntry> child = *childIt;
266 entry->removeChild(child);
269 if (parent !=
nullptr) {
270 parent->addChild(child);
274 auto nextIt = m_rib.erase(it);
283Rib::getAncestorRoutes(
const RibEntry& entry)
const
287 auto parent = entry.getParent();
288 while (parent !=
nullptr) {
289 for (
const auto& route : parent->getRoutes()) {
290 if (route.isChildInherit()) {
291 ancestorRoutes.insert(route);
295 if (parent->hasCapture()) {
299 parent = parent->getParent();
302 return ancestorRoutes;
306Rib::getAncestorRoutes(
const Name& name)
const
311 while (parent !=
nullptr) {
312 for (
const auto& route : parent->getRoutes()) {
313 if (route.isChildInherit()) {
314 ancestorRoutes.insert(route);
318 if (parent->hasCapture()) {
322 parent = parent->getParent();
325 return ancestorRoutes;
333 BOOST_ASSERT(m_fibUpdater !=
nullptr);
334 addUpdateToQueue(update, onSuccess, onFailure);
335 sendBatchFromQueue();
341 auto range = m_faceEntries.equal_range(faceId);
342 for (
auto it = range.first; it != range.second; ++it) {
343 enqueueRemoveFace(*it->second, faceId);
345 sendBatchFromQueue();
351 for (
const auto& [faceId, ribEntry] : m_faceEntries) {
352 if (activeFaceIds.count(faceId) > 0) {
355 enqueueRemoveFace(*ribEntry, faceId);
357 sendBatchFromQueue();
361Rib::enqueueRemoveFace(
const RibEntry& entry, uint64_t faceId)
363 for (
const Route& route : entry) {
364 if (route.
faceId != faceId) {
372Rib::addUpdateToQueue(
const RibUpdate& update,
376 RibUpdateBatch batch(update.route.faceId);
379 UpdateQueueItem item{batch, onSuccess, onFailure};
380 m_updateBatches.push_back(std::move(item));
384Rib::sendBatchFromQueue()
386 if (m_updateBatches.empty() || m_isUpdateInProgress) {
390 m_isUpdateInProgress =
true;
392 UpdateQueueItem item = std::move(m_updateBatches.front());
393 m_updateBatches.pop_front();
396 BOOST_ASSERT(item.batch.size() == 1);
399 [
this, batch = item.batch, successCb = item.managerSuccessCallback] (
const auto& routes) {
400 onFibUpdateSuccess(batch, routes, successCb);
402 [
this, failureCb = item.managerFailureCallback] (
const auto& code,
const auto& error) {
403 onFibUpdateFailure(failureCb, code, error);
408Rib::onFibUpdateSuccess(
const RibUpdateBatch& batch,
412 for (
const RibUpdate& update : batch) {
413 switch (update.action) {
415 insert(update.name, update.route);
419 erase(update.name, update.route);
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();
452Rib::modifyInheritedRoutes(
const RibUpdateList& inheritedRoutes)
454 for (
const RibUpdate& update : inheritedRoutes) {
455 auto ribIt = m_rib.find(update.name);
456 BOOST_ASSERT(ribIt != m_rib.end());
457 shared_ptr<RibEntry> entry(ribIt->second);
459 switch (update.action) {
475 for (
const auto& item : rib) {
476 os << *item.second <<
"\n";
Computes FibUpdates based on updates to the RIB and sends them to NFD.
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.
Represents a RIB entry, which contains one or more Routes with the same prefix.
void addInheritedRoute(const Route &route)
void removeInheritedRoute(const Route &route)
const Name & getName() const noexcept
Represents the Routing Information Base.
signal::Signal< Rib, Name > afterInsertEntry
Signals after a RIB entry is inserted.
signal::Signal< Rib, RibRouteRef > afterAddRoute
Signals after a Route is added.
void beginRemoveFailedFaces(const std::set< uint64_t > &activeFaceIds)
signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
Signals before a route is removed.
std::function< void()> UpdateSuccessCallback
void setFibUpdater(FibUpdater *updater)
void beginRemoveFace(uint64_t faceId)
Starts the FIB update process when a face has been destroyed.
RibTable::const_iterator const_iterator
Route * findLongestPrefix(const Name &prefix, const Route &route) const
void insert(const Name &prefix, const Route &route)
signal::Signal< Rib, Name > afterEraseEntry
Signals after a RIB entry is erased.
void onRouteExpiration(const Name &prefix, const Route &route)
const_iterator find(const Name &prefix) const
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
Passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
shared_ptr< RibEntry > findParent(const Name &prefix) const
Represents a route for a name prefix.
#define NFD_LOG_INIT(name)
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
std::list< RibUpdate > RibUpdateList
static bool sortRoutes(const Route &lhs, const Route &rhs)
Represents a route that will be added to or removed from a namespace.
@ REMOVE_FACE
An update triggered by a face destruction notification.