38 return std::tie(lhs.
entry->getName(), lhs.
route->faceId, lhs.
route->origin) <
51 m_fibUpdater = updater;
57 return m_rib.find(prefix);
63 auto ribIt = m_rib.find(prefix);
66 if (ribIt != m_rib.end()) {
67 shared_ptr<RibEntry> entry = ribIt->second;
68 auto routeIt = entry->findRoute(route);
69 if (routeIt != entry->end()) {
80 Route* existingRoute =
find(prefix, route);
81 if (existingRoute ==
nullptr) {
84 existingRoute =
find(parent->getName(), route);
94 auto ribIt = m_rib.find(prefix);
97 if (ribIt != m_rib.end()) {
98 shared_ptr<RibEntry> entry(ribIt->second);
101 bool didInsert =
false;
102 std::tie(entryIt, didInsert) = entry->insertRoute(route);
111 m_faceEntries.emplace(route.
faceId, entry);
116 if (entryIt->getExpirationEvent()) {
117 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " << *entryIt);
118 entryIt->cancelExpirationEvent();
126 auto entry = make_shared<RibEntry>();
128 m_rib[prefix] = entry;
131 entry->setName(prefix);
132 auto routeIt = entry->insertRoute(route).first;
135 shared_ptr<RibEntry> parent =
findParent(prefix);
138 if (parent !=
nullptr) {
139 parent->addChild(entry);
144 for (
const auto& child : children) {
145 if (child->getParent() == parent) {
147 if (parent !=
nullptr) {
148 parent->removeChild(child);
151 entry->addChild(child);
156 m_faceEntries.emplace(route.
faceId, entry);
165 Rib::erase(
const Name& prefix,
const Route& route)
167 auto ribIt = m_rib.find(prefix);
168 if (ribIt == m_rib.end()) {
173 shared_ptr<RibEntry> entry = ribIt->second;
174 auto routeIt = entry->findRoute(route);
176 if (routeIt != entry->end()) {
179 auto faceId = route.
faceId;
180 entry->eraseRoute(routeIt);
184 if (!entry->hasFaceId(faceId)) {
185 auto range = m_faceEntries.equal_range(faceId);
186 for (
auto it = range.first; it != range.second; ++it) {
187 if (it->second == entry) {
188 m_faceEntries.erase(it);
195 if (entry->getRoutes().empty()) {
217 for (
int i = prefix.size() - 1; i >= 0; i--) {
218 auto it = m_rib.find(prefix.getPrefix(i));
219 if (it != m_rib.end()) {
227 std::list<shared_ptr<RibEntry>>
228 Rib::findDescendants(
const Name& prefix)
const 230 std::list<shared_ptr<RibEntry>> children;
232 RibTable::const_iterator it = m_rib.find(prefix);
233 if (it != m_rib.end()) {
235 for (; it != m_rib.end(); ++it) {
236 if (prefix.isPrefixOf(it->first)) {
237 children.push_back((it->second));
248 std::list<shared_ptr<RibEntry>>
249 Rib::findDescendantsForNonInsertedName(
const Name& prefix)
const 251 std::list<shared_ptr<RibEntry>> children;
253 for (
const auto& pair : m_rib) {
254 if (prefix.isPrefixOf(pair.first)) {
255 children.push_back(pair.second);
262 Rib::RibTable::iterator
263 Rib::eraseEntry(RibTable::iterator it)
266 if (it == m_rib.end()) {
270 shared_ptr<RibEntry> entry(it->second);
272 shared_ptr<RibEntry> parent = entry->getParent();
275 if (parent !=
nullptr) {
276 parent->removeChild(entry);
279 for (
auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
280 shared_ptr<RibEntry> child = *childIt;
286 entry->removeChild(child);
289 if (parent !=
nullptr) {
290 parent->addChild(child);
294 auto nextIt = m_rib.erase(it);
303 Rib::getAncestorRoutes(
const RibEntry& entry)
const 307 shared_ptr<RibEntry> parent = entry.
getParent();
309 while (parent !=
nullptr) {
310 for (
const Route& route : parent->getRoutes()) {
311 if (route.isChildInherit()) {
312 ancestorRoutes.insert(route);
316 if (parent->hasCapture()) {
320 parent = parent->getParent();
323 return ancestorRoutes;
327 Rib::getAncestorRoutes(
const Name& name)
const 331 shared_ptr<RibEntry> parent =
findParent(name);
333 while (parent !=
nullptr) {
334 for (
const Route& route : parent->getRoutes()) {
335 if (route.isChildInherit()) {
336 ancestorRoutes.insert(route);
340 if (parent->hasCapture()) {
344 parent = parent->getParent();
347 return ancestorRoutes;
355 BOOST_ASSERT(m_fibUpdater !=
nullptr);
357 addUpdateToQueue(update, onSuccess, onFailure);
359 sendBatchFromQueue();
365 auto range = m_faceEntries.equal_range(faceId);
366 for (
auto it = range.first; it != range.second; ++it) {
367 enqueueRemoveFace(*it->second, faceId);
369 sendBatchFromQueue();
375 for (
auto it = m_faceEntries.begin(); it != m_faceEntries.end(); ++it) {
376 if (activeFaceIds.count(it->first) > 0) {
379 enqueueRemoveFace(*it->second, it->first);
381 sendBatchFromQueue();
385 Rib::enqueueRemoveFace(
const RibEntry& entry, uint64_t faceId)
387 for (
const Route& route : entry) {
388 if (route.
faceId != faceId) {
396 addUpdateToQueue(update,
nullptr,
nullptr);
401 Rib::addUpdateToQueue(
const RibUpdate& update,
408 UpdateQueueItem item{batch, onSuccess, onFailure};
409 m_updateBatches.push_back(std::move(item));
413 Rib::sendBatchFromQueue()
415 if (m_updateBatches.empty() || m_isUpdateInProgress) {
419 m_isUpdateInProgress =
true;
421 UpdateQueueItem item = std::move(m_updateBatches.front());
422 m_updateBatches.pop_front();
427 BOOST_ASSERT(batch.
size() == 1);
429 auto fibSuccessCb = bind(&Rib::onFibUpdateSuccess,
this, batch, _1, item.managerSuccessCallback);
430 auto fibFailureCb = bind(&Rib::onFibUpdateFailure,
this, item.managerFailureCallback, _1, _2);
453 modifyInheritedRoutes(inheritedRoutes);
455 m_isUpdateInProgress =
false;
457 if (onSuccess !=
nullptr) {
462 sendBatchFromQueue();
467 uint32_t code,
const std::string& error)
469 m_isUpdateInProgress =
false;
471 if (onFailure !=
nullptr) {
472 onFailure(code, error);
476 sendBatchFromQueue();
480 Rib::modifyInheritedRoutes(
const RibUpdateList& inheritedRoutes)
482 for (
const RibUpdate& update : inheritedRoutes) {
483 auto ribIt = m_rib.find(update.
getName());
484 BOOST_ASSERT(ribIt != m_rib.end());
485 shared_ptr<RibEntry> entry(ribIt->second);
489 entry->addInheritedRoute(update.
getRoute());
492 entry->removeInheritedRoute(update.
getRoute());
503 for (
const auto& item : rib) {
504 os << *item.second <<
"\n";
RibUpdate & setRoute(const Route &route)
represents the Routing Information Base
shared_ptr< RibEntry > findParent(const Name &prefix) const
signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
const Name & getName() const
computes FibUpdates based on updates to the RIB and sends them to NFD
static bool sortRoutes(const Route &lhs, const Route &rhs)
signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
RibTable::const_iterator const_iterator
RibUpdate & setAction(Action action)
Route * findLongestPrefix(const Name &prefix, const Route &route) const
An update triggered by a face destruction notification.
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Represents a collection of RibUpdates to be applied to a single FaceId.
signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
void setFibUpdater(FibUpdater *updater)
std::list< shared_ptr< RibEntry > > RibEntryList
void add(const RibUpdate &update)
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 ...
RibUpdate & setName(const Name &name)
std::list< RibUpdate > RibUpdateList
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void insert(const Name &prefix, const Route &route)
RouteList::iterator iterator
represents a route for a name prefix
RibEntry::const_iterator route
shared_ptr< RibEntry > entry
signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
#define NFD_LOG_INIT(name)
shared_ptr< RibEntry > getParent() const
Represents a RIB entry, which contains one or more Routes with the same prefix.
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
void onRouteExpiration(const Name &prefix, const Route &route)
const_iterator find(const Name &prefix) const
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
void beginRemoveFailedFaces(const std::set< uint64_t > &activeFaceIds)
std::function< void()> UpdateSuccessCallback
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
const Route & getRoute() const