Search in sources :

Example 41 with BooleanExpr

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

the class Simplifier method visitEqExpr.

@Override
public BooleanExpr visitEqExpr(EqExpr eqExpr) {
    IntExpr lhs = eqExpr.getLhs();
    IntExpr rhs = eqExpr.getRhs();
    if (lhs.equals(rhs)) {
        return TrueExpr.INSTANCE;
    } else if (lhs instanceof LitIntExpr && rhs instanceof LitIntExpr) {
        return FalseExpr.INSTANCE;
    } else {
        return eqExpr;
    }
}
Also used : LitIntExpr(org.batfish.z3.expr.LitIntExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr)

Example 42 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr 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 43 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr 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 44 with BooleanExpr

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

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)43 Test (org.junit.Test)27 AndExpr (org.batfish.z3.expr.AndExpr)14 NotExpr (org.batfish.z3.expr.NotExpr)13 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)13 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)10 ImmutableList (com.google.common.collect.ImmutableList)9 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)8 BoolExpr (com.microsoft.z3.BoolExpr)7 IfExpr (org.batfish.z3.expr.IfExpr)7 VarIntExpr (org.batfish.z3.expr.VarIntExpr)7 BoolExprTransformer.toBoolExpr (org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr)7 List (java.util.List)6 IpWildcard (org.batfish.datamodel.IpWildcard)6 EqExpr (org.batfish.z3.expr.EqExpr)6 OrExpr (org.batfish.z3.expr.OrExpr)6 QueryStatement (org.batfish.z3.expr.QueryStatement)6 RuleStatement (org.batfish.z3.expr.RuleStatement)6 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)6 Ip (org.batfish.datamodel.Ip)5