use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDInteger method leq.
/*
* Less than or equal to on integers
*/
public BDD leq(int val) {
BDD[] eq = new BDD[_bitvec.length];
BDD[] less = new BDD[_bitvec.length];
for (int i = _bitvec.length - 1; i >= 0; i--) {
if ((val & 1) != 0) {
eq[i] = _bitvec[i];
less[i] = _bitvec[i].not();
} else {
eq[i] = _bitvec[i].not();
less[i] = _factory.zero();
}
val >>= 1;
}
BDD acc = _factory.one();
for (int i = _bitvec.length - 1; i >= 0; i--) {
acc = less[i].or(eq[i].and(acc));
}
return acc;
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDRoute method restrict.
public BDDRoute restrict(Prefix pfx) {
int len = pfx.getPrefixLength();
long bits = pfx.getStartIp().asLong();
int[] vars = new int[len];
BDD[] vals = new BDD[len];
// NOTE: do not create a new pairing each time
// JavaBDD will start to memory leak
pairing.reset();
for (int i = 0; i < len; i++) {
// prefixIndex + i;
int var = _prefix.getBitvec()[i].var();
BDD subst = Ip.getBitAtPosition(bits, i) ? factory.one() : factory.zero();
vars[i] = var;
vals[i] = subst;
}
pairing.set(vars, vals);
BDDRoute rec = new BDDRoute(this);
BDD[] metric = rec.getMetric().getBitvec();
BDD[] adminDist = rec.getAdminDist().getBitvec();
BDD[] med = rec.getMed().getBitvec();
BDD[] localPref = rec.getLocalPref().getBitvec();
BDD[] ospfMet = rec.getOspfMetric().getInteger().getBitvec();
for (int i = 0; i < 32; i++) {
metric[i] = metric[i].veccompose(pairing);
adminDist[i] = adminDist[i].veccompose(pairing);
med[i] = med[i].veccompose(pairing);
localPref[i] = localPref[i].veccompose(pairing);
}
for (int i = 0; i < ospfMet.length; i++) {
ospfMet[i] = ospfMet[i].veccompose(pairing);
}
rec.getCommunities().replaceAll((k, v) -> v.veccompose(pairing));
return rec;
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class TransferBDD method matchCommunitySet.
/*
* Converts a community set to a boolean expression
*/
private BDD matchCommunitySet(TransferParam<BDDRoute> p, Configuration conf, CommunitySetExpr e, BDDRoute other) {
if (e instanceof InlineCommunitySet) {
Set<CommunityVar> comms = _graph.findAllCommunities(conf, e);
BDD acc = factory.one();
for (CommunityVar comm : comms) {
p.debug("Inline Community Set: " + comm);
BDD c = other.getCommunities().get(comm);
if (c == null) {
throw new BatfishException("matchCommunitySet: should not be null");
}
acc = acc.and(c);
}
return acc;
}
if (e instanceof NamedCommunitySet) {
p.debug("Named");
NamedCommunitySet x = (NamedCommunitySet) e;
CommunityList cl = conf.getCommunityLists().get(x.getName());
p.debug("Named Community Set: " + cl.getName());
return matchCommunityList(p, cl, other);
}
throw new BatfishException("TODO: match community set");
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class TransferBDD method firstBitsEqual.
/*
* Check if the first length bits match the BDDInteger
* representing the advertisement prefix.
*
* Note: We assume the prefix is never modified, so it will
* be a bitvector containing only the underlying variables:
* [var(0), ..., var(n)]
*/
public static BDD firstBitsEqual(BDD[] bits, Prefix p, int length) {
long b = p.getStartIp().asLong();
BDD acc = factory.one();
for (int i = 0; i < length; i++) {
boolean res = Ip.getBitAtPosition(b, i);
if (res) {
acc = acc.and(bits[i]);
} else {
acc = acc.and(bits[i].not());
}
}
return acc;
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class TransferBDD method returnValue.
/*
* Create a new variable reflecting the final return value of the function
*/
private TransferResult<TransferReturn, BDD> returnValue(TransferResult<TransferReturn, BDD> r, boolean val) {
BDD b = ite(r.getReturnAssignedValue(), r.getReturnValue().getSecond(), mkBDD(val));
TransferReturn ret = new TransferReturn(r.getReturnValue().getFirst(), b);
return r.setReturnValue(ret).setReturnAssignedValue(factory.one());
}
Aggregations