blob: 212bccf7fe6f0b5440782ea57c7b15704b139962 [file] [log] [blame]
Vince Lehman76c751c2014-11-18 17:36:38 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, 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
28#include "core/logger.hpp"
29
30#include <ndn-cxx/management/nfd-control-parameters.hpp>
31
32namespace nfd {
33namespace rib {
34
35using ndn::nfd::ControlParameters;
36
37NFD_LOG_INIT("FibUpdater");
38
39const unsigned int FibUpdater::MAX_NUM_TIMEOUTS = 10;
40const uint32_t FibUpdater::ERROR_FACE_NOT_FOUND = 410;
41
42FibUpdater::FibUpdater(Rib& rib, ndn::nfd::Controller& controller)
43 : m_rib(rib)
44 , m_controller(controller)
45{
46 rib.setFibUpdater(this);
47}
48
49void
50FibUpdater::computeAndSendFibUpdates(const RibUpdateBatch& batch,
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
68void
69FibUpdater::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()) {
77 case RibUpdate::REGISTER:
78 computeUpdatesForRegistration(update);
79 break;
80 case RibUpdate::UNREGISTER:
81 computeUpdatesForUnregistration(update);
82 break;
83 case RibUpdate::REMOVE_FACE:
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
94void
95FibUpdater::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
148void
149FibUpdater::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
190void
191FibUpdater::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
210void
211FibUpdater::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
222void
223FibUpdater::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
234void
235FibUpdater::sendAddNextHopUpdate(const FibUpdate& update,
236 const FibUpdateSuccessCallback& onSuccess,
237 const FibUpdateFailureCallback& onFailure,
238 uint32_t nTimeouts)
239{
240 m_controller.start<ndn::nfd::FibAddNextHopCommand>(
241 ControlParameters()
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
249void
250FibUpdater::sendRemoveNextHopUpdate(const FibUpdate& update,
251 const FibUpdateSuccessCallback& onSuccess,
252 const FibUpdateFailureCallback& onFailure,
253 uint32_t nTimeouts)
254{
255 m_controller.start<ndn::nfd::FibRemoveNextHopCommand>(
256 ControlParameters()
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
263void
264FibUpdater::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
284void
285FibUpdater::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 throw Error("Non-recoverable error: " + error + " code: " + std::to_string(code));
309 }
310}
311
312void
313FibUpdater::addFibUpdate(FibUpdate update)
314{
315 FibUpdateList& updates = (update.faceId == m_batchFaceId) ? m_updatesForBatchFaceId :
316 m_updatesForNonBatchFaceId;
317
318 // If an update with the same name and route already exists,
319 // replace it
320 FibUpdateList::iterator it = std::find_if(updates.begin(), updates.end(),
321 [&update] (const FibUpdate& other) {
322 return update.name == other.name && update.faceId == other.faceId;
323 });
324
325 if (it != updates.end()) {
326 FibUpdate& existingUpdate = *it;
327 existingUpdate.action = update.action;
328 existingUpdate.cost = update.cost;
329 }
330 else {
331 updates.push_back(update);
332 }
333}
334
335void
336FibUpdater::addInheritedRoutes(const RibEntry& entry, const Rib::Rib::RouteSet& routesToAdd)
337{
338 for (const Route& route : routesToAdd) {
339 // Don't add an ancestor faceId if the namespace has an entry for that faceId
340 if (!entry.hasFaceId(route.faceId)) {
341 // Create a record of the inherited route so it can be added to the RIB later
342 addInheritedRoute(entry.getName(), route);
343
344 addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
345 }
346 }
347}
348
349void
350FibUpdater::addInheritedRoutes(const Name& name, const Rib::Rib::RouteSet& routesToAdd,
351 const Route& ignore)
352{
353 for (const Route& route : routesToAdd) {
354 if (route.faceId != ignore.faceId) {
355 // Create a record of the inherited route so it can be added to the RIB later
356 addInheritedRoute(name, route);
357
358 addFibUpdate(FibUpdate::createAddUpdate(name, route.faceId, route.cost));
359 }
360 }
361}
362
363void
364FibUpdater::removeInheritedRoutes(const RibEntry& entry, const Rib::Rib::RouteSet& routesToRemove)
365{
366 for (const Route& route : routesToRemove) {
367 // Only remove if the route has been inherited
368 if (entry.hasInheritedRoute(route)) {
369 removeInheritedRoute(entry.getName(), route);
370 addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
371 }
372 }
373}
374
375void
376FibUpdater::createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
377 const Rib::RibEntryList& children)
378{
379 // Create FIB update for new entry
380 addFibUpdate(FibUpdate::createAddUpdate(name, route.faceId, route.cost));
381
382 // No flags are set
383 if (!route.isChildInherit() && !route.isCapture()) {
384 // Add ancestor routes to self
385 addInheritedRoutes(name, m_rib.getAncestorRoutes(name), route);
386 }
387 else if (route.isChildInherit() && route.isCapture()) {
388 // Add route to children
389 Rib::RouteSet routesToAdd;
390 routesToAdd.insert(route);
391
392 // Remove routes blocked by capture and add self to children
393 modifyChildrensInheritedRoutes(children, routesToAdd, m_rib.getAncestorRoutes(name));
394 }
395 else if (route.isChildInherit()) {
396 Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(name);
397
398 // Add ancestor routes to self
399 addInheritedRoutes(name, ancestorRoutes, route);
400
401 // If there is an ancestor route which is the same as the new route, replace it
402 // with the new route
403 Rib::RouteSet::iterator it = ancestorRoutes.find(route);
404
405 // There is a route that needs to be overwritten, erase and then replace
406 if (it != ancestorRoutes.end()) {
407 ancestorRoutes.erase(it);
408 }
409
410 // Add new route to ancestor list so it can be added to children
411 ancestorRoutes.insert(route);
412
413 // Add ancestor routes to children
414 modifyChildrensInheritedRoutes(children, ancestorRoutes, Rib::RouteSet());
415 }
416 else if (route.isCapture()) {
417 // Remove routes blocked by capture
418 modifyChildrensInheritedRoutes(children, Rib::RouteSet(), m_rib.getAncestorRoutes(name));
419 }
420}
421
422void
423FibUpdater::createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
424 bool captureWasTurnedOn)
425{
426 // Only update if the new route has a lower cost than a previously installed route
427 shared_ptr<const Route> prevRoute =
428 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 (!static_cast<bool>(prevRoute) || 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 shared_ptr<const Route> other = entry.getRouteWithLowestCostByFaceId(route.faceId);
456
457 if (!other || route.cost <= other->cost) {
458 addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
459 }
460}
461
462void
463FibUpdater::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 shared_ptr<const Route> prevRoute =
470 entry.getRouteWithLowestCostAndChildInheritByFaceId(route.faceId);
471
472 // No flags changed and cost didn't change, no change in FIB
473 if (route.flags == existingRoute.flags && !costDidChange) {
474 return;
475 }
476
477 // Cost changed so create update for the entry itself
478 if (costDidChange) {
479 // Create update if this route's cost is lower than other routes
480 if (route.cost <= entry.getRouteWithLowestCostByFaceId(route.faceId)->cost) {
481 // Create FIB update for the updated entry
482 addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), route.faceId, route.cost));
483 }
484 else if (existingRoute.cost < entry.getRouteWithLowestCostByFaceId(route.faceId)->cost) {
485 // Create update if this route used to be the lowest route but is no longer
486 // the lowest cost route.
487 addFibUpdate(FibUpdate::createAddUpdate(entry.getName(), prevRoute->faceId, prevRoute->cost));
488 }
489
490 // If another route with same faceId and lower cost and ChildInherit exists,
491 // don't update children.
492 if (!static_cast<bool>(prevRoute) || route.cost <= prevRoute->cost) {
493 // If no flags changed but child inheritance is set, need to update children
494 // with new cost
495 if ((route.flags == existingRoute.flags) && route.isChildInherit()) {
496 // Add self to children
497 Rib::RouteSet routesToAdd;
498 routesToAdd.insert(route);
499 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
500
501 return;
502 }
503 }
504 }
505
506 // Child inherit was turned on
507 if (!existingRoute.isChildInherit() && route.isChildInherit()) {
508 // If another route with same faceId and lower cost and ChildInherit exists,
509 // don't update children.
510 if (!static_cast<bool>(prevRoute) || route.cost <= prevRoute->cost) {
511 // Add self to children
512 Rib::RouteSet routesToAdd;
513 routesToAdd.insert(route);
514 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
515 }
516 } // Child inherit was turned off
517 else if (existingRoute.isChildInherit() && !route.isChildInherit()) {
518 // Remove self from children
519 Rib::RouteSet routesToRemove;
520 routesToRemove.insert(route);
521
522 Rib::RouteSet routesToAdd;
523 // If another route with same faceId and ChildInherit exists, update children with this route.
524 if (static_cast<bool>(prevRoute)) {
525 routesToAdd.insert(*prevRoute);
526 }
527 else {
528 // Look for an ancestor that was blocked previously
529 const Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
530 Rib::RouteSet::iterator it = ancestorRoutes.find(route);
531
532 // If an ancestor is found, add it to children
533 if (it != ancestorRoutes.end()) {
534 routesToAdd.insert(*it);
535 }
536 }
537
538 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
539 }
540
541 // Capture was turned on
542 if (!existingRoute.isCapture() && route.isCapture()) {
543 Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
544
545 // Remove ancestor routes from self
546 removeInheritedRoutes(entry, ancestorRoutes);
547
548 // Remove ancestor routes from children
549 modifyChildrensInheritedRoutes(entry.getChildren(), Rib::RouteSet(), ancestorRoutes);
550 } // Capture was turned off
551 else if (existingRoute.isCapture() && !route.isCapture()) {
552 Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
553
554 // Add ancestor routes to self
555 addInheritedRoutes(entry, ancestorRoutes);
556
557 // Add ancestor routes to children
558 modifyChildrensInheritedRoutes(entry.getChildren(), ancestorRoutes, Rib::RouteSet());
559 }
560}
561
562void
563FibUpdater::createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
564 const bool captureWasTurnedOff)
565{
566 addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
567
568 if (route.isChildInherit() && route.isCapture()) {
569 // Remove self from children
570 Rib::RouteSet routesToRemove;
571 routesToRemove.insert(route);
572
573 // If capture is turned off for the route, need to add ancestors
574 // to self and children
575 Rib::RouteSet routesToAdd;
576 if (captureWasTurnedOff) {
577 // Look for an ancestors that were blocked previously
578 routesToAdd = m_rib.getAncestorRoutes(entry);
579
580 // Add ancestor routes to self
581 addInheritedRoutes(entry, routesToAdd);
582 }
583
584 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
585 }
586 else if (route.isChildInherit()) {
587 // If not blocked by capture, add inherited routes to children
588 Rib::RouteSet routesToAdd;
589 if (!entry.hasCapture()) {
590 routesToAdd = m_rib.getAncestorRoutes(entry);
591 }
592
593 Rib::RouteSet routesToRemove;
594 routesToRemove.insert(route);
595
596 // Add ancestor routes to children
597 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, routesToRemove);
598 }
599 else if (route.isCapture()) {
600 // If capture is turned off for the route, need to add ancestors
601 // to self and children
602 Rib::RouteSet routesToAdd;
603 if (captureWasTurnedOff) {
604 // Look for an ancestors that were blocked previously
605 routesToAdd = m_rib.getAncestorRoutes(entry);
606
607 // Add ancestor routes to self
608 addInheritedRoutes(entry, routesToAdd);
609 }
610
611 modifyChildrensInheritedRoutes(entry.getChildren(), routesToAdd, Rib::RouteSet());
612 }
613
614 // Need to check if the removed route was blocking an inherited route
615 Rib::RouteSet ancestorRoutes = m_rib.getAncestorRoutes(entry);
616
617 if (!entry.hasCapture()) {
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
629void
630FibUpdater::createFibUpdatesForErasedRibEntry(const RibEntry& entry)
631{
632 for (const Route& route : entry.getInheritedRoutes()) {
633 addFibUpdate(FibUpdate::createRemoveUpdate(entry.getName(), route.faceId));
634 }
635}
636
637void
638FibUpdater::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
647void
648FibUpdater::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
697void
698FibUpdater::addInheritedRoute(const Name& name, const Route& route)
699{
700 RibUpdate update;
701 update.setAction(RibUpdate::REGISTER)
702 .setName(name)
703 .setRoute(route);
704
705 m_inheritedRoutes.push_back(update);
706}
707
708void
709FibUpdater::removeInheritedRoute(const Name& name, const Route& route)
710{
711 RibUpdate update;
712 update.setAction(RibUpdate::UNREGISTER)
713 .setName(name)
714 .setRoute(route);
715
716 m_inheritedRoutes.push_back(update);
717}
718
719} // namespace rib
720} // namespace nfd