use of com.ge.verdict.synthesis.dtree.ALeaf in project VERDICT by ge-high-assurance.
the class VerdictSynthesisTest method unmitigatedMixedTest.
@Test
public void unmitigatedMixedTest() {
DLeaf.Factory factory = new DLeaf.Factory();
SystemModel system = new SystemModel("S1");
int targetDal = 1;
Fraction[] costs = Util.fractionCosts(new double[] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 });
DLeaf dleaf = new DLeaf("S1", "D1", "A2", 0, targetDal, costs, factory);
DTree dtree = new DOr(new ALeaf(new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I)), dleaf);
for (Approach approach : Approach.values()) {
Optional<Pair<Set<ComponentDefense>, Double>> result = VerdictSynthesis.performSynthesisSingle(dtree, targetDal, factory, approach);
Assertions.assertThat(result.isPresent());
Assertions.assertThat(result.get().left).hasSize(1);
Assertions.assertThat(result.get().left).contains(dleaf.componentDefense);
Assertions.assertThat(result.get().right).isEqualTo(5);
}
}
use of com.ge.verdict.synthesis.dtree.ALeaf in project VERDICT by ge-high-assurance.
the class VerdictSynthesisTest method unmitigatedTest.
@Test
public void unmitigatedTest() {
DLeaf.Factory factory = new DLeaf.Factory();
SystemModel system = new SystemModel("S1");
DTree dtree = new ALeaf(new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I));
for (Approach approach : Approach.values()) {
Assertions.assertThat(VerdictSynthesis.performSynthesisSingle(dtree, 1, factory, approach)).isEmpty();
}
}
use of com.ge.verdict.synthesis.dtree.ALeaf 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()));
}
}
use of com.ge.verdict.synthesis.dtree.ALeaf in project VERDICT by ge-high-assurance.
the class DTreeConstructor method constructInternal.
/**
* Inductively-defined function over attack-defense trees.
*
* <p>The mapping from attack-defense tree to defense tree is pretty straightforward. One of the
* most important things to note is that AND and OR nodes are transposed in the transformation
* because they mean opposite things in a defense tree compared to an attack-defense tree. (An
* attack-defense tree is "how to attack", whereas a defense tree is "how to defend".)
*
* @param adtree
* @return
*/
private Optional<DTree> constructInternal(ADTree adtree) {
if (adtree instanceof Attack) {
Attack attack = (Attack) adtree;
ALeaf aleaf = new ALeaf(attack);
// keep track of all attack leaves
if (!attackALeafMap.containsKey(attack)) {
attackALeafMap.put(attack, new LinkedHashSet<>());
}
attackALeafMap.get(attack).add(aleaf);
return Optional.of(aleaf);
} else if (adtree instanceof Defense) {
Defense defense = (Defense) adtree;
defenses.add(defense);
return Optional.of(new DNot(constructDefenseTree(defense)));
} else if (adtree instanceof ADAnd) {
ADAnd adand = (ADAnd) adtree;
// Transpose and/or
return Optional.of(new DOr(adand.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
} else if (adtree instanceof ADOr) {
ADOr ador = (ADOr) adtree;
// Transpose and/or
return Optional.of(new DAnd(ador.children().stream().map(this::constructInternal).flatMap(elem -> elem.isPresent() ? Stream.of(elem.get()) : Stream.empty()).collect(Collectors.toList())));
} else if (adtree instanceof ADNot) {
ADNot adnot = (ADNot) adtree;
return constructInternal(adnot.child()).map(DNot::new);
} else if (adtree instanceof DefenseCondition) {
DCondition dcond = new DCondition((DefenseCondition) adtree);
dconditions.add(dcond);
return Optional.of(dcond);
} else {
throw new RuntimeException("got invalid adtree type: " + adtree.getClass().getCanonicalName());
}
}
use of com.ge.verdict.synthesis.dtree.ALeaf in project VERDICT by ge-high-assurance.
the class DTreeConstructorTest method testUnmitigated.
@Test
public void testUnmitigated() {
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);
DTree dtree = new ALeaf(attack1);
Assertions.assertThat(DTreeConstructor.construct(attack1, dummyCosts, dal, false, false, factory).prettyPrint()).isEqualTo(dtree.prettyPrint());
}
Aggregations