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