/** * Remove a route from backup route map if it was present and backup route map exists * * @param route Route to remove */ public final void removeBackupRoute(R route) { if (_backupRoutes != null) { SortedSet<R> routes = _backupRoutes.get(route.getNetwork()); if (routes != null) { routes.remove(route); } } }
/** * Add route to backup route map if the route map is not null * * @param route Route to add */ public final void addBackupRoute(R route) { if (_backupRoutes != null) { _backupRoutes.computeIfAbsent(route.getNetwork(), k -> new TreeSet<>()).add(route); } }
@Override protected Prefix featureValueOf(AbstractRoute actual) { return actual.getNetwork(); } }
/** * Indicate that a route was added to the RIB * * @param route that was added */ public Builder<R> add(R route) { LinkedHashMap<R, RouteAdvertisement<R>> l = _actions.computeIfAbsent(route.getNetwork(), p -> new LinkedHashMap<>(10, 1, true)); l.put(route, new RouteAdvertisement<>(route)); return this; }
@Override public final SortedSet<Prefix> getPrefixes() { SortedSet<Prefix> prefixes = new TreeSet<>(); Set<R> routes = getRoutes(); for (R route : routes) { prefixes.add(route.getNetwork()); } return prefixes; }
@Override public Prefix evaluate(Environment env) { return env.getOriginalRoute().getNetwork(); }
/** * Indicate that multiple routes have been added to the RIB * * @param routes a collection of routes */ public Builder<R> add(Collection<? extends R> routes) { for (R route : routes) { LinkedHashMap<R, RouteAdvertisement<R>> l = _actions.computeIfAbsent(route.getNetwork(), p -> new LinkedHashMap<>(10, 1, true)); l.put(route, new RouteAdvertisement<>(route)); } return this; }
public final Set<R> getRoutes(Prefix p) { // Collect routes that match the prefix return getRoutes().stream() .filter(r -> r.getNetwork().equals(p)) .collect(ImmutableSet.toImmutableSet()); }
/** * Indicate that a route was removed from the RIB * * @param route that was removed */ public Builder<R> remove(R route, Reason reason) { LinkedHashMap<R, RouteAdvertisement<R>> l = _actions.computeIfAbsent(route.getNetwork(), p -> new LinkedHashMap<>(10, 1, true)); l.put( route, RouteAdvertisement.<R>builder() .setRoute(route) .setWithdraw(true) .setReason(reason) .build()); return this; }
/** * Remove a single route from the RIB, if it exists * * @param route route to remove * @return {@link RibDelta} if the route was removed, otherwise {@code null}; */ @Nonnull RibDelta<R> removeRouteGetDelta(R route, Reason reason) { Prefix prefix = route.getNetwork(); int prefixLength = prefix.getPrefixLength(); long bits = prefix.getStartIp().asLong(); return _root.removeRoute(route, bits, prefixLength, 0, reason); }
@Nonnull RibDelta<R> removeRoute( R route, long bits, int prefixLength, int firstUnmatchedBitIndex, Reason reason) { RibTreeNode<R> node = findRouteNode(bits, prefixLength, firstUnmatchedBitIndex); if (node == null) { // No effect, return empty return RibDelta.empty(); } Builder<R> b = RibDelta.builder(); if (node._routes.remove(route)) { b.remove(route, reason); if (node._routes.isEmpty() && _owner._backupRoutes != null) { SortedSet<? extends R> backups = _owner._backupRoutes.getOrDefault(route.getNetwork(), ImmutableSortedSet.of()); if (!backups.isEmpty()) { node._routes.add(backups.first()); b.add(backups.first()); } } } // Return new delta return b.build(); }
/** * Add a new route into the RIB, potentially replacing other routes * * @param route route to add * @return a {@link RibDelta} objects indicating which routes where added and evicted from this * RIB */ @Nonnull RibDelta<R> mergeRoute(R route) { Prefix prefix = route.getNetwork(); int prefixLength = prefix.getPrefixLength(); long bits = prefix.getStartIp().asLong(); return _root.mergeRoute(route, bits, prefixLength, 0); }
/** * Indicate that multiple routes were removed from the RIB * * @param routes that were removed */ public Builder<R> remove(Collection<R> routes, Reason reason) { for (R route : routes) { LinkedHashMap<R, RouteAdvertisement<R>> l = _actions.computeIfAbsent(route.getNetwork(), p -> new LinkedHashMap<>(10, 1, true)); l.put( route, RouteAdvertisement.<R>builder() .setRoute(route) .setWithdraw(true) .setReason(reason) .build()); } return this; }
/** * Check if a static route with next hop IP can be activated. If this method returns True, an * attempt should be made to merge it into the RIB. If it returns false, an attempt should be made * to remove it from the RIB. * * @param route a {@link StaticRoute} to check * @param rib the RIB to use for establishing routabilitity to next hop IP */ public static boolean shouldActivateNextHopIpRoute( @Nonnull StaticRoute route, @Nonnull GenericRib<AbstractRoute> rib) { Set<AbstractRoute> matchingRoutes = rib.longestPrefixMatch(route.getNextHopIp()); if (matchingRoutes.isEmpty()) { // Cannot activate, next hop ip is unreachable return false; } boolean shouldActivate = false; for (AbstractRoute routeToNextHop : matchingRoutes) { if (!routeToNextHop.getNetwork().equals(route.getNetwork()) || route.equals(routeToNextHop)) { // Next hop has to be reachable through a route with a different prefix shouldActivate = true; break; } } return shouldActivate; } }
/** * Check if the route is present in the RIB * * @param route route to find * @return true if the route exists in the RIB */ boolean containsRoute(R route) { Prefix prefix = route.getNetwork(); int prefixLength = prefix.getPrefixLength(); long bits = prefix.getStartIp().asLong(); return _root.containsRoute(route, bits, prefixLength); }
/** Process all added and removed routes from a given delta */ @Nonnull public <T extends R> Builder<R> from(@Nonnull RibDelta<T> delta) { for (RouteAdvertisement<T> a : delta.getActions()) { LinkedHashMap<R, RouteAdvertisement<R>> l = _actions.computeIfAbsent( a.getRoute().getNetwork(), p -> new LinkedHashMap<>(10, 1, true)); l.put( a.getRoute(), RouteAdvertisement.<R>builder() .setRoute(a.getRoute()) .setWithdraw(a.isWithdrawn()) .setReason(a.getReason()) .build()); } return this; } }
@Override public Result evaluate(Environment environment) { AbstractRoute route = environment.getOriginalRoute(); Prefix network = route.getNetwork(); int classSize = network.getStartIp().getClassNetworkSize(); Result ret = new Result(); ret.setBooleanValue(classSize == network.getPrefixLength()); return ret; }
outputRouteBuilder.setDestinationAsn(_asn); outputRouteBuilder.setNetwork(potentialExportRoute.getNetwork()); outputRouteBuilder.setProcessAsn(_asn); outputRouteBuilder.setNonRouting(true);
.toRoutingProtocol() .getDefaultAdministrativeCost(_c.getConfigurationFormat())); outputRouteBuilder.setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = proc.getMaxMetricExternalNetworks(); long costToAdvertiser;
/** * Converts a {@link AbstractRoute} to a {@link Row} * * @param hostName {@link String} host-name of the node containing the route * @param vrfName {@link String} name of the VRF containing the route * @param abstractRoute {@link AbstractRoute} to convert * @param columnMetadataMap Column metadata of the columns for this {@link Row} c * @return {@link Row} representing the {@link AbstractRoute} */ private static Row abstractRouteToRow( String hostName, String vrfName, AbstractRoute abstractRoute, Map<String, ColumnMetadata> columnMetadataMap, @Nullable Map<Ip, Set<String>> ipOwners) { return Row.builder(columnMetadataMap) .put(COL_NODE, new Node(hostName)) .put(COL_VRF_NAME, vrfName) .put(COL_NETWORK, abstractRoute.getNetwork()) .put(COL_NEXT_HOP_IP, abstractRoute.getNextHopIp()) .put(COL_NEXT_HOP, computeNextHopNode(abstractRoute.getNextHopIp(), ipOwners)) .put(COL_PROTOCOL, abstractRoute.getProtocol()) .put( COL_TAG, abstractRoute.getTag() == AbstractRoute.NO_TAG ? null : abstractRoute.getTag()) .put(COL_ADMIN_DISTANCE, abstractRoute.getAdministrativeCost()) .put(COL_METRIC, abstractRoute.getMetric()) .build(); }