use of com.ge.verdict.stem.VerdictStem in project VERDICT by ge-high-assurance.
the class App method runMbas.
/**
* Run MBAS with CSV input files
*
* @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 runMbas(String modelName, String stemProjectDir, String debugDir, String soteriaPpBin, boolean cyberInference, boolean safetyInference) 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);
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("Soteria++");
log("Soteria++ input directory: " + stemOutputDir);
log("Soteria++ output directory: " + soteriaPpOutputDir);
log("Soteria++ is running. Please be patient...");
// Soteria has optional arguments, so need to add all args to this list
List<String> args = new ArrayList<>();
args.add("-o");
args.add(soteriaPpOutputDir);
args.add(stemOutputDir);
if (cyberInference) {
args.add("-c");
}
if (safetyInference) {
args.add("-s");
}
try {
Timer.Sample sample = Timer.start(Metrics.globalRegistry);
Binary.invokeBin(soteriaPpBin, soteriaPpOutputDir, new PumpStreamHandler(), args.toArray(new String[args.size()]));
sample.stop(Metrics.timer("Timer.mbas.soteria_pp", "model", modelName));
} catch (Binary.ExecutionException e) {
throw new VerdictRunException("Failed to execute soteria_pp", e);
}
logHeader("Finished");
}
use of com.ge.verdict.stem.VerdictStem 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");
}
Aggregations