Search in sources :

Example 6 with TransformationRuleStatement

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

the class Simplifier method visitTransformationRuleStatement.

@Override
public Statement visitTransformationRuleStatement(TransformationRuleStatement transformationRuleStatement) {
    /**
     * TODO: something smarter
     */
    BooleanExpr originalPreconditionStateIndependentConstraints = transformationRuleStatement.getPreconditionStateIndependentConstraints();
    BooleanExpr simplifiedPreconditionStateIndependentConstraints = simplifyBooleanExpr(originalPreconditionStateIndependentConstraints);
    if (originalPreconditionStateIndependentConstraints != simplifiedPreconditionStateIndependentConstraints) {
        return simplifyStatement(new TransformationRuleStatement(simplifiedPreconditionStateIndependentConstraints, transformationRuleStatement.getPreconditionPreTransformationStates(), transformationRuleStatement.getPreconditionPostTransformationStates(), transformationRuleStatement.getPostconditionTransformationState()));
    } else if (simplifiedPreconditionStateIndependentConstraints == FalseExpr.INSTANCE) {
        return VACUOUS_RULE;
    } else {
        return transformationRuleStatement;
    }
}
Also used : TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 7 with TransformationRuleStatement

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

Example 8 with TransformationRuleStatement

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

the class BoolExprTransformer method visitTransformationRuleStatement.

@Override
public BoolExpr visitTransformationRuleStatement(TransformationRuleStatement transformationRuleStatement) {
    Context ctx = _nodContext.getContext();
    ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(transformationRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
    transformationRuleStatement.getPreconditionPreTransformationStates().stream().map(preconditionPreTransformationState -> toBoolExpr(preconditionPreTransformationState, _input, _nodContext)).forEach(preconditions::add);
    transformationRuleStatement.getPreconditionPostTransformationStates().stream().map(preconditionPostTransformationState -> (BoolExpr) toBoolExpr(preconditionPostTransformationState, _input, _nodContext).substitute(_from, _to)).forEach(preconditions::add);
    return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), (BoolExpr) toBoolExpr(transformationRuleStatement.getPostconditionTransformationState(), _input, _nodContext).substitute(_from, _to));
}
Also used : Context(com.microsoft.z3.Context) NodContext(org.batfish.z3.NodContext) Statement(org.batfish.z3.expr.Statement) Arrays(java.util.Arrays) PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) OrExpr(org.batfish.z3.expr.OrExpr) TrueExpr(org.batfish.z3.expr.TrueExpr) Context(com.microsoft.z3.Context) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) GenericStatementVisitor(org.batfish.z3.expr.GenericStatementVisitor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) BoolExpr(com.microsoft.z3.BoolExpr) StateExpr(org.batfish.z3.expr.StateExpr) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Parameterizer(org.batfish.z3.state.visitors.Parameterizer) IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) FalseExpr(org.batfish.z3.expr.FalseExpr) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) IfThenElse(org.batfish.z3.expr.IfThenElse) Set(java.util.Set) NotExpr(org.batfish.z3.expr.NotExpr) Comment(org.batfish.z3.expr.Comment) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) NodContext(org.batfish.z3.NodContext) CurrentIsOriginalExpr(org.batfish.z3.expr.CurrentIsOriginalExpr) EqExpr(org.batfish.z3.expr.EqExpr) Expr(com.microsoft.z3.Expr) QueryStatement(org.batfish.z3.expr.QueryStatement) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) BoolExpr(com.microsoft.z3.BoolExpr) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)8 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)6 SynthesizerInput (org.batfish.z3.SynthesizerInput)5 BooleanExpr (org.batfish.z3.expr.BooleanExpr)5 EqExpr (org.batfish.z3.expr.EqExpr)5 PreOutEdgePostNat (org.batfish.z3.state.PreOutEdgePostNat)5 RuleStatement (org.batfish.z3.expr.RuleStatement)4 StateExpr (org.batfish.z3.expr.StateExpr)4 VarIntExpr (org.batfish.z3.expr.VarIntExpr)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 Set (java.util.Set)3 TransformationHeaderField (org.batfish.z3.TransformationHeaderField)3 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)3 NotExpr (org.batfish.z3.expr.NotExpr)3 TrueExpr (org.batfish.z3.expr.TrueExpr)3 AclDeny (org.batfish.z3.state.AclDeny)3 AclPermit (org.batfish.z3.state.AclPermit)3 PostOutEdge (org.batfish.z3.state.PostOutEdge)3