Search in sources :

Example 21 with BooleanExpr

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

the class Simplifier method visitNotExpr.

@Override
public BooleanExpr visitNotExpr(NotExpr notExpr) {
    BooleanExpr oldArg = notExpr.getArg();
    BooleanExpr newArg = simplifyBooleanExpr(oldArg);
    if (newArg == FalseExpr.INSTANCE) {
        return TrueExpr.INSTANCE;
    } else if (newArg == TrueExpr.INSTANCE) {
        return FalseExpr.INSTANCE;
    } else if (newArg instanceof NotExpr) {
        return ((NotExpr) newArg).getArg();
    } else if (newArg != oldArg) {
        return new NotExpr(newArg);
    } else {
        return notExpr;
    }
}
Also used : NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 22 with BooleanExpr

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

the class BoolExprTransformerTest method testVisitIfExpr.

@Test
public void testVisitIfExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BooleanExpr p2Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    BoolExpr p2Z3 = toBoolExpr(p2Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new IfExpr(p1Batfish, p2Batfish), _input, _nodContext), equalTo(_ctx.mkImplies(p1Z3, p2Z3)));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 23 with BooleanExpr

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

the class BoolExprTransformerTest method testVisitNotExpr.

@Test
public void testVisitNotExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new NotExpr(p1Batfish), _input, _nodContext), equalTo(_ctx.mkNot(p1Z3)));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 24 with BooleanExpr

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

the class BoolExprTransformerTest method testVisitRangeMatchExpr.

@Test
public void testVisitRangeMatchExpr() {
    BooleanExpr expr = RangeMatchExpr.fromSubRanges(BasicHeaderField.DSCP, BasicHeaderField.DSCP.getSize(), ImmutableSet.of(new SubRange(1, 3), new SubRange(5, 7)));
    assertThat(toBoolExpr(expr, _input, _nodContext), instanceOf(BoolExpr.class));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) SubRange(org.batfish.datamodel.SubRange) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 25 with BooleanExpr

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

the class IpSpaceBooleanExprTransformerTest method testVisitIp.

@Test
public void testVisitIp() {
    Ip ip = new Ip("1.2.3.4");
    BooleanExpr matchSrcExpr = ip.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchSrcExpr, equalTo(HeaderSpaceMatchExpr.matchSrcIp(ImmutableSet.of(new IpWildcard(ip)))));
    BooleanExpr matchDstExpr = ip.accept(DST_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchDstExpr, equalTo(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(ip)))));
    BooleanExpr matchSrcOrDstExpr = ip.accept(SRC_OR_DST_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(matchSrcOrDstExpr, equalTo(HeaderSpaceMatchExpr.matchSrcOrDstIp(ImmutableSet.of(new IpWildcard(ip)))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Ip(org.batfish.datamodel.Ip) BooleanExpr(org.batfish.z3.expr.BooleanExpr) 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