38 return std::tie(lhs.
entry->getName(), lhs.
route->faceId, lhs.
route->origin) <
50 , m_isUpdateInProgress(false)
57 m_fibUpdater = updater;
63 return m_rib.find(prefix);
69 auto ribIt = m_rib.find(prefix);
72 if (ribIt != m_rib.end()) {
73 shared_ptr<RibEntry> entry = ribIt->second;
74 auto routeIt = entry->findRoute(route);
75 if (routeIt != entry->end()) {
86 Route* existingRoute =
find(prefix, route);
87 if (existingRoute ==
nullptr) {
90 existingRoute =
find(parent->getName(), route);
100 auto ribIt = m_rib.find(prefix);
103 if (ribIt != m_rib.end()) {
104 shared_ptr<RibEntry> entry(ribIt->second);
107 bool didInsert =
false;
108 std::tie(entryIt, didInsert) = entry->insertRoute(route);
117 m_faceMap[route.
faceId].push_back(entry);
122 if (entryIt->getExpirationEvent()) {
123 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " << *entryIt);
124 entryIt->cancelExpirationEvent();
132 auto entry = make_shared<RibEntry>();
134 m_rib[prefix] = entry;
137 entry->setName(prefix);
138 auto routeIt = entry->insertRoute(route).first;
141 shared_ptr<RibEntry> parent =
findParent(prefix);
144 if (parent !=
nullptr) {
145 parent->addChild(entry);
150 for (
const auto& child : children) {
151 if (child->getParent() == parent) {
153 if (parent !=
nullptr) {
154 parent->removeChild(child);
157 entry->addChild(child);
162 m_faceMap[route.
faceId].push_back(entry);
171 Rib::erase(
const Name& prefix,
const Route& route)
173 auto ribIt = m_rib.find(prefix);
176 if (ribIt != m_rib.end()) {
177 shared_ptr<RibEntry> entry = ribIt->second;
178 auto routeIt = entry->findRoute(route);
180 if (routeIt != entry->end()) {
183 auto faceId = route.
faceId;
184 entry->eraseRoute(routeIt);
188 if (!entry->hasFaceId(faceId)) {
189 m_faceMap[faceId].remove(entry);
193 if (entry->getRoutes().empty()) {
216 for (
int i = prefix.
size() - 1; i >= 0; i--) {
217 auto it = m_rib.find(prefix.
getPrefix(i));
218 if (it != m_rib.end()) {
226 std::list<shared_ptr<RibEntry>>
229 std::list<shared_ptr<RibEntry>> children;
231 RibTable::const_iterator it = m_rib.find(prefix);
232 if (it != m_rib.end()) {
234 for (; it != m_rib.end(); ++it) {
236 children.push_back((it->second));
247 std::list<shared_ptr<RibEntry>>
250 std::list<shared_ptr<RibEntry>> children;
252 for (
const auto& pair : m_rib) {
254 children.push_back(pair.second);
265 if (it == m_rib.end()) {
269 shared_ptr<RibEntry> entry(it->second);
271 shared_ptr<RibEntry> parent = entry->getParent();
274 if (parent !=
nullptr) {
275 parent->removeChild(entry);
278 for (
auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
279 shared_ptr<RibEntry> child = *childIt;
285 entry->removeChild(child);
288 if (parent !=
nullptr) {
289 parent->addChild(child);
293 auto nextIt = m_rib.erase(it);
302 Rib::getAncestorRoutes(
const RibEntry& entry)
const 306 shared_ptr<RibEntry> parent = entry.getParent();
308 while (parent !=
nullptr) {
309 for (
const Route& route : parent->getRoutes()) {
311 ancestorRoutes.insert(route);
315 if (parent->hasCapture()) {
319 parent = parent->getParent();
322 return ancestorRoutes;
326 Rib::getAncestorRoutes(
const Name&
name)
const 332 while (parent !=
nullptr) {
333 for (
const Route& route : parent->getRoutes()) {
335 ancestorRoutes.insert(route);
339 if (parent->hasCapture()) {
343 parent = parent->getParent();
346 return ancestorRoutes;
354 BOOST_ASSERT(m_fibUpdater !=
nullptr);
356 addUpdateToQueue(update, onSuccess, onFailure);
358 sendBatchFromQueue();
364 for (
const auto& nameAndRoute : findRoutesWithFaceId(faceId)) {
370 addUpdateToQueue(update,
nullptr,
nullptr);
373 sendBatchFromQueue();
377 Rib::addUpdateToQueue(
const RibUpdate& update,
384 UpdateQueueItem item{batch, onSuccess, onFailure};
385 m_updateBatches.push_back(std::move(item));
389 Rib::sendBatchFromQueue()
391 if (m_updateBatches.empty() || m_isUpdateInProgress) {
395 m_isUpdateInProgress =
true;
397 UpdateQueueItem item = std::move(m_updateBatches.front());
398 m_updateBatches.pop_front();
400 RibUpdateBatch& batch = item.batch;
403 BOOST_ASSERT(batch.size() == 1);
409 if (mockFibResponse !=
nullptr) {
411 bool shouldFibSucceed = mockFibResponse(batch);
412 if (wantMockFibResponseOnce) {
413 mockFibResponse =
nullptr;
415 if (shouldFibSucceed) {
416 fibSuccessCb(m_fibUpdater->m_inheritedRoutes);
419 fibFailureCb(504,
"mocked failure");
446 modifyInheritedRoutes(inheritedRoutes);
448 m_isUpdateInProgress =
false;
450 if (onSuccess !=
nullptr) {
455 sendBatchFromQueue();
460 uint32_t code,
const std::string& error)
462 m_isUpdateInProgress =
false;
464 if (onFailure !=
nullptr) {
465 onFailure(code, error);
469 sendBatchFromQueue();
473 Rib::modifyInheritedRoutes(
const RibUpdateList& inheritedRoutes)
475 for (
const RibUpdate& update : inheritedRoutes) {
476 auto ribIt = m_rib.find(update.
getName());
477 BOOST_ASSERT(ribIt != m_rib.end());
478 shared_ptr<RibEntry> entry(ribIt->second);
482 entry->addInheritedRoute(update.
getRoute());
485 entry->removeInheritedRoute(update.
getRoute());
493 std::list<Rib::NameAndRoute>
494 Rib::findRoutesWithFaceId(uint64_t faceId)
496 std::list<NameAndRoute> routes;
498 auto lookupIt = m_faceMap.find(faceId);
499 if (lookupIt == m_faceMap.end()) {
505 for (
const auto& entry : lookupIt->second) {
507 for (
const Route& route : *entry) {
508 if (route.
faceId == faceId) {
509 routes.emplace_back(entry->getName(), route);
520 for (
const auto& item : rib) {
521 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 of the name.
represents the Routing Information Base
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.
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)
Route * findLongestPrefix(const Name &prefix, const Route &route) const
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
const_iterator find(const Name &prefix) const
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
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)
RibEntry::const_iterator route
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
RouteList::iterator iterator
std::set< Route, RouteComparePredicate > RouteSet
Table::const_iterator iterator
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.
shared_ptr< RibEntry > entry
RibUpdate & setAction(Action action)
represents a route for a name prefix
shared_ptr< RibEntry > findParent(const Name &prefix) const
Represents an absolute name.
RibTable::const_iterator const_iterator
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
bool isChildInherit() const
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
size_t size() const
Get number of components.
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
RibUpdate & setName(const Name &name)
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
#define NFD_LOG_INIT(name)
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
std::function< void()> UpdateSuccessCallback
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
void setFibUpdater(FibUpdater *updater)