NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
fib-updater.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "fib-updater.hpp"
27 
28 #include "core/logger.hpp"
29 
30 #include <ndn-cxx/management/nfd-control-parameters.hpp>
31 
32 namespace nfd {
33 namespace rib {
34 
36 
37 NFD_LOG_INIT("FibUpdater");
38 
39 const unsigned int FibUpdater::MAX_NUM_TIMEOUTS = 10;
40 const uint32_t FibUpdater::ERROR_FACE_NOT_FOUND = 410;
41 
43  : m_rib(rib)
44  , m_controller(controller)
45 {
46  rib.setFibUpdater(this);
47 }
48 
49 void
51  const FibUpdateSuccessCallback& onSuccess,
52  const FibUpdateFailureCallback& onFailure)
53 {
54  m_batchFaceId = batch.getFaceId();
55 
56  // Erase previously calculated inherited routes
57  m_inheritedRoutes.clear();
58 
59  // Erase previously calculated FIB updates
60  m_updatesForBatchFaceId.clear();
61  m_updatesForNonBatchFaceId.clear();
62 
63  computeUpdates(batch);
64 
65  sendUpdatesForBatchFaceId(onSuccess, onFailure);
66 }
67 
68 void
69 FibUpdater::computeUpdates(const RibUpdateBatch& batch)
70 {
71  NFD_LOG_DEBUG("Computing updates for batch with faceID: " << batch.getFaceId());
72 
73  // Compute updates and add to m_fibUpdates
74  for (const RibUpdate& update : batch)
75  {
76  switch(update.getAction()) {
78  computeUpdatesForRegistration(update);
79  break;
81  computeUpdatesForUnregistration(update);
82  break;
84  computeUpdatesForUnregistration(update);
85 
86  // Do not apply updates with the same face ID as the destroyed face
87  // since they will be rejected by the FIB
88  m_updatesForBatchFaceId.clear();
89  break;
90  }
91  }
92 }
93 
94 void
95 FibUpdater::computeUpdatesForRegistration(const RibUpdate& update)
96 {
97  const Name& prefix = update.getName();
98  const Route& route = update.getRoute();
99 
100  Rib::const_iterator it = m_rib.find(prefix);
101 
102  // Name prefix exists
103  if (it != m_rib.end()) {
104  shared_ptr<const RibEntry> entry(it->second);
105 
106  RibEntry::const_iterator existingRoute = entry->findRoute(route);
107 
108  // Route will be new
109  if (existingRoute == entry->end()) {
110  // Will the new route change the namespace's capture flag?
111  bool willCaptureBeTurnedOn = (entry->hasCapture() == false && route.isCapture());
112 
113  createFibUpdatesForNewRoute(*entry, route, willCaptureBeTurnedOn);
114  }
115  else {
116  // Route already exists
117  RibEntry entryCopy = *entry;
118 
119  Route& routeToUpdate = *(entryCopy.findRoute(route));
120 
121  routeToUpdate.flags = route.flags;
122  routeToUpdate.cost = route.cost;
123  routeToUpdate.expires = route.expires;
124 
125  createFibUpdatesForUpdatedRoute(entryCopy, route, *existingRoute);
126  }
127  }
128  else {
129  // New name in RIB
130  // Find prefix's parent
131  shared_ptr<RibEntry> parent = m_rib.findParent(prefix);
132 
133  Rib::RibEntryList descendants = m_rib.findDescendantsForNonInsertedName(prefix);
134  Rib::RibEntryList children;
135 
136  for (const auto& descendant : descendants) {
137  // If the child has the same parent as the new entry,
138  // the new entry must be the child's new parent
139  if (descendant->getParent() == parent) {
140  children.push_back(descendant);
141  }
142  }
143 
144  createFibUpdatesForNewRibEntry(prefix, route, children);
145  }
146 }
147 
148 void
149 FibUpdater::computeUpdatesForUnregistration(const RibUpdate& update)
150 {
151  const Name& prefix = update.getName();
152  const Route& route = update.getRoute();
153 
154  Rib::const_iterator ribIt = m_rib.find(prefix);
155 
156  // Name prefix exists
157  if (ribIt != m_rib.end()) {
158  shared_ptr<const RibEntry> entry(ribIt->second);
159 
160  const bool hadCapture = entry->hasCapture();
161 
162  RibEntry::const_iterator existing = entry->findRoute(route);
163 
164  if (existing != entry->end()) {
165  RibEntry temp = *entry;
166 
167  // Erase route in temp entry
168  temp.eraseRoute(route);
169 
170  const bool captureWasTurnedOff = (hadCapture && !temp.hasCapture());
171 
172  createFibUpdatesForErasedRoute(temp, *existing, captureWasTurnedOff);
173 
174  // The RibEntry still has the face ID; need to update FIB
175  // with lowest cost for the same face instead of removing the face from the FIB
176  const Route* next = entry->getRouteWithSecondLowestCostByFaceId(route.faceId);
177 
178  if (next != nullptr) {
179  createFibUpdatesForNewRoute(temp, *next, false);
180  }
181 
182  // The RibEntry will be empty after this removal
183  if (entry->getNRoutes() == 1) {
184  createFibUpdatesForErasedRibEntry(*entry);
185  }
186  }
187  }
188 }
189 
190 void
191 FibUpdater::sendUpdates(const FibUpdateList& updates,
192  const FibUpdateSuccessCallback& onSuccess,
193  const FibUpdateFailureCallback& onFailure)
194 {
195  std::string updateString = (updates.size() == 1) ? " update" : " updates";
196  NFD_LOG_DEBUG("Applying " << updates.size() << updateString << " to FIB");
197 
198  for (const FibUpdate& update : updates) {
199  NFD_LOG_DEBUG("Sending FIB update: " << update);
200 
201  if (update.action == FibUpdate::ADD_NEXTHOP) {
202  sendAddNextHopUpdate(update, onSuccess, onFailure);
203  }
204  else if (update.action == FibUpdate::REMOVE_NEXTHOP) {
205  sendRemoveNextHopUpdate(update, onSuccess, onFailure);
206  }
207  }
208 }
209 
210 void
211 FibUpdater::sendUpdatesForBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
212  const FibUpdateFailureCallback& onFailure)
213 {
214  if (m_updatesForBatchFaceId.size() > 0) {
215  sendUpdates(m_updatesForBatchFaceId, onSuccess, onFailure);
216  }
217  else {
218  sendUpdatesForNonBatchFaceId(onSuccess, onFailure);
219  }
220 }
221 
222 void
223 FibUpdater::sendUpdatesForNonBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
224  const FibUpdateFailureCallback& onFailure)
225 {
226  if (m_updatesForNonBatchFaceId.size() > 0) {
227  sendUpdates(m_updatesForNonBatchFaceId, onSuccess, onFailure);
228  }
229  else {
230  onSuccess(m_inheritedRoutes);
231  }
232 }
233 
234 void
235 FibUpdater::sendAddNextHopUpdate(const FibUpdate& update,
236  const FibUpdateSuccessCallback& onSuccess,
237  const FibUpdateFailureCallback& onFailure,
238  uint32_t nTimeouts)
239 {
242  .setName(update.name)
243  .setFaceId(update.faceId)
244  .setCost(update.cost),
245  bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
246  bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, _2, nTimeouts));
247 }
248 
249 void
250 FibUpdater::sendRemoveNextHopUpdate(const FibUpdate& update,
251  const FibUpdateSuccessCallback& onSuccess,
252  const FibUpdateFailureCallback& onFailure,
253  uint32_t nTimeouts)
254 {
257  .setName(update.name)
258  .setFaceId(update.faceId),
259  bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
260  bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, _2, nTimeouts));
261 }
262 
263 void
264 FibUpdater::onUpdateSuccess(const FibUpdate update,
265  const FibUpdateSuccessCallback& onSuccess,
266  const FibUpdateFailureCallback& onFailure)
267 {
268  if (update.faceId == m_batchFaceId) {
269  m_updatesForBatchFaceId.remove(update);
270 
271  if (m_updatesForBatchFaceId.size() == 0) {
272  sendUpdatesForNonBatchFaceId(onSuccess, onFailure);
273  }
274  }
275  else {
276  m_updatesForNonBatchFaceId.remove(update);
277 
278  if (m_updatesForNonBatchFaceId.size() == 0) {
279  onSuccess(m_inheritedRoutes);
280  }
281  }
282 }
283 
284 void
285 FibUpdater::onUpdateError(const FibUpdate update,
286  const FibUpdateSuccessCallback& onSuccess,
287  const FibUpdateFailureCallback& onFailure,
288  uint32_t code, const std::string& error, uint32_t nTimeouts)
289 {
290  NFD_LOG_DEBUG("Failed to apply " << update << " (code: " << code << ", error: " << error << ")");
291 
292  if (code == ndn::nfd::Controller::ERROR_TIMEOUT && nTimeouts < MAX_NUM_TIMEOUTS) {
293  sendAddNextHopUpdate(update, onSuccess, onFailure, ++nTimeouts);
294  }
295  else if (code == ERROR_FACE_NOT_FOUND) {
296  if (update.faceId == m_batchFaceId) {
297  onFailure(code, error);
298  }
299  else {
300  m_updatesForNonBatchFaceId.remove(update);
301 
302  if (m_updatesForNonBatchFaceId.size() == 0) {
303  onSuccess(m_inheritedRoutes);
304  }
305  }
306  }
307  else {
308  BOOST_THROW_EXCEPTION(Error("Non-recoverable error: " + error + " code: " +
309  std::to_string(code)));
310  }
311 }
312 
313 void
314 FibUpdater::addFibUpdate(FibUpdate update)
315 {
316  FibUpdateList& updates = (update.faceId == m_batchFaceId) ? m_updatesForBatchFaceId :
317  m_updatesForNonBatchFaceId;
318 
319  // If an update with the same name and route already exists,
320  // replace it
321  FibUpdateList::iterator it = std::find_if(updates.begin(), updates.end(),
322  [&update] (const FibUpdate& other) {
323  return update.name == other.name && update.faceId == other.faceId;
324  });
325 
326  if (it != updates.end()) {
327  FibUpdate& existingUpdate = *it;
328  existingUpdate.action = update.action;
329  existingUpdate.cost = update.cost;
330  }
331  else {
332  updates.push_back(update);
333  }
334 }
335 
336 void
337 FibUpdater::addInheritedRoutes(const RibEntry& entry, const Rib::Rib::RouteSet& routesToAdd)
338 {
339  for (const Route& route : routesToAdd) {
340  // Don't add an ancestor faceId if the namespace has an entry for that faceId
341  if (!entry.hasFaceId(route.faceId)) {
342  // Create a record of the inherited route so it can be added to the RIB later
343  addInheritedRoute(entry.getName(), route);
344 
345  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
346  }
347  }
348 }
349 
350 void
351 FibUpdater::addInheritedRoutes(const Name& name, const Rib::Rib::RouteSet& routesToAdd,
352  const Route& ignore)
353 {
354  for (const Route& route : routesToAdd) {
355  if (route.faceId != ignore.faceId) {
356  // Create a record of the inherited route so it can be added to the RIB later
357  addInheritedRoute(name, route);
358 
359  addFibUpdate(FibUpdate::createAddUpdate(name, route.faceId, route.cost));
360  }
361  }
362 }
363 
364 void
365 FibUpdater::removeInheritedRoutes(const RibEntry& entry, const Rib::Rib::RouteSet& routesToRemove)
366 {
367  for (const Route& route : routesToRemove) {
368  // Only remove if the route has been inherited
369  if (entry.hasInheritedRoute(route)) {
370  removeInheritedRoute(entry.getName(), route);
371  addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
372  }
373  }
374 }
375 
376 void
377 FibUpdater::createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
378  const Rib::RibEntryList& children)
379 {
380  // Create FIB update for new entry
381  addFibUpdate(FibUpdate::createAddUpdate(name, route.faceId, route.cost));
382 
383  // No flags are set
384  if (!route.isChildInherit() && !route.isCapture()) {
385  // Add ancestor routes to self
386  addInheritedRoutes(name, m_rib.getAncestorRoutes(name), route);
387  }
388  else if (route.isChildInherit() && route.isCapture()) {
389  // Add route to children
390  Rib::RouteSet routesToAdd;
391  routesToAdd.insert(route);
392 
393  // Remove routes blocked by capture and add self to children
394  modifyChildrensInheritedRoutes(children, routesToAdd, m_rib.getAncestorRoutes(name));
395  }
396  else if (route.isChildInherit()) {
397  Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(name);
398 
399  // Add ancestor routes to self
400  addInheritedRoutes(name, ancestorRoutes, route);
401 
402  // If there is an ancestor route which is the same as the new route, replace it
403  // with the new route
404  Rib::RouteSet::iterator it = ancestorRoutes.find(route);
405 
406  // There is a route that needs to be overwritten, erase and then replace
407  if (it != ancestorRoutes.end()) {
408  ancestorRoutes.erase(it);
409  }
410 
411  // Add new route to ancestor list so it can be added to children
412  ancestorRoutes.insert(route);
413 
414  // Add ancestor routes to children
415  modifyChildrensInheritedRoutes(children, ancestorRoutes, Rib::RouteSet());
416  }
417  else if (route.isCapture()) {
418  // Remove routes blocked by capture
419  modifyChildrensInheritedRoutes(children, Rib::RouteSet(), m_rib.getAncestorRoutes(name));
420  }
421 }
422 
423 void
424 FibUpdater::createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
425  bool captureWasTurnedOn)
426 {
427  // Only update if the new route has a lower cost than a previously installed route
428  const Route* prevRoute = entry.getRouteWithLowestCostAndChildInheritByFaceId(route.faceId);
429 
430  Rib::RouteSet routesToAdd;
431  if (route.isChildInherit()) {
432  // Add to children if this new route doesn't override a previous lower cost, or
433  // add to children if this new route is lower cost than a previous route.
434  // Less than equal, since entry may find this route
435  if (prevRoute == nullptr || route.cost <= prevRoute->cost) {
436  // Add self to children
437  routesToAdd.insert(route);
438  }
439  }
440 
441  Rib::RouteSet routesToRemove;
442  if (captureWasTurnedOn) {
443  // Capture flag on
444  routesToRemove = m_rib.getAncestorRoutes(entry);
445 
446  // Remove ancestor routes from self
447  removeInheritedRoutes(entry, routesToRemove);
448  }
449 
450  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
451 
452  // If another route with same faceId and lower cost exists, don't update.
453  // Must be done last so that add updates replace removal updates
454  // Create FIB update for new entry
455  const Route* other = entry.getRouteWithLowestCostByFaceId(route.faceId);
456 
457  if (other == nullptr || route.cost <= other->cost) {
458  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
459  }
460 }
461 
462 void
463 FibUpdater::createFibUpdatesForUpdatedRoute(const RibEntry& entry, const Route& route,
464  const Route& existingRoute)
465 {
466  const bool costDidChange = (route.cost != existingRoute.cost);
467 
468  // Look for an installed route with the lowest cost and child inherit set
469  const Route* prevRoute = entry.getRouteWithLowestCostAndChildInheritByFaceId(route.faceId);
470 
471  // No flags changed and cost didn't change, no change in FIB
472  if (route.flags == existingRoute.flags && !costDidChange) {
473  return;
474  }
475 
476  // Cost changed so create update for the entry itself
477  if (costDidChange) {
478  // Create update if this route's cost is lower than other routes
479  if (route.cost <= entry.getRouteWithLowestCostByFaceId(route.faceId)->cost) {
480  // Create FIB update for the updated entry
481  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
482  }
483  else if (existingRoute.cost < entry.getRouteWithLowestCostByFaceId(route.faceId)->cost) {
484  // Create update if this route used to be the lowest route but is no longer
485  // the lowest cost route.
486  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), prevRoute->faceId, prevRoute->cost));
487  }
488 
489  // If another route with same faceId and lower cost and ChildInherit exists,
490  // don't update children.
491  if (prevRoute == nullptr || route.cost <= prevRoute->cost) {
492  // If no flags changed but child inheritance is set, need to update children
493  // with new cost
494  if ((route.flags == existingRoute.flags) && route.isChildInherit()) {
495  // Add self to children
496  Rib::RouteSet routesToAdd;
497  routesToAdd.insert(route);
498  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
499 
500  return;
501  }
502  }
503  }
504 
505  // Child inherit was turned on
506  if (!existingRoute.isChildInherit() && route.isChildInherit()) {
507  // If another route with same faceId and lower cost and ChildInherit exists,
508  // don't update children.
509  if (prevRoute == nullptr || route.cost <= prevRoute->cost) {
510  // Add self to children
511  Rib::RouteSet routesToAdd;
512  routesToAdd.insert(route);
513  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
514  }
515  } // Child inherit was turned off
516  else if (existingRoute.isChildInherit() && !route.isChildInherit()) {
517  // Remove self from children
518  Rib::RouteSet routesToRemove;
519  routesToRemove.insert(route);
520 
521  Rib::RouteSet routesToAdd;
522  // If another route with same faceId and ChildInherit exists, update children with this route.
523  if (prevRoute != nullptr) {
524  routesToAdd.insert(*prevRoute);
525  }
526  else {
527  // Look for an ancestor that was blocked previously
528  const Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
529  Rib::RouteSet::iterator it = ancestorRoutes.find(route);
530 
531  // If an ancestor is found, add it to children
532  if (it != ancestorRoutes.end()) {
533  routesToAdd.insert(*it);
534  }
535  }
536 
537  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
538  }
539 
540  // Capture was turned on
541  if (!existingRoute.isCapture() && route.isCapture()) {
542  Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
543 
544  // Remove ancestor routes from self
545  removeInheritedRoutes(entry, ancestorRoutes);
546 
547  // Remove ancestor routes from children
548  modifyChildrensInheritedRoutes(entry.getChildren(), Rib::RouteSet(), ancestorRoutes);
549  } // Capture was turned off
550  else if (existingRoute.isCapture() && !route.isCapture()) {
551  Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
552 
553  // Add ancestor routes to self
554  addInheritedRoutes(entry, ancestorRoutes);
555 
556  // Add ancestor routes to children
557  modifyChildrensInheritedRoutes(entry.getChildren(), ancestorRoutes, Rib::RouteSet());
558  }
559 }
560 
561 void
562 FibUpdater::createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
563  const bool captureWasTurnedOff)
564 {
565  addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
566 
567  if (route.isChildInherit() && route.isCapture()) {
568  // Remove self from children
569  Rib::RouteSet routesToRemove;
570  routesToRemove.insert(route);
571 
572  // If capture is turned off for the route, need to add ancestors
573  // to self and children
574  Rib::RouteSet routesToAdd;
575  if (captureWasTurnedOff) {
576  // Look for an ancestors that were blocked previously
577  routesToAdd = m_rib.getAncestorRoutes(entry);
578 
579  // Add ancestor routes to self
580  addInheritedRoutes(entry, routesToAdd);
581  }
582 
583  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
584  }
585  else if (route.isChildInherit()) {
586  // If not blocked by capture, add inherited routes to children
587  Rib::RouteSet routesToAdd;
588  if (!entry.hasCapture()) {
589  routesToAdd = m_rib.getAncestorRoutes(entry);
590  }
591 
592  Rib::RouteSet routesToRemove;
593  routesToRemove.insert(route);
594 
595  // Add ancestor routes to children
596  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
597  }
598  else if (route.isCapture()) {
599  // If capture is turned off for the route, need to add ancestors
600  // to self and children
601  Rib::RouteSet routesToAdd;
602  if (captureWasTurnedOff) {
603  // Look for an ancestors that were blocked previously
604  routesToAdd = m_rib.getAncestorRoutes(entry);
605 
606  // Add ancestor routes to self
607  addInheritedRoutes(entry, routesToAdd);
608  }
609 
610  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
611  }
612 
613  // Need to check if the removed route was blocking an inherited route
614  Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
615 
616  // If the current entry has capture set or is pending removal, don't add inherited route
617  if (!entry.hasCapture() && entry.getNRoutes() != 0) {
618  // If there is an ancestor route which is the same as the erased route, add that route
619  // to the current entry
620  Rib::RouteSet::iterator it = ancestorRoutes.find(route);
621 
622  if (it != ancestorRoutes.end()) {
623  addInheritedRoute(entry.getName(), *it);
624  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), it->faceId, it->cost));
625  }
626  }
627 }
628 
629 void
630 FibUpdater::createFibUpdatesForErasedRibEntry(const RibEntry& entry)
631 {
632  for (const Route& route : entry.getInheritedRoutes()) {
633  addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
634  }
635 }
636 
637 void
638 FibUpdater::modifyChildrensInheritedRoutes(const Rib::RibEntryList& children,
639  const Rib::RouteSet& routesToAdd,
640  const Rib::RouteSet& routesToRemove)
641 {
642  for (const auto& child : children) {
643  traverseSubTree(*child, routesToAdd, routesToRemove);
644  }
645 }
646 
647 void
648 FibUpdater::traverseSubTree(const RibEntry& entry, Rib::Rib::RouteSet routesToAdd,
649  Rib::Rib::RouteSet routesToRemove)
650 {
651  // If a route on the namespace has the capture flag set, ignore self and children
652  if (entry.hasCapture()) {
653  return;
654  }
655 
656  // Remove inherited routes from current namespace
657  for (Rib::RouteSet::const_iterator removeIt = routesToRemove.begin();
658  removeIt != routesToRemove.end(); )
659  {
660  // If a route on the namespace has the same face ID and child inheritance set,
661  // ignore this route
662  if (entry.hasChildInheritOnFaceId(removeIt->faceId)) {
663  routesToRemove.erase(removeIt++);
664  continue;
665  }
666 
667  // Only remove route if it removes an existing inherited route
668  if (entry.hasInheritedRoute(*removeIt)) {
669  removeInheritedRoute(entry.getName(), *removeIt);
670  addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), removeIt->faceId));
671  }
672 
673  ++removeIt;
674  }
675 
676  // Add inherited routes to current namespace
677  for (Rib::RouteSet::const_iterator addIt = routesToAdd.begin(); addIt != routesToAdd.end(); ) {
678 
679  // If a route on the namespace has the same face ID and child inherit set, ignore this face
680  if (entry.hasChildInheritOnFaceId(addIt->faceId)) {
681  routesToAdd.erase(addIt++);
682  continue;
683  }
684 
685  // Only add route if it does not override an existing route
686  if (!entry.hasFaceId(addIt->faceId)) {
687  addInheritedRoute(entry.getName(), *addIt);
688  addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), addIt->faceId, addIt->cost));
689  }
690 
691  ++addIt;
692  }
693 
694  modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
695 }
696 
697 void
698 FibUpdater::addInheritedRoute(const Name& name, const Route& route)
699 {
700  RibUpdate update;
702  .setName(name)
703  .setRoute(route);
704 
705  m_inheritedRoutes.push_back(update);
706 }
707 
708 void
709 FibUpdater::removeInheritedRoute(const Name& name, const Route& route)
710 {
711  RibUpdate update;
713  .setName(name)
714  .setRoute(route);
715 
716  m_inheritedRoutes.push_back(update);
717 }
718 
719 } // namespace rib
720 } // namespace nfd
RibUpdate & setRoute(const Route &route)
Definition: rib-update.hpp:107
void start(const ControlParameters &parameters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
Definition: fib-updater.cpp:42
const Route & getRoute() const
Definition: rib-update.hpp:114
represents the RIB
Definition: rib.hpp:45
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:36
represents a fib/add-nexthop command
function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
Definition: fib-updater.hpp:57
time::steady_clock::TimePoint expires
Definition: route.hpp:83
iterator findRoute(const Route &route)
Definition: rib-entry.cpp:38
const Route * getRouteWithLowestCostByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID.
Definition: rib-entry.cpp:179
represents a collection of RibUpdates to be applied to a single FaceId
std::list< FibUpdate > FibUpdateList
Definition: fib-updater.hpp:55
uint64_t cost
Definition: route.hpp:82
uint64_t faceId
Definition: route.hpp:79
shared_ptr< RibEntry > findParent(const Name &prefix) const
Definition: rib.cpp:200
function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
Definition: fib-updater.hpp:58
represents a fib/remove-nexthop command
static const uint32_t ERROR_TIMEOUT
error code for timeout
uint64_t getFaceId() const
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:53
represents a FIB update
Definition: fib-update.hpp:37
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:48
static FibUpdate createRemoveUpdate(const Name &name, const uint64_t faceId)
Definition: fib-update.cpp:45
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
static FibUpdate createAddUpdate(const Name &name, const uint64_t faceId, const uint64_t cost)
Definition: fib-update.cpp:32
RibUpdate & setAction(Action action)
Definition: rib-update.hpp:81
represents a RIB entry, which contains one or more Routes with the same prefix
Definition: rib-entry.hpp:36
represents a route for a name prefix
Definition: route.hpp:37
NFD Management protocol - ControlCommand client.
const Name & getName() const
Definition: rib-update.hpp:101
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const std::list< shared_ptr< RibEntry > > & getChildren() const
Definition: rib-entry.hpp:220
RibTable::const_iterator const_iterator
Definition: rib.hpp:50
const Name & getName() const
Definition: rib-entry.hpp:202
const RouteList & getInheritedRoutes() const
Returns the routes this namespace has inherited.
Definition: rib-entry.hpp:232
size_t getNRoutes() const
Definition: rib-entry.cpp:92
bool isChildInherit() const
Definition: route.hpp:67
const_iterator end() const
Definition: rib.hpp:243
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
uint64_t flags
Definition: route.hpp:81
RibUpdate & setName(const Name &name)
Definition: rib-update.hpp:94
bool hasFaceId(const uint64_t faceId) const
Definition: rib-entry.cpp:84
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:41
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...
Definition: rib-entry.cpp:222
const_iterator find(const Name &prefix) const
Definition: rib.cpp:59
void eraseRoute(const Route &route)
erases a Route with the same faceId and origin
Definition: rib-entry.cpp:69
bool hasInheritedRoute(const Route &route) const
Determines if the entry has an inherited route with a matching face ID.
Definition: rib-entry.cpp:153
bool isCapture() const
Definition: route.hpp:73
bool hasCapture() const
Definition: rib-entry.cpp:161
An update triggered by a face destruction notification.
Definition: rib-update.hpp:51
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...
Definition: rib-entry.cpp:167
void computeAndSendFibUpdates(const RibUpdateBatch &batch, const FibUpdateSuccessCallback &onSuccess, const FibUpdateFailureCallback &onFailure)
computes FibUpdates using the provided RibUpdateBatch and then sends the updates to NFD&#39;s FIB ...
Definition: fib-updater.cpp:50
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:236
void setFibUpdater(FibUpdater *updater)
Definition: rib.cpp:53