Search in sources :

Example 1 with BitVecExpr

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

the class AbstractNodJob method getOriginateVrfConstraints.

/**
 * Try to find a model for each OriginateVrf. If an OriginateVrf does not have an entry in the
 * Map, then the query is unsat when originating from there.
 */
protected Map<OriginateVrf, Map<String, Long>> getOriginateVrfConstraints(Context ctx, SmtInput smtInput) {
    Solver solver = ctx.mkSolver();
    solver.add(smtInput._expr);
    int originateVrfBvSize = _originateVrfInstrumentation.getFieldBits();
    BitVecExpr originateVrfFieldConst = ctx.mkBVConst(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, originateVrfBvSize);
    ImmutableMap.Builder<OriginateVrf, Map<String, Long>> models = ImmutableMap.builder();
    // keep refining until no new models
    while (true) {
        try {
            Map<String, Long> constraints = getSolution(solver, smtInput._variablesAsConsts);
            int originateVrfId = Math.toIntExact(constraints.get(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME));
            OriginateVrf originateVrf = _originateVrfInstrumentation.getOriginateVrfs().get(originateVrfId);
            models.put(originateVrf, constraints);
            // refine: different OriginateVrf
            solver.add(ctx.mkNot(ctx.mkEq(originateVrfFieldConst, ctx.mkBV(originateVrfId, originateVrfBvSize))));
        } catch (QueryUnsatException e) {
            break;
        }
    }
    return models.build();
}
Also used : Solver(com.microsoft.z3.Solver) BitVecExpr(com.microsoft.z3.BitVecExpr) OriginateVrf(org.batfish.z3.state.OriginateVrf) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with BitVecExpr

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

the class BoolExprTransformerTest method testVisitEqExpr.

@Test
public void testVisitEqExpr() {
    IntExpr i1Batfish = newIntAtom();
    IntExpr i2Batfish = newIntAtom();
    BitVecExpr i1Z3 = toBitVecExpr(i1Batfish, _nodContext);
    BitVecExpr i2Z3 = toBitVecExpr(i2Batfish, _nodContext);
    assertThat(toBoolExpr(new EqExpr(i1Batfish, i2Batfish), _input, _nodContext), equalTo(_ctx.mkEq(i1Z3, i2Z3)));
}
Also used : BitVecExprTransformer.toBitVecExpr(org.batfish.z3.expr.visitors.BitVecExprTransformer.toBitVecExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) Test(org.junit.Test)

Example 3 with BitVecExpr

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

the class ExprPrinter method visitBitVecExpr.

@Override
public void visitBitVecExpr(BitVecExpr bitVecExpr) {
    List<Expr> subExpressions = ImmutableList.of(new IdExpr("_"), new IdExpr("BitVec"), new IdExpr(Integer.toString(bitVecExpr.getSize())));
    printCollapsedComplexExpr(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)

Aggregations

BitVecExpr (com.microsoft.z3.BitVecExpr)2 EqExpr (org.batfish.z3.expr.EqExpr)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Solver (com.microsoft.z3.Solver)1 Map (java.util.Map)1 AndExpr (org.batfish.z3.expr.AndExpr)1 BitVecExpr (org.batfish.z3.expr.BitVecExpr)1 CurrentIsOriginalExpr (org.batfish.z3.expr.CurrentIsOriginalExpr)1 Expr (org.batfish.z3.expr.Expr)1 ExtractExpr (org.batfish.z3.expr.ExtractExpr)1 FalseExpr (org.batfish.z3.expr.FalseExpr)1 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)1 IdExpr (org.batfish.z3.expr.IdExpr)1 IfExpr (org.batfish.z3.expr.IfExpr)1 IntExpr (org.batfish.z3.expr.IntExpr)1 IpSpaceMatchExpr (org.batfish.z3.expr.IpSpaceMatchExpr)1 ListExpr (org.batfish.z3.expr.ListExpr)1 LitIntExpr (org.batfish.z3.expr.LitIntExpr)1 NotExpr (org.batfish.z3.expr.NotExpr)1 OrExpr (org.batfish.z3.expr.OrExpr)1