Search in sources :

Example 6 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class ReachabilityProgramOptimizerTest method testStraightLineNoPruning.

@Test
public void testStraightLineNoPruning() {
    StateExpr initialState = freshStateExpr();
    RuleStatement axiom = addRuleFor(initialState);
    StateExpr queryState = freshQueryStateExpr();
    RuleStatement rule = addRuleFor(queryState, initialState);
    Set<RuleStatement> rules = optimize();
    assertThat(rules, hasSize(2));
    assertThat(rules, hasItems(axiom, rule));
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Example 7 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class ReachabilityProgramOptimizerTest method pruneUnreachable.

@Test
public void pruneUnreachable() {
    StateExpr state1 = freshStateExpr();
    StateExpr state2 = freshQueryStateExpr();
    addRuleFor(state2, state1);
    Set<RuleStatement> rules = optimize();
    assertThat(rules, empty());
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Example 8 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class ReachabilityProgramOptimizerTest method pruneStateWithMissingDependency.

@Test
public void pruneStateWithMissingDependency() {
    StateExpr state1 = freshStateExpr();
    StateExpr state2 = freshStateExpr();
    StateExpr state3 = freshStateExpr();
    StateExpr goal = freshQueryStateExpr();
    RuleStatement state1Axiom = addRuleFor(state1);
    RuleStatement state3Rule = addRuleFor(state3, state1, state2);
    RuleStatement goalState1Rule = addRuleFor(goal, state1);
    RuleStatement goalState3Rule = addRuleFor(goal, state3);
    Set<RuleStatement> rules = optimize();
    // all rules involving state 3 have been removed
    assertThat(rules, not(hasItem(state3Rule)));
    assertThat(rules, not(hasItem(goalState3Rule)));
    // all other rules remain
    assertThat(rules, hasItems(goalState1Rule, state1Axiom));
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Example 9 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class ReachabilityProgramOptimizerTest method pruneStateWithMissingDependency2.

/*
   * Round 1 should remove the rule for state2 because state3 is underivable
   * Round 2 should remove the axiom for state1 because it's irrelevant (it can only lead to
   * the goal through state2).
   */
@Test
public void pruneStateWithMissingDependency2() {
    StateExpr state1 = freshStateExpr();
    StateExpr state2 = freshStateExpr();
    StateExpr state3 = freshStateExpr();
    StateExpr goal = freshQueryStateExpr();
    addRuleFor(state1);
    addRuleFor(state2, state1, state3);
    addRuleFor(goal, state2);
    Set<RuleStatement> rules = optimize();
    // all rules involving state 3 have been removed
    assertThat(rules, empty());
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Example 10 with StateExpr

use of org.batfish.z3.expr.StateExpr in project batfish by batfish.

the class ReachabilityProgramOptimizerTest method keepRulesThatBecomeUsableAfterVisitingDerivingState.

@Test
public void keepRulesThatBecomeUsableAfterVisitingDerivingState() {
    StateExpr init1 = freshStateExpr();
    StateExpr init2 = freshStateExpr();
    StateExpr a = freshStateExpr();
    StateExpr b = freshStateExpr();
    StateExpr c = freshStateExpr();
    StateExpr goal = freshQueryStateExpr();
    addRuleFor(init1);
    addRuleFor(init2);
    addRuleFor(a, init1);
    addRuleFor(b, init2);
    addRuleFor(c, b);
    addRuleFor(a, c);
    addRuleFor(goal, a);
    Set<RuleStatement> rules = optimize();
    // no rules should be removed
    assertThat(rules, hasSize(7));
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 StateExpr (org.batfish.z3.expr.StateExpr)9 TestStateExpr (org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)7 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 ImmutableList (com.google.common.collect.ImmutableList)4 NodeAccept (org.batfish.z3.state.NodeAccept)4 NodeDrop (org.batfish.z3.state.NodeDrop)4 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 BooleanExpr (org.batfish.z3.expr.BooleanExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 Accept (org.batfish.z3.state.Accept)3 AclDeny (org.batfish.z3.state.AclDeny)3 Debug (org.batfish.z3.state.Debug)3 Drop (org.batfish.z3.state.Drop)3 DropAcl (org.batfish.z3.state.DropAcl)3 DropAclIn (org.batfish.z3.state.DropAclIn)3