@Test public void testComputeAsPair() { assertPair(null, null, ALL_AS_NUMBERS, 3L, null, ALL_AS_NUMBERS, null); assertPair(1L, null, ALL_AS_NUMBERS, null, null, ALL_AS_NUMBERS, null); assertPair( 1L, null, ALL_AS_NUMBERS, 2L, null, ALL_AS_NUMBERS, new AsPair(1, 2, ConfedSessionType.NO_CONFED)); assertPair( 1L, null, LongSpace.of(2), 2L, null, LongSpace.of(1), new AsPair(1, 2, ConfedSessionType.NO_CONFED)); assertPair(1L, null, LongSpace.of(2), 2L, null, LongSpace.of(3), null); assertPair( 1L, 55L, LongSpace.of(2), 2L, 55L, LongSpace.of(1), new AsPair(1, 2, ConfedSessionType.WITHIN_CONFED)); assertPair( 1L, 55L, LongSpace.of(56), 2L, 56L, LongSpace.of(55), new AsPair(55, 56, ConfedSessionType.ACROSS_CONFED_BORDER)); assertPair( 1L, 3L, LongSpace.of(4), 4L, null, LongSpace.of(3L), new AsPair(3, 4, ConfedSessionType.ACROSS_CONFED_BORDER)); assertPair(1L, 3L, LongSpace.of(4), 4L, null, LongSpace.of(5), null); assertPair(1L, 3L, LongSpace.of(4), 4L, 9L, LongSpace.of(5), null); assertPair( 1L, 3L, LongSpace.of(1L), 1L, null, LongSpace.of(1L), new AsPair(1, 1, ConfedSessionType.WITHIN_CONFED)); assertPair(1L, 3L, LongSpace.of(2L), 1L, null, LongSpace.of(1L), null); assertPair(1L, 3L, LongSpace.of(1L), 1L, null, LongSpace.of(2L), null); assertPair(1L, 3L, LongSpace.of(4), 4L, 9L, LongSpace.of(1), null); }
@Nullable @VisibleForTesting static AsPair computeAsPair( @Nullable Long initiatorLocalAs, @Nullable Long initiatorConfed, @Nonnull LongSpace initiatorRemoteAsns, @Nullable Long listenerLocalAs, @Nullable Long listenerConfed, @Nonnull LongSpace listenerRemoteAsns) { if (initiatorLocalAs == null || listenerLocalAs == null) { return null; } if (initiatorConfed == null && listenerConfed == null) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.NO_CONFED); } else { return null; } } if (initiatorConfed != null && listenerConfed != null) { if (initiatorConfed.equals(listenerConfed)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else { if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair( initiatorConfed, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } } if (initiatorConfed != null) { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorConfed, listenerLocalAs, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } else { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair(initiatorLocalAs, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } } return null; }
BgpTopologyUtils { @Nullable @VisibleForTesting static AsPair computeAsPair( @Nullable Long initiatorLocalAs, @Nullable Long initiatorConfed, @Nonnull LongSpace initiatorRemoteAsns, @Nullable Long listenerLocalAs, @Nullable Long listenerConfed, @Nonnull LongSpace listenerRemoteAsns) { if (initiatorLocalAs == null || listenerLocalAs == null) { return null; } if (initiatorConfed == null && listenerConfed == null) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.NO_CONFED); } else { return null; } } if (initiatorConfed != null && listenerConfed != null) { if (initiatorConfed.equals(listenerConfed)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else { if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair( initiatorConfed, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } } if (initiatorConfed != null) { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorConfed, listenerLocalAs, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } else { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair(initiatorLocalAs, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } } return null; } }
BgpTopologyUtils { @Nullable @VisibleForTesting static AsPair computeAsPair( @Nullable Long initiatorLocalAs, @Nullable Long initiatorConfed, @Nonnull LongSpace initiatorRemoteAsns, @Nullable Long listenerLocalAs, @Nullable Long listenerConfed, @Nonnull LongSpace listenerRemoteAsns) { if (initiatorLocalAs == null || listenerLocalAs == null) { return null; } if (initiatorConfed == null && listenerConfed == null) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.NO_CONFED); } else { return null; } } if (initiatorConfed != null && listenerConfed != null) { if (initiatorConfed.equals(listenerConfed)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else { if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair( initiatorConfed, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } } if (initiatorConfed != null) { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorConfed, listenerLocalAs, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } else { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair(initiatorLocalAs, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } } return null; } private  BgpTopologyUtils(); }
BgpTopologyUtils { @Nullable @VisibleForTesting static AsPair computeAsPair( @Nullable Long initiatorLocalAs, @Nullable Long initiatorConfed, @Nonnull LongSpace initiatorRemoteAsns, @Nullable Long listenerLocalAs, @Nullable Long listenerConfed, @Nonnull LongSpace listenerRemoteAsns) { if (initiatorLocalAs == null || listenerLocalAs == null) { return null; } if (initiatorConfed == null && listenerConfed == null) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.NO_CONFED); } else { return null; } } if (initiatorConfed != null && listenerConfed != null) { if (initiatorConfed.equals(listenerConfed)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else { if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair( initiatorConfed, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } } if (initiatorConfed != null) { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorConfed, listenerLocalAs, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } else { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair(initiatorLocalAs, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } } return null; } private  BgpTopologyUtils(); static @Nonnull BgpTopology initBgpTopology(
      Map<String, Configuration> configurations,
      Map<Ip, Map<String, Set<String>>> ipOwners,
      boolean keepInvalid,
      @Nullable Layer2Topology layer2Topology); static @Nonnull BgpTopology initBgpTopology(
      Map<String, Configuration> configurations,
      Map<Ip, Map<String, Set<String>>> ipVrfOwners,
      boolean keepInvalid,
      boolean checkReachability,
      @Nullable TracerouteEngine tracerouteEngine,
      @Nullable Layer2Topology layer2Topology); @VisibleForTesting static boolean isReachableBgpNeighbor(
      @Nonnull BgpPeerConfigId initiatorId,
      @Nonnull BgpPeerConfigId listenerId,
      @Nonnull BgpActivePeerConfig initiator,
      @Nonnull TracerouteEngine tracerouteEngine); }
BgpTopologyUtils { @Nullable @VisibleForTesting static AsPair computeAsPair( @Nullable Long initiatorLocalAs, @Nullable Long initiatorConfed, @Nonnull LongSpace initiatorRemoteAsns, @Nullable Long listenerLocalAs, @Nullable Long listenerConfed, @Nonnull LongSpace listenerRemoteAsns) { if (initiatorLocalAs == null || listenerLocalAs == null) { return null; } if (initiatorConfed == null && listenerConfed == null) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.NO_CONFED); } else { return null; } } if (initiatorConfed != null && listenerConfed != null) { if (initiatorConfed.equals(listenerConfed)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else { if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair( initiatorConfed, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } } if (initiatorConfed != null) { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorConfed) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorConfed, listenerLocalAs, ConfedSessionType.ACROSS_CONFED_BORDER); } else { return null; } } else { if (initiatorLocalAs.equals(listenerLocalAs)) { if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerLocalAs)) { return new AsPair(initiatorLocalAs, listenerLocalAs, ConfedSessionType.WITHIN_CONFED); } else { return null; } } else if (listenerRemoteAsns.contains(initiatorLocalAs) && initiatorRemoteAsns.contains(listenerConfed)) { return new AsPair(initiatorLocalAs, listenerConfed, ConfedSessionType.ACROSS_CONFED_BORDER); } } return null; } private  BgpTopologyUtils(); static @Nonnull BgpTopology initBgpTopology(
      Map<String, Configuration> configurations,
      Map<Ip, Map<String, Set<String>>> ipOwners,
      boolean keepInvalid,
      @Nullable Layer2Topology layer2Topology); static @Nonnull BgpTopology initBgpTopology(
      Map<String, Configuration> configurations,
      Map<Ip, Map<String, Set<String>>> ipVrfOwners,
      boolean keepInvalid,
      boolean checkReachability,
      @Nullable TracerouteEngine tracerouteEngine,
      @Nullable Layer2Topology layer2Topology); @VisibleForTesting static boolean isReachableBgpNeighbor(
      @Nonnull BgpPeerConfigId initiatorId,
      @Nonnull BgpPeerConfigId listenerId,
      @Nonnull BgpActivePeerConfig initiator,
      @Nonnull TracerouteEngine tracerouteEngine);  }