Search in sources :

Example 6 with SmtOneAnswerElement

use of org.batfish.symbolic.answers.SmtOneAnswerElement in project batfish by batfish.

the class PropertyChecker method checkLoadBalancing.

/*
   * Computes whether load balancing for each source node in a collection is
   * within some threshold k of the each other.
   */
public AnswerElement checkLoadBalancing(HeaderLocationQuestion q, int k) {
    return checkProperty(q, (enc, srcRouters, destPorts) -> {
        PropertyAdder pa = new PropertyAdder(enc.getMainSlice());
        Map<String, ArithExpr> loads = pa.instrumentLoad(destPorts);
        Map<String, BoolExpr> prop = new HashMap<>();
        // TODO: implement this properly after refactoring
        loads.forEach((name, ae) -> prop.put(name, enc.mkTrue()));
        return prop;
    }, (vp) -> new SmtOneAnswerElement(vp.getResult()));
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr) HashMap(java.util.HashMap) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement)

Example 7 with SmtOneAnswerElement

use of org.batfish.symbolic.answers.SmtOneAnswerElement in project batfish by batfish.

the class PropertyChecker method checkEqualLength.

/*
   * Computes whether a collection of source routers will always have
   * equal path length to destination port(s).
   */
public AnswerElement checkEqualLength(HeaderLocationQuestion q) {
    return checkProperty(q, (enc, srcRouters, destPorts) -> {
        PropertyAdder pa = new PropertyAdder(enc.getMainSlice());
        Map<String, ArithExpr> lenVars = pa.instrumentPathLength(destPorts);
        Map<String, BoolExpr> eqVars = new HashMap<>();
        List<Expr> lens = new ArrayList<>();
        for (String router : srcRouters) {
            lens.add(lenVars.get(router));
        }
        BoolExpr allEqual = PropertyAdder.allEqual(enc.getCtx(), lens);
        enc.add(enc.mkNot(allEqual));
        for (Entry<String, ArithExpr> entry : lenVars.entrySet()) {
            String name = entry.getKey();
            BoolExpr b = srcRouters.contains(name) ? allEqual : enc.mkTrue();
            eqVars.put(name, b);
        }
        return eqVars;
    }, (vp) -> new SmtOneAnswerElement(vp.getResult()));
}
Also used : ArithExpr(com.microsoft.z3.ArithExpr) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) ArithExpr(com.microsoft.z3.ArithExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement)

Aggregations

SmtOneAnswerElement (org.batfish.symbolic.answers.SmtOneAnswerElement)7 BoolExpr (com.microsoft.z3.BoolExpr)6 HashMap (java.util.HashMap)5 Graph (org.batfish.symbolic.Graph)4 ArithExpr (com.microsoft.z3.ArithExpr)3 ArrayList (java.util.ArrayList)3 Context (com.microsoft.z3.Context)2 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 BatfishException (org.batfish.common.BatfishException)2 Configuration (org.batfish.datamodel.Configuration)2 GraphEdge (org.batfish.symbolic.GraphEdge)2 BitVecExpr (com.microsoft.z3.BitVecExpr)1 Expr (com.microsoft.z3.Expr)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1