@Test public void testFilterInterAreaRoutesToPropagateAtABR() { OspfInterAreaRoute route0 = OspfInterAreaRoute.builder() .setArea(0) .setNetwork(Prefix.ZERO) .setMetric(1) .setNextHopIp(Ip.parse("8.8.8.8")) .build(); OspfInterAreaRoute route1 = OspfInterAreaRoute.builder() .setArea(1) .setNetwork(Prefix.parse("1.0.0.0/8")) .setMetric(42) .setNextHopIp(Ip.parse("8.8.8.8")) .build(); final Ip nextHopIp = Ip.parse("9.9.9.9"); Ip neighborIp = Ip.parse("2.2.2.2"); final RibDelta<OspfInterAreaRoute> delta = RibDelta.<OspfInterAreaRoute>builder().add(route0).add(route1).build(); List<RouteAdvertisement<OspfInterAreaRoute>> transformed = filterInterAreaRoutesToPropagateAtABR( delta, AREA0_CONFIG, null, neighborIp, nextHopIp, null) .collect(Collectors.toList()); assertThat( transformed, contains( hasRoute( allOf( hasPrefix(route1.getNetwork()), hasNextHopIp(equalTo(nextHopIp)), hasMetric(route1.getMetric()))))); transformed = filterInterAreaRoutesToPropagateAtABR( delta, AREA0_CONFIG, null, neighborIp, nextHopIp, 999L) .collect(Collectors.toList()); assertThat( transformed, contains( hasRoute( allOf( hasPrefix(route1.getNetwork()), hasNextHopIp(equalTo(nextHopIp)), hasMetric(999L))))); transformed = filterInterAreaRoutesToPropagateAtABR( delta, AREA0_CONFIG, new RouteFilterList( "filter", ImmutableList.of( new RouteFilterLine( LineAction.DENY, Prefix.parse("1.0.0.0/8"), SubRange.singleton(8)))), neighborIp, nextHopIp, 999L) .collect(Collectors.toList()); assertThat(transformed, empty()); transformed = filterInterAreaRoutesToPropagateAtABR( delta, OspfArea.builder() .setStub(StubSettings.builder().setSuppressType3(true).build()) .setNumber(2) .build(), null, neighborIp, nextHopIp, null) .collect(Collectors.toList()); assertThat(transformed, empty()); transformed = filterInterAreaRoutesToPropagateAtABR( delta, OspfArea.builder() .setNssa(NssaSettings.builder().setSuppressType3(true).build()) .setNumber(2) .build(), null, neighborIp, nextHopIp, null) .collect(Collectors.toList()); assertThat(transformed, empty()); }
@Nonnull @VisibleForTesting static Stream<RouteAdvertisement<OspfInterAreaRoute>> filterInterAreaRoutesToPropagateAtABR( RibDelta<OspfInterAreaRoute> delta, OspfArea areaConfig, @Nullable RouteFilterList filterList, Ip neighborIp, Ip nextHopIp, @Nullable Long customMetric) { if (areaConfig.getStubType() == StubType.STUB && areaConfig.getStub().getSuppressType3() || areaConfig.getStubType() == StubType.NSSA && areaConfig.getNssa().getSuppressType3()) { return Stream.empty(); } return delta .getActions() .filter(r -> r.getRoute().getArea() != areaConfig.getAreaNumber()) .filter(r -> !r.getRoute().getNextHopIp().equals(neighborIp)) .filter(r -> filterList == null || filterList.permits(r.getRoute().getNetwork())) .map( r -> r.toBuilder() .setRoute( r.getRoute() .toBuilder() .setArea(areaConfig.getAreaNumber()) .setMetric(firstNonNull(customMetric, r.getRoute().getMetric())) .setNextHopIp(nextHopIp) .build()) .build()); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting static Stream<RouteAdvertisement<OspfInterAreaRoute>> filterInterAreaRoutesToPropagateAtABR( RibDelta<OspfInterAreaRoute> delta, OspfArea areaConfig, @Nullable RouteFilterList filterList, Ip neighborIp, Ip nextHopIp, @Nullable Long customMetric) { if (areaConfig.getStubType() == StubType.STUB && areaConfig.getStub().getSuppressType3() || areaConfig.getStubType() == StubType.NSSA && areaConfig.getNssa().getSuppressType3()) { return Stream.empty(); } return delta .getActions() .filter(r -> r.getRoute().getArea() != areaConfig.getAreaNumber()) .filter(r -> !r.getRoute().getNextHopIp().equals(neighborIp)) .filter(r -> filterList == null || filterList.permits(r.getRoute().getNetwork())) .map( r -> r.toBuilder() .setRoute( r.getRoute() .toBuilder() .setArea(areaConfig.getAreaNumber()) .setMetric(firstNonNull(customMetric, r.getRoute().getMetric())) .setNextHopIp(nextHopIp) .build()) .build()); } }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting static Stream<RouteAdvertisement<OspfInterAreaRoute>> filterInterAreaRoutesToPropagateAtABR( RibDelta<OspfInterAreaRoute> delta, OspfArea areaConfig, @Nullable RouteFilterList filterList, Ip neighborIp, Ip nextHopIp, @Nullable Long customMetric) { if (areaConfig.getStubType() == StubType.STUB && areaConfig.getStub().getSuppressType3() || areaConfig.getStubType() == StubType.NSSA && areaConfig.getNssa().getSuppressType3()) { return Stream.empty(); } return delta .getActions() .filter(r -> r.getRoute().getArea() != areaConfig.getAreaNumber()) .filter(r -> !r.getRoute().getNextHopIp().equals(neighborIp)) .filter(r -> filterList == null || filterList.permits(r.getRoute().getNetwork())) .map( r -> r.toBuilder() .setRoute( r.getRoute() .toBuilder() .setArea(areaConfig.getAreaNumber()) .setMetric(firstNonNull(customMetric, r.getRoute().getMetric())) .setNextHopIp(nextHopIp) .build()) .build()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting static Stream<RouteAdvertisement<OspfInterAreaRoute>> filterInterAreaRoutesToPropagateAtABR( RibDelta<OspfInterAreaRoute> delta, OspfArea areaConfig, @Nullable RouteFilterList filterList, Ip neighborIp, Ip nextHopIp, @Nullable Long customMetric) { if (areaConfig.getStubType() == StubType.STUB && areaConfig.getStub().getSuppressType3() || areaConfig.getStubType() == StubType.NSSA && areaConfig.getNssa().getSuppressType3()) { return Stream.empty(); } return delta .getActions() .filter(r -> r.getRoute().getArea() != areaConfig.getAreaNumber()) .filter(r -> !r.getRoute().getNextHopIp().equals(neighborIp)) .filter(r -> filterList == null || filterList.permits(r.getRoute().getNetwork())) .map( r -> r.toBuilder() .setRoute( r.getRoute() .toBuilder() .setArea(areaConfig.getAreaNumber()) .setMetric(firstNonNull(customMetric, r.getRoute().getMetric())) .setNextHopIp(nextHopIp) .build()) .build()); } 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 static Stream<RouteAdvertisement<OspfInterAreaRoute>> filterInterAreaRoutesToPropagateAtABR( RibDelta<OspfInterAreaRoute> delta, OspfArea areaConfig, @Nullable RouteFilterList filterList, Ip neighborIp, Ip nextHopIp, @Nullable Long customMetric) { if (areaConfig.getStubType() == StubType.STUB && areaConfig.getStub().getSuppressType3() || areaConfig.getStubType() == StubType.NSSA && areaConfig.getNssa().getSuppressType3()) { return Stream.empty(); } return delta .getActions() .filter(r -> r.getRoute().getArea() != areaConfig.getAreaNumber()) .filter(r -> !r.getRoute().getNextHopIp().equals(neighborIp)) .filter(r -> filterList == null || filterList.permits(r.getRoute().getNetwork())) .map( r -> r.toBuilder() .setRoute( r.getRoute() .toBuilder() .setArea(areaConfig.getAreaNumber()) .setMetric(firstNonNull(customMetric, r.getRoute().getMetric())) .setNextHopIp(nextHopIp) .build()) .build()); } 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();  }