@Test public void testCombineIspConfigurationsCommonAsn() { NetworkFactory nf = new NetworkFactory(); long remoteAsn = 1234L; String bgpIfaceName = "iface"; Ip localBgpIp1 = Ip.parse("1.1.1.1"); Ip remoteBgpIp1 = Ip.parse("1.1.1.2"); Configuration c1 = createBgpNode(nf, "c1", bgpIfaceName, localBgpIp1); addBgpPeer(c1, remoteBgpIp1, remoteAsn, localBgpIp1); Ip localBgpIp2 = Ip.parse("2.1.1.1"); Ip remoteBgpIp2 = Ip.parse("2.1.1.2"); Configuration c2 = createBgpNode(nf, "c2", bgpIfaceName, localBgpIp2); addBgpPeer(c2, remoteBgpIp2, remoteAsn, localBgpIp2); Map<Long, IspModel> combinedMap = IspModelingUtils.combineIspConfigurations( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2), ImmutableList.of( new IspConfiguration( ImmutableList.of( new BorderInterfaceInfo( NodeInterfacePair.of(c1.getHostname(), bgpIfaceName))), IspFilter.ALLOW_ALL), new IspConfiguration( ImmutableList.of( new BorderInterfaceInfo( NodeInterfacePair.of(c2.getHostname(), bgpIfaceName))), IspFilter.ALLOW_ALL)), new Warnings()); assertThat( combinedMap, equalTo( ImmutableMap.of( remoteAsn, IspModel.builder() .setAsn(remoteAsn) .setName(null) .setRemotes( new Remote( c1.getHostname(), getOnlyElement(c1.getAllInterfaces().keySet()), ConcreteInterfaceAddress.create(remoteBgpIp1, 24), getOnlyElement( c1.getDefaultVrf().getBgpProcess().getActiveNeighbors().values())), new Remote( c2.getHostname(), getOnlyElement(c2.getAllInterfaces().keySet()), ConcreteInterfaceAddress.create(remoteBgpIp2, 24), getOnlyElement( c2.getDefaultVrf().getBgpProcess().getActiveNeighbors().values()))) .setTrafficFiltering(IspTrafficFiltering.blockReservedAddressesAtInternet()) .build()))); }
@VisibleForTesting static Map<Long, IspModel> combineIspConfigurations( Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) { Map<Long, IspModel> asnToIspInfos = new HashMap<>(); for (IspConfiguration ispConfiguration : ispConfigurations) { Map<String, Set<String>> interfaceSetByNodes = ispConfiguration.getBorderInterfaces().stream() .map(BorderInterfaceInfo::getBorderInterface) .collect( Collectors.groupingBy( nodeInterfacePair -> nodeInterfacePair.getHostname().toLowerCase(), Collectors.mapping(NodeInterfacePair::getInterface, Collectors.toSet()))); for (Entry<String, Set<String>> remoteNodeAndInterfaces : interfaceSetByNodes.entrySet()) { Configuration remoteCfg = configurations.get(remoteNodeAndInterfaces.getKey()); if (remoteCfg == null) { warnings.redFlag( String.format( "ISP Modeling: Non-existent border node %s specified in ISP configuration", remoteNodeAndInterfaces.getKey())); continue; } populateIspModels( remoteCfg, remoteNodeAndInterfaces.getValue(), ispConfiguration.getFilter().getOnlyRemoteIps(), ispConfiguration.getFilter().getOnlyRemoteAsns(), ispConfiguration.getIspNodeInfos(), asnToIspInfos, warnings); } } return asnToIspInfos; }
IspModelingUtils { @VisibleForTesting static Map<Long, IspModel> combineIspConfigurations( Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) { Map<Long, IspModel> asnToIspInfos = new HashMap<>(); for (IspConfiguration ispConfiguration : ispConfigurations) { Map<String, Set<String>> interfaceSetByNodes = ispConfiguration.getBorderInterfaces().stream() .map(BorderInterfaceInfo::getBorderInterface) .collect( Collectors.groupingBy( nodeInterfacePair -> nodeInterfacePair.getHostname().toLowerCase(), Collectors.mapping(NodeInterfacePair::getInterface, Collectors.toSet()))); for (Entry<String, Set<String>> remoteNodeAndInterfaces : interfaceSetByNodes.entrySet()) { Configuration remoteCfg = configurations.get(remoteNodeAndInterfaces.getKey()); if (remoteCfg == null) { warnings.redFlag( String.format( "ISP Modeling: Non-existent border node %s specified in ISP configuration", remoteNodeAndInterfaces.getKey())); continue; } populateIspModels( remoteCfg, remoteNodeAndInterfaces.getValue(), ispConfiguration.getFilter().getOnlyRemoteIps(), ispConfiguration.getFilter().getOnlyRemoteAsns(), ispConfiguration.getIspNodeInfos(), asnToIspInfos, warnings); } } return asnToIspInfos; } }
IspModelingUtils { @VisibleForTesting static Map<Long, IspModel> combineIspConfigurations( Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) { Map<Long, IspModel> asnToIspInfos = new HashMap<>(); for (IspConfiguration ispConfiguration : ispConfigurations) { Map<String, Set<String>> interfaceSetByNodes = ispConfiguration.getBorderInterfaces().stream() .map(BorderInterfaceInfo::getBorderInterface) .collect( Collectors.groupingBy( nodeInterfacePair -> nodeInterfacePair.getHostname().toLowerCase(), Collectors.mapping(NodeInterfacePair::getInterface, Collectors.toSet()))); for (Entry<String, Set<String>> remoteNodeAndInterfaces : interfaceSetByNodes.entrySet()) { Configuration remoteCfg = configurations.get(remoteNodeAndInterfaces.getKey()); if (remoteCfg == null) { warnings.redFlag( String.format( "ISP Modeling: Non-existent border node %s specified in ISP configuration", remoteNodeAndInterfaces.getKey())); continue; } populateIspModels( remoteCfg, remoteNodeAndInterfaces.getValue(), ispConfiguration.getFilter().getOnlyRemoteIps(), ispConfiguration.getFilter().getOnlyRemoteAsns(), ispConfiguration.getIspNodeInfos(), asnToIspInfos, warnings); } } return asnToIspInfos; } private  IspModelingUtils(); }
IspModelingUtils { @VisibleForTesting static Map<Long, IspModel> combineIspConfigurations( Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) { Map<Long, IspModel> asnToIspInfos = new HashMap<>(); for (IspConfiguration ispConfiguration : ispConfigurations) { Map<String, Set<String>> interfaceSetByNodes = ispConfiguration.getBorderInterfaces().stream() .map(BorderInterfaceInfo::getBorderInterface) .collect( Collectors.groupingBy( nodeInterfacePair -> nodeInterfacePair.getHostname().toLowerCase(), Collectors.mapping(NodeInterfacePair::getInterface, Collectors.toSet()))); for (Entry<String, Set<String>> remoteNodeAndInterfaces : interfaceSetByNodes.entrySet()) { Configuration remoteCfg = configurations.get(remoteNodeAndInterfaces.getKey()); if (remoteCfg == null) { warnings.redFlag( String.format( "ISP Modeling: Non-existent border node %s specified in ISP configuration", remoteNodeAndInterfaces.getKey())); continue; } populateIspModels( remoteCfg, remoteNodeAndInterfaces.getValue(), ispConfiguration.getFilter().getOnlyRemoteIps(), ispConfiguration.getFilter().getOnlyRemoteAsns(), ispConfiguration.getIspNodeInfos(), asnToIspInfos, warnings); } } return asnToIspInfos; } 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 Map<Long, IspModel> combineIspConfigurations( Map<String, Configuration> configurations, List<IspConfiguration> ispConfigurations, Warnings warnings) { Map<Long, IspModel> asnToIspInfos = new HashMap<>(); for (IspConfiguration ispConfiguration : ispConfigurations) { Map<String, Set<String>> interfaceSetByNodes = ispConfiguration.getBorderInterfaces().stream() .map(BorderInterfaceInfo::getBorderInterface) .collect( Collectors.groupingBy( nodeInterfacePair -> nodeInterfacePair.getHostname().toLowerCase(), Collectors.mapping(NodeInterfacePair::getInterface, Collectors.toSet()))); for (Entry<String, Set<String>> remoteNodeAndInterfaces : interfaceSetByNodes.entrySet()) { Configuration remoteCfg = configurations.get(remoteNodeAndInterfaces.getKey()); if (remoteCfg == null) { warnings.redFlag( String.format( "ISP Modeling: Non-existent border node %s specified in ISP configuration", remoteNodeAndInterfaces.getKey())); continue; } populateIspModels( remoteCfg, remoteNodeAndInterfaces.getValue(), ispConfiguration.getFilter().getOnlyRemoteIps(), ispConfiguration.getFilter().getOnlyRemoteAsns(), ispConfiguration.getIspNodeInfos(), asnToIspInfos, warnings); } } return asnToIspInfos; } 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; }