use of com.microsoft.z3.ArithExpr in project batfish by batfish.
the class CounterExample method buildFailedLinks.
SortedSet<Edge> buildFailedLinks(Encoder enc) {
Set<GraphEdge> failed = new HashSet<>();
Graph g = enc.getMainSlice().getGraph();
for (List<GraphEdge> edges : g.getEdgeMap().values()) {
for (GraphEdge ge : edges) {
ArithExpr e = enc.getSymbolicFailures().getFailedVariable(ge);
assert e != null;
if (intVal(e) != 0) {
// Don't add both directions?
GraphEdge other = g.getOtherEnd().get(ge);
if (other == null || !failed.contains(other)) {
failed.add(ge);
}
}
}
}
// Convert to Batfish Edge type
SortedSet<Edge> failedEdges = new TreeSet<>();
for (GraphEdge ge : failed) {
failedEdges.add(fromGraphEdge(ge));
}
return failedEdges;
}
use of com.microsoft.z3.ArithExpr in project batfish by batfish.
the class PropertyChecker method checkBoundedLength.
/*
* Compute whether the path length will always be bounded by a constant k
* for a collection of source routers to any of a number of destination ports.
*/
public AnswerElement checkBoundedLength(HeaderLocationQuestion q, int k) {
return checkProperty(q, (enc, srcRouters, destPorts) -> {
ArithExpr bound = enc.mkInt(k);
PropertyAdder pa = new PropertyAdder(enc.getMainSlice());
Map<String, ArithExpr> lenVars = pa.instrumentPathLength(destPorts);
Map<String, BoolExpr> boundVars = new HashMap<>();
lenVars.forEach((n, ae) -> boundVars.put(n, enc.mkLe(ae, bound)));
return boundVars;
}, (vp) -> new SmtOneAnswerElement(vp.getResult()));
}
use of com.microsoft.z3.ArithExpr 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);
}
}
}
use of com.microsoft.z3.ArithExpr 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);
}
}
use of com.microsoft.z3.ArithExpr 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;
}
Aggregations