@Test public void testIsValidBgpPeerInterfaceNeighbor() { Set<Ip> validLocalIps = ImmutableSet.of(LINK_LOCAL_IP); BgpUnnumberedPeerConfig invalidPeer = BgpUnnumberedPeerConfig.builder() .setPeerInterface("iface") .setRemoteAs(1L) .setLocalIp(Ip.parse("2.2.2.2")) .setLocalAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpUnnumberedPeerConfig validPeer = BgpUnnumberedPeerConfig.builder() .setPeerInterface("iface") .setRemoteAs(1L) .setLocalIp(LINK_LOCAL_IP) .setLocalAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); assertFalse( IspModelingUtils.isValidBgpPeerConfig( invalidPeer, validLocalIps, ImmutableSet.of(), ALL_AS_NUMBERS)); assertTrue( IspModelingUtils.isValidBgpPeerConfig( validPeer, validLocalIps, ImmutableSet.of(), ALL_AS_NUMBERS)); }
@VisibleForTesting static boolean isValidBgpPeerConfig( @Nonnull BgpPeerConfig bgpPeerConfig, @Nonnull Set<Ip> localIps, @Nonnull Set<Ip> remoteIps, @Nonnull LongSpace remoteAsns) { boolean commonCriteria = Objects.nonNull(bgpPeerConfig.getLocalIp()) && Objects.nonNull(bgpPeerConfig.getLocalAs()) && !bgpPeerConfig.getRemoteAsns().equals(LongSpace.of(bgpPeerConfig.getLocalAs())) && localIps.contains(bgpPeerConfig.getLocalIp()) && !remoteAsns.intersection(bgpPeerConfig.getRemoteAsns()).isEmpty(); if (!commonCriteria) { return false; } if (bgpPeerConfig instanceof BgpActivePeerConfig) { BgpActivePeerConfig activePeerConfig = (BgpActivePeerConfig) bgpPeerConfig; return Objects.nonNull(activePeerConfig.getPeerAddress()) && (remoteIps.isEmpty() || remoteIps.contains(activePeerConfig.getPeerAddress())); } else if (bgpPeerConfig instanceof BgpUnnumberedPeerConfig) { return true; } else { return false; } }
IspModelingUtils { @VisibleForTesting static boolean isValidBgpPeerConfig( @Nonnull BgpPeerConfig bgpPeerConfig, @Nonnull Set<Ip> localIps, @Nonnull Set<Ip> remoteIps, @Nonnull LongSpace remoteAsns) { boolean commonCriteria = Objects.nonNull(bgpPeerConfig.getLocalIp()) && Objects.nonNull(bgpPeerConfig.getLocalAs()) && !bgpPeerConfig.getRemoteAsns().equals(LongSpace.of(bgpPeerConfig.getLocalAs())) && localIps.contains(bgpPeerConfig.getLocalIp()) && !remoteAsns.intersection(bgpPeerConfig.getRemoteAsns()).isEmpty(); if (!commonCriteria) { return false; } if (bgpPeerConfig instanceof BgpActivePeerConfig) { BgpActivePeerConfig activePeerConfig = (BgpActivePeerConfig) bgpPeerConfig; return Objects.nonNull(activePeerConfig.getPeerAddress()) && (remoteIps.isEmpty() || remoteIps.contains(activePeerConfig.getPeerAddress())); } else if (bgpPeerConfig instanceof BgpUnnumberedPeerConfig) { return true; } else { return false; } } }
IspModelingUtils { @VisibleForTesting static boolean isValidBgpPeerConfig( @Nonnull BgpPeerConfig bgpPeerConfig, @Nonnull Set<Ip> localIps, @Nonnull Set<Ip> remoteIps, @Nonnull LongSpace remoteAsns) { boolean commonCriteria = Objects.nonNull(bgpPeerConfig.getLocalIp()) && Objects.nonNull(bgpPeerConfig.getLocalAs()) && !bgpPeerConfig.getRemoteAsns().equals(LongSpace.of(bgpPeerConfig.getLocalAs())) && localIps.contains(bgpPeerConfig.getLocalIp()) && !remoteAsns.intersection(bgpPeerConfig.getRemoteAsns()).isEmpty(); if (!commonCriteria) { return false; } if (bgpPeerConfig instanceof BgpActivePeerConfig) { BgpActivePeerConfig activePeerConfig = (BgpActivePeerConfig) bgpPeerConfig; return Objects.nonNull(activePeerConfig.getPeerAddress()) && (remoteIps.isEmpty() || remoteIps.contains(activePeerConfig.getPeerAddress())); } else if (bgpPeerConfig instanceof BgpUnnumberedPeerConfig) { return true; } else { return false; } } private  IspModelingUtils(); }
IspModelingUtils { @VisibleForTesting static boolean isValidBgpPeerConfig( @Nonnull BgpPeerConfig bgpPeerConfig, @Nonnull Set<Ip> localIps, @Nonnull Set<Ip> remoteIps, @Nonnull LongSpace remoteAsns) { boolean commonCriteria = Objects.nonNull(bgpPeerConfig.getLocalIp()) && Objects.nonNull(bgpPeerConfig.getLocalAs()) && !bgpPeerConfig.getRemoteAsns().equals(LongSpace.of(bgpPeerConfig.getLocalAs())) && localIps.contains(bgpPeerConfig.getLocalIp()) && !remoteAsns.intersection(bgpPeerConfig.getRemoteAsns()).isEmpty(); if (!commonCriteria) { return false; } if (bgpPeerConfig instanceof BgpActivePeerConfig) { BgpActivePeerConfig activePeerConfig = (BgpActivePeerConfig) bgpPeerConfig; return Objects.nonNull(activePeerConfig.getPeerAddress()) && (remoteIps.isEmpty() || remoteIps.contains(activePeerConfig.getPeerAddress())); } else if (bgpPeerConfig instanceof BgpUnnumberedPeerConfig) { return true; } else { return false; } } private  IspModelingUtils(); static String getDefaultIspNodeName(long asn); static String internetToIspInterfaceName(String ispHostname); static String ispToRemoteInterfaceName(String remoteHostname, String remoteInterfaceName); static ModeledNodes getInternetAndIspNodes(
      @Nonnull Map<String, Configuration> configurations,
      @Nonnull List<IspConfiguration> ispConfigurations,
      @Nonnull BatfishLogger logger,
      @Nonnull Warnings warnings); static RoutingPolicy installRoutingPolicyAdvertiseStatic(
      String policyName, Configuration node, PrefixSpace prefixSpace); static Statement getAdvertiseStaticStatement(PrefixSpace prefixSpace); static Statement getAdvertiseBgpStatement(); }
IspModelingUtils { @VisibleForTesting static boolean isValidBgpPeerConfig( @Nonnull BgpPeerConfig bgpPeerConfig, @Nonnull Set<Ip> localIps, @Nonnull Set<Ip> remoteIps, @Nonnull LongSpace remoteAsns) { boolean commonCriteria = Objects.nonNull(bgpPeerConfig.getLocalIp()) && Objects.nonNull(bgpPeerConfig.getLocalAs()) && !bgpPeerConfig.getRemoteAsns().equals(LongSpace.of(bgpPeerConfig.getLocalAs())) && localIps.contains(bgpPeerConfig.getLocalIp()) && !remoteAsns.intersection(bgpPeerConfig.getRemoteAsns()).isEmpty(); if (!commonCriteria) { return false; } if (bgpPeerConfig instanceof BgpActivePeerConfig) { BgpActivePeerConfig activePeerConfig = (BgpActivePeerConfig) bgpPeerConfig; return Objects.nonNull(activePeerConfig.getPeerAddress()) && (remoteIps.isEmpty() || remoteIps.contains(activePeerConfig.getPeerAddress())); } else if (bgpPeerConfig instanceof BgpUnnumberedPeerConfig) { return true; } else { return false; } } private  IspModelingUtils(); static String getDefaultIspNodeName(long asn); static String internetToIspInterfaceName(String ispHostname); static String ispToRemoteInterfaceName(String remoteHostname, String remoteInterfaceName); static ModeledNodes getInternetAndIspNodes(
      @Nonnull Map<String, Configuration> configurations,
      @Nonnull List<IspConfiguration> ispConfigurations,
      @Nonnull BatfishLogger logger,
      @Nonnull Warnings warnings); static RoutingPolicy installRoutingPolicyAdvertiseStatic(
      String policyName, Configuration node, PrefixSpace prefixSpace); static Statement getAdvertiseStaticStatement(PrefixSpace prefixSpace); static Statement getAdvertiseBgpStatement(); static final String INTERNET_HOST_NAME; static final String INTERNET_OUT_INTERFACE; static final Set<Prefix> INTERNET_NULL_ROUTED_PREFIXES; }