Search in sources :

Example 1 with Fixedpoint

use of com.microsoft.z3.Fixedpoint in project batfish by batfish.

the class NodFirstUnsatJob method call.

@Override
public NodFirstUnsatResult<KeyT, ResultT> call() {
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
        ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
        NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
        Fixedpoint fix = mkFixedpoint(program, false);
        KeyT key = _query.getKey();
        for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
            BoolExpr query = program.getQueries().get(queryNum);
            Status status = fix.query(query);
            switch(status) {
                case SATISFIABLE:
                    break;
                case UNKNOWN:
                    return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
                case UNSATISFIABLE:
                    return new NodFirstUnsatResult<>(key, queryNum, _query.getResultsByQueryIndex().get(queryNum), _logger.getHistory(), startTime);
                default:
                    return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
            }
        }
        return new NodFirstUnsatResult<>(key, null, null, _logger.getHistory(), startTime);
    } catch (Z3Exception e) {
        return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) Fixedpoint(com.microsoft.z3.Fixedpoint) Fixedpoint(com.microsoft.z3.Fixedpoint) Z3Exception(com.microsoft.z3.Z3Exception)

Example 2 with Fixedpoint

use of com.microsoft.z3.Fixedpoint in project batfish by batfish.

the class NodSatJob method call.

@Override
public NodSatResult<KeyT> call() {
    Map<KeyT, Boolean> results = new LinkedHashMap<>();
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
        ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
        NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
        Fixedpoint fix = mkFixedpoint(program, false);
        for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
            BoolExpr query = program.getQueries().get(queryNum);
            KeyT key = _query.getKeys().get(queryNum);
            Status status = fix.query(query);
            switch(status) {
                case SATISFIABLE:
                    results.put(key, true);
                    break;
                case UNKNOWN:
                    return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
                case UNSATISFIABLE:
                    results.put(key, false);
                    break;
                default:
                    return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
            }
        }
        return new NodSatResult<>(results, _logger.getHistory(), startTime);
    } catch (Z3Exception e) {
        return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) Fixedpoint(com.microsoft.z3.Fixedpoint) LinkedHashMap(java.util.LinkedHashMap) Fixedpoint(com.microsoft.z3.Fixedpoint) Z3Exception(com.microsoft.z3.Z3Exception)

Example 3 with Fixedpoint

use of com.microsoft.z3.Fixedpoint in project batfish by batfish.

the class Z3ContextJob method computeSmtConstraintsViaNod.

protected BoolExpr computeSmtConstraintsViaNod(NodProgram program, boolean negate) {
    Fixedpoint fix = mkFixedpoint(program, true);
    Expr answer = answerFixedPoint(fix, program);
    return getSolverInput(answer, program, negate);
}
Also used : BitVecExpr(com.microsoft.z3.BitVecExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Fixedpoint(com.microsoft.z3.Fixedpoint)

Example 4 with Fixedpoint

use of com.microsoft.z3.Fixedpoint in project batfish by batfish.

the class Z3ContextJob method mkFixedpoint.

protected Fixedpoint mkFixedpoint(NodProgram program, boolean printAnswer) {
    Context ctx = program.getNodContext().getContext();
    Params p = ctx.mkParams();
    p.add("timeout", _settings.getZ3timeout());
    p.add("fixedpoint.engine", "datalog");
    p.add("fixedpoint.datalog.default_relation", "doc");
    p.add("fixedpoint.print_answer", printAnswer);
    Fixedpoint fix = ctx.mkFixedpoint();
    fix.setParameters(p);
    for (FuncDecl relationDeclaration : program.getNodContext().getRelationDeclarations().values()) {
        fix.registerRelation(relationDeclaration);
    }
    for (BoolExpr rule : program.getRules()) {
        fix.addRule(rule, null);
    }
    return fix;
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) Fixedpoint(com.microsoft.z3.Fixedpoint) Params(com.microsoft.z3.Params) FuncDecl(com.microsoft.z3.FuncDecl)

Example 5 with Fixedpoint

use of com.microsoft.z3.Fixedpoint in project batfish by batfish.

the class NodJob method computeNodSat.

protected Status computeNodSat(long startTime, Context ctx) {
    NodProgram program = getNodProgram(ctx);
    Fixedpoint fix = mkFixedpoint(program, true);
    for (BoolExpr query : program.getQueries()) {
        Status status = fix.query(query);
        switch(status) {
            case SATISFIABLE:
                return status;
            case UNKNOWN:
                throw new BatfishException("Query satisfiability unknown");
            case UNSATISFIABLE:
                return status;
            default:
                throw new BatfishException("invalid status");
        }
    }
    throw new BatfishException("No queries");
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) Fixedpoint(com.microsoft.z3.Fixedpoint)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)5 Fixedpoint (com.microsoft.z3.Fixedpoint)5 Context (com.microsoft.z3.Context)3 Status (com.microsoft.z3.Status)3 BatfishException (org.batfish.common.BatfishException)3 Z3Exception (com.microsoft.z3.Z3Exception)2 BitVecExpr (com.microsoft.z3.BitVecExpr)1 Expr (com.microsoft.z3.Expr)1 FuncDecl (com.microsoft.z3.FuncDecl)1 Params (com.microsoft.z3.Params)1 LinkedHashMap (java.util.LinkedHashMap)1