use of org.batfish.datamodel.FlowHistory in project batfish by batfish.
the class Batfish method getHistory.
@Override
public FlowHistory getHistory() {
FlowHistory flowHistory = new FlowHistory();
if (_settings.getDiffQuestion()) {
String flowTag = getDifferentialFlowTag();
// String baseEnvTag = _baseTestrigSettings.getEnvName() + ":"
// + _baseTestrigSettings.getEnvironmentSettings().getEnvName();
String baseEnvTag = getFlowTag(_baseTestrigSettings);
// String deltaName = _deltaTestrigSettings.getEnvName() + ":"
// + _deltaTestrigSettings.getEnvironmentSettings().getEnvName();
String deltaEnvTag = getFlowTag(_deltaTestrigSettings);
pushBaseEnvironment();
Environment baseEnv = getEnvironment();
populateFlowHistory(flowHistory, baseEnvTag, baseEnv, flowTag);
popEnvironment();
pushDeltaEnvironment();
Environment deltaEnv = getEnvironment();
populateFlowHistory(flowHistory, deltaEnvTag, deltaEnv, flowTag);
popEnvironment();
} else {
String flowTag = getFlowTag();
// String name = testrigSettings.getEnvName() + ":"
// + testrigSettings.getEnvironmentSettings().getEnvName();
String envTag = flowTag;
Environment env = getEnvironment();
populateFlowHistory(flowHistory, envTag, env, flowTag);
}
_logger.debug(flowHistory.toString());
return flowHistory;
}
use of org.batfish.datamodel.FlowHistory in project batfish by batfish.
the class PropertyChecker method checkReachability.
/*
* Check if a collection of routers will be reachable to
* one or more destinations.
*/
public AnswerElement checkReachability(HeaderLocationQuestion q) {
return checkProperty(q, (enc, srcRouters, destPorts) -> {
PropertyAdder pa = new PropertyAdder(enc.getMainSlice());
return pa.instrumentReachability(destPorts);
}, (vp) -> {
if (vp.getResult().isVerified()) {
return new SmtReachabilityAnswerElement(vp.getResult(), new FlowHistory());
} else {
FlowHistory fh;
CounterExample ce = new CounterExample(vp.getModel());
String testrigName = _batfish.getTestrigName();
if (q.getDiffType() != null) {
fh = ce.buildFlowHistoryDiff(testrigName, vp.getSrcRouters(), vp.getEnc(), vp.getEncDiff(), vp.getProp(), vp.getPropDiff());
} else {
Map<String, Boolean> reachVals = vp.getProp().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> ce.isTrue(entry.getValue()) ^ q.getNegate()));
fh = ce.buildFlowHistory(testrigName, vp.getSrcRouters(), vp.getEnc(), reachVals);
}
return new SmtReachabilityAnswerElement(vp.getResult(), fh);
}
});
}
use of org.batfish.datamodel.FlowHistory in project batfish by batfish.
the class CounterExample method buildFlowHistoryDiff.
/*
* Create a trace-based counterexample demonstrating
* the difference between two networks on a single packet.
*/
FlowHistory buildFlowHistoryDiff(String testRigName, Collection<String> sourceRouters, Encoder enc, Encoder enc2, Map<String, BoolExpr> reach, Map<String, BoolExpr> reach2) {
FlowHistory fh = new FlowHistory();
assert (reach2 != null);
for (String source : sourceRouters) {
BoolExpr sourceVar1 = reach.get(source);
BoolExpr sourceVar2 = reach2.get(source);
String val1 = evaluate(sourceVar1);
String val2 = evaluate(sourceVar2);
if (!Objects.equals(val1, val2)) {
Tuple<Flow, FlowTrace> diff = buildFlowTrace(enc, source);
Tuple<Flow, FlowTrace> base = buildFlowTrace(enc2, source);
SortedSet<Edge> failedLinksDiff = buildFailedLinks(enc);
SortedSet<Edge> failedLinksBase = buildFailedLinks(enc2);
SortedSet<BgpAdvertisement> envRoutesDiff = buildEnvRoutingTable(enc);
SortedSet<BgpAdvertisement> envRoutesBase = buildEnvRoutingTable(enc2);
Environment baseEnv = new Environment("BASE", testRigName, failedLinksBase, null, null, null, null, envRoutesBase);
Environment failedEnv = new Environment("DELTA", testRigName, failedLinksDiff, null, null, null, null, envRoutesDiff);
fh.addFlowTrace(base.getFirst(), "BASE", baseEnv, base.getSecond());
fh.addFlowTrace(diff.getFirst(), "DELTA", failedEnv, diff.getSecond());
}
}
return fh;
}
use of org.batfish.datamodel.FlowHistory in project batfish by batfish.
the class CounterExample method buildFlowHistory.
/*
* Creates a trace-based example of what happens
* to a packet (e.g., why it is not reachable).
*/
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
FlowHistory fh = new FlowHistory();
for (String source : sourceRouters) {
Boolean sourceVar = reach.get(source);
if (!sourceVar) {
Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
SortedSet<Edge> failedLinks = buildFailedLinks(enc);
SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
}
}
return fh;
}
Aggregations