Search in sources :

Example 96 with BoolExpr

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

the class EncoderSlice method equal.

/*
   * Check for equality of a (best) symbolic record and another
   * symbolic record (vars). It checks pairwise that all fields
   * are equal, while filling in values missing due to optimizations
   * with default values based on the protocol.
   * If there is no corresponding edge e, then the value null can be used
   */
public BoolExpr equal(Configuration conf, Protocol proto, SymbolicRoute best, SymbolicRoute vars, @Nullable LogicalEdge e, boolean compareCommunities) {
    ArithExpr defaultLocal = mkInt(defaultLocalPref());
    ArithExpr defaultAdmin = defaultAdminDistance(conf, proto, vars);
    ArithExpr defaultMet = mkInt(defaultMetric());
    ArithExpr defaultMed = mkInt(defaultMed(proto));
    ArithExpr defaultLen = mkInt(defaultLength());
    ArithExpr defaultIgp = mkInt(defaultIgpMetric());
    BoolExpr equalLen;
    BoolExpr equalAd;
    BoolExpr equalLp;
    BoolExpr equalMet;
    BoolExpr equalMed;
    BoolExpr equalOspfArea;
    BoolExpr equalOspfType;
    BoolExpr equalId;
    BoolExpr equalHistory;
    BoolExpr equalBgpInternal;
    BoolExpr equalClientIds;
    BoolExpr equalIgpMet;
    BoolExpr equalCommunities;
    equalLen = equalHelper(best.getPrefixLength(), vars.getPrefixLength(), defaultLen);
    equalAd = equalHelper(best.getAdminDist(), vars.getAdminDist(), defaultAdmin);
    equalLp = equalHelper(best.getLocalPref(), vars.getLocalPref(), defaultLocal);
    equalMet = equalHelper(best.getMetric(), vars.getMetric(), defaultMet);
    equalMed = equalHelper(best.getMed(), vars.getMed(), defaultMed);
    equalIgpMet = equalHelper(best.getIgpMetric(), vars.getIgpMetric(), defaultIgp);
    equalOspfType = equalTypes(best, vars);
    equalOspfArea = equalAreas(best, vars, e);
    equalId = equalIds(best, vars, proto, e);
    equalHistory = equalHistories(best, vars);
    equalBgpInternal = equalBgpInternal(best, vars);
    equalClientIds = equalClientIds(conf.getName(), best, vars);
    equalCommunities = (compareCommunities ? equalCommunities(best, vars) : mkTrue());
    return mkAnd(equalLen, equalAd, equalLp, equalMet, equalMed, equalOspfArea, equalOspfType, equalId, equalHistory, equalBgpInternal, equalClientIds, equalIgpMet, equalCommunities);
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr)

Example 97 with BoolExpr

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

the class EncoderSlice method computeWildcardMatch.

/*
   * Convert a set of wildcards and a packet field to a symbolic boolean expression
   */
private BoolExpr computeWildcardMatch(Set<IpWildcard> wcs, BitVecExpr field) {
    BoolExpr acc = mkFalse();
    for (IpWildcard wc : wcs) {
        ipWildCardBound(field, wc);
        acc = mkOr(acc, ipWildCardBound(field, wc));
    }
    return (BoolExpr) acc.simplify();
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BoolExpr(com.microsoft.z3.BoolExpr)

Example 98 with BoolExpr

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

the class EncoderSlice method addCommunityConstraints.

/*
   * Constraints each community regex match. A regex match
   * will be true, if either one of its subsumed exact values is
   * attached to the message, or some other community that matches
   * the regex is instead:
   *
   * c_regex = (c_1 or ... or c_n) or c_other
   *
   * where the regex matches c_i. The regex match is determined
   * ahead of time based on the configuration.
   */
private void addCommunityConstraints() {
    for (SymbolicRoute r : getAllSymbolicRecords()) {
        for (Entry<CommunityVar, BoolExpr> entry : r.getCommunities().entrySet()) {
            CommunityVar cvar = entry.getKey();
            BoolExpr e = entry.getValue();
            if (cvar.getType() == CommunityVar.Type.REGEX) {
                BoolExpr acc = mkFalse();
                List<CommunityVar> deps = getGraph().getCommunityDependencies().get(cvar);
                for (CommunityVar dep : deps) {
                    BoolExpr depExpr = r.getCommunities().get(dep);
                    acc = mkOr(acc, depExpr);
                }
                BoolExpr regex = mkEq(acc, e);
                add(regex);
            }
        }
    }
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr)

Example 99 with BoolExpr

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

the class EncoderSlice method equalIds.

/*
   * Creates a symbolic test to check for equal router IDs
   * after accounting for null values introduced by optimizations
   */
private BoolExpr equalIds(SymbolicRoute best, SymbolicRoute vars, Protocol proto, @Nullable LogicalEdge e) {
    BoolExpr equalId;
    if (vars.getRouterId() == null) {
        if (best.getRouterId() == null || e == null) {
            equalId = mkTrue();
        } else {
            long peerId = getGraph().findRouterId(e.getEdge(), proto);
            equalId = mkEq(best.getRouterId(), mkInt(peerId));
        }
    } else {
        equalId = mkEq(best.getRouterId(), vars.getRouterId());
    }
    return equalId;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr)

Example 100 with BoolExpr

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

the class EncoderSlice method equalTypes.

/*
   * Creates a symbolic test to check for equal ospf types (OI, OIA, E1, E2)
   * after accounting for null values introduced by optimizations
   */
private BoolExpr equalTypes(SymbolicRoute best, SymbolicRoute vars) {
    BoolExpr equalOspfType;
    boolean hasBestType = (best.getOspfType() != null && best.getOspfType().getBitVec() != null);
    boolean hasVarsType = (vars.getOspfType() != null && vars.getOspfType().getBitVec() != null);
    if (hasVarsType) {
        equalOspfType = best.getOspfType().mkEq(vars.getOspfType());
    } else if (hasBestType) {
        equalOspfType = best.getOspfType().isDefaultValue();
    } else {
        equalOspfType = mkTrue();
    }
    return equalOspfType;
}
Also used : 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