@Test public void testGetMatchingBdd() { BDDPacket pkt = new BDDPacket(); IpAccessListToBdd ipAccessListToBdd = new IpAccessListToBddImpl( pkt, BDDSourceManager.empty(pkt), ImmutableMap.of(), ImmutableMap.of()); Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("1.1.1.2"); Prefix prefix = Prefix.parse("1.1.1.0/24"); HeaderSpace ip1HeaderSpace = HeaderSpace.builder().setDstIps(ip1.toIpSpace()).build(); HeaderSpace ip2HeaderSpace = HeaderSpace.builder().setDstIps(ip2.toIpSpace()).build(); HeaderSpace prefixHeaderSpace = HeaderSpace.builder().setDstIps(prefix.toIpSpace()).build(); IpAccessList acl = IpAccessList.builder() .setName("acl") .setLines( ImmutableList.of( acceptingHeaderSpace(ip1HeaderSpace), rejectingHeaderSpace(ip2HeaderSpace), acceptingHeaderSpace(prefixHeaderSpace))) .build(); HeaderSpaceToBDD headerSpaceToBDD = new HeaderSpaceToBDD(pkt, ImmutableMap.of()); BDD ip1Bdd = headerSpaceToBDD.toBDD(ip1HeaderSpace); BDD ip2Bdd = headerSpaceToBDD.toBDD(ip2HeaderSpace); BDD prefixBdd = headerSpaceToBDD.toBDD(prefixHeaderSpace); MatchLineQuery matchLine0 = new MatchLineQuery(0); assertThat(matchLine0.getMatchingBdd(acl, ipAccessListToBdd, pkt), equalTo(ip1Bdd)); MatchLineQuery matchLine1 = new MatchLineQuery(1); assertThat(matchLine1.getMatchingBdd(acl, ipAccessListToBdd, pkt), equalTo(ip2Bdd)); MatchLineQuery matchLine2 = new MatchLineQuery(2); BDD expectedBdd = prefixBdd.diff(ip1Bdd.or(ip2Bdd)); assertThat(matchLine2.getMatchingBdd(acl, ipAccessListToBdd, pkt), equalTo(expectedBdd)); }
@Override @Nonnull public BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt) { checkArgument(canQuery(acl), "ACL %s is too short to apply match line query", acl.getName()); BDD matchingTargetLine = ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(_lineNum)).getMatchBdd(); List<BDD> prevLineBdds = IntStream.range(0, _lineNum) .mapToObj( i -> ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(i)).getMatchBdd()) .collect(ImmutableList.toImmutableList()); return matchingTargetLine.diff(pkt.getFactory().orAll(prevLineBdds)); }
MatchLineQuery implements SearchFiltersQuery { @Override @Nonnull public BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt) { checkArgument(canQuery(acl), "ACL %s is too short to apply match line query", acl.getName()); BDD matchingTargetLine = ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(_lineNum)).getMatchBdd(); List<BDD> prevLineBdds = IntStream.range(0, _lineNum) .mapToObj( i -> ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(i)).getMatchBdd()) .collect(ImmutableList.toImmutableList()); return matchingTargetLine.diff(pkt.getFactory().orAll(prevLineBdds)); } }
MatchLineQuery implements SearchFiltersQuery { @Override @Nonnull public BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt) { checkArgument(canQuery(acl), "ACL %s is too short to apply match line query", acl.getName()); BDD matchingTargetLine = ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(_lineNum)).getMatchBdd(); List<BDD> prevLineBdds = IntStream.range(0, _lineNum) .mapToObj( i -> ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(i)).getMatchBdd()) .collect(ImmutableList.toImmutableList()); return matchingTargetLine.diff(pkt.getFactory().orAll(prevLineBdds)); } MatchLineQuery(int lineNum); }
MatchLineQuery implements SearchFiltersQuery { @Override @Nonnull public BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt) { checkArgument(canQuery(acl), "ACL %s is too short to apply match line query", acl.getName()); BDD matchingTargetLine = ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(_lineNum)).getMatchBdd(); List<BDD> prevLineBdds = IntStream.range(0, _lineNum) .mapToObj( i -> ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(i)).getMatchBdd()) .collect(ImmutableList.toImmutableList()); return matchingTargetLine.diff(pkt.getFactory().orAll(prevLineBdds)); } MatchLineQuery(int lineNum); int getLineNum(); @Override boolean canQuery(IpAccessList acl); @Override @Nonnull BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt); }
MatchLineQuery implements SearchFiltersQuery { @Override @Nonnull public BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt) { checkArgument(canQuery(acl), "ACL %s is too short to apply match line query", acl.getName()); BDD matchingTargetLine = ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(_lineNum)).getMatchBdd(); List<BDD> prevLineBdds = IntStream.range(0, _lineNum) .mapToObj( i -> ipAccessListToBdd.toPermitAndDenyBdds(acl.getLines().get(i)).getMatchBdd()) .collect(ImmutableList.toImmutableList()); return matchingTargetLine.diff(pkt.getFactory().orAll(prevLineBdds)); } MatchLineQuery(int lineNum); int getLineNum(); @Override boolean canQuery(IpAccessList acl); @Override @Nonnull BDD getMatchingBdd(IpAccessList acl, IpAccessListToBdd ipAccessListToBdd, BDDPacket pkt);  }