@Test public void testBuildScreensPerZone() { JuniperConfiguration config = createConfig(); List<ScreenOption> screenOptionList1 = ImmutableList.of(IcmpLarge.INSTANCE, IpUnknownProtocol.INSTANCE, TcpFinNoAck.INSTANCE); List<ScreenOption> screenOptionList2 = ImmutableList.of(TcpSynFin.INSTANCE, TcpNoFlag.INSTANCE); Screen screen1 = new Screen("screen1"); for (ScreenOption option : screenOptionList1) { screen1.getScreenOptions().add(option); } Screen screen2 = new Screen("screen2"); for (ScreenOption option : screenOptionList2) { screen2.getScreenOptions().add(option); } screen2.setAction(ScreenAction.ALARM_WITHOUT_DROP); Screen screen3 = new Screen("screen3"); config.getMasterLogicalSystem().getScreens().put("screen1", screen1); config.getMasterLogicalSystem().getScreens().put("screen2", screen2); config.getMasterLogicalSystem().getScreens().put("screen3", screen3); Zone zone = new Zone("zone", null); zone.getScreens().add("screen1"); zone.getScreens().add("screen2"); zone.getScreens().add("screen3"); IpAccessList screenAcl = config.buildScreensPerZone(zone, "~SCREEN_ZONE~zone"); assertThat( screenAcl, equalTo( IpAccessList.builder() .setName("~SCREEN_ZONE~zone") .setLines( ImmutableList.of( ExprAclLine.accepting( new AndMatchExpr( ImmutableList.of(new PermittedByAcl("~SCREEN~screen1")))))) .build())); assertThat(config._c.getIpAccessLists().get("~SCREEN~screen1"), notNullValue()); assertThat(config._c.getIpAccessLists().get("~SCREEN~screen2"), nullValue()); assertThat(config._c.getIpAccessLists().get("~SCREEN~screen3"), nullValue()); assertThat( config._c.getIpAccessLists().get("~SCREEN~screen1"), equalTo( IpAccessList.builder() .setName("~SCREEN~screen1") .setLines( ImmutableList.of( ExprAclLine.rejecting( new OrMatchExpr( screenOptionList1.stream() .map(ScreenOption::getAclLineMatchExpr) .collect(Collectors.toList()))), ExprAclLine.ACCEPT_ALL)) .build())); }
@Nullable @VisibleForTesting IpAccessList buildScreensPerZone(@Nonnull Zone zone, String aclName) { List<AclLineMatchExpr> matches = zone.getScreens().stream() .map( screenName -> { Screen screen = _masterLogicalSystem.getScreens().get(screenName); String screenAclName = ACL_NAME_SCREEN + screenName; IpAccessList screenAcl = _c.getIpAccessLists() .computeIfAbsent(screenAclName, x -> buildScreen(screen, screenAclName)); return screenAcl != null ? new PermittedByAcl(screenAcl.getName()) : null; }) .filter(Objects::nonNull) .collect(Collectors.toList()); return matches.isEmpty() ? null : IpAccessList.builder() .setName(aclName) .setLines(ImmutableList.of(ExprAclLine.accepting(new AndMatchExpr(matches)))) .build(); }
JuniperConfiguration extends VendorConfiguration { @Nullable @VisibleForTesting IpAccessList buildScreensPerZone(@Nonnull Zone zone, String aclName) { List<AclLineMatchExpr> matches = zone.getScreens().stream() .map( screenName -> { Screen screen = _masterLogicalSystem.getScreens().get(screenName); String screenAclName = ACL_NAME_SCREEN + screenName; IpAccessList screenAcl = _c.getIpAccessLists() .computeIfAbsent(screenAclName, x -> buildScreen(screen, screenAclName)); return screenAcl != null ? new PermittedByAcl(screenAcl.getName()) : null; }) .filter(Objects::nonNull) .collect(Collectors.toList()); return matches.isEmpty() ? null : IpAccessList.builder() .setName(aclName) .setLines(ImmutableList.of(ExprAclLine.accepting(new AndMatchExpr(matches)))) .build(); } }
JuniperConfiguration extends VendorConfiguration { @Nullable @VisibleForTesting IpAccessList buildScreensPerZone(@Nonnull Zone zone, String aclName) { List<AclLineMatchExpr> matches = zone.getScreens().stream() .map( screenName -> { Screen screen = _masterLogicalSystem.getScreens().get(screenName); String screenAclName = ACL_NAME_SCREEN + screenName; IpAccessList screenAcl = _c.getIpAccessLists() .computeIfAbsent(screenAclName, x -> buildScreen(screen, screenAclName)); return screenAcl != null ? new PermittedByAcl(screenAcl.getName()) : null; }) .filter(Objects::nonNull) .collect(Collectors.toList()); return matches.isEmpty() ? null : IpAccessList.builder() .setName(aclName) .setLines(ImmutableList.of(ExprAclLine.accepting(new AndMatchExpr(matches)))) .build(); } JuniperConfiguration(); }
JuniperConfiguration extends VendorConfiguration { @Nullable @VisibleForTesting IpAccessList buildScreensPerZone(@Nonnull Zone zone, String aclName) { List<AclLineMatchExpr> matches = zone.getScreens().stream() .map( screenName -> { Screen screen = _masterLogicalSystem.getScreens().get(screenName); String screenAclName = ACL_NAME_SCREEN + screenName; IpAccessList screenAcl = _c.getIpAccessLists() .computeIfAbsent(screenAclName, x -> buildScreen(screen, screenAclName)); return screenAcl != null ? new PermittedByAcl(screenAcl.getName()) : null; }) .filter(Objects::nonNull) .collect(Collectors.toList()); return matches.isEmpty() ? null : IpAccessList.builder() .setName(aclName) .setLines(ImmutableList.of(ExprAclLine.accepting(new AndMatchExpr(matches)))) .build(); } JuniperConfiguration(); static @Nonnull String computeFirewallFilterTermName(
      @Nonnull String filterName, @Nonnull String termName); static @Nonnull String computeSecurityPolicyTermName(
      @Nonnull String policyName, @Nonnull String termName); @VisibleForTesting static TraceElement matchingFirewallFilter(String filename, String filterName); @VisibleForTesting static TraceElement matchingFirewallFilterTerm(
      String filename, String filterName, String termName); @VisibleForTesting static TraceElement matchingSecurityPolicyTerm(
      String filename, String policyName, String termName); static String computePeerExportPolicyName(Prefix remoteAddress); static String computeOspfExportPolicyName(String vrfName); Map<String, NodeDevice> getNodeDevices(); @Override void setVendor(ConfigurationFormat format); static String computeContributorRouteFilterListName(Prefix prefix); static String computeAggregatedRouteGenerationPolicyName(Prefix prefix); static String computeGeneratedRouteGenerationPolicyName(Prefix prefix); static String computeIsisExportPolicyName(String routingInstanceName); @Override List<Configuration> toVendorIndependentConfigurations(); static String computeLogicalSystemDefaultHostname(
      String masterHostname, String logicalSystemName); @Nonnull Map<String, LogicalSystem> getLogicalSystems(); LogicalSystem getMasterLogicalSystem(); @Override String getHostname(); @Override void setHostname(String hostname); }
JuniperConfiguration extends VendorConfiguration { @Nullable @VisibleForTesting IpAccessList buildScreensPerZone(@Nonnull Zone zone, String aclName) { List<AclLineMatchExpr> matches = zone.getScreens().stream() .map( screenName -> { Screen screen = _masterLogicalSystem.getScreens().get(screenName); String screenAclName = ACL_NAME_SCREEN + screenName; IpAccessList screenAcl = _c.getIpAccessLists() .computeIfAbsent(screenAclName, x -> buildScreen(screen, screenAclName)); return screenAcl != null ? new PermittedByAcl(screenAcl.getName()) : null; }) .filter(Objects::nonNull) .collect(Collectors.toList()); return matches.isEmpty() ? null : IpAccessList.builder() .setName(aclName) .setLines(ImmutableList.of(ExprAclLine.accepting(new AndMatchExpr(matches)))) .build(); } JuniperConfiguration(); static @Nonnull String computeFirewallFilterTermName(
      @Nonnull String filterName, @Nonnull String termName); static @Nonnull String computeSecurityPolicyTermName(
      @Nonnull String policyName, @Nonnull String termName); @VisibleForTesting static TraceElement matchingFirewallFilter(String filename, String filterName); @VisibleForTesting static TraceElement matchingFirewallFilterTerm(
      String filename, String filterName, String termName); @VisibleForTesting static TraceElement matchingSecurityPolicyTerm(
      String filename, String policyName, String termName); static String computePeerExportPolicyName(Prefix remoteAddress); static String computeOspfExportPolicyName(String vrfName); Map<String, NodeDevice> getNodeDevices(); @Override void setVendor(ConfigurationFormat format); static String computeContributorRouteFilterListName(Prefix prefix); static String computeAggregatedRouteGenerationPolicyName(Prefix prefix); static String computeGeneratedRouteGenerationPolicyName(Prefix prefix); static String computeIsisExportPolicyName(String routingInstanceName); @Override List<Configuration> toVendorIndependentConfigurations(); static String computeLogicalSystemDefaultHostname(
      String masterHostname, String logicalSystemName); @Nonnull Map<String, LogicalSystem> getLogicalSystems(); LogicalSystem getMasterLogicalSystem(); @Override String getHostname(); @Override void setHostname(String hostname); static final String ACL_NAME_COMBINED_INCOMING; static final String ACL_NAME_GLOBAL_POLICY; static final String ACL_NAME_SCREEN; static final String ACL_NAME_SCREEN_INTERFACE; static final String ACL_NAME_SCREEN_ZONE; static final String ACL_NAME_SECURITY_POLICY; @VisibleForTesting static final int DEFAULT_ISIS_COST; }