Search in sources :

Example 56 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project batfish by batfish.

the class PropertyChecker method addEnvironmentConstraints.

private void addEnvironmentConstraints(Encoder enc, EnvironmentType t) {
    LogicalGraph lg = enc.getMainSlice().getLogicalGraph();
    Context ctx = enc.getCtx();
    switch(t) {
        case ANY:
            break;
        case NONE:
            for (SymbolicRoute vars : lg.getEnvironmentVars().values()) {
                enc.add(ctx.mkNot(vars.getPermitted()));
            }
            break;
        case SANE:
            for (SymbolicRoute vars : lg.getEnvironmentVars().values()) {
                enc.add(ctx.mkLe(vars.getMetric(), ctx.mkInt(50)));
            }
            break;
        default:
            break;
    }
}
Also used : Context(com.microsoft.z3.Context)

Example 57 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project batfish by batfish.

the class PropertyChecker method checkBlackHole.

/*
   * Compute if there can ever be a black hole for routers that are
   * not at the edge of the network. This is almost certainly a bug.
   */
public AnswerElement checkBlackHole(HeaderQuestion q) {
    Graph graph = new Graph(_batfish);
    Encoder enc = new Encoder(_settings, graph, q);
    enc.computeEncoding();
    Context ctx = enc.getCtx();
    EncoderSlice slice = enc.getMainSlice();
    // Collect routers that have no host/environment edge
    List<String> toCheck = new ArrayList<>();
    for (Entry<String, List<GraphEdge>> entry : graph.getEdgeMap().entrySet()) {
        String router = entry.getKey();
        List<GraphEdge> edges = entry.getValue();
        boolean check = true;
        for (GraphEdge edge : edges) {
            if (edge.getEnd() == null) {
                check = false;
                break;
            }
        }
        if (check) {
            toCheck.add(router);
        }
    }
    // Ensure the router never receives traffic and then drops the traffic
    BoolExpr someBlackHole = ctx.mkBool(false);
    for (String router : toCheck) {
        Map<GraphEdge, BoolExpr> edges = slice.getSymbolicDecisions().getDataForwarding().get(router);
        BoolExpr doesNotFwd = ctx.mkBool(true);
        for (Map.Entry<GraphEdge, BoolExpr> entry : edges.entrySet()) {
            BoolExpr dataFwd = entry.getValue();
            doesNotFwd = ctx.mkAnd(doesNotFwd, ctx.mkNot(dataFwd));
        }
        BoolExpr isFwdTo = ctx.mkBool(false);
        Set<String> neighbors = graph.getNeighbors().get(router);
        for (String n : neighbors) {
            for (Map.Entry<GraphEdge, BoolExpr> entry : slice.getSymbolicDecisions().getDataForwarding().get(n).entrySet()) {
                GraphEdge ge = entry.getKey();
                BoolExpr fwd = entry.getValue();
                if (router.equals(ge.getPeer())) {
                    isFwdTo = ctx.mkOr(isFwdTo, fwd);
                }
            }
        }
        someBlackHole = ctx.mkOr(someBlackHole, ctx.mkAnd(isFwdTo, doesNotFwd));
    }
    enc.add(someBlackHole);
    VerificationResult result = enc.verify().getFirst();
    return new SmtOneAnswerElement(result);
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) ArrayList(java.util.ArrayList) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement) Graph(org.batfish.symbolic.Graph) List(java.util.List) ArrayList(java.util.ArrayList) GraphEdge(org.batfish.symbolic.GraphEdge) Map(java.util.Map) EnumMap(java.util.EnumMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 58 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context 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 59 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context 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 60 with Context

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context in project batfish by batfish.

the class AbstractNodJob method call.

@Override
public final NodJobResult call() {
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        SmtInput smtInput = computeSmtInput(startTime, ctx);
        Map<OriginateVrf, Map<String, Long>> originateVrfConstraints = getOriginateVrfConstraints(ctx, smtInput);
        Set<Flow> flows = getFlows(originateVrfConstraints);
        return new NodJobResult(startTime, _logger.getHistory(), flows);
    } catch (Z3Exception e) {
        return new NodJobResult(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) BatfishException(org.batfish.common.BatfishException) OriginateVrf(org.batfish.z3.state.OriginateVrf) Z3Exception(com.microsoft.z3.Z3Exception) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Flow(org.batfish.datamodel.Flow)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)35 Test (org.junit.Test)24 BoolExpr (com.microsoft.z3.BoolExpr)23 List (java.util.List)20 IOException (java.io.IOException)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)18 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 HashMap (java.util.HashMap)16 File (java.io.File)14 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)12 IStatus (org.eclipse.core.runtime.IStatus)12 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Z3Exception (com.microsoft.z3.Z3Exception)9