Search in sources :

Example 6 with DLeaf

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

the class VerdictSynthesisTest method resultsXmlTest.

@Test
public void resultsXmlTest() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs = Util.fractionCosts(new double[] { 2, 5, 9, 15, 16, 18, 20, 25, 30, 37 });
    DTree dtree = new DLeaf("S1", "D1", "A2", 0, 3, costs, factory);
    CostModel costModel = new CostModel(new Triple<>("S1", "D1", costs));
    Optional<ResultsInstance> result = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, false, false, false, false);
    Assertions.assertThat(result.isPresent());
    try {
        File file = File.createTempFile("testOutput", ".xml");
        result.get().toFileXml(file);
        Assertions.assertThat(result.get()).isEqualTo(ResultsInstance.fromFile(file));
    } catch (SAXException | IOException | ParserConfigurationException e) {
        e.printStackTrace();
        Assertions.fail(e.toString());
    }
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) Fraction(org.apache.commons.math3.fraction.Fraction) IOException(java.io.IOException) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) Test(org.junit.Test)

Example 7 with DLeaf

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

the class DTreeConstructor method perform.

/**
 * This is the part that actually constructs the dtree.
 *
 * @param adtree
 * @return
 */
private DTree perform(ADTree adtree) {
    Optional<DTree> resultOpt = constructInternal(adtree);
    if (!resultOpt.isPresent()) {
        return new DOr(Collections.emptyList());
    } else {
        DTree result = resultOpt.get();
        // remove raw attack leaves that are covered by a defense
        for (Defense defense : defenses) {
            if (!attackALeafMap.containsKey(defense.getAttack())) {
                throw new RuntimeException("defense references undefined attack: " + defense.getAttack().getName());
            }
            // it isn't included in the final tree
            for (ALeaf aleaf : attackALeafMap.get(defense.getAttack())) {
                aleaf.setMitigated();
            }
        }
        // these are the raw attack leaves that aren't covered by a defense
        Set<ALeaf> unmitigated = new LinkedHashSet<>();
        for (Set<ALeaf> set : attackALeafMap.values()) {
            for (ALeaf aleaf : set) {
                if (!aleaf.isMitigated()) {
                    unmitigated.add(aleaf);
                }
            }
        }
        // raw attacks without corresponding defenses
        for (ALeaf aleaf : unmitigated) {
            System.out.println("Warning: Unmitigated attack: " + aleaf.getAttack().toString());
        }
        // connect the defense condition to its corresponding dleaf
        for (DCondition dcond : dconditions) {
            Optional<DLeaf.ComponentDefense> compDef = factory.lookup(dcond.defenseCond.getAttackable().getParentName(), dcond.defenseCond.getDefenseProperty());
            if (compDef.isPresent()) {
                dcond.setCompDef(compDef.get());
            } else {
                // This means that the defense isn't part of the attack-defense tree,
                // so we need to create a dleaf (which implicitly creates an SMT variable)
                // for it so that the DAL can get forced down to zero if necessary
                // TODO this doesn't actually work. This is the screwy case that we need to fix.
                DLeaf dleaf = new DLeaf(dcond.defenseCond.getAttackable().getParentName(), dcond.defenseCond.getDefenseProperty(), "", dcond.defenseCond.getImplDal(), 0, costModel, factory, usePartialSolution, meritAssignment);
                dcond.setCompDef(dleaf.componentDefense);
            }
        }
        // important to call prepare - collapses nested NOTs and removes unmitigated raw attack
        // leaves
        Optional<DTree> prepared = result.prepare();
        return prepared.orElse(new DOr(Collections.emptyList()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) DCondition(com.ge.verdict.synthesis.dtree.DCondition) Defense(com.ge.verdict.attackdefensecollector.adtree.Defense)

Example 8 with DLeaf

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

the class DLeafTest method testLookup.

@Test
public void testLookup() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs = Util.fractionCosts(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
    DLeaf leaf1 = new DLeaf("A", "A", "A", 0, 1, costs, factory);
    DLeaf leaf2 = new DLeaf("B", "B", "A", 0, 1, costs, factory);
    Assertions.assertThat(factory.fromId(leaf1.componentDefense.id) == leaf1.componentDefense).isTrue();
    Assertions.assertThat(factory.fromId(leaf2.componentDefense.id) == leaf2.componentDefense).isTrue();
    Assertions.assertThat(factory.fromId(leaf1.componentDefense.id) == leaf2.componentDefense).isFalse();
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) Fraction(org.apache.commons.math3.fraction.Fraction) Test(org.junit.Test)

Example 9 with DLeaf

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

the class DLeafTest method testUnique.

@Test
public void testUnique() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs = Util.fractionCosts(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
    DLeaf leaf1 = new DLeaf("A", "A", "A", 0, 1, costs, factory);
    DLeaf leaf1Dup = new DLeaf("A", "A", "A", 0, 1, costs, factory);
    DLeaf leaf2 = new DLeaf("A", "B", "A", 0, 1, costs, factory);
    DLeaf leaf3 = new DLeaf("B", "A", "A", 0, 1, costs, factory);
    // should be aliases because the whole point is to uniquely identify instances
    Assertions.assertThat(leaf1.componentDefense == leaf1Dup.componentDefense).isTrue();
    Assertions.assertThat(leaf2.componentDefense == leaf1.componentDefense).isFalse();
    Assertions.assertThat(leaf3.componentDefense == leaf1.componentDefense).isFalse();
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) Fraction(org.apache.commons.math3.fraction.Fraction) Test(org.junit.Test)

Example 10 with DLeaf

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

the class DTreeConstructorTest method testConstruct.

@Test
public void testConstruct() {
    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);
    Defense defense1 = new Defense(attack1);
    defense1.addDefenseClause(Collections.singletonList(new Defense.DefenseLeaf("D1", Optional.empty())));
    ADTree adtree = new ADOr(new ADAnd(new ADNot(defense1), attack1));
    Fraction[] costs = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    DTree dtree = new DAnd(Collections.singletonList(new DOr(Collections.singletonList(new DOr(Collections.singletonList(new DAnd(Collections.singletonList(new DLeaf("S1", "D1", "A1", 0, dal, costs, factory)))))))));
    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) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) 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)

Aggregations

DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)16 Fraction (org.apache.commons.math3.fraction.Fraction)14 Test (org.junit.Test)14 ADTree (com.ge.verdict.attackdefensecollector.adtree.ADTree)11 DTree (com.ge.verdict.synthesis.dtree.DTree)11 ADOr (com.ge.verdict.attackdefensecollector.adtree.ADOr)9 DOr (com.ge.verdict.synthesis.dtree.DOr)9 ADAnd (com.ge.verdict.attackdefensecollector.adtree.ADAnd)7 DAnd (com.ge.verdict.synthesis.dtree.DAnd)7 File (java.io.File)6 ADNot (com.ge.verdict.attackdefensecollector.adtree.ADNot)5 Attack (com.ge.verdict.attackdefensecollector.adtree.Attack)5 Defense (com.ge.verdict.attackdefensecollector.adtree.Defense)5 SystemModel (com.ge.verdict.attackdefensecollector.model.SystemModel)5 ALeaf (com.ge.verdict.synthesis.dtree.ALeaf)3 ComponentDefense (com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense)3 ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)3 Pair (com.ge.verdict.synthesis.util.Pair)2 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)1 Pair (com.ge.verdict.attackdefensecollector.Pair)1