Search in sources :

Example 1 with RuleStatement

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

the class MultipathInconsistencyQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    addOriginateRules(rules);
    ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
    rules.add(new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(Accept.INSTANCE, Drop.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Accept.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Drop.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 2 with RuleStatement

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

the class EarliestMoreGeneralReachableLineQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    int unreachableLineIndex = _unreachableLine.getLine();
    IpAccessListLine unreachableLine = _list.getLines().get(unreachableLineIndex);
    BooleanExpr matchUnreachableLineHeaderSpace = new HeaderSpaceMatchExpr(unreachableLine);
    ImmutableList.Builder<QueryStatement> queries = ImmutableList.builder();
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    for (AclLine earlierReachableLine : _earlierReachableLines) {
        int earlierLineIndex = earlierReachableLine.getLine();
        IpAccessListLine earlierLine = _list.getLines().get(earlierLineIndex);
        BooleanExpr matchEarlierLineHeaderSpace = new HeaderSpaceMatchExpr(earlierLine);
        NumberedQuery queryRel = new NumberedQuery(earlierLineIndex);
        rules.add(new BasicRuleStatement(new AndExpr(ImmutableList.of(new NotExpr(matchEarlierLineHeaderSpace), matchUnreachableLineHeaderSpace, SaneExpr.INSTANCE)), queryRel));
        QueryStatement query = new QueryStatement(queryRel);
        queries.add(query);
        _resultsByQueryIndex.add(earlierLineIndex);
    }
    return ReachabilityProgram.builder().setInput(input).setQueries(queries.build()).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) NumberedQuery(org.batfish.z3.state.NumberedQuery) ImmutableList(com.google.common.collect.ImmutableList) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 3 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitDropAcl.

@Test
public void testVisitDropAcl() {
    SynthesizerInput input = MockSynthesizerInput.builder().build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(DropAcl.State.INSTANCE)));
    Set<RuleStatement> expectedCopyDropAclIn = ImmutableSet.of(new BasicRuleStatement(DropAclIn.INSTANCE, DropAcl.INSTANCE));
    Set<RuleStatement> expectedCopyDropAclOut = ImmutableSet.of(new BasicRuleStatement(DropAclOut.INSTANCE, DropAcl.INSTANCE));
    assertThat(rules, equalTo(Sets.union(expectedCopyDropAclIn, expectedCopyDropAclOut)));
}
Also used : MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 4 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitPreOutEdge.

@Test
public void testVisitPreOutEdge() {
    SynthesizerInput input = MockSynthesizerInput.builder().setArpTrueEdge(ImmutableMap.of(NODE1, ImmutableMap.of(VRF1, ImmutableMap.of(INTERFACE1, ImmutableMap.of(NODE3, ImmutableMap.of(INTERFACE3, b(1), INTERFACE4, b(2)), NODE4, ImmutableMap.of(INTERFACE3, b(3))), INTERFACE2, ImmutableMap.of(NODE3, ImmutableMap.of(INTERFACE3, b(4)))), VRF2, ImmutableMap.of(INTERFACE3, ImmutableMap.of(NODE3, ImmutableMap.of(INTERFACE3, b(5))))), NODE2, ImmutableMap.of(VRF1, ImmutableMap.of(INTERFACE1, ImmutableMap.of(NODE3, ImmutableMap.of(INTERFACE3, b(6))))))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdge.State.INSTANCE)));
    // DestinationRouting
    assertThat(rules, hasItem(new BasicRuleStatement(b(1), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new PreOutEdge(NODE1, INTERFACE1, NODE3, INTERFACE3))));
    assertThat(rules, hasItem(new BasicRuleStatement(b(2), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new PreOutEdge(NODE1, INTERFACE1, NODE3, INTERFACE4))));
    assertThat(rules, hasItem(new BasicRuleStatement(b(3), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new PreOutEdge(NODE1, INTERFACE1, NODE4, INTERFACE3))));
    assertThat(rules, hasItem(new BasicRuleStatement(b(4), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new PreOutEdge(NODE1, INTERFACE2, NODE3, INTERFACE3))));
    assertThat(rules, hasItem(new BasicRuleStatement(b(5), ImmutableSet.of(new PostInVrf(NODE1, VRF2), new PreOut(NODE1)), new PreOutEdge(NODE1, INTERFACE3, NODE3, INTERFACE3))));
    assertThat(rules, hasItem(new BasicRuleStatement(b(6), ImmutableSet.of(new PostInVrf(NODE2, VRF1), new PreOut(NODE2)), new PreOutEdge(NODE2, INTERFACE1, NODE3, INTERFACE3))));
}
Also used : PreOut(org.batfish.z3.state.PreOut) PreOutEdge(org.batfish.z3.state.PreOutEdge) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 5 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitAclDeny.

@Test
public void testVisitAclDeny() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclActions(aclActions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclDeny.State.INSTANCE)));
    // MatchDenyLine
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 1), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 3), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 0), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 2), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 1), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 3), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 0), new AclDeny(NODE2, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 2), new AclDeny(NODE2, ACL2))));
    // MatchNoLines
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE1, ACL1, 3), new AclDeny(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE1, ACL2, 3), new AclDeny(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclDeny(NODE1, ACL3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE2, ACL1, 3), new AclDeny(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineNoMatch(NODE2, ACL2, 3), new AclDeny(NODE2, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclDeny(NODE1, ACL3))));
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) AclDeny(org.batfish.z3.state.AclDeny) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)35 RuleStatement (org.batfish.z3.expr.RuleStatement)34 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)30 SynthesizerInput (org.batfish.z3.SynthesizerInput)30 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)30 TestStateExpr (org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)6 PreOut (org.batfish.z3.state.PreOut)6 PreOutEdge (org.batfish.z3.state.PreOutEdge)6 ImmutableList (com.google.common.collect.ImmutableList)5 Edge (org.batfish.datamodel.Edge)5 BooleanExpr (org.batfish.z3.expr.BooleanExpr)5 NotExpr (org.batfish.z3.expr.NotExpr)5 AclLineMatch (org.batfish.z3.state.AclLineMatch)5 AclPermit (org.batfish.z3.state.AclPermit)5 NodeDropAclIn (org.batfish.z3.state.NodeDropAclIn)5 NodeDropNoRoute (org.batfish.z3.state.NodeDropNoRoute)5 PostOutEdge (org.batfish.z3.state.PostOutEdge)5 QueryStatement (org.batfish.z3.expr.QueryStatement)4 AclDeny (org.batfish.z3.state.AclDeny)4