@Test public void testCreateAclWithSymmetricalLines() { IpAccessList ipAccessList = _nf.aclBuilder() .setLines( ImmutableList.of( ExprAclLine.accepting() .setName("permit ip 1.1.1.1 0.0.0.0 2.2.2.2 0.0.0.0") .setMatchCondition( new MatchHeaderSpace( HeaderSpace.builder() .setSrcIps(IpWildcard.parse("1.1.1.1").toIpSpace()) .setDstIps(IpWildcard.parse("2.2.2.2").toIpSpace()) .setNotSrcIps(IpWildcard.parse("3.3.3.3").toIpSpace()) .build())) .build())) .build(); assertThat(createAclWithSymmetricalLines(ipAccessList), nullValue()); }
@VisibleForTesting @Nullable static IpAccessList createAclWithSymmetricalLines(IpAccessList ipAccessList) { List<AclLine> aclLines = new ArrayList<>(ipAccessList.getLines()); for (AclLine line : ipAccessList.getLines()) { if (!(line instanceof ExprAclLine)) { return null; } ExprAclLine exprAclLine = (ExprAclLine) line; HeaderSpace originalHeaderSpace = HeaderSpaceConverter.convert(exprAclLine.getMatchCondition()); if (!originalHeaderSpace.equals( HeaderSpace.builder() .setSrcIps(originalHeaderSpace.getSrcIps()) .setDstIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getSrcPorts()) .setDstPorts(originalHeaderSpace.getDstPorts()) .setIpProtocols(originalHeaderSpace.getIpProtocols()) .setIcmpCodes(originalHeaderSpace.getIcmpCodes()) .setTcpFlags(originalHeaderSpace.getTcpFlags()) .build())) { return null; } else { HeaderSpace.Builder reversedHeaderSpaceBuilder = originalHeaderSpace.toBuilder(); aclLines.add( ExprAclLine.builder() .setMatchCondition( new MatchHeaderSpace( reversedHeaderSpaceBuilder .setSrcIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getDstPorts()) .setDstIps(originalHeaderSpace.getSrcIps()) .setDstPorts(originalHeaderSpace.getSrcPorts()) .build())) .setAction(exprAclLine.getAction()) .build()); } } return IpAccessList.builder().setName(ipAccessList.getName()).setLines(aclLines).build(); }
CiscoConversions { @VisibleForTesting @Nullable static IpAccessList createAclWithSymmetricalLines(IpAccessList ipAccessList) { List<AclLine> aclLines = new ArrayList<>(ipAccessList.getLines()); for (AclLine line : ipAccessList.getLines()) { if (!(line instanceof ExprAclLine)) { return null; } ExprAclLine exprAclLine = (ExprAclLine) line; HeaderSpace originalHeaderSpace = HeaderSpaceConverter.convert(exprAclLine.getMatchCondition()); if (!originalHeaderSpace.equals( HeaderSpace.builder() .setSrcIps(originalHeaderSpace.getSrcIps()) .setDstIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getSrcPorts()) .setDstPorts(originalHeaderSpace.getDstPorts()) .setIpProtocols(originalHeaderSpace.getIpProtocols()) .setIcmpCodes(originalHeaderSpace.getIcmpCodes()) .setTcpFlags(originalHeaderSpace.getTcpFlags()) .build())) { return null; } else { HeaderSpace.Builder reversedHeaderSpaceBuilder = originalHeaderSpace.toBuilder(); aclLines.add( ExprAclLine.builder() .setMatchCondition( new MatchHeaderSpace( reversedHeaderSpaceBuilder .setSrcIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getDstPorts()) .setDstIps(originalHeaderSpace.getSrcIps()) .setDstPorts(originalHeaderSpace.getSrcPorts()) .build())) .setAction(exprAclLine.getAction()) .build()); } } return IpAccessList.builder().setName(ipAccessList.getName()).setLines(aclLines).build(); } }
CiscoConversions { @VisibleForTesting @Nullable static IpAccessList createAclWithSymmetricalLines(IpAccessList ipAccessList) { List<AclLine> aclLines = new ArrayList<>(ipAccessList.getLines()); for (AclLine line : ipAccessList.getLines()) { if (!(line instanceof ExprAclLine)) { return null; } ExprAclLine exprAclLine = (ExprAclLine) line; HeaderSpace originalHeaderSpace = HeaderSpaceConverter.convert(exprAclLine.getMatchCondition()); if (!originalHeaderSpace.equals( HeaderSpace.builder() .setSrcIps(originalHeaderSpace.getSrcIps()) .setDstIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getSrcPorts()) .setDstPorts(originalHeaderSpace.getDstPorts()) .setIpProtocols(originalHeaderSpace.getIpProtocols()) .setIcmpCodes(originalHeaderSpace.getIcmpCodes()) .setTcpFlags(originalHeaderSpace.getTcpFlags()) .build())) { return null; } else { HeaderSpace.Builder reversedHeaderSpaceBuilder = originalHeaderSpace.toBuilder(); aclLines.add( ExprAclLine.builder() .setMatchCondition( new MatchHeaderSpace( reversedHeaderSpaceBuilder .setSrcIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getDstPorts()) .setDstIps(originalHeaderSpace.getSrcIps()) .setDstPorts(originalHeaderSpace.getSrcPorts()) .build())) .setAction(exprAclLine.getAction()) .build()); } } return IpAccessList.builder().setName(ipAccessList.getName()).setLines(aclLines).build(); } private  CiscoConversions(); }
CiscoConversions { @VisibleForTesting @Nullable static IpAccessList createAclWithSymmetricalLines(IpAccessList ipAccessList) { List<AclLine> aclLines = new ArrayList<>(ipAccessList.getLines()); for (AclLine line : ipAccessList.getLines()) { if (!(line instanceof ExprAclLine)) { return null; } ExprAclLine exprAclLine = (ExprAclLine) line; HeaderSpace originalHeaderSpace = HeaderSpaceConverter.convert(exprAclLine.getMatchCondition()); if (!originalHeaderSpace.equals( HeaderSpace.builder() .setSrcIps(originalHeaderSpace.getSrcIps()) .setDstIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getSrcPorts()) .setDstPorts(originalHeaderSpace.getDstPorts()) .setIpProtocols(originalHeaderSpace.getIpProtocols()) .setIcmpCodes(originalHeaderSpace.getIcmpCodes()) .setTcpFlags(originalHeaderSpace.getTcpFlags()) .build())) { return null; } else { HeaderSpace.Builder reversedHeaderSpaceBuilder = originalHeaderSpace.toBuilder(); aclLines.add( ExprAclLine.builder() .setMatchCondition( new MatchHeaderSpace( reversedHeaderSpaceBuilder .setSrcIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getDstPorts()) .setDstIps(originalHeaderSpace.getSrcIps()) .setDstPorts(originalHeaderSpace.getSrcPorts()) .build())) .setAction(exprAclLine.getAction()) .build()); } } return IpAccessList.builder().setName(ipAccessList.getName()).setLines(aclLines).build(); } private  CiscoConversions(); static CommunityList toCommunityList(StandardCommunityList scList); }
CiscoConversions { @VisibleForTesting @Nullable static IpAccessList createAclWithSymmetricalLines(IpAccessList ipAccessList) { List<AclLine> aclLines = new ArrayList<>(ipAccessList.getLines()); for (AclLine line : ipAccessList.getLines()) { if (!(line instanceof ExprAclLine)) { return null; } ExprAclLine exprAclLine = (ExprAclLine) line; HeaderSpace originalHeaderSpace = HeaderSpaceConverter.convert(exprAclLine.getMatchCondition()); if (!originalHeaderSpace.equals( HeaderSpace.builder() .setSrcIps(originalHeaderSpace.getSrcIps()) .setDstIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getSrcPorts()) .setDstPorts(originalHeaderSpace.getDstPorts()) .setIpProtocols(originalHeaderSpace.getIpProtocols()) .setIcmpCodes(originalHeaderSpace.getIcmpCodes()) .setTcpFlags(originalHeaderSpace.getTcpFlags()) .build())) { return null; } else { HeaderSpace.Builder reversedHeaderSpaceBuilder = originalHeaderSpace.toBuilder(); aclLines.add( ExprAclLine.builder() .setMatchCondition( new MatchHeaderSpace( reversedHeaderSpaceBuilder .setSrcIps(originalHeaderSpace.getDstIps()) .setSrcPorts(originalHeaderSpace.getDstPorts()) .setDstIps(originalHeaderSpace.getSrcIps()) .setDstPorts(originalHeaderSpace.getSrcPorts()) .build())) .setAction(exprAclLine.getAction()) .build()); } } return IpAccessList.builder().setName(ipAccessList.getName()).setLines(aclLines).build(); } private  CiscoConversions(); static CommunityList toCommunityList(StandardCommunityList scList);  }