@Test public void testAddBgpPeerToIsp_preferConfederationAs() { Ip ispIp = Ip.parse("1.1.1.1"); Ip remoteIp = Ip.parse("2.2.2.2"); BgpActivePeerConfig remotePeerConfig = BgpActivePeerConfig.builder() .setPeerAddress(ispIp) .setRemoteAs(1L) .setLocalIp(remoteIp) .setLocalAs(2L) .setConfederation(1000L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpProcess bgpProcess = new BgpProcess(Ip.ZERO, ConfigurationFormat.CISCO_IOS); addBgpPeerToIsp(remotePeerConfig, "iface", bgpProcess); BgpActivePeerConfig reversedPeer = getOnlyElement(bgpProcess.getActiveNeighbors().values()); assertThat( reversedPeer, equalTo( BgpActivePeerConfig.builder() .setLocalIp(ispIp) .setPeerAddress(remoteIp) .setLocalAs(1L) .setRemoteAs(1000L) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .build())); }
@VisibleForTesting static void addBgpPeerToIsp( BgpPeerConfig remotePeerConfig, String localInterfaceName, BgpProcess bgpProcess) { BgpPeerConfig.Builder<?, ?> ispPeerConfig = remotePeerConfig instanceof BgpActivePeerConfig ? BgpActivePeerConfig.builder() .setPeerAddress(remotePeerConfig.getLocalIp()) .setLocalIp(((BgpActivePeerConfig) remotePeerConfig).getPeerAddress()) : BgpUnnumberedPeerConfig.builder() .setPeerInterface(localInterfaceName) .setLocalIp(LINK_LOCAL_IP); ispPeerConfig .setRemoteAs( firstNonNull(remotePeerConfig.getConfederationAsn(), remotePeerConfig.getLocalAs())) .setLocalAs(remotePeerConfig.getRemoteAsns().least()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .setBgpProcess(bgpProcess) .build(); }
IspModelingUtils { @VisibleForTesting static void addBgpPeerToIsp( BgpPeerConfig remotePeerConfig, String localInterfaceName, BgpProcess bgpProcess) { BgpPeerConfig.Builder<?, ?> ispPeerConfig = remotePeerConfig instanceof BgpActivePeerConfig ? BgpActivePeerConfig.builder() .setPeerAddress(remotePeerConfig.getLocalIp()) .setLocalIp(((BgpActivePeerConfig) remotePeerConfig).getPeerAddress()) : BgpUnnumberedPeerConfig.builder() .setPeerInterface(localInterfaceName) .setLocalIp(LINK_LOCAL_IP); ispPeerConfig .setRemoteAs( firstNonNull(remotePeerConfig.getConfederationAsn(), remotePeerConfig.getLocalAs())) .setLocalAs(remotePeerConfig.getRemoteAsns().least()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .setBgpProcess(bgpProcess) .build(); } }
IspModelingUtils { @VisibleForTesting static void addBgpPeerToIsp( BgpPeerConfig remotePeerConfig, String localInterfaceName, BgpProcess bgpProcess) { BgpPeerConfig.Builder<?, ?> ispPeerConfig = remotePeerConfig instanceof BgpActivePeerConfig ? BgpActivePeerConfig.builder() .setPeerAddress(remotePeerConfig.getLocalIp()) .setLocalIp(((BgpActivePeerConfig) remotePeerConfig).getPeerAddress()) : BgpUnnumberedPeerConfig.builder() .setPeerInterface(localInterfaceName) .setLocalIp(LINK_LOCAL_IP); ispPeerConfig .setRemoteAs( firstNonNull(remotePeerConfig.getConfederationAsn(), remotePeerConfig.getLocalAs())) .setLocalAs(remotePeerConfig.getRemoteAsns().least()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .setBgpProcess(bgpProcess) .build(); } private  IspModelingUtils(); }
IspModelingUtils { @VisibleForTesting static void addBgpPeerToIsp( BgpPeerConfig remotePeerConfig, String localInterfaceName, BgpProcess bgpProcess) { BgpPeerConfig.Builder<?, ?> ispPeerConfig = remotePeerConfig instanceof BgpActivePeerConfig ? BgpActivePeerConfig.builder() .setPeerAddress(remotePeerConfig.getLocalIp()) .setLocalIp(((BgpActivePeerConfig) remotePeerConfig).getPeerAddress()) : BgpUnnumberedPeerConfig.builder() .setPeerInterface(localInterfaceName) .setLocalIp(LINK_LOCAL_IP); ispPeerConfig .setRemoteAs( firstNonNull(remotePeerConfig.getConfederationAsn(), remotePeerConfig.getLocalAs())) .setLocalAs(remotePeerConfig.getRemoteAsns().least()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .setBgpProcess(bgpProcess) .build(); } 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 void addBgpPeerToIsp( BgpPeerConfig remotePeerConfig, String localInterfaceName, BgpProcess bgpProcess) { BgpPeerConfig.Builder<?, ?> ispPeerConfig = remotePeerConfig instanceof BgpActivePeerConfig ? BgpActivePeerConfig.builder() .setPeerAddress(remotePeerConfig.getLocalIp()) .setLocalIp(((BgpActivePeerConfig) remotePeerConfig).getPeerAddress()) : BgpUnnumberedPeerConfig.builder() .setPeerInterface(localInterfaceName) .setLocalIp(LINK_LOCAL_IP); ispPeerConfig .setRemoteAs( firstNonNull(remotePeerConfig.getConfederationAsn(), remotePeerConfig.getLocalAs())) .setLocalAs(remotePeerConfig.getRemoteAsns().least()) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .setBgpProcess(bgpProcess) .build(); } 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; }