30 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>    39 const unsigned int FibUpdater::MAX_NUM_TIMEOUTS = 10;
    40 const uint32_t FibUpdater::ERROR_FACE_NOT_FOUND = 410;
    44   , m_controller(controller)
    57   m_inheritedRoutes.clear();
    60   m_updatesForBatchFaceId.clear();
    61   m_updatesForNonBatchFaceId.clear();
    63   computeUpdates(batch);
    65   sendUpdatesForBatchFaceId(onSuccess, onFailure);
    75     switch (update.getAction()) {
    77         computeUpdatesForRegistration(update);
    80         computeUpdatesForUnregistration(update);
    83         computeUpdatesForUnregistration(update);
    87         m_updatesForBatchFaceId.clear();
    94 FibUpdater::computeUpdatesForRegistration(
const RibUpdate& update)
   102   if (it != m_rib.
end()) {
   103     shared_ptr<const RibEntry> entry(it->second);
   108     if (existingRoute == entry->end()) {
   110       bool willCaptureBeTurnedOn = (entry->hasCapture() == 
false && route.
isRibCapture());
   112       createFibUpdatesForNewRoute(*entry, route, willCaptureBeTurnedOn);
   124       createFibUpdatesForUpdatedRoute(entryCopy, route, *existingRoute);
   130     shared_ptr<RibEntry> parent = m_rib.
findParent(prefix);
   135     for (
const auto& descendant : descendants) {
   138       if (descendant->getParent() == parent) {
   139         children.push_back(descendant);
   143     createFibUpdatesForNewRibEntry(prefix, route, children);
   148 FibUpdater::computeUpdatesForUnregistration(
const RibUpdate& update)
   156   if (ribIt != m_rib.
end()) {
   157     shared_ptr<const RibEntry> entry(ribIt->second);
   159     const bool hadCapture = entry->hasCapture();
   163     if (existing != entry->end()) {
   169       const bool captureWasTurnedOff = (hadCapture && !temp.
hasCapture());
   171       createFibUpdatesForErasedRoute(temp, *existing, captureWasTurnedOff);
   175       const Route* next = entry->getRouteWithSecondLowestCostByFaceId(route.
faceId);
   177       if (next != 
nullptr) {
   178         createFibUpdatesForNewRoute(temp, *next, 
false);
   182       if (entry->getNRoutes() == 1) {
   183         createFibUpdatesForErasedRibEntry(*entry);
   194   std::string updateString = (updates.size() == 1) ? 
" update" : 
" updates";
   195   NFD_LOG_DEBUG(
"Applying " << updates.size() << updateString << 
" to FIB");
   197   for (
const FibUpdate& update : updates) {
   201       sendAddNextHopUpdate(update, onSuccess, onFailure);
   204       sendRemoveNextHopUpdate(update, onSuccess, onFailure);
   213   if (m_updatesForBatchFaceId.size() > 0) {
   214     sendUpdates(m_updatesForBatchFaceId, onSuccess, onFailure);
   217     sendUpdatesForNonBatchFaceId(onSuccess, onFailure);
   225   if (m_updatesForNonBatchFaceId.size() > 0) {
   226     sendUpdates(m_updatesForNonBatchFaceId, onSuccess, onFailure);
   229     onSuccess(m_inheritedRoutes);
   234 FibUpdater::sendAddNextHopUpdate(
const FibUpdate& update,
   241       .setName(update.
name)
   243       .setCost(update.
cost),
   244     bind(&FibUpdater::onUpdateSuccess, 
this, update, onSuccess, onFailure),
   245     bind(&FibUpdater::onUpdateError, 
this, update, onSuccess, onFailure, _1, nTimeouts));
   249 FibUpdater::sendRemoveNextHopUpdate(
const FibUpdate& update,
   256       .setName(update.
name)
   257       .setFaceId(update.
faceId),
   258     bind(&FibUpdater::onUpdateSuccess, 
this, update, onSuccess, onFailure),
   259     bind(&FibUpdater::onUpdateError, 
this, update, onSuccess, onFailure, _1, nTimeouts));
   263 FibUpdater::onUpdateSuccess(
const FibUpdate update,
   267   if (update.
faceId == m_batchFaceId) {
   268     m_updatesForBatchFaceId.remove(update);
   270     if (m_updatesForBatchFaceId.size() == 0) {
   271       sendUpdatesForNonBatchFaceId(onSuccess, onFailure);
   275     m_updatesForNonBatchFaceId.remove(update);
   277     if (m_updatesForNonBatchFaceId.size() == 0) {
   278       onSuccess(m_inheritedRoutes);
   284 FibUpdater::onUpdateError(
const FibUpdate update,
   289   uint32_t code = response.
getCode();
   291                 " (code: " << code << 
", error: " << response.
getText() << 
")");
   294     sendAddNextHopUpdate(update, onSuccess, onFailure, ++nTimeouts);
   296   else if (code == ERROR_FACE_NOT_FOUND) {
   297     if (update.
faceId == m_batchFaceId) {
   298       onFailure(code, response.
getText());
   301       m_updatesForNonBatchFaceId.remove(update);
   303       if (m_updatesForNonBatchFaceId.size() == 0) {
   304         onSuccess(m_inheritedRoutes);
   309     BOOST_THROW_EXCEPTION(
Error(
"Non-recoverable error: " + response.
getText() +
   315 FibUpdater::addFibUpdate(
FibUpdate update)
   318                                                               m_updatesForNonBatchFaceId;
   324       return update.
name == other.name && update.
faceId == other.faceId;
   327   if (it != updates.end()) {
   333     updates.push_back(update);
   340   for (
const Route& route : routesToAdd) {
   344       addInheritedRoute(entry.
getName(), route);
   355   for (
const Route& route : routesToAdd) {
   356     if (route.faceId != ignore.
faceId) {
   358       addInheritedRoute(name, route);
   366 FibUpdater::removeInheritedRoutes(
const RibEntry& entry, 
const Rib::Rib::RouteSet& routesToRemove)
   368   for (
const Route& route : routesToRemove) {
   371       removeInheritedRoute(entry.
getName(), route);
   378 FibUpdater::createFibUpdatesForNewRibEntry(
const Name& name, 
const Route& route,
   387     addInheritedRoutes(name, m_rib.getAncestorRoutes(name), route);
   392     routesToAdd.insert(route);
   395     modifyChildrensInheritedRoutes(children, routesToAdd, m_rib.getAncestorRoutes(name));
   398     Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(name);
   401     addInheritedRoutes(name, ancestorRoutes, route);
   408     if (it != ancestorRoutes.end()) {
   409       ancestorRoutes.erase(it);
   413     ancestorRoutes.insert(route);
   416     modifyChildrensInheritedRoutes(children, ancestorRoutes, 
Rib::RouteSet());
   420     modifyChildrensInheritedRoutes(children, 
Rib::RouteSet(), m_rib.getAncestorRoutes(name));
   425 FibUpdater::createFibUpdatesForNewRoute(
const RibEntry& entry, 
const Route& route,
   426                                         bool captureWasTurnedOn)
   436     if (prevRoute == 
nullptr || route.
cost <= prevRoute->
cost) {
   438       routesToAdd.insert(route);
   443   if (captureWasTurnedOn) {
   445     routesToRemove = m_rib.getAncestorRoutes(entry);
   448     removeInheritedRoutes(entry, routesToRemove);
   451   modifyChildrensInheritedRoutes(entry.
getChildren(), routesToAdd, routesToRemove);
   458   if (other == 
nullptr || route.
cost <= other->cost) {
   464 FibUpdater::createFibUpdatesForUpdatedRoute(
const RibEntry& entry, 
const Route& route,
   465                                             const Route& existingRoute)
   467   const bool costDidChange = (route.
cost != existingRoute.
cost);
   473   if (route.
flags == existingRoute.
flags && !costDidChange) {
   492     if (prevRoute == 
nullptr || route.
cost <= prevRoute->
cost) {
   498         routesToAdd.insert(route);
   510     if (prevRoute == 
nullptr || route.
cost <= prevRoute->
cost) {
   513       routesToAdd.insert(route);
   520     routesToRemove.insert(route);
   524     if (prevRoute != 
nullptr) {
   525       routesToAdd.insert(*prevRoute);
   529       const Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
   533       if (it != ancestorRoutes.end()) {
   534         routesToAdd.insert(*it);
   538     modifyChildrensInheritedRoutes(entry.
getChildren(), routesToAdd, routesToRemove);
   543     Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
   546     removeInheritedRoutes(entry, ancestorRoutes);
   552     Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
   555     addInheritedRoutes(entry, ancestorRoutes);
   563 FibUpdater::createFibUpdatesForErasedRoute(
const RibEntry& entry, 
const Route& route,
   564                                                const bool captureWasTurnedOff)
   571     routesToRemove.insert(route);
   576     if (captureWasTurnedOff && entry.
getNRoutes() != 0) {
   578       routesToAdd = m_rib.getAncestorRoutes(entry);
   581       addInheritedRoutes(entry, routesToAdd);
   584     modifyChildrensInheritedRoutes(entry.
getChildren(), routesToAdd, routesToRemove);
   590       routesToAdd = m_rib.getAncestorRoutes(entry);
   594     routesToRemove.insert(route);
   597     modifyChildrensInheritedRoutes(entry.
getChildren(), routesToAdd, routesToRemove);
   603     if (captureWasTurnedOff && entry.
getNRoutes() != 0) {
   605       routesToAdd = m_rib.getAncestorRoutes(entry);
   608       addInheritedRoutes(entry, routesToAdd);
   615   Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
   623     if (it != ancestorRoutes.end()) {
   624       addInheritedRoute(entry.
getName(), *it);
   631 FibUpdater::createFibUpdatesForErasedRibEntry(
const RibEntry& entry)
   643   for (
const auto& child : children) {
   644     traverseSubTree(*child, routesToAdd, routesToRemove);
   649 FibUpdater::traverseSubTree(
const RibEntry& entry, Rib::Rib::RouteSet routesToAdd,
   650                             Rib::Rib::RouteSet routesToRemove)
   658   for (Rib::RouteSet::const_iterator removeIt = routesToRemove.begin();
   659        removeIt != routesToRemove.end(); )
   664       routesToRemove.erase(removeIt++);
   670       removeInheritedRoute(entry.
getName(), *removeIt);
   678   for (Rib::RouteSet::const_iterator addIt = routesToAdd.begin(); addIt != routesToAdd.end(); ) {
   682       routesToAdd.erase(addIt++);
   688       addInheritedRoute(entry.
getName(), *addIt);
   695   modifyChildrensInheritedRoutes(entry.
getChildren(), routesToAdd, routesToRemove);
   699 FibUpdater::addInheritedRoute(
const Name& name, 
const Route& route)
   706   m_inheritedRoutes.push_back(update);
   710 FibUpdater::removeInheritedRoute(
const Name& name, 
const Route& route)
   717   m_inheritedRoutes.push_back(update);
 RibUpdate & setRoute(const Route &route)
 
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution 
 
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
 
const Route & getRoute() const 
 
represents the Routing Information Base 
 
bool isChildInherit() const 
 
represents a fib/add-nexthop command 
 
function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
 
iterator findRoute(const Route &route)
 
const Route * getRouteWithLowestCostByFaceId(uint64_t faceId) const 
Returns the route with the lowest cost that has the passed face ID. 
 
represents a collection of RibUpdates to be applied to a single FaceId 
 
std::underlying_type< ndn::nfd::RouteFlags >::type flags
 
std::list< FibUpdate > FibUpdateList
 
#define NFD_LOG_DEBUG(expression)
 
shared_ptr< RibEntry > findParent(const Name &prefix) const 
 
function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
 
ndn::optional< time::steady_clock::TimePoint > expires
 
represents a fib/remove-nexthop command 
 
const std::string & getText() const 
 
static const uint32_t ERROR_TIMEOUT
error code for timeout 
 
uint64_t getFaceId() const 
 
std::set< Route, RouteComparePredicate > RouteSet
 
Table::const_iterator iterator
 
std::list< shared_ptr< RibEntry > > RibEntryList
 
static FibUpdate createRemoveUpdate(const Name &name, const uint64_t faceId)
 
Copyright (c) 2011-2015 Regents of the University of California. 
 
static FibUpdate createAddUpdate(const Name &name, const uint64_t faceId, const uint64_t cost)
 
bool isRibCapture() const 
 
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 
 
NFD Management protocol client. 
 
const Name & getName() const 
 
Represents an absolute name. 
 
const std::list< shared_ptr< RibEntry > > & getChildren() const 
 
RibTable::const_iterator const_iterator
 
const Name & getName() const 
 
const RouteList & getInheritedRoutes() const 
Returns the routes this namespace has inherited. 
 
size_t getNRoutes() const 
 
const_iterator end() const 
 
RibUpdate & setName(const Name &name)
 
bool hasFaceId(const uint64_t faceId) const 
 
RouteList::const_iterator const_iterator
 
const Route * getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const 
Returns the route with the lowest cost that has the passed face ID and its child inherit flag set...
 
const_iterator find(const Name &prefix) const 
 
void eraseRoute(const Route &route)
erases a Route with the same faceId and origin 
 
bool hasInheritedRoute(const Route &route) const 
Determines if the entry has an inherited route with a matching face ID. 
 
std::string to_string(const V &v)
 
An update triggered by a face destruction notification. 
 
bool hasChildInheritOnFaceId(uint64_t faceId) const 
Determines if the entry has an inherited route with the passed face ID and its child inherit flag set...
 
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)
 
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const 
finds namespaces under the passed prefix 
 
void setFibUpdater(FibUpdater *updater)