Search in sources :

Example 11 with DTree

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());
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) Fraction(org.apache.commons.math3.fraction.Fraction) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) File(java.io.File) Test(org.junit.Test)

Example 12 with DTree

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());
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) Fraction(org.apache.commons.math3.fraction.Fraction) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) DNot(com.ge.verdict.synthesis.dtree.DNot) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) Test(org.junit.Test)

Example 13 with DTree

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");
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) Optional(java.util.Optional) AttackDefenseCollector(com.ge.verdict.attackdefensecollector.AttackDefenseCollector) IOException(java.io.IOException) Result(com.ge.verdict.attackdefensecollector.AttackDefenseCollector.Result) MalformedInputException(com.ge.verdict.attackdefensecollector.CSVFile.MalformedInputException) File(java.io.File)

Example 14 with DTree

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());
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) Fraction(org.apache.commons.math3.fraction.Fraction) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) File(java.io.File) Pair(com.ge.verdict.attackdefensecollector.Pair) Test(org.junit.Test)

Example 15 with DTree

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());
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) ADNot(com.ge.verdict.attackdefensecollector.adtree.ADNot) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) CyberReq(com.ge.verdict.attackdefensecollector.model.CyberReq) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) AttackDefenseCollector(com.ge.verdict.attackdefensecollector.AttackDefenseCollector) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) File(java.io.File) Test(org.junit.Test)

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