Search in sources :

Example 26 with RuleStatement

use of org.batfish.z3.expr.RuleStatement 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)

Example 27 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testPreOutEdgePostNat.

@Test
public void testPreOutEdgePostNat() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE1, NODE2, INTERFACE2), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE2), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE2), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdgePostNat.State.INSTANCE)));
    BooleanExpr newSrcIpEqualsCurrentSrcIp = new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent()));
    // PreOutEdgePostNatForTopologyEdges
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE2))));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) 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) EqExpr(org.batfish.z3.expr.EqExpr) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) Edge(org.batfish.datamodel.Edge) PostOutEdge(org.batfish.z3.state.PostOutEdge) PreOutEdge(org.batfish.z3.state.PreOutEdge) BooleanExpr(org.batfish.z3.expr.BooleanExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) Test(org.junit.Test)

Example 28 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitPostInInterface.

@Test
public void testVisitPostInInterface() {
    SynthesizerInput input = MockSynthesizerInput.builder().setIncomingAcls(ImmutableMap.of(NODE1, ImmutableMap.of(INTERFACE1, ACL1, INTERFACE2, ACL2), NODE2, ImmutableMap.of(INTERFACE1, ACL1, INTERFACE2, ACL2))).setTopologyInterfaces(ImmutableMap.of(NODE1, ImmutableSet.of(INTERFACE1, INTERFACE2, INTERFACE3), NODE2, ImmutableSet.of(INTERFACE1, INTERFACE2, INTERFACE3))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PostInInterface.State.INSTANCE)));
    // PassIncomingAcl
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE1, ACL1), new PreInInterface(NODE1, INTERFACE1)), new PostInInterface(NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE1, ACL2), new PreInInterface(NODE1, INTERFACE2)), new PostInInterface(NODE1, INTERFACE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new PreInInterface(NODE1, INTERFACE3), new PostInInterface(NODE1, INTERFACE3))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE2, ACL1), new PreInInterface(NODE2, INTERFACE1)), new PostInInterface(NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE2, ACL2), new PreInInterface(NODE2, INTERFACE2)), new PostInInterface(NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new PreInInterface(NODE2, INTERFACE3), new PostInInterface(NODE2, INTERFACE3))));
}
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) PostInInterface(org.batfish.z3.state.PostInInterface) AclPermit(org.batfish.z3.state.AclPermit) PreInInterface(org.batfish.z3.state.PreInInterface) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 29 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitDropNoRoute.

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

Example 30 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitPreOutEdgePostNat_topologyInterfaceWithNAT.

/**
 * Test the transitions generated for PreOutEdgePostNat for an edge with a source nat.
 */
@Test
public void testVisitPreOutEdgePostNat_topologyInterfaceWithNAT() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE2))).setTopologyInterfaces(ImmutableMap.of(NODE1, ImmutableSet.of(INTERFACE1))).setSourceNats(ImmutableMap.of(NODE1, ImmutableMap.of(INTERFACE1, ImmutableList.of(Maps.immutableEntry(new AclPermit(NODE1, NAT_ACL1), B1))))).build();
    List<RuleStatement> rules = DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdgePostNat.State.INSTANCE));
    RuleStatement permitRule = new TransformationRuleStatement(B1, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2), new AclPermit(NODE1, NAT_ACL1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2));
    RuleStatement denyRule = new TransformationRuleStatement(new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent())), ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2), new AclDeny(NODE1, NAT_ACL1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2));
    assertThat(rules, containsInAnyOrder(permitRule, denyRule));
}
Also used : AclDeny(org.batfish.z3.state.AclDeny) PreOutEdge(org.batfish.z3.state.PreOutEdge) VarIntExpr(org.batfish.z3.expr.VarIntExpr) 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) EqExpr(org.batfish.z3.expr.EqExpr) AclPermit(org.batfish.z3.state.AclPermit) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) Edge(org.batfish.datamodel.Edge) PostOutEdge(org.batfish.z3.state.PostOutEdge) PreOutEdge(org.batfish.z3.state.PreOutEdge) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) 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