Search in sources :

Example 1 with NodeAccept

use of org.batfish.z3.state.NodeAccept in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitAccept.

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

Example 2 with NodeAccept

use of org.batfish.z3.state.NodeAccept 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 3 with NodeAccept

use of org.batfish.z3.state.NodeAccept in project batfish by batfish.

the class StandardReachabilityQuerySynthesizer method computeFinalActions.

/**
 * Create query condition for action at final node(s)
 */
private List<StateExpr> computeFinalActions() {
    ImmutableList.Builder<StateExpr> finalActionsBuilder = ImmutableList.builder();
    for (ForwardingAction action : _actions) {
        switch(action) {
            case ACCEPT:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr accept = new NodeAccept(finalNode);
                        finalActionsBuilder.add(accept);
                    }
                } else {
                    finalActionsBuilder.add(Accept.INSTANCE);
                }
                break;
            case DEBUG:
                finalActionsBuilder.add(Debug.INSTANCE);
                break;
            case DROP:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDrop(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(Drop.INSTANCE);
                }
                break;
            case DROP_ACL:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDropAcl(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(DropAcl.INSTANCE);
                }
                break;
            case DROP_ACL_IN:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDropAclIn(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(DropAclIn.INSTANCE);
                }
                break;
            case DROP_ACL_OUT:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDropAclOut(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(DropAclOut.INSTANCE);
                }
                break;
            case DROP_NO_ROUTE:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDropNoRoute(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(DropNoRoute.INSTANCE);
                }
                break;
            case DROP_NULL_ROUTE:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeDropNullRoute(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(DropNullRoute.INSTANCE);
                }
                break;
            case NEIGHBOR_UNREACHABLE_OR_EXITS_NETWORK:
                if (_finalNodes.size() > 0) {
                    for (String finalNode : _finalNodes) {
                        StateExpr drop = new NodeNeighborUnreachable(finalNode);
                        finalActionsBuilder.add(drop);
                    }
                } else {
                    finalActionsBuilder.add(NeighborUnreachable.INSTANCE);
                }
                break;
            case FORWARD:
            default:
                throw new BatfishException("unsupported action");
        }
    }
    return finalActionsBuilder.build();
}
Also used : ForwardingAction(org.batfish.datamodel.ForwardingAction) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) BatfishException(org.batfish.common.BatfishException) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) ImmutableList(com.google.common.collect.ImmutableList) NodeAccept(org.batfish.z3.state.NodeAccept) StateExpr(org.batfish.z3.expr.StateExpr) NodeDrop(org.batfish.z3.state.NodeDrop) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut)

Aggregations

NodeAccept (org.batfish.z3.state.NodeAccept)3 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)2 SynthesizerInput (org.batfish.z3.SynthesizerInput)2 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)2 RuleStatement (org.batfish.z3.expr.RuleStatement)2 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 BatfishException (org.batfish.common.BatfishException)1 ForwardingAction (org.batfish.datamodel.ForwardingAction)1 IpWildcard (org.batfish.datamodel.IpWildcard)1 StateExpr (org.batfish.z3.expr.StateExpr)1 NodeDrop (org.batfish.z3.state.NodeDrop)1 NodeDropAcl (org.batfish.z3.state.NodeDropAcl)1 NodeDropAclIn (org.batfish.z3.state.NodeDropAclIn)1 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)1 NodeDropNoRoute (org.batfish.z3.state.NodeDropNoRoute)1 NodeDropNullRoute (org.batfish.z3.state.NodeDropNullRoute)1 NodeNeighborUnreachable (org.batfish.z3.state.NodeNeighborUnreachable)1 PostIn (org.batfish.z3.state.PostIn)1