@Override public Void visitMatchHeaderSpace(MatchHeaderSpace matchHeaderSpace) { addConstraint(matchHeaderSpace); return null; }
/** * This method is the public API of the class. It normalizes the input {@link AclLineMatchExpr}. */ public static AclLineMatchExpr normalize(IpAccessListToBDD toBDD, AclLineMatchExpr expr) { AclLineMatchExprNormalizer normalizer = new AclLineMatchExprNormalizer(toBDD); expr.accept(normalizer); Set<AclLineMatchExpr> disjuncts = normalizer._conjunctsBuilders.stream() .filter(conjunctsBuilder -> !conjunctsBuilder.unsat()) .map(ConjunctsBuilder::build) .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())); return disjuncts.contains(TRUE) ? TRUE : or(disjuncts); }
private static AclLineMatchExprWithProvenance<IpAccessListLineIndex> explainWithProvenance( IpAccessListToBDD ipAccessListToBDD, IpAccessList acl, Map<String, IpAccessList> namedAcls, IdentityHashMap<AclLineMatchExpr, IpAccessListLineIndex> literalsToLines) { // Convert acl to a single expression. AclLineMatchExpr aclExpr = AclToAclLineMatchExpr.toAclLineMatchExpr(ipAccessListToBDD, acl, namedAcls); // Reduce that expression to normal form. AclLineMatchExpr aclExprNf = AclLineMatchExprNormalizer.normalize(ipAccessListToBDD, aclExpr); // Simplify the normal form AclLineMatchExprWithProvenance<AclLineMatchExpr> aclExprNfExplained = AclExplanation.explainNormalForm(aclExprNf); // join the provenance information from the normal form with the literalsToLines mapping // above to obtain provenance back to the original acl lines IdentityHashMap<AclLineMatchExpr, Set<IpAccessListLineIndex>> conjunctsToLines = new IdentityHashMap<>(); for (Map.Entry<AclLineMatchExpr, Set<AclLineMatchExpr>> entry : aclExprNfExplained.getProvenance().entrySet()) { AclLineMatchExpr conjunct = entry.getKey(); conjunctsToLines.put( conjunct, entry.getValue().stream() .map(literalsToLines::get) .collect(ImmutableSet.toImmutableSet())); } return new AclLineMatchExprWithProvenance<>( aclExprNfExplained.getMatchExpr(), conjunctsToLines); }
@Override public Void visitOrMatchExpr(OrMatchExpr orMatchExpr) { _conjunctsBuilders = orMatchExpr.getDisjuncts().stream() .flatMap( disjunct -> { AclLineMatchExprNormalizer normalizer = new AclLineMatchExprNormalizer(this); disjunct.accept(normalizer); return normalizer._conjunctsBuilders.stream() .filter(conjunctsBuilder -> !conjunctsBuilder.unsat()); }) .collect(Collectors.toSet()); return null; }
@Override public Void visitMatchSrcInterface(MatchSrcInterface matchSrcInterface) { addConstraint(matchSrcInterface); return null; }
@Override public Void visitOriginatingFromDevice(OriginatingFromDevice originatingFromDevice) { addConstraint(originatingFromDevice); return null; }
@Override public Void visitNotMatchExpr(NotMatchExpr notMatchExpr) { AclLineMatchExpr negatedOperand = Negate.negate(notMatchExpr.getOperand()); if (negatedOperand instanceof NotMatchExpr) { // negated leaf node. rather than recurse, just add to the conjuctsBuilders. addConstraint(notMatchExpr); } else { negatedOperand.accept(this); } return null; }