Search in sources :

Example 36 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitAclLineMatch.

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

Example 37 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitNodeDropAclIn.

@Test
public void testVisitNodeDropAclIn() {
    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), NODE2, ImmutableSet.of(INTERFACE1, INTERFACE2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropAclIn.State.INSTANCE)));
    // FailIncomingAcl
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclDeny(NODE1, ACL1), new PreInInterface(NODE1, INTERFACE1)), new NodeDropAclIn(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclDeny(NODE1, ACL2), new PreInInterface(NODE1, INTERFACE2)), new NodeDropAclIn(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclDeny(NODE2, ACL1), new PreInInterface(NODE2, INTERFACE1)), new NodeDropAclIn(NODE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclDeny(NODE2, ACL2), new PreInInterface(NODE2, INTERFACE2)), new NodeDropAclIn(NODE2))));
}
Also used : AclDeny(org.batfish.z3.state.AclDeny) 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) PreInInterface(org.batfish.z3.state.PreInInterface) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 38 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitPreOut.

@Test
public void testVisitPreOut() {
    SynthesizerInput input = MockSynthesizerInput.builder().setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOut.State.INSTANCE)));
    // PostInNotMine
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2)))), ImmutableSet.of(new PostIn(NODE1)), new PreOut(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4)))), ImmutableSet.of(new PostIn(NODE2)), new PreOut(NODE2))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) PostIn(org.batfish.z3.state.PostIn) PreOut(org.batfish.z3.state.PreOut) 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) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 39 with RuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitNodeAccept.

@Test
public void testVisitNodeAccept() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeAccept.State.INSTANCE)));
    // PostInForMe
    assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2))), ImmutableSet.of(new PostIn(NODE1)), new NodeAccept(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4))), ImmutableSet.of(new PostIn(NODE2)), new NodeAccept(NODE2))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) PostIn(org.batfish.z3.state.PostIn) 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) NodeAccept(org.batfish.z3.state.NodeAccept) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 40 with RuleStatement

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

the class StandardReachabilityQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    List<StateExpr> finalActions = computeFinalActions();
    ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
    finalActions.stream().map(finalAction -> new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(finalAction), Query.INSTANCE)).forEach(rules::add);
    addOriginateRules(rules);
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAction(org.batfish.datamodel.ForwardingAction) DropAcl(org.batfish.z3.state.DropAcl) DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) BatfishException(org.batfish.common.BatfishException) Drop(org.batfish.z3.state.Drop) DropNullRoute(org.batfish.z3.state.DropNullRoute) NodeAccept(org.batfish.z3.state.NodeAccept) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) StateExpr(org.batfish.z3.expr.StateExpr) Nonnull(javax.annotation.Nonnull) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) ImmutableSet(com.google.common.collect.ImmutableSet) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) Set(java.util.Set) Query(org.batfish.z3.state.Query) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) List(java.util.List) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) QueryStatement(org.batfish.z3.expr.QueryStatement) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) AndExpr(org.batfish.z3.expr.AndExpr) StateExpr(org.batfish.z3.expr.StateExpr) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

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