38 return std::tie(lhs.
entry->getName(), lhs.
route->faceId, lhs.
route->origin) <
50 , m_isUpdateInProgress(false)
59 m_fibUpdater = updater;
65 return m_rib.find(prefix);
71 auto ribIt = m_rib.find(prefix);
74 if (ribIt != m_rib.end()) {
75 shared_ptr<RibEntry> entry = ribIt->second;
76 auto routeIt = entry->findRoute(route);
77 if (routeIt != entry->end()) {
88 auto ribIt = m_rib.find(prefix);
91 if (ribIt != m_rib.end()) {
92 shared_ptr<RibEntry> entry(ribIt->second);
95 bool didInsert =
false;
96 std::tie(entryIt, didInsert) = entry->insertRoute(route);
105 m_faceMap[route.
faceId].push_back(entry);
110 if (static_cast<bool>(entryIt->getExpirationEvent())) {
111 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " 124 auto entry = make_shared<RibEntry>();
126 m_rib[prefix] = entry;
129 entry->setName(prefix);
130 auto routeIt = entry->insertRoute(route).first;
133 shared_ptr<RibEntry> parent =
findParent(prefix);
136 if (parent !=
nullptr) {
137 parent->addChild(entry);
142 for (
const auto& child : children) {
143 if (child->getParent() == parent) {
145 if (parent !=
nullptr) {
146 parent->removeChild(child);
149 entry->addChild(child);
154 m_faceMap[route.
faceId].push_back(entry);
163 Rib::erase(
const Name& prefix,
const Route& route)
165 auto ribIt = m_rib.find(prefix);
168 if (ribIt != m_rib.end()) {
169 shared_ptr<RibEntry> entry = ribIt->second;
170 auto routeIt = entry->findRoute(route);
172 if (routeIt != entry->end()) {
175 auto faceId = route.
faceId;
176 entry->eraseRoute(routeIt);
180 if (!entry->hasFaceId(faceId)) {
181 m_faceMap[faceId].remove(entry);
185 if (entry->getRoutes().empty()) {
208 for (
int i = prefix.size() - 1; i >= 0; i--) {
209 auto it = m_rib.find(prefix.getPrefix(i));
210 if (it != m_rib.end()) {
218 std::list<shared_ptr<RibEntry>>
221 std::list<shared_ptr<RibEntry>> children;
223 RibTable::const_iterator it = m_rib.find(prefix);
224 if (it != m_rib.end()) {
226 for (; it != m_rib.end(); ++it) {
227 if (prefix.isPrefixOf(it->first)) {
228 children.push_back((it->second));
239 std::list<shared_ptr<RibEntry>>
242 std::list<shared_ptr<RibEntry>> children;
244 for (
const auto& pair : m_rib) {
245 if (prefix.isPrefixOf(pair.first)) {
246 children.push_back(pair.second);
257 if (it == m_rib.end()) {
261 shared_ptr<RibEntry> entry(it->second);
263 shared_ptr<RibEntry> parent = entry->getParent();
266 if (parent !=
nullptr) {
267 parent->removeChild(entry);
270 for (
auto childIt = entry->getChildren().begin(); childIt != entry->getChildren().end(); ) {
271 shared_ptr<RibEntry> child = *childIt;
277 entry->removeChild(child);
280 if (parent !=
nullptr) {
281 parent->addChild(child);
285 auto nextIt = m_rib.erase(it);
294 Rib::getAncestorRoutes(
const RibEntry& entry)
const 298 shared_ptr<RibEntry> parent = entry.
getParent();
300 while (parent !=
nullptr) {
301 for (
const Route& route : parent->getRoutes()) {
302 if (route.isChildInherit()) {
303 ancestorRoutes.insert(route);
307 if (parent->hasCapture()) {
311 parent = parent->getParent();
314 return ancestorRoutes;
318 Rib::getAncestorRoutes(
const Name& name)
const 322 shared_ptr<RibEntry> parent =
findParent(name);
324 while (parent !=
nullptr) {
325 for (
const Route& route : parent->getRoutes()) {
326 if (route.isChildInherit()) {
327 ancestorRoutes.insert(route);
331 if (parent->hasCapture()) {
335 parent = parent->getParent();
338 return ancestorRoutes;
346 BOOST_ASSERT(m_fibUpdater !=
nullptr);
348 addUpdateToQueue(update, onSuccess, onFailure);
350 sendBatchFromQueue();
356 for (
const auto& nameAndRoute : findRoutesWithFaceId(faceId)) {
362 addUpdateToQueue(update,
nullptr,
nullptr);
365 sendBatchFromQueue();
369 Rib::addUpdateToQueue(
const RibUpdate& update,
376 UpdateQueueItem item{batch, onSuccess, onFailure};
377 m_updateBatches.push_back(std::move(item));
381 Rib::sendBatchFromQueue()
383 if (m_updateBatches.empty() || m_isUpdateInProgress) {
387 m_isUpdateInProgress =
true;
389 UpdateQueueItem item = std::move(m_updateBatches.front());
390 m_updateBatches.pop_front();
395 BOOST_ASSERT(batch.
size() == 1);
401 if (mockFibResponse !=
nullptr) {
403 bool shouldFibSucceed = mockFibResponse(batch);
404 if (wantMockFibResponseOnce) {
405 mockFibResponse =
nullptr;
407 if (shouldFibSucceed) {
408 fibSuccessCb(m_fibUpdater->m_inheritedRoutes);
411 fibFailureCb(504,
"mocked failure");
438 modifyInheritedRoutes(inheritedRoutes);
440 m_isUpdateInProgress =
false;
442 if (onSuccess !=
nullptr) {
447 sendBatchFromQueue();
452 uint32_t code,
const std::string& error)
454 m_isUpdateInProgress =
false;
456 if (onFailure !=
nullptr) {
457 onFailure(code, error);
461 sendBatchFromQueue();
465 Rib::modifyInheritedRoutes(
const RibUpdateList& inheritedRoutes)
467 for (
const RibUpdate& update : inheritedRoutes) {
468 auto ribIt = m_rib.find(update.
getName());
469 BOOST_ASSERT(ribIt != m_rib.end());
470 shared_ptr<RibEntry> entry(ribIt->second);
474 entry->addInheritedRoute(update.
getRoute());
477 entry->removeInheritedRoute(update.
getRoute());
485 std::list<Rib::NameAndRoute>
486 Rib::findRoutesWithFaceId(uint64_t faceId)
488 std::list<NameAndRoute> routes;
490 auto lookupIt = m_faceMap.find(faceId);
491 if (lookupIt == m_faceMap.end()) {
497 for (
const auto& entry : lookupIt->second) {
499 for (
const Route& route : *entry) {
500 if (route.
faceId == faceId) {
501 routes.emplace_back(entry->getName(), route);
512 for (
const auto& item : rib) {
513 os << *item.second <<
"\n";
RibUpdate & setRoute(const Route &route)
represents the Routing Information Base
std::set< Route, RouteComparePredicate > RouteSet
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
computes FibUpdates based on updates to the RIB and sends them to NFD
void cancel(const EventId &eventId)
Cancel a scheduled event.
static bool sortRoutes(const Route &lhs, const Route &rhs)
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
RibUpdate & setAction(Action action)
An update triggered by a face destruction notification.
const_iterator find(const Name &prefix) const
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
const Name & getName() const
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Represents a collection of RibUpdates to be applied to a single FaceId.
void setFibUpdater(FibUpdater *updater)
void add(const RibUpdate &update)
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
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 ...
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
Table::const_iterator iterator
RibUpdate & setName(const Name &name)
std::list< RibUpdate > RibUpdateList
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
std::list< shared_ptr< RibEntry > > RibEntryList
void insert(const Name &prefix, const Route &route)
void setExpirationEvent(const scheduler::EventId eid)
RouteList::iterator iterator
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
represents a route for a name prefix
RibEntry::const_iterator route
shared_ptr< RibEntry > entry
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
const scheduler::EventId & getExpirationEvent() const
shared_ptr< RibEntry > getParent() const
#define NFD_LOG_INIT(name)
const Route & getRoute() const
void onFibUpdateSuccess(const RibUpdateBatch &batch, const RibUpdateList &inheritedRoutes, const Rib::UpdateSuccessCallback &onSuccess)
RibTable::const_iterator const_iterator
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)
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
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.
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
shared_ptr< RibEntry > findParent(const Name &prefix) const