Search in sources :

Example 6 with AclDeny

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

the class DefaultTransitionGenerator method visitAclDeny.

@Override
public void visitAclDeny(AclDeny.State aclDeny) {
    // MatchDenyLine
    _input.getAclActions().forEach((node, nodeAcls) -> nodeAcls.forEach((acl, linesActions) -> {
        int lineNumber = 0;
        for (LineAction linesAction : linesActions) {
            if (linesAction == LineAction.REJECT) {
                _rules.add(new BasicRuleStatement(new AclLineMatch(node, acl, lineNumber), new AclDeny(node, acl)));
            }
            lineNumber++;
        }
    }));
    // MatchNoLines
    _input.getAclActions().entrySet().stream().flatMap(aclActionsEntryByNode -> {
        String hostname = aclActionsEntryByNode.getKey();
        return aclActionsEntryByNode.getValue().entrySet().stream().map(aclActionsEntryByAclName -> {
            String acl = aclActionsEntryByAclName.getKey();
            List<LineAction> lineActions = aclActionsEntryByAclName.getValue();
            AclDeny deny = new AclDeny(hostname, acl);
            if (lineActions.isEmpty()) {
                return new BasicRuleStatement(deny);
            } else {
                int lastLine = lineActions.size() - 1;
                return new BasicRuleStatement(new AclLineNoMatch(hostname, acl, lastLine), deny);
            }
        });
    }).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) LineAction(org.batfish.datamodel.LineAction) AclLineMatch(org.batfish.z3.state.AclLineMatch) AclDeny(org.batfish.z3.state.AclDeny) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 7 with AclDeny

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

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

the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateMatchSourceNatRules.

private void visitPreOutEdgePostNat_generateMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
    List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().get(node1).get(iface1);
    for (int natNumber = 0; natNumber < sourceNats.size(); natNumber++) {
        ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
        preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
        // does not match any previous source NAT.
        sourceNats.subList(0, natNumber).stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
        // does match the current source NAT.
        preStates.add(sourceNats.get(natNumber).getKey());
        BooleanExpr transformationExpr = sourceNats.get(natNumber).getValue();
        _rules.add(new TransformationRuleStatement(transformationExpr, preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
    }
}
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) AclDeny(org.batfish.z3.state.AclDeny) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) StateExpr(org.batfish.z3.expr.StateExpr) Entry(java.util.Map.Entry) PreOutEdge(org.batfish.z3.state.PreOutEdge) ImmutableSet(com.google.common.collect.ImmutableSet) BooleanExpr(org.batfish.z3.expr.BooleanExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat)

Aggregations

BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)8 AclDeny (org.batfish.z3.state.AclDeny)8 SynthesizerInput (org.batfish.z3.SynthesizerInput)7 RuleStatement (org.batfish.z3.expr.RuleStatement)7 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)7 EqExpr (org.batfish.z3.expr.EqExpr)5 VarIntExpr (org.batfish.z3.expr.VarIntExpr)5 AclLineMatch (org.batfish.z3.state.AclLineMatch)5 AclLineNoMatch (org.batfish.z3.state.AclLineNoMatch)5 AclPermit (org.batfish.z3.state.AclPermit)5 PreOutEdgePostNat (org.batfish.z3.state.PreOutEdgePostNat)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 IpWildcard (org.batfish.datamodel.IpWildcard)4 LineAction (org.batfish.datamodel.LineAction)4 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)4