+ break;
+ case SUBTREE_MODIFIED:
+ case WRITE:
+ entry = this.routeEntries.get(routeKey);
+ if (entry == null) {
+ entry = createEntry(routeKey);
+ }
+
+ final NormalizedNode routeAfter = route.getDataAfter().get();
+ verify(routeAfter instanceof MapEntryNode, "Unexpected route %s", routeAfter);
+ entry.addRoute(routerId, pathId, (MapEntryNode) routeAfter);
+ this.totalPathsCounter.increment();
+ break;
+ default:
+ throw new IllegalStateException("Unhandled route modification " + route);
+ }
+
+ final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(routerId, routeKey);
+ LOG.debug("Updated route {} entry {}", routeKey, entry);
+ routes.put(routeUpdateKey, entry);
+ }
+ }
+
+ private void walkThrough(final DOMDataTreeWriteOperations tx,
+ final Set<Entry<RouteUpdateKey, RouteEntry<C, S>>> toUpdate) {
+ final List<StaleBestPathRoute> staleRoutes = new ArrayList<>();
+ final List<AdvertizedRoute<C, S>> newRoutes = new ArrayList<>();
+ for (final Entry<RouteUpdateKey, RouteEntry<C, S>> e : toUpdate) {
+ LOG.trace("Walking through {}", e);
+ final RouteEntry<C, S> entry = e.getValue();
+
+ if (!entry.selectBest(this.ribSupport, this.ourAs)) {
+ LOG.trace("Best path has not changed, continuing");
+ continue;
+ }
+
+ entry.removeStalePaths(this.ribSupport, e.getKey().getRouteId()).ifPresent(staleRoutes::add);
+ newRoutes.addAll(entry.newBestPaths(this.ribSupport, e.getKey().getRouteId()));
+ }
+ updateLocRib(newRoutes, staleRoutes, tx);
+ this.peerTracker.getNonInternalPeers().parallelStream()
+ .filter(toPeer -> toPeer.supportsTable(this.entryDep.getLocalTablesKey()))
+ .forEach(toPeer -> toPeer.refreshRibOut(this.entryDep, staleRoutes, newRoutes));
+ }
+
+ private void updateLocRib(final List<AdvertizedRoute<C, S>> newRoutes, final List<StaleBestPathRoute> staleRoutes,
+ final DOMDataTreeWriteOperations tx) {
+ final YangInstanceIdentifier locRibTarget = this.entryDep.getLocRibTableTarget();
+
+ for (final StaleBestPathRoute staleContainer : staleRoutes) {
+ for (final NodeIdentifierWithPredicates routeId : staleContainer.getStaleRouteKeyIdentifiers()) {
+ final YangInstanceIdentifier routeTarget = ribSupport.createRouteIdentifier(locRibTarget, routeId);
+ LOG.debug("Delete route from LocRib {}", routeTarget);
+ tx.delete(LogicalDatastoreType.OPERATIONAL, routeTarget);
+ }