use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class TransferSSA method joinPoint.
/*
* The [phi] function from SSA that merges variables that may differ across
* different branches of an mkIf statement.
*/
private Pair<Expr, Expr> joinPoint(TransferParam<SymbolicRoute> p, TransferResult<BoolExpr, BoolExpr> r, BoolExpr guard, Pair<String, Pair<Expr, Expr>> values) {
String variableName = values.getFirst();
Expr trueBranch = values.getSecond().getFirst();
Expr falseBranch = values.getSecond().getSecond();
if (variableName.equals("RETURN") || variableName.equals("FALLTHROUGH")) {
Expr t = (trueBranch == null ? _enc.mkFalse() : // can use False because the value has not been assigned
trueBranch);
Expr f = (falseBranch == null ? _enc.mkFalse() : falseBranch);
Expr tass = (trueBranch == null ? r.getReturnAssignedValue() : _enc.mkTrue());
Expr fass = (falseBranch == null ? r.getReturnAssignedValue() : _enc.mkTrue());
BoolExpr newAss = _enc.mkIf(guard, (BoolExpr) tass, (BoolExpr) fass);
BoolExpr retAss = createBoolVariableWith(p, "ASSIGNED", newAss);
BoolExpr variable = (variableName.equals("RETURN") ? r.getReturnValue() : r.getFallthroughValue());
BoolExpr newValue = _enc.mkIf(r.getReturnAssignedValue(), variable, _enc.mkIf(guard, (BoolExpr) t, (BoolExpr) f));
BoolExpr ret = createBoolVariableWith(p, variableName, newValue);
return new Pair<>(ret, retAss);
}
if (variableName.equals("PREFIX-LEN")) {
Expr t = (trueBranch == null ? p.getData().getPrefixLength() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getPrefixLength() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getPrefixLength(), newValue);
ArithExpr ret = createArithVariableWith(p, "PREFIX-LEN", newValue);
p.getData().setPrefixLength(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("ADMIN-DIST")) {
Expr t = (trueBranch == null ? p.getData().getAdminDist() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getAdminDist() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getAdminDist(), newValue);
ArithExpr ret = createArithVariableWith(p, "ADMIN-DIST", newValue);
p.getData().setAdminDist(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("LOCAL-PREF")) {
Expr t = (trueBranch == null ? p.getData().getLocalPref() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getLocalPref() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getLocalPref(), newValue);
ArithExpr ret = createArithVariableWith(p, "LOCAL-PREF", newValue);
p.getData().setLocalPref(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("METRIC")) {
Expr t = (trueBranch == null ? p.getData().getMetric() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getMetric() : falseBranch);
ArithExpr newValue = _enc.mkIf(guard, (ArithExpr) t, (ArithExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getMetric(), newValue);
ArithExpr ret = createArithVariableWith(p, "METRIC", newValue);
p.getData().setMetric(ret);
return new Pair<>(ret, null);
}
if (variableName.equals("OSPF-TYPE")) {
Expr t = (trueBranch == null ? p.getData().getOspfType().getBitVec() : trueBranch);
Expr f = (falseBranch == null ? p.getData().getOspfType().getBitVec() : falseBranch);
BitVecExpr newValue = _enc.mkIf(guard, (BitVecExpr) t, (BitVecExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getOspfType().getBitVec(), newValue);
BitVecExpr ret = createBitVecVariableWith(p, "OSPF-TYPE", 2, newValue);
p.getData().getOspfType().setBitVec(ret);
return new Pair<>(ret, null);
}
for (Map.Entry<CommunityVar, BoolExpr> entry : p.getData().getCommunities().entrySet()) {
CommunityVar cvar = entry.getKey();
if (variableName.equals(cvar.getValue())) {
Expr t = (trueBranch == null ? p.getData().getCommunities().get(cvar) : trueBranch);
Expr f = (falseBranch == null ? p.getData().getCommunities().get(cvar) : falseBranch);
BoolExpr newValue = _enc.mkIf(guard, (BoolExpr) t, (BoolExpr) f);
newValue = _enc.mkIf(r.getReturnAssignedValue(), p.getData().getCommunities().get(cvar), newValue);
BoolExpr ret = createBoolVariableWith(p, cvar.getValue(), newValue);
p.getData().getCommunities().put(cvar, ret);
return new Pair<>(ret, null);
}
}
throw new BatfishException("[joinPoint]: unhandled case for " + variableName);
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class TransferSSA method matchFilterList.
/*
* Converts a route filter list to a boolean expression.
*/
private BoolExpr matchFilterList(RouteFilterList x, SymbolicRoute other) {
BoolExpr acc = _enc.mkFalse();
List<RouteFilterLine> lines = new ArrayList<>(x.getLines());
Collections.reverse(lines);
for (RouteFilterLine line : lines) {
Prefix p = line.getPrefix();
SubRange r = line.getLengthRange();
PrefixRange range = new PrefixRange(p, r);
BoolExpr matches = _enc.isRelevantFor(other.getPrefixLength(), range);
BoolExpr action = _enc.mkBool(line.getAction() == LineAction.ACCEPT);
acc = _enc.mkIf(matches, action, acc);
}
return acc;
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class NodFirstUnsatJob method call.
@Override
public NodFirstUnsatResult<KeyT, ResultT> call() {
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
KeyT key = _query.getKey();
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
break;
case UNKNOWN:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
return new NodFirstUnsatResult<>(key, queryNum, _query.getResultsByQueryIndex().get(queryNum), _logger.getHistory(), startTime);
default:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodFirstUnsatResult<>(key, null, null, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class NodJob method computeSmtInput.
@Override
protected SmtInput computeSmtInput(long startTime, Context ctx) {
NodProgram program = getNodProgram(ctx);
BoolExpr expr = computeSmtConstraintsViaNod(program, _querySynthesizer.getNegate());
Map<String, BitVecExpr> variablesAsConsts = program.getNodContext().getVariablesAsConsts();
return new SmtInput(expr, variablesAsConsts);
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class NodSatJob method call.
@Override
public NodSatResult<KeyT> call() {
Map<KeyT, Boolean> results = new LinkedHashMap<>();
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
KeyT key = _query.getKeys().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
results.put(key, true);
break;
case UNKNOWN:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
results.put(key, false);
break;
default:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodSatResult<>(results, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
Aggregations