Search in sources :

Example 41 with BasicRuleStatement

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

the class DefaultTransitionGenerator method visitPostInVrf.

@Override
public void visitPostInVrf(PostInVrf.State postInVrf) {
    // CopyOriginateVrf
    _input.getEnabledInterfacesByNodeVrf().entrySet().stream().flatMap(enabledInterfacesByNodeEntry -> {
        String hostname = enabledInterfacesByNodeEntry.getKey();
        return enabledInterfacesByNodeEntry.getValue().entrySet().stream().map(enabledInterfacesByVrfEntry -> {
            String vrf = enabledInterfacesByVrfEntry.getKey();
            return new BasicRuleStatement(new OriginateVrf(hostname, vrf), new PostInVrf(hostname, vrf));
        });
    }).forEach(_rules::add);
    // PostInInterfaceCorrespondingVrf
    _input.getEnabledInterfacesByNodeVrf().entrySet().stream().flatMap(enabledInterfacesByNodeEntry -> {
        String hostname = enabledInterfacesByNodeEntry.getKey();
        return enabledInterfacesByNodeEntry.getValue().entrySet().stream().flatMap(enabledInterfacesByVrfEntry -> {
            String vrfName = enabledInterfacesByVrfEntry.getKey();
            return enabledInterfacesByVrfEntry.getValue().stream().map(ifaceName -> new BasicRuleStatement(new PostInInterface(hostname, ifaceName), new PostInVrf(hostname, vrfName)));
        });
    }).forEach(_rules::add);
}
Also used : DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) AclLineMatch(org.batfish.z3.state.AclLineMatch) Drop(org.batfish.z3.state.Drop) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) NumberedQuery(org.batfish.z3.state.NumberedQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PostIn(org.batfish.z3.state.PostIn) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) State(org.batfish.z3.expr.StateExpr.State) Originate(org.batfish.z3.state.Originate) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Query(org.batfish.z3.state.Query) PostOutEdge(org.batfish.z3.state.PostOutEdge) List(java.util.List) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) OriginateVrf(org.batfish.z3.state.OriginateVrf) PreOutEdge(org.batfish.z3.state.PreOutEdge) Entry(java.util.Map.Entry) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) IpWildcard(org.batfish.datamodel.IpWildcard) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) TrueExpr(org.batfish.z3.expr.TrueExpr) DropAcl(org.batfish.z3.state.DropAcl) DropNullRoute(org.batfish.z3.state.DropNullRoute) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) NodeAccept(org.batfish.z3.state.NodeAccept) ImmutableList(com.google.common.collect.ImmutableList) StateExpr(org.batfish.z3.expr.StateExpr) LineAction(org.batfish.datamodel.LineAction) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) PreOut(org.batfish.z3.state.PreOut) AclDeny(org.batfish.z3.state.AclDeny) NotExpr(org.batfish.z3.expr.NotExpr) AclPermit(org.batfish.z3.state.AclPermit) VarIntExpr(org.batfish.z3.expr.VarIntExpr) PreInInterface(org.batfish.z3.state.PreInInterface) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) EqExpr(org.batfish.z3.expr.EqExpr) PostInInterface(org.batfish.z3.state.PostInInterface) PostInInterface(org.batfish.z3.state.PostInInterface) OriginateVrf(org.batfish.z3.state.OriginateVrf) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 42 with BasicRuleStatement

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

the class DefaultTransitionGenerator method visitNodeDropAclOut.

@Override
public void visitNodeDropAclOut(NodeDropAclOut.State nodeDropAclOut) {
    _input.getEnabledEdges().forEach(edge -> {
        String node1 = edge.getNode1();
        String iface1 = edge.getInt1();
        String node2 = edge.getNode2();
        String iface2 = edge.getInt2();
        String outAcl = _input.getOutgoingAcls().get(node1).get(iface1);
        // There has to be an ACL -- no ACL is an implicit Permit.
        if (outAcl != null) {
            Set<StateExpr> postTransformationPreStates = ImmutableSet.of(new AclDeny(node1, outAcl), new PreOutEdgePostNat(node1, iface1, node2, iface2));
            _rules.add(new BasicRuleStatement(TrueExpr.INSTANCE, postTransformationPreStates, new NodeDropAclOut(node1)));
        }
    });
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) AclDeny(org.batfish.z3.state.AclDeny) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut)

Example 43 with BasicRuleStatement

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

Example 44 with BasicRuleStatement

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

the class AclReachabilityQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ReachabilityProgram.Builder builder = ReachabilityProgram.builder().setInput(input);
    ImmutableList.Builder<QueryStatement> queries = ImmutableList.builder();
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    for (int line = 0; line < _numLines; line++) {
        NumberedQuery query = new NumberedQuery(line);
        rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(new AclLineMatch(_hostname, _aclName, line)), new NumberedQuery(line)));
        queries.add(new QueryStatement(query));
        _keys.add(new AclLine(_hostname, _aclName, line));
    }
    return builder.setInput(input).setQueries(queries.build()).setRules(rules.build()).build();
}
Also used : AclLineMatch(org.batfish.z3.state.AclLineMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) NumberedQuery(org.batfish.z3.state.NumberedQuery) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Aggregations

BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)44 RuleStatement (org.batfish.z3.expr.RuleStatement)37 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)35 SynthesizerInput (org.batfish.z3.SynthesizerInput)34 Test (org.junit.Test)29 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)28 ImmutableList (com.google.common.collect.ImmutableList)12 BooleanExpr (org.batfish.z3.expr.BooleanExpr)12 NotExpr (org.batfish.z3.expr.NotExpr)12 PreOut (org.batfish.z3.state.PreOut)11 AclLineMatch (org.batfish.z3.state.AclLineMatch)10 NodeDropAclIn (org.batfish.z3.state.NodeDropAclIn)10 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)10 NodeDropNoRoute (org.batfish.z3.state.NodeDropNoRoute)10 NodeDropNullRoute (org.batfish.z3.state.NodeDropNullRoute)10 StateExpr (org.batfish.z3.expr.StateExpr)9 AclDeny (org.batfish.z3.state.AclDeny)9 AclLineNoMatch (org.batfish.z3.state.AclLineNoMatch)9 AclPermit (org.batfish.z3.state.AclPermit)9 NodeAccept (org.batfish.z3.state.NodeAccept)9