use of org.batfish.z3.expr.AndExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyEmptyAnd.
/**
* Test that an empty AND node is simplified to true (the identity under AND).
*/
@Test
public void testSimplifyEmptyAnd() {
AndExpr and = new AndExpr(of());
assertThat(simplifyBooleanExpr(and), equalTo(TrueExpr.INSTANCE));
}
use of org.batfish.z3.expr.AndExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyAndExprNestedConjuncts.
/**
* Test that nested ANDs get flattened into one AND.
*/
@Test
public void testSimplifyAndExprNestedConjuncts() {
BooleanExpr p1 = newAtom();
BooleanExpr p2 = newAtom();
BooleanExpr p3 = newAtom();
AndExpr leftNested = new AndExpr(of(new AndExpr(of(p1, p2)), p3));
AndExpr rightNested = new AndExpr(of(p1, new AndExpr(of(p2, p3))));
assertThat(leftNested, not(equalTo(rightNested)));
assertThat(simplifyBooleanExpr(leftNested), equalTo(new AndExpr(of(p1, p2, p3))));
assertThat(simplifyBooleanExpr(rightNested), equalTo(new AndExpr(of(p1, p2, p3))));
}
use of org.batfish.z3.expr.AndExpr in project batfish by batfish.
the class ExprPrinter method visitAndExpr.
@Override
public void visitAndExpr(AndExpr andExpr) {
List<Expr> subExpressions = ImmutableList.<Expr>builder().add(new IdExpr("and")).addAll(andExpr.getConjuncts()).build();
printExpandedComplexExpr(subExpressions);
}
use of org.batfish.z3.expr.AndExpr 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.AndExpr in project batfish by batfish.
the class StandardReachabilityQuerySynthesizer method getReachabilityProgram.
@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
List<StateExpr> finalActions = computeFinalActions();
ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
finalActions.stream().map(finalAction -> new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(finalAction), Query.INSTANCE)).forEach(rules::add);
addOriginateRules(rules);
return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Aggregations