Search in sources :

Example 41 with Status

use of com.arbindo.mimock.manage.mimocks.models.v1.Status 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 42 with Status

use of com.arbindo.mimock.manage.mimocks.models.v1.Status in project batfish by batfish.

the class NodJobTest method testNotNattedSat.

/**
 * Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns SAT when we
 * constrain to only allow NOT-NATed results.
 */
@Test
public void testNotNattedSat() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
    NodJob nodJob = getNodJob(headerSpace, false);
    Context z3Context = new Context();
    Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
    assertThat(status, equalTo(Status.SATISFIABLE));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) HeaderSpace(org.batfish.datamodel.HeaderSpace) Test(org.junit.Test)

Example 43 with Status

use of com.arbindo.mimock.manage.mimocks.models.v1.Status in project batfish by batfish.

the class NodJobTest method testNattedUnsat.

/**
 * Test that traffic originating from 3.0.0.0 that is expected to be NATed returns UNSAT when we
 * constrain to only allow NOT-NATed results.
 */
@Test
public void testNattedUnsat() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.0")));
    NodJob nodJob = getNodJob(headerSpace, false);
    Context z3Context = new Context();
    Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
    assertThat(status, equalTo(Status.UNSATISFIABLE));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) HeaderSpace(org.batfish.datamodel.HeaderSpace) Test(org.junit.Test)

Example 44 with Status

use of com.arbindo.mimock.manage.mimocks.models.v1.Status in project bmoth by hhu-stups.

the class BoundedModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    for (int k = 0; k < maxSteps; k++) {
        // get a clean solver
        solver.reset();
        // INIT(V0)
        solver.add(init());
        // CONJUNCTION i from 1 to k T(Vi-1, Vi)
        for (int i = 1; i <= k; i++) {
            solver.add(transition(i - 1, i));
        }
        // not INV(Vk)
        solver.add(getContext().mkNot(invariant(k)));
        // CONJUNCTION i from 1 to k, j from i + 1 to k (Vi != Vj)
        solver.add(distinctVectors(k));
        Status check = solver.check();
        if (check == Status.SATISFIABLE) {
            // counter example found!
            State counterExample = getStateFromModel(solver.getModel(), k);
            return ModelCheckingResult.createCounterExampleFound(k, counterExample, null);
        }
    }
    // no counter example found after maxStep steps
    return ModelCheckingResult.createExceededMaxSteps(maxSteps);
}
Also used : Status(com.microsoft.z3.Status) State(de.bmoth.modelchecker.State)

Example 45 with Status

use of com.arbindo.mimock.manage.mimocks.models.v1.Status in project bmoth by hhu-stups.

the class ExplicitStateModelChecker method labelStateSpace.

private void labelStateSpace() {
    Queue<State> statesToUpdate = new ArrayDeque<>();
    statesToUpdate.addAll(stateSpace.vertexSet());
    while (!statesToUpdate.isEmpty()) {
        State current = statesToUpdate.poll();
        final Set<BuechiAutomatonNode> buechiNodes = new HashSet<>();
        final Set<BuechiAutomatonNode> candidates = new HashSet<>();
        if (stateSpace.rootVertexSet().contains(current)) {
            candidates.addAll(buechiAutomaton.getInitialStates());
        } else {
            Set<DefaultEdge> incomingEdges = stateSpace.incomingEdgesOf(current);
            for (DefaultEdge incomingEdge : incomingEdges) {
                State predecessor = stateSpace.getEdgeSource(incomingEdge);
                predecessor.getBuechiNodes().forEach(n -> candidates.addAll(n.getSuccessors()));
            }
        }
        for (BuechiAutomatonNode node : candidates) {
            if (node.getLabels().isEmpty()) {
                buechiNodes.add(node);
            }
            // TODO use all labels?
            for (PredicateNode label : node.getLabels()) {
                labelSolver.reset();
                labelSolver.add(FormulaToZ3Translator.translatePredicate(label, getContext(), getMachineTranslator().getZ3TypeInference()));
                labelSolver.add(current.getStateConstraint(getContext()));
                Status status = labelSolver.check();
                switch(status) {
                    case UNSATISFIABLE:
                        break;
                    case UNKNOWN:
                        throw new UnsupportedOperationException("should not be undefined");
                    case SATISFIABLE:
                        buechiNodes.add(node);
                }
            }
        }
        buechiNodes.stream().filter(n -> !current.getBuechiNodes().contains(n)).forEach(newBuechiNode -> {
            // found a new node, need to update successors again
            current.addBuechiNode(newBuechiNode);
            Set<DefaultEdge> outgoingEdges = stateSpace.outgoingEdgesOf(current);
            for (DefaultEdge outgoingEdge : outgoingEdges) {
                State successor = stateSpace.getEdgeTarget(outgoingEdge);
                if (!statesToUpdate.contains(successor)) {
                    statesToUpdate.add(successor);
                }
            }
        });
    }
}
Also used : Status(com.microsoft.z3.Status) Z3SolverFactory(de.bmoth.backend.z3.Z3SolverFactory) de.bmoth.modelchecker(de.bmoth.modelchecker) java.util(java.util) FormulaToZ3Translator(de.bmoth.backend.z3.FormulaToZ3Translator) DefaultEdge(org.jgrapht.graph.DefaultEdge) Solver(com.microsoft.z3.Solver) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) SolutionFinder(de.bmoth.backend.z3.SolutionFinder) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) NOT(de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode.Kind.NOT) TarjanSimpleCycles(org.jgrapht.alg.cycle.TarjanSimpleCycles) Model(com.microsoft.z3.Model) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) de.bmoth.parser.ast.nodes.ltl(de.bmoth.parser.ast.nodes.ltl) BoolExpr(com.microsoft.z3.BoolExpr) LTLTransformations(de.bmoth.backend.ltl.LTLTransformations) Status(com.microsoft.z3.Status) TranslationOptions(de.bmoth.backend.TranslationOptions) BMothPreferences(de.bmoth.preferences.BMothPreferences) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) DefaultEdge(org.jgrapht.graph.DefaultEdge)

Aggregations

Status (com.microsoft.z3.Status)63 BoolExpr (com.microsoft.z3.BoolExpr)55 Test (org.junit.Test)49 Test (org.junit.jupiter.api.Test)21 JsonMapper.convertObjectToJsonString (com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString)13 RandomDataGenerator.generateRandomAlphabeticString (com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)13 MvcResult (org.springframework.test.web.servlet.MvcResult)13 Mock (com.arbindo.mimock.entities.Mock)12 Expr (com.microsoft.z3.Expr)10 IOException (java.io.IOException)10 MockRequest (com.arbindo.mimock.manage.mimocks.models.v1.MockRequest)9 ProcessedMockRequest (com.arbindo.mimock.manage.mimocks.models.v1.ProcessedMockRequest)9 Status (com.arbindo.mimock.manage.mimocks.models.v1.Status)9 Context (com.microsoft.z3.Context)9 Pageable (org.springframework.data.domain.Pageable)9 HttpStatus (org.springframework.http.HttpStatus)9 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)9