39 return std::tie(lhs.
entry->getName(), lhs.
route->faceId, lhs.
route->origin) <
51 , m_isUpdateInProgress(false)
62 m_fibUpdater = updater;
68 return m_rib.find(prefix);
74 RibTable::const_iterator ribIt = m_rib.find(prefix);
77 if (ribIt != m_rib.end()) {
78 shared_ptr<RibEntry> entry = ribIt->second;
82 if (routeIt != entry->end()) {
96 if (ribIt != m_rib.end()) {
97 shared_ptr<RibEntry> entry(ribIt->second);
100 bool didInsert =
false;
101 std::tie(entryIt, didInsert) = entry->insertRoute(route);
110 m_faceMap[route.
faceId].push_back(entry);
115 if (static_cast<bool>(entryIt->getExpirationEvent())) {
116 NFD_LOG_TRACE(
"Cancelling expiration event for " << entry->getName() <<
" " 124 entryIt->flags = route.
flags;
125 entryIt->cost = route.
cost;
126 entryIt->expires = route.
expires;
131 shared_ptr<RibEntry> entry = make_shared<RibEntry>();
133 m_rib[prefix] = entry;
136 entry->setName(prefix);
140 shared_ptr<RibEntry> parent =
findParent(prefix);
143 if (parent !=
nullptr) {
144 parent->addChild(entry);
149 for (
const auto& child : children) {
150 if (child->getParent() == parent) {
152 if (parent !=
nullptr) {
153 parent->removeChild(child);
156 entry->addChild(child);
161 m_faceMap[route.
faceId].push_back(entry);
170 Rib::erase(
const Name& prefix,
const Route& route)
175 if (ribIt != m_rib.end()) {
176 shared_ptr<RibEntry> entry = ribIt->second;
179 if (routeIt != entry->end()) {
182 auto faceId = route.
faceId;
183 entry->eraseRoute(routeIt);
187 if (!entry->hasFaceId(faceId)) {
188 m_faceMap[faceId].remove(entry);
192 if (entry->getRoutes().empty()) {
215 for (
int i = prefix.
size() - 1; i >= 0; i--) {
216 RibTable::const_iterator it = m_rib.find(prefix.
getPrefix(i));
218 if (it != m_rib.end()) {
223 return shared_ptr<RibEntry>();
226 std::list<shared_ptr<RibEntry> >
229 std::list<shared_ptr<RibEntry> > children;
231 RibTable::const_iterator it = m_rib.find(prefix);
233 if (it != m_rib.end()) {
235 for (; it != m_rib.end(); ++it) {
237 children.push_back((it->second));
248 std::list<shared_ptr<RibEntry>>
251 std::list<shared_ptr<RibEntry>> children;
253 for (std::pair<
Name, shared_ptr<RibEntry>> pair : m_rib) {
255 children.push_back(pair.second);
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);
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()) {
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()) {
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 for (
const auto& nameAndRoute : findRoutesWithFaceId(faceId)) {
371 addUpdateToQueue(update,
nullptr,
nullptr);
374 sendBatchFromQueue();
378 Rib::addUpdateToQueue(
const RibUpdate& update,
385 UpdateQueueItem item{batch, onSuccess, onFailure};
386 m_updateBatches.push_back(std::move(item));
390 Rib::sendBatchFromQueue()
392 if (m_updateBatches.empty() || m_isUpdateInProgress) {
396 m_isUpdateInProgress =
true;
398 UpdateQueueItem item = std::move(m_updateBatches.front());
399 m_updateBatches.pop_front();
404 BOOST_ASSERT(batch.
size() == 1);
411 batch, _1, managerSuccessCallback),
413 managerFailureCallback, _1, _2));
415 if (m_onSendBatchFromQueue !=
nullptr) {
416 m_onSendBatchFromQueue(batch);
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) {
470 BOOST_ASSERT(ribIt != m_rib.end());
471 shared_ptr<RibEntry> entry(ribIt->second);
475 entry->addInheritedRoute(update.
getRoute());
478 entry->removeInheritedRoute(update.
getRoute());
486 std::list<Rib::NameAndRoute>
487 Rib::findRoutesWithFaceId(uint64_t faceId)
489 std::list<NameAndRoute> routes;
494 if (lookupIt == m_faceMap.end()) {
501 for (
const shared_ptr<RibEntry>& entry : ribEntries) {
503 for (
const Route& route : *entry) {
504 if (route.
faceId == faceId) {
505 routes.push_back(NameAndRoute(entry->getName(), route));
516 for (
const auto& item : rib) {
517 os << *item.second <<
"\n";
RibUpdate & setRoute(const Route &route)
const Route & getRoute() const
represents the Routing Information Base
bool isChildInherit() const
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
void cancel(const EventId &eventId)
cancel a scheduled event
void add(const RibUpdate &update)
static bool sortRoutes(const Route &lhs, const Route &rhs)
shared_ptr< RibEntry > getParent() const
represents a collection of RibUpdates to be applied to a single FaceId
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
std::underlying_type< ndn::nfd::RouteFlags >::type flags
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
#define NFD_LOG_DEBUG(expression)
void onFibUpdateSuccess(const RibUpdateBatch &batch, const RibUpdateList &inheritedRoutes, const Rib::UpdateSuccessCallback &onSuccess)
RibEntry::const_iterator route
shared_ptr< RibEntry > findParent(const Name &prefix) const
ndn::optional< time::steady_clock::TimePoint > expires
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
#define NFD_LOG_TRACE(expression)
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 RIB entry, which contains one or more Routes with the same prefix
represents a route for a name prefix
const Name & getName() const
size_t size() const
Get number of components.
Represents an absolute name.
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another 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
signals after a RIB entry is inserted
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)
const_iterator find(const Name &prefix) const
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
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 ...
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
#define NFD_LOG_INIT(name)
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
const scheduler::EventId & getExpirationEvent() const
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
void setFibUpdater(FibUpdater *updater)