@Test public void testFilterToIpAccessList_hasTerm() { JuniperConfiguration config = createConfig(); ConcreteFirewallFilter filter = new ConcreteFirewallFilter("filter", Family.INET); FwTerm term = new FwTerm("term"); String ipAddrPrefix = "1.2.3.0/24"; term.getFroms().add(new FwFromSourceAddress(IpWildcard.parse(ipAddrPrefix), ipAddrPrefix)); term.getThens().add(FwThenAccept.INSTANCE); filter.getTerms().put("term", term); IpAccessList headerSpaceAcl = config.filterToIpAccessList(filter); AclLine headerSpaceAclLine = Iterables.getOnlyElement(headerSpaceAcl.getLines()); assertThat( headerSpaceAclLine, equalTo( ExprAclLine.builder() .setName("term") .setAction(LineAction.PERMIT) .setTraceElement( TraceElement.builder() .add("Matched ") .add( "term", new VendorStructureId( "file", FIREWALL_FILTER_TERM.getDescription(), "filter term")) .build()) .setMatchCondition( new AndMatchExpr( ImmutableList.of( new MatchHeaderSpace( HeaderSpace.builder() .setSrcIps(IpWildcard.parse(ipAddrPrefix).toIpSpace()) .build(), TraceElement.of("Matched source-address 1.2.3.0/24"))))) .build())); }
@VisibleForTesting IpAccessList filterToIpAccessList(FirewallFilter f) throws VendorConversionException { String name = f.getName(); if (f instanceof ConcreteFirewallFilter) { ConcreteFirewallFilter filter = (ConcreteFirewallFilter) f; assert !filter.getFromZone().isPresent(); return fwTermsToIpAccessList( name, filter.getTerms().values(), null, JuniperStructureType.FIREWALL_FILTER); } else { assert f instanceof CompositeFirewallFilter; CompositeFirewallFilter filter = (CompositeFirewallFilter) f; ImmutableList.Builder<AclLine> lines = ImmutableList.builder(); for (FirewallFilter inner : filter.getInner()) { String filterName = inner.getName(); lines.add( new AclAclLine(filterName, filterName, matchingFirewallFilter(_filename, filterName))); } return IpAccessList.builder().setName(filter.getName()).setLines(lines.build()).build(); } }
JuniperConfiguration extends VendorConfiguration { @VisibleForTesting IpAccessList filterToIpAccessList(FirewallFilter f) throws VendorConversionException { String name = f.getName(); if (f instanceof ConcreteFirewallFilter) { ConcreteFirewallFilter filter = (ConcreteFirewallFilter) f; assert !filter.getFromZone().isPresent(); return fwTermsToIpAccessList( name, filter.getTerms().values(), null, JuniperStructureType.FIREWALL_FILTER); } else { assert f instanceof CompositeFirewallFilter; CompositeFirewallFilter filter = (CompositeFirewallFilter) f; ImmutableList.Builder<AclLine> lines = ImmutableList.builder(); for (FirewallFilter inner : filter.getInner()) { String filterName = inner.getName(); lines.add( new AclAclLine(filterName, filterName, matchingFirewallFilter(_filename, filterName))); } return IpAccessList.builder().setName(filter.getName()).setLines(lines.build()).build(); } } }
JuniperConfiguration extends VendorConfiguration { @VisibleForTesting IpAccessList filterToIpAccessList(FirewallFilter f) throws VendorConversionException { String name = f.getName(); if (f instanceof ConcreteFirewallFilter) { ConcreteFirewallFilter filter = (ConcreteFirewallFilter) f; assert !filter.getFromZone().isPresent(); return fwTermsToIpAccessList( name, filter.getTerms().values(), null, JuniperStructureType.FIREWALL_FILTER); } else { assert f instanceof CompositeFirewallFilter; CompositeFirewallFilter filter = (CompositeFirewallFilter) f; ImmutableList.Builder<AclLine> lines = ImmutableList.builder(); for (FirewallFilter inner : filter.getInner()) { String filterName = inner.getName(); lines.add( new AclAclLine(filterName, filterName, matchingFirewallFilter(_filename, filterName))); } return IpAccessList.builder().setName(filter.getName()).setLines(lines.build()).build(); } } JuniperConfiguration(); }
JuniperConfiguration extends VendorConfiguration { @VisibleForTesting IpAccessList filterToIpAccessList(FirewallFilter f) throws VendorConversionException { String name = f.getName(); if (f instanceof ConcreteFirewallFilter) { ConcreteFirewallFilter filter = (ConcreteFirewallFilter) f; assert !filter.getFromZone().isPresent(); return fwTermsToIpAccessList( name, filter.getTerms().values(), null, JuniperStructureType.FIREWALL_FILTER); } else { assert f instanceof CompositeFirewallFilter; CompositeFirewallFilter filter = (CompositeFirewallFilter) f; ImmutableList.Builder<AclLine> lines = ImmutableList.builder(); for (FirewallFilter inner : filter.getInner()) { String filterName = inner.getName(); lines.add( new AclAclLine(filterName, filterName, matchingFirewallFilter(_filename, filterName))); } return IpAccessList.builder().setName(filter.getName()).setLines(lines.build()).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 { @VisibleForTesting IpAccessList filterToIpAccessList(FirewallFilter f) throws VendorConversionException { String name = f.getName(); if (f instanceof ConcreteFirewallFilter) { ConcreteFirewallFilter filter = (ConcreteFirewallFilter) f; assert !filter.getFromZone().isPresent(); return fwTermsToIpAccessList( name, filter.getTerms().values(), null, JuniperStructureType.FIREWALL_FILTER); } else { assert f instanceof CompositeFirewallFilter; CompositeFirewallFilter filter = (CompositeFirewallFilter) f; ImmutableList.Builder<AclLine> lines = ImmutableList.builder(); for (FirewallFilter inner : filter.getInner()) { String filterName = inner.getName(); lines.add( new AclAclLine(filterName, filterName, matchingFirewallFilter(_filename, filterName))); } return IpAccessList.builder().setName(filter.getName()).setLines(lines.build()).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; }