use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method testUnmitigatedMixed.
@Test
public void testUnmitigatedMixed() {
DLeaf.Factory factory = new DLeaf.Factory();
CostModel dummyCosts = new CostModel(new File(getClass().getResource("dummyCosts.xml").getPath()));
int dal = 5;
SystemModel system = new SystemModel("S1");
Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
Attack attack2 = new Attack(system.getAttackable(), "A2", "An attack", Prob.certain(), CIA.I);
Defense defense1 = new Defense(attack1);
defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.empty())));
ADTree adtree = new ADOr(new ADNot(defense1), attack1, attack2);
Fraction[] costs = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
DTree dtree = new DAnd(Arrays.asList(new DOr(Collections.singletonList(new DAnd(Collections.singletonList(new DLeaf("S1", "D1", "A1", 0, dal, costs, factory))))), new ALeaf(attack2)));
Assertions.assertThat(DTreeConstructor.construct(adtree, dummyCosts, dal, false, false, factory).prettyPrint()).isEqualTo(dtree.prettyPrint());
}
use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method testFlattenNot.
@Test
public void testFlattenNot() {
// Note: comparing the results of prettyPrint() instead of the trees directly
// because we have not implemented equals for the DTree classes
DLeaf.Factory factory = new DLeaf.Factory();
Fraction[] costs = Util.fractionCosts(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
DTree leaf = new DLeaf("A", "A", "A", 0, 1, costs, factory);
DTree dtree = new DNot(new DNot(leaf));
Assertions.assertThat(dtree.prepare().get().prettyPrint()).isEqualTo(leaf.prettyPrint());
DTree dtree2 = new DAnd(Collections.singletonList(new DOr(Collections.singletonList(dtree))));
DTree dtree3 = new DAnd(Collections.singletonList(new DOr(Collections.singletonList(leaf))));
Assertions.assertThat(dtree2.prepare().get().prettyPrint()).isEqualTo(dtree3.prettyPrint());
}
use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.
the class App method main.
/**
* This is just used for testing purposes. Uses CSV, not VDM (so out of date). See below for
* invocation.
*
* @param args
*/
public static void main(String[] args) {
if (args.length < 2) {
throw new RuntimeException("Must specify STEM output directory and cost model XML!");
}
long startTime = System.currentTimeMillis();
// Usage:
String stemOutDir = args[0];
String costModelXml = args[1];
boolean inference = arrayContains(args, "--inference");
boolean meritAssignment = arrayContains(args, "--merit-assignment");
boolean partialSolution = arrayContains(args, "--partial-solution") || meritAssignment;
boolean dumpSmtLib = arrayContains(args, "--dump-smtlib");
if (dumpSmtLib) {
System.out.println("Will dump SMT-LIB format to verdict-synthesis-dump.smtlib for debugging");
System.out.println("Parent directory: " + System.getProperty("user.dir"));
}
final CostModel costModel = timed("Load cost model", () -> new CostModel(new File(costModelXml)));
AttackDefenseCollector collector = timed("Load CSV", () -> {
try {
return new AttackDefenseCollector(stemOutDir, inference);
} catch (IOException | MalformedInputException e) {
throw new RuntimeException(e);
}
});
List<Result> results = timed("Build attack-defense tree", () -> collector.perform());
// This part is for the single cyber requirement version
// disabled because it doesn't work anymore
// for (Result result : results) {
// System.out.println();
// System.out.println("Result for cyber req: " + result.cyberReq.getName());
// DLeaf.Factory factory = new DLeaf.Factory();
// DTree dtree =
// timed(
// "Construct defense tree",
// () ->
// DTreeConstructor.construct(
// result.adtree,
// costModel,
// result.cyberReq.getSeverityDal(),
// partialSolution,
// false,
// factory));
// Optional<Pair<Set<ComponentDefense>, Double>> selected =
// timed(
// "Perform synthesis",
// () ->
// VerdictSynthesis.performSynthesisSingle(
// dtree,
// result.cyberReq.getSeverityDal(),
// factory,
// VerdictSynthesis.Approach.MAXSMT));
// if (selected.isPresent()) {
// for (ComponentDefense pair : selected.get().left) {
// System.out.println("Selected leaf: " + pair.toString());
// }
// System.out.println("Total cost: " + selected.get().right);
// }
// }
System.out.println("\n\n\n");
{
DLeaf.Factory factory = new DLeaf.Factory();
DTree dtree = timed("Construct defense tree", () -> DTreeConstructor.construct(results, costModel, partialSolution, meritAssignment, factory));
Optional<ResultsInstance> selected = timed("Perform synthesis", () -> VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, partialSolution, true, meritAssignment, dumpSmtLib));
if (selected.isPresent()) {
selected.get().toStreamXml(System.out);
} else {
System.out.println("Failure?");
}
}
System.out.println(" == Total time: " + (System.currentTimeMillis() - startTime) + " milliseconds");
}
use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method partialSolutionTest.
@Test
public void partialSolutionTest() {
DLeaf.Factory factory = new DLeaf.Factory();
CostModel dummyCosts = new CostModel(new File(getClass().getResource("dummyCosts.xml").getPath()));
int dal = 5;
SystemModel system = new SystemModel("S1");
Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
Attack attack2 = new Attack(system.getAttackable(), "A2", "An attack", Prob.certain(), CIA.A);
Defense defense1 = new Defense(attack1);
defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.of(new Pair<>("D1", 3)))));
Defense defense2 = new Defense(attack2);
defense2.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D2", Optional.empty())));
ADTree adtree = new ADOr(new ADNot(defense1), attack1, new ADNot(defense2), attack2);
Fraction[] costs = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
DTree dtree = new DAnd(new DOr(new DAnd(new DLeaf("S1", "D1", "A1", 3, dal, costs, factory))), new DOr(new DAnd(new DLeaf("S1", "D2", "A2", 0, dal, costs, factory))));
Assertions.assertThat(DTreeConstructor.construct(adtree, dummyCosts, dal, true, false, factory).prepare().get().prettyPrint()).isEqualTo(dtree.prettyPrint());
}
use of com.ge.verdict.synthesis.dtree.DTree in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method multipleRequirementsTest.
@Test
public void multipleRequirementsTest() {
DLeaf.Factory factory = new DLeaf.Factory();
CostModel dummyCosts = new CostModel(new File(getClass().getResource("dummyCosts.xml").getPath()));
SystemModel system = new SystemModel("S1");
Attack attack1 = new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I);
Defense defense1 = new Defense(attack1);
defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.empty())));
List<AttackDefenseCollector.Result> results = Arrays.asList(new AttackDefenseCollector.Result(system, new CyberReq("req1", "mission1", 5, "port1", CIA.I), new ADAnd(new ADNot(defense1), attack1), Prob.certain()), new AttackDefenseCollector.Result(system, new CyberReq("req1", "mission1", 7, "port1", CIA.I), new ADAnd(new ADNot(defense1), attack1), Prob.certain()));
DTree dtree = new DAnd(new DOr(new DOr(new DAnd(new DLeaf("S1", "D1", "A1", 0, 5, dummyCosts, factory, false, false)))), new DOr(new DOr(new DAnd(new DLeaf("S1", "D1", "A1", 0, 7, dummyCosts, factory, false, false)))));
Assertions.assertThat(DTreeConstructor.construct(results, dummyCosts, false, false, factory).prepare().get().prettyPrint()).isEqualTo(dtree.prettyPrint());
}
Aggregations