Search in sources :

Example 71 with BoolExpr

use of com.microsoft.z3.BoolExpr in project batfish by batfish.

the class PropertyChecker method equal.

private BoolExpr equal(Encoder e, Configuration conf, SymbolicRoute r1, SymbolicRoute r2) {
    EncoderSlice main = e.getMainSlice();
    BoolExpr eq = main.equal(conf, Protocol.CONNECTED, r1, r2, null, true);
    BoolExpr samePermitted = e.mkEq(r1.getPermitted(), r2.getPermitted());
    return e.mkAnd(eq, samePermitted);
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr)

Example 72 with BoolExpr

use of com.microsoft.z3.BoolExpr in project batfish by batfish.

the class TransferSSA method computeIntermediatePrefixLen.

/*
   * Create a new variable representing the new prefix length after
   * applying the effect of aggregation.
   */
private void computeIntermediatePrefixLen(TransferParam<SymbolicRoute> param) {
    ArithExpr prefixLen = param.getData().getPrefixLength();
    if (_isExport && _proto.isBgp()) {
        _aggregates = aggregateRoutes();
        if (_aggregates.size() > 0) {
            for (Map.Entry<Prefix, Boolean> entry : _aggregates.entrySet()) {
                Prefix p = entry.getKey();
                Boolean isSuppressed = entry.getValue();
                ArithExpr len = _enc.mkInt(p.getPrefixLength());
                BoolExpr relevantPfx = _enc.isRelevantFor(p, _enc.getSymbolicPacket().getDstIp());
                BoolExpr relevantLen = _enc.mkGt(param.getData().getPrefixLength(), len);
                BoolExpr relevant = _enc.mkAnd(relevantPfx, relevantLen, _enc.mkBool(isSuppressed));
                prefixLen = _enc.mkIf(relevant, len, prefixLen);
            }
            ArithExpr i = createArithVariableWith(param, "PREFIX-LEN", prefixLen);
            param.getData().setPrefixLength(i);
        }
    }
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr) Prefix(org.batfish.datamodel.Prefix) Map(java.util.Map) HashMap(java.util.HashMap)

Example 73 with BoolExpr

use of com.microsoft.z3.BoolExpr in project batfish by batfish.

the class TransferSSA method matchCommunityList.

/*
   * Converts a community list to a boolean expression.
   */
private BoolExpr matchCommunityList(CommunityList cl, SymbolicRoute other) {
    List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
    Collections.reverse(lines);
    BoolExpr acc = _enc.mkFalse();
    for (CommunityListLine line : lines) {
        boolean action = (line.getAction() == LineAction.ACCEPT);
        CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
        BoolExpr c = other.getCommunities().get(cvar);
        acc = _enc.mkIf(c, _enc.mkBool(action), acc);
    }
    return acc;
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr) CommunityListLine(org.batfish.datamodel.CommunityListLine) ArrayList(java.util.ArrayList)

Example 74 with BoolExpr

use of com.microsoft.z3.BoolExpr in project batfish by batfish.

the class TransferSSA method applyMetricUpdate.

private void applyMetricUpdate(TransferParam<SymbolicRoute> p) {
    boolean updateOspf = (!_isExport && _proto.isOspf());
    boolean updateBgp = (_isExport && _proto.isBgp());
    boolean updateMetric = updateOspf || updateBgp;
    if (updateMetric) {
        // If it is a BGP route learned from IGP, then we use metric 0
        ArithExpr newValue;
        ArithExpr cost = _enc.mkInt(_addedCost);
        ArithExpr sum = _enc.mkSum(p.getData().getMetric(), cost);
        if (_proto.isBgp()) {
            BoolExpr isBGP;
            String router = _conf.getName();
            boolean hasProtocolVar = _other.getProtocolHistory() != null;
            boolean onlyBGP = _enc.getOptimizations().getSliceHasSingleProtocol().contains(router);
            if (hasProtocolVar) {
                isBGP = _other.getProtocolHistory().checkIfValue(Protocol.BGP);
            } else if (onlyBGP) {
                isBGP = _enc.mkTrue();
            } else {
                isBGP = _enc.mkFalse();
            }
            newValue = _enc.mkIf(isBGP, sum, cost);
        } else {
            newValue = sum;
        }
        p.getData().setMetric(newValue);
    }
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr)

Example 75 with BoolExpr

use of com.microsoft.z3.BoolExpr in project batfish by batfish.

the class TransferSSA method createArithVariableWith.

/*
   * A collection of functions to create new SSA variables on-the-fly,
   * while also simultaneously setting their value based on an old value.
   */
private ArithExpr createArithVariableWith(TransferParam<SymbolicRoute> p, String name, ArithExpr e) {
    e = (ArithExpr) e.simplify();
    if (canInline(e)) {
        p.debug(name + "=" + e);
        return e;
    }
    String s = "SSA_" + name + generateId();
    ArithExpr x = _enc.getCtx().mkIntConst(s);
    // _enc.getAllVariables().add(x);
    BoolExpr eq = _enc.mkEq(x, e);
    _enc.add(eq);
    p.debug(eq.toString());
    return x;
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)141 Status (com.microsoft.z3.Status)55 Test (org.junit.Test)51 ArithExpr (com.microsoft.z3.ArithExpr)27 GraphEdge (org.batfish.symbolic.GraphEdge)25 Context (com.microsoft.z3.Context)24 HashMap (java.util.HashMap)22 Expr (com.microsoft.z3.Expr)21 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)18 BitVecExpr (com.microsoft.z3.BitVecExpr)17 Event (dartagnan.program.Event)17 MemEvent (dartagnan.program.MemEvent)17 Program (dartagnan.program.Program)16 Map (java.util.Map)16 Local (dartagnan.program.Local)15 ArrayList (java.util.ArrayList)15 BatfishException (org.batfish.common.BatfishException)14 Graph (org.batfish.symbolic.Graph)14 com.microsoft.z3 (com.microsoft.z3)12