@Test public void testGetAddressFamilyIntersection() { Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("2.2.2.2"); BgpActivePeerConfig.Builder peerBuilder = BgpActivePeerConfig.builder() .setLocalIp(ip1) .setLocalAs(1L) .setRemoteAs(2L) .setPeerAddress(ip2) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setAddressFamilyCapabilities( AddressFamilyCapabilities.builder().setAdvertiseInactive(true).build()) .build()); BgpActivePeerConfig peer1 = peerBuilder.build(); assertThat(getAddressFamilyIntersection(peer1, peer1), contains(Type.IPV4_UNICAST)); assertThat( getAddressFamilyIntersection( peer1, peerBuilder .setEvpnAddressFamily( EvpnAddressFamily.builder() .setL2Vnis(ImmutableSet.of()) .setL3Vnis(ImmutableSet.of()) .setPropagateUnmatched(true) .build()) .build()), contains(Type.IPV4_UNICAST)); assertThat( getAddressFamilyIntersection(peer1, peerBuilder.setIpv4UnicastAddressFamily(null).build()), empty()); }
@VisibleForTesting static EnumSet<Type> getAddressFamilyIntersection(BgpPeerConfig a, BgpPeerConfig b) { Set<Type> setA = a.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Set<Type> setB = b.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Collection<Type> intersection = Sets.intersection(setA, setB); return intersection.isEmpty() ? EnumSet.noneOf(Type.class) : EnumSet.copyOf(intersection); }
BgpSessionProperties { @VisibleForTesting static EnumSet<Type> getAddressFamilyIntersection(BgpPeerConfig a, BgpPeerConfig b) { Set<Type> setA = a.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Set<Type> setB = b.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Collection<Type> intersection = Sets.intersection(setA, setB); return intersection.isEmpty() ? EnumSet.noneOf(Type.class) : EnumSet.copyOf(intersection); } }
BgpSessionProperties { @VisibleForTesting static EnumSet<Type> getAddressFamilyIntersection(BgpPeerConfig a, BgpPeerConfig b) { Set<Type> setA = a.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Set<Type> setB = b.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Collection<Type> intersection = Sets.intersection(setA, setB); return intersection.isEmpty() ? EnumSet.noneOf(Type.class) : EnumSet.copyOf(intersection); } private  BgpSessionProperties(
      Collection<Type> addressFamilies,
      Map<Type, RouteExchange> routeExchangeSettings,
      long tailAs,
      long headAs,
      Ip tailIp,
      Ip headIp,
      SessionType sessionType,
      ConfedSessionType confedType); }
BgpSessionProperties { @VisibleForTesting static EnumSet<Type> getAddressFamilyIntersection(BgpPeerConfig a, BgpPeerConfig b) { Set<Type> setA = a.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Set<Type> setB = b.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Collection<Type> intersection = Sets.intersection(setA, setB); return intersection.isEmpty() ? EnumSet.noneOf(Type.class) : EnumSet.copyOf(intersection); } private  BgpSessionProperties(
      Collection<Type> addressFamilies,
      Map<Type, RouteExchange> routeExchangeSettings,
      long tailAs,
      long headAs,
      Ip tailIp,
      Ip headIp,
      SessionType sessionType,
      ConfedSessionType confedType); static @Nonnull Builder builder(); @JsonIgnore boolean getAdvertiseExternal(); @JsonIgnore boolean getAdvertiseInactive(); @JsonIgnore boolean getAdditionalPaths(); @JsonIgnore boolean isEbgp(); @JsonProperty(PROP_TAIL_AS) long getTailAs(); @JsonProperty(PROP_HEAD_AS) long getHeadAs(); @JsonProperty(PROP_TAIL_IP) @Nonnull Ip getTailIp(); @JsonProperty(PROP_HEAD_IP) @Nonnull Ip getHeadIp(); @JsonProperty(PROP_SESSION_TYPE) SessionType getSessionType(); @JsonProperty(PROP_CONFEDERATION_TYPE) @Nonnull ConfedSessionType getConfedSessionType(); boolean advertiseUnchangedMed(); boolean advertiseUnchangedLocalPref(); @Nonnull @JsonProperty(PROP_ADDRESS_FAMILIES) Set<Type> getAddressFamilies(); @JsonProperty(PROP_ROUTE_EXCHANGE) @Nonnull Map<Type, RouteExchange> getRouteExchangeSettings(); static BgpSessionProperties from(
      BgpPeerConfig initiator,
      BgpPeerConfig listener,
      boolean reverseDirection,
      long initiatorLocalAs,
      long listenerLocalAs,
      ConfedSessionType confedSessionType); @VisibleForTesting static BgpSessionProperties from(
      BgpPeerConfig initiator, BgpPeerConfig listener, boolean reverseDirection); static @Nonnull SessionType getSessionType(BgpPeerConfig initiator); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); }
BgpSessionProperties { @VisibleForTesting static EnumSet<Type> getAddressFamilyIntersection(BgpPeerConfig a, BgpPeerConfig b) { Set<Type> setA = a.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Set<Type> setB = b.getAllAddressFamilies().stream() .map(AddressFamily::getType) .collect(Sets.toImmutableEnumSet()); Collection<Type> intersection = Sets.intersection(setA, setB); return intersection.isEmpty() ? EnumSet.noneOf(Type.class) : EnumSet.copyOf(intersection); } private  BgpSessionProperties(
      Collection<Type> addressFamilies,
      Map<Type, RouteExchange> routeExchangeSettings,
      long tailAs,
      long headAs,
      Ip tailIp,
      Ip headIp,
      SessionType sessionType,
      ConfedSessionType confedType); static @Nonnull Builder builder(); @JsonIgnore boolean getAdvertiseExternal(); @JsonIgnore boolean getAdvertiseInactive(); @JsonIgnore boolean getAdditionalPaths(); @JsonIgnore boolean isEbgp(); @JsonProperty(PROP_TAIL_AS) long getTailAs(); @JsonProperty(PROP_HEAD_AS) long getHeadAs(); @JsonProperty(PROP_TAIL_IP) @Nonnull Ip getTailIp(); @JsonProperty(PROP_HEAD_IP) @Nonnull Ip getHeadIp(); @JsonProperty(PROP_SESSION_TYPE) SessionType getSessionType(); @JsonProperty(PROP_CONFEDERATION_TYPE) @Nonnull ConfedSessionType getConfedSessionType(); boolean advertiseUnchangedMed(); boolean advertiseUnchangedLocalPref(); @Nonnull @JsonProperty(PROP_ADDRESS_FAMILIES) Set<Type> getAddressFamilies(); @JsonProperty(PROP_ROUTE_EXCHANGE) @Nonnull Map<Type, RouteExchange> getRouteExchangeSettings(); static BgpSessionProperties from(
      BgpPeerConfig initiator,
      BgpPeerConfig listener,
      boolean reverseDirection,
      long initiatorLocalAs,
      long listenerLocalAs,
      ConfedSessionType confedSessionType); @VisibleForTesting static BgpSessionProperties from(
      BgpPeerConfig initiator, BgpPeerConfig listener, boolean reverseDirection); static @Nonnull SessionType getSessionType(BgpPeerConfig initiator); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString();  }