Search in sources :

Example 16 with DTree

use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.

the class App method runMbasSynthesis.

/**
 * Run MBAS Synthesis with CSV input files
 *
 * @param vdmPath VDM input file for synthesis
 * @param modelName Name of model
 * @param stemDir output directory for STEM input files
 * @param soteriaDir output directory for Soteria++ input files
 * @throws VerdictRunException
 */
public static void runMbasSynthesis(String vdmPath, String modelName, String stemProjectDir, String debugDir, String soteriaPpBin, boolean cyberInference, boolean safetyInference, boolean partialSolution, String costModelPath, String outputPath) throws VerdictRunException {
    String stemCsvDir = (new File(stemProjectDir, "CSVData")).getAbsolutePath();
    String stemOutputDir = (new File(stemProjectDir, "Output")).getAbsolutePath();
    String stemGraphsDir = (new File(stemProjectDir, "Graphs")).getAbsolutePath();
    String stemSadlFile = (new File(stemProjectDir, "Run.sadl")).getAbsolutePath();
    File soteriaOutputDir = new File(stemOutputDir, "Soteria_Output");
    soteriaOutputDir.mkdirs();
    String soteriaPpOutputDir = soteriaOutputDir.getAbsolutePath();
    checkFile(stemCsvDir, true, true, true, false, null);
    checkFile(stemOutputDir, true, true, true, false, null);
    checkFile(stemGraphsDir, true, true, true, false, null);
    checkFile(stemSadlFile, true, false, false, false, null);
    checkFile(soteriaPpOutputDir, true, true, true, false, null);
    checkFile(soteriaPpBin, true, false, false, true, null);
    checkFile(vdmPath, true, false, false, false, "xml");
    checkFile(costModelPath, true, false, false, false, "xml");
    checkFile(outputPath, false, false, true, false, "xml");
    deleteDirectoryContents(stemGraphsDir);
    deleteDirectoryContents(soteriaPpOutputDir);
    if (debugDir != null) {
        logHeader("DEBUGGING XML OUTPUT");
    }
    try {
        // Copy Soteria++ pngs
        for (String soteria_png : soteria_pngs) {
            Binary.copyResource("soteria_pngs/" + soteria_png + ".png", new File(soteriaPpOutputDir, soteria_png + ".png"), false);
        }
    } catch (Binary.ExecutionException e) {
        throw new VerdictRunException("Failed to copy Soteria++ pngs", e);
    }
    logHeader("STEM");
    log("STEM project directory: " + stemProjectDir);
    log("STEM output directory: " + stemOutputDir);
    log("STEM graphs directory: " + stemGraphsDir);
    log("STEM is running. Please be patient...");
    VerdictStem stemRunner = new VerdictStem();
    Metrics.timer("Timer.mbas.stem", "model", modelName).record(() -> stemRunner.runStem(new File(stemProjectDir), new File(stemOutputDir), new File(stemGraphsDir)));
    log("STEM finished!");
    logHeader("Synthesis");
    try {
        Timer.Sample sample = Timer.start(Metrics.globalRegistry);
        CostModel costModel = new CostModel(new File(costModelPath));
        AttackDefenseCollector collector = new AttackDefenseCollector(new File(vdmPath), new File(stemOutputDir), cyberInference);
        List<AttackDefenseCollector.Result> results = collector.perform();
        boolean sat = results.stream().allMatch(result -> Prob.lte(result.prob, result.cyberReq.getSeverity()));
        boolean performMeritAssignment = partialSolution && sat;
        DLeaf.Factory factory = new DLeaf.Factory();
        DTree dtree = DTreeConstructor.construct(results, costModel, partialSolution, performMeritAssignment, factory);
        Optional<ResultsInstance> selected = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, partialSolution, sat, performMeritAssignment, false);
        if (selected.isPresent()) {
            if (performMeritAssignment) {
                ResultsInstance withExtraDefProps = VerdictSynthesis.addExtraImplDefenses(selected.get(), collector.getImplDal(), costModel);
                withExtraDefProps.toFileXml(new File(outputPath));
            } else {
                selected.get().toFileXml(new File(outputPath));
            }
            log("Synthesis results output to " + outputPath);
        } else {
            logError("Synthesis failed");
        }
        sample.stop(Metrics.timer("Timer.mbas.synthesis", "model", modelName));
    } catch (IOException | MalformedInputException e) {
        throw new VerdictRunException("Failed to execute synthesis", e);
    }
    logHeader("Finished");
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) VerdictStem(com.ge.verdict.stem.VerdictStem) CostModel(com.ge.verdict.synthesis.CostModel) AttackDefenseCollector(com.ge.verdict.attackdefensecollector.AttackDefenseCollector) IOException(java.io.IOException) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Timer(io.micrometer.core.instrument.Timer) MalformedInputException(com.ge.verdict.attackdefensecollector.CSVFile.MalformedInputException) File(java.io.File)

Aggregations

DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)16 DTree (com.ge.verdict.synthesis.dtree.DTree)16 ADTree (com.ge.verdict.attackdefensecollector.adtree.ADTree)14 Test (org.junit.Test)11 ADOr (com.ge.verdict.attackdefensecollector.adtree.ADOr)10 DOr (com.ge.verdict.synthesis.dtree.DOr)10 Fraction (org.apache.commons.math3.fraction.Fraction)9 ADAnd (com.ge.verdict.attackdefensecollector.adtree.ADAnd)8 Attack (com.ge.verdict.attackdefensecollector.adtree.Attack)8 DAnd (com.ge.verdict.synthesis.dtree.DAnd)8 File (java.io.File)8 SystemModel (com.ge.verdict.attackdefensecollector.model.SystemModel)7 ADNot (com.ge.verdict.attackdefensecollector.adtree.ADNot)6 Defense (com.ge.verdict.attackdefensecollector.adtree.Defense)6 ALeaf (com.ge.verdict.synthesis.dtree.ALeaf)6 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)4 ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)4 IOException (java.io.IOException)3 MalformedInputException (com.ge.verdict.attackdefensecollector.CSVFile.MalformedInputException)2 Approach (com.ge.verdict.synthesis.VerdictSynthesis.Approach)2