use of com.microsoft.z3.Context in project batfish by batfish.
the class PropertyChecker method checkBlackHole.
/*
* Compute if there can ever be a black hole for routers that are
* not at the edge of the network. This is almost certainly a bug.
*/
public AnswerElement checkBlackHole(HeaderQuestion q) {
Graph graph = new Graph(_batfish);
Encoder enc = new Encoder(_settings, graph, q);
enc.computeEncoding();
Context ctx = enc.getCtx();
EncoderSlice slice = enc.getMainSlice();
// Collect routers that have no host/environment edge
List<String> toCheck = new ArrayList<>();
for (Entry<String, List<GraphEdge>> entry : graph.getEdgeMap().entrySet()) {
String router = entry.getKey();
List<GraphEdge> edges = entry.getValue();
boolean check = true;
for (GraphEdge edge : edges) {
if (edge.getEnd() == null) {
check = false;
break;
}
}
if (check) {
toCheck.add(router);
}
}
// Ensure the router never receives traffic and then drops the traffic
BoolExpr someBlackHole = ctx.mkBool(false);
for (String router : toCheck) {
Map<GraphEdge, BoolExpr> edges = slice.getSymbolicDecisions().getDataForwarding().get(router);
BoolExpr doesNotFwd = ctx.mkBool(true);
for (Map.Entry<GraphEdge, BoolExpr> entry : edges.entrySet()) {
BoolExpr dataFwd = entry.getValue();
doesNotFwd = ctx.mkAnd(doesNotFwd, ctx.mkNot(dataFwd));
}
BoolExpr isFwdTo = ctx.mkBool(false);
Set<String> neighbors = graph.getNeighbors().get(router);
for (String n : neighbors) {
for (Map.Entry<GraphEdge, BoolExpr> entry : slice.getSymbolicDecisions().getDataForwarding().get(n).entrySet()) {
GraphEdge ge = entry.getKey();
BoolExpr fwd = entry.getValue();
if (router.equals(ge.getPeer())) {
isFwdTo = ctx.mkOr(isFwdTo, fwd);
}
}
}
someBlackHole = ctx.mkOr(someBlackHole, ctx.mkAnd(isFwdTo, doesNotFwd));
}
enc.add(someBlackHole);
VerificationResult result = enc.verify().getFirst();
return new SmtOneAnswerElement(result);
}
use of com.microsoft.z3.Context in project batfish by batfish.
the class PropertyChecker method ignoredDestinations.
/*
* Creates a boolean variable representing destinations we don't want
* to consider due to local differences.
*/
private BoolExpr ignoredDestinations(Context ctx, EncoderSlice e1, String r1, Configuration conf1) {
BoolExpr validDest = ctx.mkBool(true);
for (Protocol proto1 : e1.getProtocols().get(r1)) {
Set<Prefix> prefixes = Graph.getOriginatedNetworks(conf1, proto1);
BoolExpr dest = e1.relevantOrigination(prefixes);
validDest = ctx.mkAnd(validDest, ctx.mkNot(dest));
}
return validDest;
}
use of com.microsoft.z3.Context 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.Context 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.Context 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