@Test public void testTransformType1RouteOnExportWithMetricOverride() { final long overrideMetric = 8888L; Builder ospfProcess = OspfProcess.builder() .setRouterId(Ip.ZERO) .setProcessId("1") .setReferenceBandwidth(10e9) .setAreas(ImmutableSortedMap.of(0L, AREA0_CONFIG)) .setMaxMetricSummaryNetworks(overrideMetric); OspfRoutingProcess routingProcess = new OspfRoutingProcess(ospfProcess.build(), VRF_NAME, _c, _emptyOspfTopology); final OspfExternalRoute.Builder builder = OspfExternalType1Route.builder() .setNetwork(Prefix.parse("2.2.2.2/32")) .setLsaMetric(10L) .setCostToAdvertiser(0L) .setAdvertiser("someNode") .setArea(1L) .setAdmin(0) .setNextHopIp(Ip.parse("1.1.1.1")); Stream<RouteAdvertisement<OspfExternalType1Route>> routes = Stream.of(new RouteAdvertisement<>((OspfExternalType1Route) builder.build())); assertThat( routingProcess.transformType1RoutesOnExport(routes, AREA0_CONFIG), contains( new RouteAdvertisement<>( (OspfExternalType1Route) builder .setCostToAdvertiser(overrideMetric) .setMetric(overrideMetric + 10) .setArea(0) .build()))); assertThat( routingProcess.transformType1RoutesOnExport( Stream.of( new RouteAdvertisement<>( (OspfExternalType1Route) builder.setArea(OspfRoute.NO_AREA).build())), AREA0_CONFIG), contains(new RouteAdvertisement<>((OspfExternalType1Route) builder.setArea(0).build()))); }
@Nonnull @VisibleForTesting Collection<RouteAdvertisement<OspfExternalType1Route>> transformType1RoutesOnExport( Stream<RouteAdvertisement<OspfExternalType1Route>> routeAdvertisements, OspfArea areaConfig) { Long metricOverride = _process.getMaxMetricSummaryNetworks(); return routeAdvertisements .filter( r -> r.getRoute().getArea() == 0 || areaConfig.getAreaNumber() == 0 || r.getRoute().getArea() == areaConfig.getAreaNumber() || r.getRoute().getArea() == OspfRoute.NO_AREA) .map( r -> { final OspfExternalType1Route route = r.getRoute(); return r.toBuilder() .setRoute( (OspfExternalType1Route) route .toBuilder() .setMetric( metricOverride != null && route.getArea() != OspfRoute.NO_AREA && areaConfig.getAreaNumber() != route.getArea() ? metricOverride + route.getLsaMetric() : route.getMetric()) .setCostToAdvertiser( firstNonNull(metricOverride, route.getCostToAdvertiser())) .setArea(areaConfig.getAreaNumber()) .build()) .build(); }) .collect(ImmutableSet.toImmutableSet()); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Collection<RouteAdvertisement<OspfExternalType1Route>> transformType1RoutesOnExport( Stream<RouteAdvertisement<OspfExternalType1Route>> routeAdvertisements, OspfArea areaConfig) { Long metricOverride = _process.getMaxMetricSummaryNetworks(); return routeAdvertisements .filter( r -> r.getRoute().getArea() == 0 || areaConfig.getAreaNumber() == 0 || r.getRoute().getArea() == areaConfig.getAreaNumber() || r.getRoute().getArea() == OspfRoute.NO_AREA) .map( r -> { final OspfExternalType1Route route = r.getRoute(); return r.toBuilder() .setRoute( (OspfExternalType1Route) route .toBuilder() .setMetric( metricOverride != null && route.getArea() != OspfRoute.NO_AREA && areaConfig.getAreaNumber() != route.getArea() ? metricOverride + route.getLsaMetric() : route.getMetric()) .setCostToAdvertiser( firstNonNull(metricOverride, route.getCostToAdvertiser())) .setArea(areaConfig.getAreaNumber()) .build()) .build(); }) .collect(ImmutableSet.toImmutableSet()); } }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Collection<RouteAdvertisement<OspfExternalType1Route>> transformType1RoutesOnExport( Stream<RouteAdvertisement<OspfExternalType1Route>> routeAdvertisements, OspfArea areaConfig) { Long metricOverride = _process.getMaxMetricSummaryNetworks(); return routeAdvertisements .filter( r -> r.getRoute().getArea() == 0 || areaConfig.getAreaNumber() == 0 || r.getRoute().getArea() == areaConfig.getAreaNumber() || r.getRoute().getArea() == OspfRoute.NO_AREA) .map( r -> { final OspfExternalType1Route route = r.getRoute(); return r.toBuilder() .setRoute( (OspfExternalType1Route) route .toBuilder() .setMetric( metricOverride != null && route.getArea() != OspfRoute.NO_AREA && areaConfig.getAreaNumber() != route.getArea() ? metricOverride + route.getLsaMetric() : route.getMetric()) .setCostToAdvertiser( firstNonNull(metricOverride, route.getCostToAdvertiser())) .setArea(areaConfig.getAreaNumber()) .build()) .build(); }) .collect(ImmutableSet.toImmutableSet()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Collection<RouteAdvertisement<OspfExternalType1Route>> transformType1RoutesOnExport( Stream<RouteAdvertisement<OspfExternalType1Route>> routeAdvertisements, OspfArea areaConfig) { Long metricOverride = _process.getMaxMetricSummaryNetworks(); return routeAdvertisements .filter( r -> r.getRoute().getArea() == 0 || areaConfig.getAreaNumber() == 0 || r.getRoute().getArea() == areaConfig.getAreaNumber() || r.getRoute().getArea() == OspfRoute.NO_AREA) .map( r -> { final OspfExternalType1Route route = r.getRoute(); return r.toBuilder() .setRoute( (OspfExternalType1Route) route .toBuilder() .setMetric( metricOverride != null && route.getArea() != OspfRoute.NO_AREA && areaConfig.getAreaNumber() != route.getArea() ? metricOverride + route.getLsaMetric() : route.getMetric()) .setCostToAdvertiser( firstNonNull(metricOverride, route.getCostToAdvertiser())) .setArea(areaConfig.getAreaNumber()) .build()) .build(); }) .collect(ImmutableSet.toImmutableSet()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); @Override void initialize(Node n); @Override void executeIteration(Map<String, Node> allNodes); @Override void updateTopology(OspfTopology topology); @Nonnull @Override RibDelta<OspfRoute> getUpdatesForMainRib(); @Override void redistribute(RibDelta<? extends AnnotatedRoute<AbstractRoute>> mainRibDelta); @Override boolean isDirty(); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Collection<RouteAdvertisement<OspfExternalType1Route>> transformType1RoutesOnExport( Stream<RouteAdvertisement<OspfExternalType1Route>> routeAdvertisements, OspfArea areaConfig) { Long metricOverride = _process.getMaxMetricSummaryNetworks(); return routeAdvertisements .filter( r -> r.getRoute().getArea() == 0 || areaConfig.getAreaNumber() == 0 || r.getRoute().getArea() == areaConfig.getAreaNumber() || r.getRoute().getArea() == OspfRoute.NO_AREA) .map( r -> { final OspfExternalType1Route route = r.getRoute(); return r.toBuilder() .setRoute( (OspfExternalType1Route) route .toBuilder() .setMetric( metricOverride != null && route.getArea() != OspfRoute.NO_AREA && areaConfig.getAreaNumber() != route.getArea() ? metricOverride + route.getLsaMetric() : route.getMetric()) .setCostToAdvertiser( firstNonNull(metricOverride, route.getCostToAdvertiser())) .setArea(areaConfig.getAreaNumber()) .build()) .build(); }) .collect(ImmutableSet.toImmutableSet()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); @Override void initialize(Node n); @Override void executeIteration(Map<String, Node> allNodes); @Override void updateTopology(OspfTopology topology); @Nonnull @Override RibDelta<OspfRoute> getUpdatesForMainRib(); @Override void redistribute(RibDelta<? extends AnnotatedRoute<AbstractRoute>> mainRibDelta); @Override boolean isDirty();  }