Search in sources :

Example 26 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class IpSpaceBooleanExprTransformerTest method testVisitIpWildcardSetIpSpace.

@Test
public void testVisitIpWildcardSetIpSpace() {
    IpWildcard includeWildcard = new IpWildcard("1.1.1.1");
    IpWildcard excludeWildcard = new IpWildcard("2.2.2.2");
    IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(includeWildcard).excluding(excludeWildcard).build();
    BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr includeExpr = includeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr excludeExpr = excludeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(new AndExpr(ImmutableList.of(new NotExpr(excludeExpr), includeExpr))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) AndExpr(org.batfish.z3.expr.AndExpr) IpWildcardSetIpSpace(org.batfish.datamodel.IpWildcardSetIpSpace) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 27 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyAndExprFalseConjunct.

/**
 * Test simplifications: false AND E --> false E AND false --> false.
 */
@Test
public void testSimplifyAndExprFalseConjunct() {
    BooleanExpr p1 = newAtom();
    AndExpr leftFalse = new AndExpr(of(FalseExpr.INSTANCE, p1));
    AndExpr rightFalse = new AndExpr(of(p1, FalseExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(leftFalse), equalTo(FalseExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(rightFalse), equalTo(FalseExpr.INSTANCE));
}
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 28 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyOr1.

/**
 * Test that an OR node with a single child (other than TRUE or FALSE) simplifies to that child.
 */
@Test
public void testSimplifyOr1() {
    BooleanExpr p1 = newAtom();
    OrExpr or = new OrExpr(of(p1));
    assertThat(simplifyBooleanExpr(or), equalTo(p1));
}
Also used : BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) OrExpr(org.batfish.z3.expr.OrExpr) Test(org.junit.Test)

Example 29 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyIfStaticallyTrue.

/**
 * Test that an IF with antecedent statically FALSE, or consequent statically TRUE, or antecedent
 * statically equal to consequent simplifies to TRUE.
 */
@Test
public void testSimplifyIfStaticallyTrue() {
    BooleanExpr p1 = newAtom();
    // Antecedent is false
    assertThat(simplifyBooleanExpr(new IfExpr(FalseExpr.INSTANCE, newAtom())), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(FalseExpr.INSTANCE)), newAtom())), equalTo(TrueExpr.INSTANCE));
    // Consequent is true
    assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), TrueExpr.INSTANCE)), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), new NotExpr(FalseExpr.INSTANCE))), equalTo(TrueExpr.INSTANCE));
    // Antecedent == Consequent
    assertThat(simplifyBooleanExpr(new IfExpr(p1, p1)), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(p1)), p1)), equalTo(TrueExpr.INSTANCE));
}
Also used : IfExpr(org.batfish.z3.expr.IfExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 30 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyIfUnchanged.

/**
 * Test that an IF with unsimplifiable antecedent and consequent is unchanged by simplification.
 */
@Test
public void testSimplifyIfUnchanged() {
    BooleanExpr p1 = newAtom();
    BooleanExpr p2 = newAtom();
    BooleanExpr ifExpr = new IfExpr(p1, p2);
    assertThat(simplifyBooleanExpr(ifExpr), sameInstance(ifExpr));
}
Also used : IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)43 Test (org.junit.Test)27 AndExpr (org.batfish.z3.expr.AndExpr)14 NotExpr (org.batfish.z3.expr.NotExpr)13 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)13 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)10 ImmutableList (com.google.common.collect.ImmutableList)9 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)8 BoolExpr (com.microsoft.z3.BoolExpr)7 IfExpr (org.batfish.z3.expr.IfExpr)7 VarIntExpr (org.batfish.z3.expr.VarIntExpr)7 BoolExprTransformer.toBoolExpr (org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr)7 List (java.util.List)6 IpWildcard (org.batfish.datamodel.IpWildcard)6 EqExpr (org.batfish.z3.expr.EqExpr)6 OrExpr (org.batfish.z3.expr.OrExpr)6 QueryStatement (org.batfish.z3.expr.QueryStatement)6 RuleStatement (org.batfish.z3.expr.RuleStatement)6 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)6 Ip (org.batfish.datamodel.Ip)5