@Test public void testBestPathComparator_ClusterListAsIgpCost() { BgpRib<Bgpv4Route> rib = new Bgpv4Rib(null, BgpTieBreaker.ROUTER_ID, 1, null, false, true); Bgpv4Route.Builder rb = Bgpv4Route.builder() .setNetwork(Prefix.ZERO) .setNextHopIp(Ip.ZERO) .setOriginType(OriginType.IGP) .setOriginatorIp(Ip.ZERO) .setProtocol(RoutingProtocol.IBGP); List<Ip> decreasingIps = ImmutableList.of(Ip.parse("1.1.1.1"), Ip.ZERO); List<Set<Long>> decreasingLengthClusterLists = ImmutableList.of(ImmutableSet.of(1L, 2L), ImmutableSet.of(1L), ImmutableSet.of()); List<Bgpv4Route> ordered = new ArrayList<>(); for (Set<Long> clusterList : decreasingLengthClusterLists) { rb.setClusterList(clusterList); for (Ip originatorIp : decreasingIps) { rb.setOriginatorIp(originatorIp); ordered.add(rb.setReceivedFromIp(null).build()); for (Ip receivedFromIp : decreasingIps) { ordered.add(rb.setReceivedFromIp(receivedFromIp).build()); } } } for (int i = 0; i < ordered.size(); i++) { for (int j = 0; j < ordered.size(); j++) { assertThat( Integer.signum(rib.comparePreference(ordered.get(i), (ordered.get(j)))), equalTo(Integer.signum(i - j))); } } }
@Override public int comparePreference(R lhs, R rhs) { int multipathCompare = Comparator .comparing(R::getWeight) .thenComparing(R::getLocalPreference) .thenComparing(r -> getAggregatePreference(r.getProtocol())) .thenComparing(r -> r.getAsPath().length(), Comparator.reverseOrder()) .thenComparing(r -> r.getOriginType().getPreference()) .thenComparing(r -> getTypeCost(r.getProtocol())) .thenComparing(R::getMetric, Comparator.reverseOrder()) .thenComparing(this::getIgpCostToNextHopIp, Comparator.reverseOrder()) .thenComparing(this::getClusterListLength, Comparator.reverseOrder()) .thenComparing(this::compareRouteAsPath) .compare(lhs, rhs); if (multipathCompare != 0 || isMultipath()) { return multipathCompare; } else { return Comparator.comparing(Function.identity(), this::bestPathComparator).compare(lhs, rhs); } }
BgpRib extends AbstractRib<R> { @Override public int comparePreference(R lhs, R rhs) { int multipathCompare = Comparator .comparing(R::getWeight) .thenComparing(R::getLocalPreference) .thenComparing(r -> getAggregatePreference(r.getProtocol())) .thenComparing(r -> r.getAsPath().length(), Comparator.reverseOrder()) .thenComparing(r -> r.getOriginType().getPreference()) .thenComparing(r -> getTypeCost(r.getProtocol())) .thenComparing(R::getMetric, Comparator.reverseOrder()) .thenComparing(this::getIgpCostToNextHopIp, Comparator.reverseOrder()) .thenComparing(this::getClusterListLength, Comparator.reverseOrder()) .thenComparing(this::compareRouteAsPath) .compare(lhs, rhs); if (multipathCompare != 0 || isMultipath()) { return multipathCompare; } else { return Comparator.comparing(Function.identity(), this::bestPathComparator).compare(lhs, rhs); } } }
BgpRib extends AbstractRib<R> { @Override public int comparePreference(R lhs, R rhs) { int multipathCompare = Comparator .comparing(R::getWeight) .thenComparing(R::getLocalPreference) .thenComparing(r -> getAggregatePreference(r.getProtocol())) .thenComparing(r -> r.getAsPath().length(), Comparator.reverseOrder()) .thenComparing(r -> r.getOriginType().getPreference()) .thenComparing(r -> getTypeCost(r.getProtocol())) .thenComparing(R::getMetric, Comparator.reverseOrder()) .thenComparing(this::getIgpCostToNextHopIp, Comparator.reverseOrder()) .thenComparing(this::getClusterListLength, Comparator.reverseOrder()) .thenComparing(this::compareRouteAsPath) .compare(lhs, rhs); if (multipathCompare != 0 || isMultipath()) { return multipathCompare; } else { return Comparator.comparing(Function.identity(), this::bestPathComparator).compare(lhs, rhs); } } protected  BgpRib(
      @Nullable GenericRibReadOnly<AnnotatedRoute<AbstractRoute>> mainRib,
      BgpTieBreaker tieBreaker,
      @Nullable Integer maxPaths,
      @Nullable MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode,
      boolean withBackups,
      boolean clusterListAsIgpCost); }
BgpRib extends AbstractRib<R> { @Override public int comparePreference(R lhs, R rhs) { int multipathCompare = Comparator .comparing(R::getWeight) .thenComparing(R::getLocalPreference) .thenComparing(r -> getAggregatePreference(r.getProtocol())) .thenComparing(r -> r.getAsPath().length(), Comparator.reverseOrder()) .thenComparing(r -> r.getOriginType().getPreference()) .thenComparing(r -> getTypeCost(r.getProtocol())) .thenComparing(R::getMetric, Comparator.reverseOrder()) .thenComparing(this::getIgpCostToNextHopIp, Comparator.reverseOrder()) .thenComparing(this::getClusterListLength, Comparator.reverseOrder()) .thenComparing(this::compareRouteAsPath) .compare(lhs, rhs); if (multipathCompare != 0 || isMultipath()) { return multipathCompare; } else { return Comparator.comparing(Function.identity(), this::bestPathComparator).compare(lhs, rhs); } } protected  BgpRib(
      @Nullable GenericRibReadOnly<AnnotatedRoute<AbstractRoute>> mainRib,
      BgpTieBreaker tieBreaker,
      @Nullable Integer maxPaths,
      @Nullable MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode,
      boolean withBackups,
      boolean clusterListAsIgpCost); @Override int comparePreference(R lhs, R rhs); @Nonnull @Override RibDelta<R> mergeRouteGetDelta(R route); @Nonnull @Override RibDelta<R> removeRouteGetDelta(R route, Reason reason); @Override @Nonnull final Set<R> getTypedRoutes(); Set<R> getBestPathRoutes(); boolean isMultipath(); }
BgpRib extends AbstractRib<R> { @Override public int comparePreference(R lhs, R rhs) { int multipathCompare = Comparator .comparing(R::getWeight) .thenComparing(R::getLocalPreference) .thenComparing(r -> getAggregatePreference(r.getProtocol())) .thenComparing(r -> r.getAsPath().length(), Comparator.reverseOrder()) .thenComparing(r -> r.getOriginType().getPreference()) .thenComparing(r -> getTypeCost(r.getProtocol())) .thenComparing(R::getMetric, Comparator.reverseOrder()) .thenComparing(this::getIgpCostToNextHopIp, Comparator.reverseOrder()) .thenComparing(this::getClusterListLength, Comparator.reverseOrder()) .thenComparing(this::compareRouteAsPath) .compare(lhs, rhs); if (multipathCompare != 0 || isMultipath()) { return multipathCompare; } else { return Comparator.comparing(Function.identity(), this::bestPathComparator).compare(lhs, rhs); } } protected  BgpRib(
      @Nullable GenericRibReadOnly<AnnotatedRoute<AbstractRoute>> mainRib,
      BgpTieBreaker tieBreaker,
      @Nullable Integer maxPaths,
      @Nullable MultipathEquivalentAsPathMatchMode multipathEquivalentAsPathMatchMode,
      boolean withBackups,
      boolean clusterListAsIgpCost); @Override int comparePreference(R lhs, R rhs); @Nonnull @Override RibDelta<R> mergeRouteGetDelta(R route); @Nonnull @Override RibDelta<R> removeRouteGetDelta(R route, Reason reason); @Override @Nonnull final Set<R> getTypedRoutes(); Set<R> getBestPathRoutes(); boolean isMultipath();  }