- }
-
- private void addPathToDataStore(
- final RouteEntryDependenciesContainer entryDep,
- final AddPathBestPath path,
- final boolean isFirstBestPath,
- final String routeKey,
- final WriteTransaction tx) {
- final RIBSupport ribSup = entryDep.getRibSupport();
- final Identifier routeIdAddPath = ribSup.createRouteListKey(path.getPathId(), routeKey);
- final Identifier routeIdAddNonPath = ribSup.createRouteListKey(NON_PATH_ID_VALUE, routeKey);
- final Route routeAddPath = createRoute(ribSup, routeKey, path.getPathId(), path);
- final Route routeNonAddPath = createRoute(ribSup, routeKey, NON_PATH_ID_VALUE, path);
-
- final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDep.getLocRibTableTarget();
- final InstanceIdentifier routeTarget = ribSup.createRouteIdentifier(locRibTarget, routeIdAddPath);
- LOG.debug("Write route to LocRib {}", routeAddPath);
- tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, routeAddPath);
-
- fillAdjRibsOut(isFirstBestPath, path.getAttributes(), routeNonAddPath, routeAddPath, routeIdAddNonPath,
- routeIdAddPath, path.getPeerId(), entryDep.getLocalTablesKey(), entryDep, tx);
- }
-
- @SuppressWarnings("unchecked")
- private void fillAdjRibsOut(
- final boolean isFirstBestPath,
- final Attributes attributes,
- final Route routeNonAddPath,
- final Route routeAddPath,
- final Identifier routeKeyAddNonPath,
- final Identifier routeKeyAddPath,
- final PeerId fromPeerId,
- final TablesKey localTK,
- final RouteEntryDependenciesContainer routeEntryDep,
- final WriteTransaction tx) {
- /*
- * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
- * expose from which client a particular route was learned from in the local RIB, and have
- * the listener perform filtering.
- *
- * We walk the policy set in order to minimize the amount of work we do for multiple peers:
- * if we have two eBGP peers, for example, there is no reason why we should perform the translation
- * multiple times.
- */
- final RIBSupport ribSupport = routeEntryDep.getRibSupport();
- for (final Peer toPeer : this.peerTracker.getPeers()) {
- if (!filterRoutes(fromPeerId, toPeer, localTK)) {
- continue;
- }
- final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTK);
-
- if (toPeer.getPeerId().getValue().equals("bgp://127.0.0.5")) {
- LOG.debug("Write route {} to peer AdjRibsOut {}", toPeer.getPeerId());
- }
- if (peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
-
- Optional<Attributes> effAttrib = Optional.empty();
- final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
-
- if (fromPeer != null && attributes != null) {
- final BGPRouteEntryExportParameters baseExp
- = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
- effAttrib = routeEntryDep.getRoutingPolicies()
- .applyExportPolicies(baseExp, attributes, routeEntryDep.getAfiSafType());
- }
- Route newRoute = null;
- InstanceIdentifier ribOutRoute = null;
- if (destPeerSupAddPath) {
- newRoute = routeAddPath;
- ribOutRoute
- = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddPath);
- } else if (!this.oldNonAddPathBestPathTheSame) {
- ribOutRoute
- = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddNonPath);
- newRoute = routeNonAddPath;
- }
-
- if (effAttrib.isPresent() && newRoute != null) {
- LOG.debug("Write route {} to peer AdjRibsOut {}", newRoute, toPeer.getPeerId());
- tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute, newRoute);
- tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute.child(Attributes.class), effAttrib.get());
- } else if (ribOutRoute != null) {
- LOG.trace("Removing {} from transaction for peer {}", ribOutRoute, toPeer.getPeerId());
- tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutRoute);
- }
- }