use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class EncoderSlice method equal.
/*
* Check for equality of a (best) symbolic record and another
* symbolic record (vars). It checks pairwise that all fields
* are equal, while filling in values missing due to optimizations
* with default values based on the protocol.
* If there is no corresponding edge e, then the value null can be used
*/
public BoolExpr equal(Configuration conf, Protocol proto, SymbolicRoute best, SymbolicRoute vars, @Nullable LogicalEdge e, boolean compareCommunities) {
ArithExpr defaultLocal = mkInt(defaultLocalPref());
ArithExpr defaultAdmin = defaultAdminDistance(conf, proto, vars);
ArithExpr defaultMet = mkInt(defaultMetric());
ArithExpr defaultMed = mkInt(defaultMed(proto));
ArithExpr defaultLen = mkInt(defaultLength());
ArithExpr defaultIgp = mkInt(defaultIgpMetric());
BoolExpr equalLen;
BoolExpr equalAd;
BoolExpr equalLp;
BoolExpr equalMet;
BoolExpr equalMed;
BoolExpr equalOspfArea;
BoolExpr equalOspfType;
BoolExpr equalId;
BoolExpr equalHistory;
BoolExpr equalBgpInternal;
BoolExpr equalClientIds;
BoolExpr equalIgpMet;
BoolExpr equalCommunities;
equalLen = equalHelper(best.getPrefixLength(), vars.getPrefixLength(), defaultLen);
equalAd = equalHelper(best.getAdminDist(), vars.getAdminDist(), defaultAdmin);
equalLp = equalHelper(best.getLocalPref(), vars.getLocalPref(), defaultLocal);
equalMet = equalHelper(best.getMetric(), vars.getMetric(), defaultMet);
equalMed = equalHelper(best.getMed(), vars.getMed(), defaultMed);
equalIgpMet = equalHelper(best.getIgpMetric(), vars.getIgpMetric(), defaultIgp);
equalOspfType = equalTypes(best, vars);
equalOspfArea = equalAreas(best, vars, e);
equalId = equalIds(best, vars, proto, e);
equalHistory = equalHistories(best, vars);
equalBgpInternal = equalBgpInternal(best, vars);
equalClientIds = equalClientIds(conf.getName(), best, vars);
equalCommunities = (compareCommunities ? equalCommunities(best, vars) : mkTrue());
return mkAnd(equalLen, equalAd, equalLp, equalMet, equalMed, equalOspfArea, equalOspfType, equalId, equalHistory, equalBgpInternal, equalClientIds, equalIgpMet, equalCommunities);
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class EncoderSlice method computeWildcardMatch.
/*
* Convert a set of wildcards and a packet field to a symbolic boolean expression
*/
private BoolExpr computeWildcardMatch(Set<IpWildcard> wcs, BitVecExpr field) {
BoolExpr acc = mkFalse();
for (IpWildcard wc : wcs) {
ipWildCardBound(field, wc);
acc = mkOr(acc, ipWildCardBound(field, wc));
}
return (BoolExpr) acc.simplify();
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class EncoderSlice method addCommunityConstraints.
/*
* Constraints each community regex match. A regex match
* will be true, if either one of its subsumed exact values is
* attached to the message, or some other community that matches
* the regex is instead:
*
* c_regex = (c_1 or ... or c_n) or c_other
*
* where the regex matches c_i. The regex match is determined
* ahead of time based on the configuration.
*/
private void addCommunityConstraints() {
for (SymbolicRoute r : getAllSymbolicRecords()) {
for (Entry<CommunityVar, BoolExpr> entry : r.getCommunities().entrySet()) {
CommunityVar cvar = entry.getKey();
BoolExpr e = entry.getValue();
if (cvar.getType() == CommunityVar.Type.REGEX) {
BoolExpr acc = mkFalse();
List<CommunityVar> deps = getGraph().getCommunityDependencies().get(cvar);
for (CommunityVar dep : deps) {
BoolExpr depExpr = r.getCommunities().get(dep);
acc = mkOr(acc, depExpr);
}
BoolExpr regex = mkEq(acc, e);
add(regex);
}
}
}
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class EncoderSlice method equalIds.
/*
* Creates a symbolic test to check for equal router IDs
* after accounting for null values introduced by optimizations
*/
private BoolExpr equalIds(SymbolicRoute best, SymbolicRoute vars, Protocol proto, @Nullable LogicalEdge e) {
BoolExpr equalId;
if (vars.getRouterId() == null) {
if (best.getRouterId() == null || e == null) {
equalId = mkTrue();
} else {
long peerId = getGraph().findRouterId(e.getEdge(), proto);
equalId = mkEq(best.getRouterId(), mkInt(peerId));
}
} else {
equalId = mkEq(best.getRouterId(), vars.getRouterId());
}
return equalId;
}
use of com.microsoft.z3.BoolExpr in project batfish by batfish.
the class EncoderSlice method equalTypes.
/*
* Creates a symbolic test to check for equal ospf types (OI, OIA, E1, E2)
* after accounting for null values introduced by optimizations
*/
private BoolExpr equalTypes(SymbolicRoute best, SymbolicRoute vars) {
BoolExpr equalOspfType;
boolean hasBestType = (best.getOspfType() != null && best.getOspfType().getBitVec() != null);
boolean hasVarsType = (vars.getOspfType() != null && vars.getOspfType().getBitVec() != null);
if (hasVarsType) {
equalOspfType = best.getOspfType().mkEq(vars.getOspfType());
} else if (hasBestType) {
equalOspfType = best.getOspfType().isDefaultValue();
} else {
equalOspfType = mkTrue();
}
return equalOspfType;
}
Aggregations