@Test public void testCreateInternetNode() { ModeledNodes modeledNodes = new ModeledNodes(); createInternetNode(modeledNodes); Configuration internet = modeledNodes.getConfigurations().get(INTERNET_HOST_NAME); InterfaceAddress interfaceAddress = ConcreteInterfaceAddress.create( IspModelingUtils.INTERNET_OUT_ADDRESS, IspModelingUtils.INTERNET_OUT_SUBNET.getPrefixLength()); assertThat( internet, allOf( hasHostname(IspModelingUtils.INTERNET_HOST_NAME), hasDeviceType(equalTo(DeviceType.INTERNET)), hasInterface( IspModelingUtils.INTERNET_OUT_INTERFACE, hasAllAddresses(equalTo(ImmutableSet.of(interfaceAddress)))), hasVrf( DEFAULT_VRF_NAME, allOf( hasStaticRoutes( equalTo( new ImmutableSortedSet.Builder<StaticRoute>(Comparator.naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface( IspModelingUtils.INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build())), hasBgpProcess( allOf( hasRouterId(IspModelingUtils.INTERNET_OUT_ADDRESS), hasMultipathEbgp(true))))))); assertThat(internet.getRoutingPolicies(), hasKey(IspModelingUtils.EXPORT_POLICY_ON_INTERNET)); assertThat( internet.getLocationInfo(), hasEntry( new InterfaceLinkLocation(INTERNET_HOST_NAME, INTERNET_OUT_INTERFACE), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); }
@VisibleForTesting static void createInternetNode(ModeledNodes modeledNodes) { Configuration.Builder cb = Configuration.builder(); Configuration internetConfiguration = cb.setHostname(INTERNET_HOST_NAME) .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setDeviceModel(DeviceModel.BATFISH_INTERNET) .build(); internetConfiguration.setDeviceType(DeviceType.INTERNET); Vrf defaultVrf = Vrf.builder().setName(DEFAULT_VRF_NAME).setOwner(internetConfiguration).build(); Interface internetOutInterface = Interface.builder() .setName(INTERNET_OUT_INTERFACE) .setOwner(internetConfiguration) .setVrf(defaultVrf) .setAddress( ConcreteInterfaceAddress.create( INTERNET_OUT_ADDRESS, INTERNET_OUT_SUBNET.getPrefixLength())) .build(); internetConfiguration .getDefaultVrf() .setStaticRoutes( new ImmutableSortedSet.Builder<StaticRoute>(naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface(INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build()); BgpProcess bgpProcess = BgpProcess.builder() .setRouterId(INTERNET_OUT_ADDRESS) .setVrf(defaultVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.CISCO_IOS) .build(); bgpProcess.setMultipathEbgp(true); bgpProcess.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.PATH_LENGTH); internetConfiguration.setRoutingPolicies( ImmutableSortedMap.of( EXPORT_POLICY_ON_INTERNET, installRoutingPolicyAdvertiseStatic( EXPORT_POLICY_ON_INTERNET, internetConfiguration, new PrefixSpace(PrefixRange.fromPrefix(Prefix.ZERO))))); internetConfiguration.setLocationInfo( ImmutableMap.of( interfaceLinkLocation(internetOutInterface), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); modeledNodes.addConfiguration(internetConfiguration); }
IspModelingUtils { @VisibleForTesting static void createInternetNode(ModeledNodes modeledNodes) { Configuration.Builder cb = Configuration.builder(); Configuration internetConfiguration = cb.setHostname(INTERNET_HOST_NAME) .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setDeviceModel(DeviceModel.BATFISH_INTERNET) .build(); internetConfiguration.setDeviceType(DeviceType.INTERNET); Vrf defaultVrf = Vrf.builder().setName(DEFAULT_VRF_NAME).setOwner(internetConfiguration).build(); Interface internetOutInterface = Interface.builder() .setName(INTERNET_OUT_INTERFACE) .setOwner(internetConfiguration) .setVrf(defaultVrf) .setAddress( ConcreteInterfaceAddress.create( INTERNET_OUT_ADDRESS, INTERNET_OUT_SUBNET.getPrefixLength())) .build(); internetConfiguration .getDefaultVrf() .setStaticRoutes( new ImmutableSortedSet.Builder<StaticRoute>(naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface(INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build()); BgpProcess bgpProcess = BgpProcess.builder() .setRouterId(INTERNET_OUT_ADDRESS) .setVrf(defaultVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.CISCO_IOS) .build(); bgpProcess.setMultipathEbgp(true); bgpProcess.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.PATH_LENGTH); internetConfiguration.setRoutingPolicies( ImmutableSortedMap.of( EXPORT_POLICY_ON_INTERNET, installRoutingPolicyAdvertiseStatic( EXPORT_POLICY_ON_INTERNET, internetConfiguration, new PrefixSpace(PrefixRange.fromPrefix(Prefix.ZERO))))); internetConfiguration.setLocationInfo( ImmutableMap.of( interfaceLinkLocation(internetOutInterface), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); modeledNodes.addConfiguration(internetConfiguration); } }
IspModelingUtils { @VisibleForTesting static void createInternetNode(ModeledNodes modeledNodes) { Configuration.Builder cb = Configuration.builder(); Configuration internetConfiguration = cb.setHostname(INTERNET_HOST_NAME) .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setDeviceModel(DeviceModel.BATFISH_INTERNET) .build(); internetConfiguration.setDeviceType(DeviceType.INTERNET); Vrf defaultVrf = Vrf.builder().setName(DEFAULT_VRF_NAME).setOwner(internetConfiguration).build(); Interface internetOutInterface = Interface.builder() .setName(INTERNET_OUT_INTERFACE) .setOwner(internetConfiguration) .setVrf(defaultVrf) .setAddress( ConcreteInterfaceAddress.create( INTERNET_OUT_ADDRESS, INTERNET_OUT_SUBNET.getPrefixLength())) .build(); internetConfiguration .getDefaultVrf() .setStaticRoutes( new ImmutableSortedSet.Builder<StaticRoute>(naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface(INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build()); BgpProcess bgpProcess = BgpProcess.builder() .setRouterId(INTERNET_OUT_ADDRESS) .setVrf(defaultVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.CISCO_IOS) .build(); bgpProcess.setMultipathEbgp(true); bgpProcess.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.PATH_LENGTH); internetConfiguration.setRoutingPolicies( ImmutableSortedMap.of( EXPORT_POLICY_ON_INTERNET, installRoutingPolicyAdvertiseStatic( EXPORT_POLICY_ON_INTERNET, internetConfiguration, new PrefixSpace(PrefixRange.fromPrefix(Prefix.ZERO))))); internetConfiguration.setLocationInfo( ImmutableMap.of( interfaceLinkLocation(internetOutInterface), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); modeledNodes.addConfiguration(internetConfiguration); } private  IspModelingUtils(); }
IspModelingUtils { @VisibleForTesting static void createInternetNode(ModeledNodes modeledNodes) { Configuration.Builder cb = Configuration.builder(); Configuration internetConfiguration = cb.setHostname(INTERNET_HOST_NAME) .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setDeviceModel(DeviceModel.BATFISH_INTERNET) .build(); internetConfiguration.setDeviceType(DeviceType.INTERNET); Vrf defaultVrf = Vrf.builder().setName(DEFAULT_VRF_NAME).setOwner(internetConfiguration).build(); Interface internetOutInterface = Interface.builder() .setName(INTERNET_OUT_INTERFACE) .setOwner(internetConfiguration) .setVrf(defaultVrf) .setAddress( ConcreteInterfaceAddress.create( INTERNET_OUT_ADDRESS, INTERNET_OUT_SUBNET.getPrefixLength())) .build(); internetConfiguration .getDefaultVrf() .setStaticRoutes( new ImmutableSortedSet.Builder<StaticRoute>(naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface(INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build()); BgpProcess bgpProcess = BgpProcess.builder() .setRouterId(INTERNET_OUT_ADDRESS) .setVrf(defaultVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.CISCO_IOS) .build(); bgpProcess.setMultipathEbgp(true); bgpProcess.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.PATH_LENGTH); internetConfiguration.setRoutingPolicies( ImmutableSortedMap.of( EXPORT_POLICY_ON_INTERNET, installRoutingPolicyAdvertiseStatic( EXPORT_POLICY_ON_INTERNET, internetConfiguration, new PrefixSpace(PrefixRange.fromPrefix(Prefix.ZERO))))); internetConfiguration.setLocationInfo( ImmutableMap.of( interfaceLinkLocation(internetOutInterface), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); modeledNodes.addConfiguration(internetConfiguration); } 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 createInternetNode(ModeledNodes modeledNodes) { Configuration.Builder cb = Configuration.builder(); Configuration internetConfiguration = cb.setHostname(INTERNET_HOST_NAME) .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setDeviceModel(DeviceModel.BATFISH_INTERNET) .build(); internetConfiguration.setDeviceType(DeviceType.INTERNET); Vrf defaultVrf = Vrf.builder().setName(DEFAULT_VRF_NAME).setOwner(internetConfiguration).build(); Interface internetOutInterface = Interface.builder() .setName(INTERNET_OUT_INTERFACE) .setOwner(internetConfiguration) .setVrf(defaultVrf) .setAddress( ConcreteInterfaceAddress.create( INTERNET_OUT_ADDRESS, INTERNET_OUT_SUBNET.getPrefixLength())) .build(); internetConfiguration .getDefaultVrf() .setStaticRoutes( new ImmutableSortedSet.Builder<StaticRoute>(naturalOrder()) .add( StaticRoute.builder() .setNetwork(Prefix.ZERO) .setNextHopInterface(INTERNET_OUT_INTERFACE) .setAdministrativeCost(1) .build()) .addAll( INTERNET_NULL_ROUTED_PREFIXES.stream() .map( prefix -> StaticRoute.builder() .setNetwork(prefix) .setNextHopInterface(NULL_INTERFACE_NAME) .setAdministrativeCost(1) .build()) .collect(ImmutableSet.toImmutableSet())) .build()); BgpProcess bgpProcess = BgpProcess.builder() .setRouterId(INTERNET_OUT_ADDRESS) .setVrf(defaultVrf) .setAdminCostsToVendorDefaults(ConfigurationFormat.CISCO_IOS) .build(); bgpProcess.setMultipathEbgp(true); bgpProcess.setMultipathEquivalentAsPathMatchMode( MultipathEquivalentAsPathMatchMode.PATH_LENGTH); internetConfiguration.setRoutingPolicies( ImmutableSortedMap.of( EXPORT_POLICY_ON_INTERNET, installRoutingPolicyAdvertiseStatic( EXPORT_POLICY_ON_INTERNET, internetConfiguration, new PrefixSpace(PrefixRange.fromPrefix(Prefix.ZERO))))); internetConfiguration.setLocationInfo( ImmutableMap.of( interfaceLinkLocation(internetOutInterface), INTERNET_OUT_INTERFACE_LINK_LOCATION_INFO)); modeledNodes.addConfiguration(internetConfiguration); } 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; }