Search in sources :

Example 1 with IfThenElse

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

the class IpSpaceBooleanExprTransformerTest method testVisitAclIpSpace.

@Test
public void testVisitAclIpSpace() {
    AclIpSpace ipSpace = AclIpSpace.builder().thenRejecting(UniverseIpSpace.INSTANCE).thenPermitting(EmptyIpSpace.INSTANCE).build();
    BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(new IfThenElse(// Matches UniverseIpSpace
    TrueExpr.INSTANCE, // Reject
    FalseExpr.INSTANCE, new IfThenElse(// Matches EmptyIpSpace
    FalseExpr.INSTANCE, // Accept
    TrueExpr.INSTANCE, // Matches nothing so reject
    FalseExpr.INSTANCE))));
}
Also used : AclIpSpace(org.batfish.datamodel.AclIpSpace) IfThenElse(org.batfish.z3.expr.IfThenElse) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 2 with IfThenElse

use of org.batfish.z3.expr.IfThenElse 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;
}
Also used : AclIpSpaceLine(org.batfish.datamodel.AclIpSpaceLine) IfThenElse(org.batfish.z3.expr.IfThenElse) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)2 IfThenElse (org.batfish.z3.expr.IfThenElse)2 AclIpSpace (org.batfish.datamodel.AclIpSpace)1 AclIpSpaceLine (org.batfish.datamodel.AclIpSpaceLine)1 Test (org.junit.Test)1