use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class PropertyChecker method equal.
private BoolExpr equal(Encoder e, Configuration conf, SymbolicRoute r1, SymbolicRoute r2) {
EncoderSlice main = e.getMainSlice();
BoolExpr eq = main.equal(conf, Protocol.CONNECTED, r1, r2, null, true);
BoolExpr samePermitted = e.mkEq(r1.getPermitted(), r2.getPermitted());
return e.mkAnd(eq, samePermitted);
}
use of com.microsoft.z3.BoolExpr 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.BoolExpr in project batfish by batfish.
the class TransferSSA method matchCommunityList.
/*
* Converts a community list to a boolean expression.
*/
private BoolExpr matchCommunityList(CommunityList cl, SymbolicRoute other) {
List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
Collections.reverse(lines);
BoolExpr acc = _enc.mkFalse();
for (CommunityListLine line : lines) {
boolean action = (line.getAction() == LineAction.ACCEPT);
CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
BoolExpr c = other.getCommunities().get(cvar);
acc = _enc.mkIf(c, _enc.mkBool(action), acc);
}
return acc;
}
use of com.microsoft.z3.BoolExpr 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.BoolExpr 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