use of org.kie.dmn.model.v1_1.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 org.kie.dmn.model.v1_1.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 org.kie.dmn.model.v1_1.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));
}
}
use of org.kie.dmn.model.v1_1.Context in project batfish by batfish.
the class AbstractNodJob method call.
@Override
public final NodJobResult call() {
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
SmtInput smtInput = computeSmtInput(startTime, ctx);
Map<OriginateVrf, Map<String, Long>> originateVrfConstraints = getOriginateVrfConstraints(ctx, smtInput);
Set<Flow> flows = getFlows(originateVrfConstraints);
return new NodJobResult(startTime, _logger.getHistory(), flows);
} catch (Z3Exception e) {
return new NodJobResult(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of org.kie.dmn.model.v1_1.Context in project batfish by batfish.
the class BoolExprTransformerTest method setup.
@Before
public void setup() {
_stateExpr = Accept.INSTANCE;
_transformationStateExpr = new PreOutEdgePostNat("host1", "interface1", "host2", "interface2");
_ctx = new Context();
_input = MockSynthesizerInput.builder().build();
_nodContext = new NodContext(_ctx, ReachabilityProgram.builder().setInput(_input).setRules(of(new BasicRuleStatement(_stateExpr), new TransformationRuleStatement(_transformationStateExpr))).build());
}
Aggregations