@Test public void testGetInternetAndIspNodes() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder(); Configuration configuration = cb.setHostname("conf").setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); nf.vrfBuilder().setName(DEFAULT_VRF_NAME).setOwner(configuration).build(); nf.interfaceBuilder() .setName("interface") .setOwner(configuration) .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); configuration.getDefaultVrf().setBgpProcess(bgpProcess); ModeledNodes modeledNodes = IspModelingUtils.getInternetAndIspNodes( ImmutableMap.of(configuration.getHostname(), configuration), ImmutableList.of( new IspConfiguration( ImmutableList.of( new BorderInterfaceInfo(NodeInterfacePair.of("conf", "interface"))), IspFilter.ALLOW_ALL)), new BatfishLogger("output", false), new Warnings()); Map<String, Configuration> configurations = modeledNodes.getConfigurations(); assertThat(configurations, hasKey(IspModelingUtils.INTERNET_HOST_NAME)); Configuration internetNode = configurations.get(IspModelingUtils.INTERNET_HOST_NAME); assertThat( internetNode, allOf( hasHostname(IspModelingUtils.INTERNET_HOST_NAME), hasInterface( internetToIspInterfaceName("isp_1"), hasAllAddresses(equalTo(ImmutableSet.of(LINK_LOCAL_ADDRESS)))), hasVrf( DEFAULT_VRF_NAME, hasBgpProcess( hasInterfaceNeighbors( equalTo( ImmutableMap.of( internetToIspInterfaceName("isp_1"), BgpUnnumberedPeerConfig.builder() .setPeerInterface(internetToIspInterfaceName("isp_1")) .setRemoteAs(1L) .setLocalIp(LINK_LOCAL_IP) .setLocalAs(IspModelingUtils.INTERNET_AS) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy( IspModelingUtils.EXPORT_POLICY_ON_INTERNET) .build()) .build()))))))); assertThat(configurations, hasKey("isp_1")); Configuration ispNode = configurations.get("isp_1"); ImmutableSet<InterfaceAddress> interfaceAddresses = ispNode.getAllInterfaces().values().stream() .flatMap(iface -> iface.getAllAddresses().stream()) .collect(ImmutableSet.toImmutableSet()); assertThat( interfaceAddresses, equalTo( ImmutableSet.of( LINK_LOCAL_ADDRESS, ConcreteInterfaceAddress.create(Ip.parse("1.1.1.1"), 24)))); assertThat( ispNode, hasVrf( DEFAULT_VRF_NAME, hasBgpProcess( allOf( hasNeighbors( equalTo( ImmutableMap.of( Prefix.parse("2.2.2.2/32"), BgpActivePeerConfig.builder() .setPeerAddress(Ip.parse("2.2.2.2")) .setRemoteAs(2L) .setLocalIp(Ip.parse("1.1.1.1")) .setLocalAs(1L) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_CUSTOMERS) .build()) .build()))), hasInterfaceNeighbors( equalTo( ImmutableMap.of( ISP_TO_INTERNET_INTERFACE_NAME, BgpUnnumberedPeerConfig.builder() .setPeerInterface(ISP_TO_INTERNET_INTERFACE_NAME) .setRemoteAs(IspModelingUtils.INTERNET_AS) .setLocalIp(LINK_LOCAL_IP) .setLocalAs(1L) .setIpv4UnicastAddressFamily( Ipv4UnicastAddressFamily.builder() .setExportPolicy(EXPORT_POLICY_ON_ISP_TO_INTERNET) .build()) .build()))))))); Layer1Node internetLayer1 = new Layer1Node(INTERNET_HOST_NAME, internetToIspInterfaceName("isp_1")); Layer1Node ispLayer1Iface0 = new Layer1Node( ispNode.getHostname(), ispToRemoteInterfaceName(configuration.getHostname(), "interface")); Layer1Node ispLayer1Iface2 = new Layer1Node(ispNode.getHostname(), ISP_TO_INTERNET_INTERFACE_NAME); Layer1Node borderLayer1 = new Layer1Node(configuration.getHostname(), "interface"); assertThat( modeledNodes.getLayer1Edges(), equalTo( ImmutableSet.of( new Layer1Edge(borderLayer1, ispLayer1Iface0), new Layer1Edge(ispLayer1Iface0, borderLayer1), new Layer1Edge(internetLayer1, ispLayer1Iface2), new Layer1Edge(ispLayer1Iface2, internetLayer1)))); }
public static ModeledNodes getInternetAndIspNodes( @Nonnull Map<String, Configuration> configurations, @Nonnull List<IspConfiguration> ispConfigurations, @Nonnull BatfishLogger logger, @Nonnull Warnings warnings) { NetworkFactory nf = new NetworkFactory(); Map<Long, IspModel> asnToIspInfos = combineIspConfigurations(configurations, ispConfigurations, warnings); List<String> conflicts = ispNameConflicts(configurations, asnToIspInfos); if (!conflicts.isEmpty()) { conflicts.forEach(warnings::redFlag); return new ModeledNodes(); } return createInternetAndIspNodes(asnToIspInfos, nf, logger); }
IspModelingUtils { public static ModeledNodes getInternetAndIspNodes( @Nonnull Map<String, Configuration> configurations, @Nonnull List<IspConfiguration> ispConfigurations, @Nonnull BatfishLogger logger, @Nonnull Warnings warnings) { NetworkFactory nf = new NetworkFactory(); Map<Long, IspModel> asnToIspInfos = combineIspConfigurations(configurations, ispConfigurations, warnings); List<String> conflicts = ispNameConflicts(configurations, asnToIspInfos); if (!conflicts.isEmpty()) { conflicts.forEach(warnings::redFlag); return new ModeledNodes(); } return createInternetAndIspNodes(asnToIspInfos, nf, logger); } }
IspModelingUtils { public static ModeledNodes getInternetAndIspNodes( @Nonnull Map<String, Configuration> configurations, @Nonnull List<IspConfiguration> ispConfigurations, @Nonnull BatfishLogger logger, @Nonnull Warnings warnings) { NetworkFactory nf = new NetworkFactory(); Map<Long, IspModel> asnToIspInfos = combineIspConfigurations(configurations, ispConfigurations, warnings); List<String> conflicts = ispNameConflicts(configurations, asnToIspInfos); if (!conflicts.isEmpty()) { conflicts.forEach(warnings::redFlag); return new ModeledNodes(); } return createInternetAndIspNodes(asnToIspInfos, nf, logger); } private  IspModelingUtils(); }
IspModelingUtils { public static ModeledNodes getInternetAndIspNodes( @Nonnull Map<String, Configuration> configurations, @Nonnull List<IspConfiguration> ispConfigurations, @Nonnull BatfishLogger logger, @Nonnull Warnings warnings) { NetworkFactory nf = new NetworkFactory(); Map<Long, IspModel> asnToIspInfos = combineIspConfigurations(configurations, ispConfigurations, warnings); List<String> conflicts = ispNameConflicts(configurations, asnToIspInfos); if (!conflicts.isEmpty()) { conflicts.forEach(warnings::redFlag); return new ModeledNodes(); } return createInternetAndIspNodes(asnToIspInfos, nf, logger); } 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 { public static ModeledNodes getInternetAndIspNodes( @Nonnull Map<String, Configuration> configurations, @Nonnull List<IspConfiguration> ispConfigurations, @Nonnull BatfishLogger logger, @Nonnull Warnings warnings) { NetworkFactory nf = new NetworkFactory(); Map<Long, IspModel> asnToIspInfos = combineIspConfigurations(configurations, ispConfigurations, warnings); List<String> conflicts = ispNameConflicts(configurations, asnToIspInfos); if (!conflicts.isEmpty()) { conflicts.forEach(warnings::redFlag); return new ModeledNodes(); } return createInternetAndIspNodes(asnToIspInfos, nf, logger); } 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; }