use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class IpSpaceBooleanExprTransformer method visitAclIpSpace.
@Override
public BooleanExpr visitAclIpSpace(AclIpSpace aclIpSpace) {
// right fold
BooleanExpr expr = FalseExpr.INSTANCE;
for (int i = aclIpSpace.getLines().size() - 1; i >= 0; i--) {
AclIpSpaceLine line = aclIpSpace.getLines().get(i);
expr = new IfThenElse(line.getIpSpace().accept(this), line.getAction() == LineAction.ACCEPT ? TrueExpr.INSTANCE : FalseExpr.INSTANCE, expr);
}
return expr;
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class IpSpaceBooleanExprTransformer method visitIpWildcardSetIpSpace.
@Override
public BooleanExpr visitIpWildcardSetIpSpace(IpWildcardSetIpSpace ipWildcardSetIpSpace) {
BooleanExpr matchBlacklist = HeaderSpaceMatchExpr.matchIp(ipWildcardSetIpSpace.getBlacklist(), _useSrc, _useDst);
BooleanExpr matchWhitelist = HeaderSpaceMatchExpr.matchIp(ipWildcardSetIpSpace.getWhitelist(), _useSrc, _useDst);
return new AndExpr(ImmutableList.of(new NotExpr(matchBlacklist), matchWhitelist));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class Simplifier method visitOrExpr.
@Override
public BooleanExpr visitOrExpr(OrExpr orExpr) {
boolean changed = false;
List<BooleanExpr> oldDisjuncts = orExpr.getDisjuncts();
ImmutableList.Builder<BooleanExpr> newDisjunctsBuilder = ImmutableList.builder();
// first check for nested ORs
if (oldDisjuncts.stream().anyMatch(Predicates.instanceOf(OrExpr.class))) {
return simplifyBooleanExpr(new OrExpr(oldDisjuncts.stream().flatMap(disjunct -> disjunct instanceof OrExpr ? ((OrExpr) disjunct).getDisjuncts().stream() : Stream.of(disjunct)).collect(ImmutableList.toImmutableList())));
}
// no nested ORs, so just simplify all disjuncts
for (BooleanExpr disjunct : oldDisjuncts) {
BooleanExpr simplifiedDisjunct = simplifyBooleanExpr(disjunct);
if (disjunct != simplifiedDisjunct) {
changed = true;
}
if (simplifiedDisjunct == TrueExpr.INSTANCE) {
return TrueExpr.INSTANCE;
} else if (simplifiedDisjunct != FalseExpr.INSTANCE) {
newDisjunctsBuilder.add(simplifiedDisjunct);
} else {
changed = true;
}
}
List<BooleanExpr> newDisjuncts = newDisjunctsBuilder.build();
if (newDisjuncts.size() == 0) {
return FalseExpr.INSTANCE;
} else if (newDisjuncts.size() == 1) {
return newDisjuncts.get(0);
} else if (!changed) {
return orExpr;
} else {
return new OrExpr(newDisjuncts);
}
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class Simplifier method visitIfExpr.
@Override
public BooleanExpr visitIfExpr(IfExpr ifExpr) {
BooleanExpr oldAntecedent = ifExpr.getAntecedent();
BooleanExpr oldConsequent = ifExpr.getConsequent();
BooleanExpr newAntecedent = simplifyBooleanExpr(oldAntecedent);
BooleanExpr newConsequent = simplifyBooleanExpr(oldConsequent);
if (newAntecedent == FalseExpr.INSTANCE || newConsequent == TrueExpr.INSTANCE || newAntecedent.equals(newConsequent)) {
return TrueExpr.INSTANCE;
} else if (newAntecedent == TrueExpr.INSTANCE) {
return newConsequent;
} else if (newAntecedent != oldAntecedent || newConsequent != oldConsequent) {
return new IfExpr(newAntecedent, newConsequent);
} else {
return ifExpr;
}
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class Simplifier method visitBasicRuleStatement.
@Override
public Statement visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
/**
* TODO: something smarter
*/
BooleanExpr originalPreconditionStateIndependentConstraints = basicRuleStatement.getPreconditionStateIndependentConstraints();
BooleanExpr simplifiedPreconditionStateIndependentConstraints = simplifyBooleanExpr(originalPreconditionStateIndependentConstraints);
if (originalPreconditionStateIndependentConstraints != simplifiedPreconditionStateIndependentConstraints) {
return simplifyStatement(new BasicRuleStatement(simplifiedPreconditionStateIndependentConstraints, basicRuleStatement.getPreconditionStates(), basicRuleStatement.getPostconditionState()));
} else if (simplifiedPreconditionStateIndependentConstraints == FalseExpr.INSTANCE) {
return VACUOUS_RULE;
} else {
return basicRuleStatement;
}
}
Aggregations