@Test public void testNonExistentNode() { NetworkFactory nf = new NetworkFactory(); Warnings warnings = new Warnings(true, true, true); IspModelingUtils.combineIspConfigurations( ImmutableMap.of("conf", nf.configurationBuilder().setHostname("conf").build()), ImmutableList.of( new IspConfiguration( ImmutableList.of(new BorderInterfaceInfo(NodeInterfacePair.of("conf1", "init1"))), IspFilter.ALLOW_ALL)), warnings); assertThat( warnings.getRedFlagWarnings(), equalTo( ImmutableList.of( new Warning( "ISP Modeling: Non-existent border node conf1 specified in ISP configuration", TAG_RED_FLAG)))); }
@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; }