Search in sources :

Example 11 with AndExpr

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));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) Test(org.junit.Test)

Example 12 with AndExpr

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))));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 13 with AndExpr

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);
}
Also used : PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) OrExpr(org.batfish.z3.expr.OrExpr) TrueExpr(org.batfish.z3.expr.TrueExpr) ExtractExpr(org.batfish.z3.expr.ExtractExpr) StateExpr(org.batfish.z3.expr.StateExpr) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) IfExpr(org.batfish.z3.expr.IfExpr) Expr(org.batfish.z3.expr.Expr) BitVecExpr(org.batfish.z3.expr.BitVecExpr) FalseExpr(org.batfish.z3.expr.FalseExpr) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) NotExpr(org.batfish.z3.expr.NotExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) CurrentIsOriginalExpr(org.batfish.z3.expr.CurrentIsOriginalExpr) EqExpr(org.batfish.z3.expr.EqExpr) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) IdExpr(org.batfish.z3.expr.IdExpr) ListExpr(org.batfish.z3.expr.ListExpr) IdExpr(org.batfish.z3.expr.IdExpr)

Example 14 with AndExpr

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));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 15 with AndExpr

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();
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAction(org.batfish.datamodel.ForwardingAction) DropAcl(org.batfish.z3.state.DropAcl) DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) BatfishException(org.batfish.common.BatfishException) Drop(org.batfish.z3.state.Drop) DropNullRoute(org.batfish.z3.state.DropNullRoute) NodeAccept(org.batfish.z3.state.NodeAccept) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) StateExpr(org.batfish.z3.expr.StateExpr) Nonnull(javax.annotation.Nonnull) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) ImmutableSet(com.google.common.collect.ImmutableSet) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) Set(java.util.Set) Query(org.batfish.z3.state.Query) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) List(java.util.List) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) QueryStatement(org.batfish.z3.expr.QueryStatement) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) AndExpr(org.batfish.z3.expr.AndExpr) StateExpr(org.batfish.z3.expr.StateExpr) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Aggregations

AndExpr (org.batfish.z3.expr.AndExpr)15 BooleanExpr (org.batfish.z3.expr.BooleanExpr)13 Test (org.junit.Test)8 NotExpr (org.batfish.z3.expr.NotExpr)6 ImmutableList (com.google.common.collect.ImmutableList)5 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 QueryStatement (org.batfish.z3.expr.QueryStatement)5 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)5 EqExpr (org.batfish.z3.expr.EqExpr)3 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)3 LitIntExpr (org.batfish.z3.expr.LitIntExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 SaneExpr (org.batfish.z3.expr.SaneExpr)3 StateExpr (org.batfish.z3.expr.StateExpr)3 VarIntExpr (org.batfish.z3.expr.VarIntExpr)3 List (java.util.List)2 BitVecExpr (org.batfish.z3.expr.BitVecExpr)2 CurrentIsOriginalExpr (org.batfish.z3.expr.CurrentIsOriginalExpr)2 Expr (org.batfish.z3.expr.Expr)2 ExtractExpr (org.batfish.z3.expr.ExtractExpr)2