Search in sources :

Example 11 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitAclLineNoMatch.

@Test
public void testVisitAclLineNoMatch() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclConditions(aclConditions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclLineNoMatch.State.INSTANCE)));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 0)), new AclLineNoMatch(NODE1, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 1)), new AclLineNoMatch(NODE1, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 2)), new AclLineNoMatch(NODE1, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 0)), new AclLineNoMatch(NODE1, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 1)), new AclLineNoMatch(NODE1, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 2)), new AclLineNoMatch(NODE1, ACL2, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 0)), new AclLineNoMatch(NODE2, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 1)), new AclLineNoMatch(NODE2, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 2)), new AclLineNoMatch(NODE2, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 0)), new AclLineNoMatch(NODE2, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 1)), new AclLineNoMatch(NODE2, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 2)), new AclLineNoMatch(NODE2, ACL2, 3))));
}
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) NotExpr(org.batfish.z3.expr.NotExpr) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 12 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitNodeDropAcl.

@Test
public void testVisitNodeDropAcl() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropAcl.State.INSTANCE)));
    Set<RuleStatement> expectedCopyNodeDropAclIn = ImmutableSet.of(new BasicRuleStatement(new NodeDropAclIn(NODE1), new NodeDropAcl(NODE1)), new BasicRuleStatement(new NodeDropAclIn(NODE2), new NodeDropAcl(NODE2)));
    Set<RuleStatement> expectedCopyNodeDropAclOut = ImmutableSet.of(new BasicRuleStatement(new NodeDropAclOut(NODE1), new NodeDropAcl(NODE1)), new BasicRuleStatement(new NodeDropAclOut(NODE2), new NodeDropAcl(NODE2)));
    assertThat(rules, equalTo(Sets.union(expectedCopyNodeDropAclIn, expectedCopyNodeDropAclOut)));
}
Also used : NodeDropAcl(org.batfish.z3.state.NodeDropAcl) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) Test(org.junit.Test)

Example 13 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitNodeDropNoRoute.

@Test
public void testVisitNodeDropNoRoute() {
    SynthesizerInput input = MockSynthesizerInput.builder().setRoutableIps(ImmutableMap.of(NODE1, ImmutableMap.of(VRF1, B1, VRF2, B2), NODE2, ImmutableMap.of(VRF1, B1, VRF2, B2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropNoRoute.State.INSTANCE)));
    // DestinationRouting
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B1), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new NodeDropNoRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B2), ImmutableSet.of(new PostInVrf(NODE1, VRF2), new PreOut(NODE1)), new NodeDropNoRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B1), ImmutableSet.of(new PostInVrf(NODE2, VRF1), new PreOut(NODE2)), new NodeDropNoRoute(NODE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B2), ImmutableSet.of(new PostInVrf(NODE2, VRF2), new PreOut(NODE2)), new NodeDropNoRoute(NODE2))));
}
Also used : PreOut(org.batfish.z3.state.PreOut) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) 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) NotExpr(org.batfish.z3.expr.NotExpr) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 14 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitDropAclIn.

@Test
public void testVisitDropAclIn() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(DropAclIn.State.INSTANCE)));
    assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropAclIn(NODE1), DropAclIn.INSTANCE)));
    assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropAclIn(NODE2), DropAclIn.INSTANCE)));
}
Also used : MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) 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 15 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitAclPermit.

@Test
public void testVisitAclPermit() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclActions(aclActions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclPermit.State.INSTANCE)));
    // MatchPermitLine
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 0), new AclPermit(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL1, 2), new AclPermit(NODE1, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 1), new AclPermit(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE1, ACL2, 3), new AclPermit(NODE1, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 0), new AclPermit(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL1, 2), new AclPermit(NODE2, ACL1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 1), new AclPermit(NODE2, ACL2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new AclLineMatch(NODE2, ACL2, 3), new AclPermit(NODE2, ACL2))));
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) 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) AclPermit(org.batfish.z3.state.AclPermit) 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