@Test public void testGetAsnOfIspNode() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder(); Configuration ispConfiguration = cb.setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); nf.vrfBuilder().setName(DEFAULT_VRF_NAME).setOwner(ispConfiguration).build(); nf.interfaceBuilder() .setName("interface") .setOwner(ispConfiguration) .setAddress(ConcreteInterfaceAddress.create(Ip.parse("2.2.2.2"), 24)) .build(); BgpActivePeerConfig peer = BgpActivePeerConfig.builder() .setPeerAddress(Ip.parse("1.1.1.1")) .setRemoteAs(1L) .setLocalIp(Ip.parse("2.2.2.2")) .setLocalAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpProcess bgpProcess = new BgpProcess(Ip.ZERO, ConfigurationFormat.CISCO_IOS); bgpProcess.getActiveNeighbors().put(Prefix.parse("1.1.1.1/32"), peer); ispConfiguration.getDefaultVrf().setBgpProcess(bgpProcess); assertThat(IspModelingUtils.getAsnOfIspNode(ispConfiguration), equalTo(2L)); }
@VisibleForTesting @Nonnull static Long getAsnOfIspNode(Configuration ispConfiguration) { checkState( Objects.nonNull(ispConfiguration.getDefaultVrf()), "default VRF should be present in ISP"); checkState( Objects.nonNull(ispConfiguration.getDefaultVrf().getBgpProcess()), "default VRF should have a BGP process"); BgpProcess bgpProcess = ispConfiguration.getDefaultVrf().getBgpProcess(); checkState( !(bgpProcess.getActiveNeighbors().isEmpty() && bgpProcess.getInterfaceNeighbors().isEmpty()), "ISP should have greater than 0 BGP peers"); Long localAs = ispConfiguration .getDefaultVrf() .getBgpProcess() .getAllPeerConfigs() .iterator() .next() .getLocalAs(); checkState(Objects.nonNull(localAs), "Local AS of all eBGP peers should be set on ISP"); return localAs; }
IspModelingUtils { @VisibleForTesting @Nonnull static Long getAsnOfIspNode(Configuration ispConfiguration) { checkState( Objects.nonNull(ispConfiguration.getDefaultVrf()), "default VRF should be present in ISP"); checkState( Objects.nonNull(ispConfiguration.getDefaultVrf().getBgpProcess()), "default VRF should have a BGP process"); BgpProcess bgpProcess = ispConfiguration.getDefaultVrf().getBgpProcess(); checkState( !(bgpProcess.getActiveNeighbors().isEmpty() && bgpProcess.getInterfaceNeighbors().isEmpty()), "ISP should have greater than 0 BGP peers"); Long localAs = ispConfiguration .getDefaultVrf() .getBgpProcess() .getAllPeerConfigs() .iterator() .next() .getLocalAs(); checkState(Objects.nonNull(localAs), "Local AS of all eBGP peers should be set on ISP"); return localAs; } }
IspModelingUtils { @VisibleForTesting @Nonnull static Long getAsnOfIspNode(Configuration ispConfiguration) { checkState( Objects.nonNull(ispConfiguration.getDefaultVrf()), "default VRF should be present in ISP"); checkState( Objects.nonNull(ispConfiguration.getDefaultVrf().getBgpProcess()), "default VRF should have a BGP process"); BgpProcess bgpProcess = ispConfiguration.getDefaultVrf().getBgpProcess(); checkState( !(bgpProcess.getActiveNeighbors().isEmpty() && bgpProcess.getInterfaceNeighbors().isEmpty()), "ISP should have greater than 0 BGP peers"); Long localAs = ispConfiguration .getDefaultVrf() .getBgpProcess() .getAllPeerConfigs() .iterator() .next() .getLocalAs(); checkState(Objects.nonNull(localAs), "Local AS of all eBGP peers should be set on ISP"); return localAs; } private  IspModelingUtils(); }
IspModelingUtils { @VisibleForTesting @Nonnull static Long getAsnOfIspNode(Configuration ispConfiguration) { checkState( Objects.nonNull(ispConfiguration.getDefaultVrf()), "default VRF should be present in ISP"); checkState( Objects.nonNull(ispConfiguration.getDefaultVrf().getBgpProcess()), "default VRF should have a BGP process"); BgpProcess bgpProcess = ispConfiguration.getDefaultVrf().getBgpProcess(); checkState( !(bgpProcess.getActiveNeighbors().isEmpty() && bgpProcess.getInterfaceNeighbors().isEmpty()), "ISP should have greater than 0 BGP peers"); Long localAs = ispConfiguration .getDefaultVrf() .getBgpProcess() .getAllPeerConfigs() .iterator() .next() .getLocalAs(); checkState(Objects.nonNull(localAs), "Local AS of all eBGP peers should be set on ISP"); return localAs; } 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 @Nonnull static Long getAsnOfIspNode(Configuration ispConfiguration) { checkState( Objects.nonNull(ispConfiguration.getDefaultVrf()), "default VRF should be present in ISP"); checkState( Objects.nonNull(ispConfiguration.getDefaultVrf().getBgpProcess()), "default VRF should have a BGP process"); BgpProcess bgpProcess = ispConfiguration.getDefaultVrf().getBgpProcess(); checkState( !(bgpProcess.getActiveNeighbors().isEmpty() && bgpProcess.getInterfaceNeighbors().isEmpty()), "ISP should have greater than 0 BGP peers"); Long localAs = ispConfiguration .getDefaultVrf() .getBgpProcess() .getAllPeerConfigs() .iterator() .next() .getLocalAs(); checkState(Objects.nonNull(localAs), "Local AS of all eBGP peers should be set on ISP"); return localAs; } 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; }