Search in sources :

Example 16 with StateExpr

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

Test (org.junit.Test)10 StateExpr (org.batfish.z3.expr.StateExpr)9 TestStateExpr (org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)7 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 ImmutableList (com.google.common.collect.ImmutableList)4 NodeAccept (org.batfish.z3.state.NodeAccept)4 NodeDrop (org.batfish.z3.state.NodeDrop)4 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 BooleanExpr (org.batfish.z3.expr.BooleanExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 Accept (org.batfish.z3.state.Accept)3 AclDeny (org.batfish.z3.state.AclDeny)3 Debug (org.batfish.z3.state.Debug)3 Drop (org.batfish.z3.state.Drop)3 DropAcl (org.batfish.z3.state.DropAcl)3 DropAclIn (org.batfish.z3.state.DropAclIn)3