use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDPacket method restrict.
public BDD restrict(BDD bdd, Prefix pfx) {
int len = pfx.getPrefixLength();
long bits = pfx.getStartIp().asLong();
int[] vars = new int[len];
BDD[] vals = new BDD[len];
pairing.reset();
for (int i = 0; i < len; i++) {
// dstIpIndex + i;
int var = _dstIp.getBitvec()[i].var();
BDD subst = Ip.getBitAtPosition(bits, i) ? factory.one() : factory.zero();
vars[i] = var;
vals[i] = subst;
}
pairing.set(vars, vals);
return bdd.veccompose(pairing);
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDRoute method orWith.
/*
* Take the point-wise disjunction of two BDDRecords
*/
public void orWith(BDDRoute other) {
BDD[] metric = getMetric().getBitvec();
BDD[] adminDist = getAdminDist().getBitvec();
BDD[] med = getMed().getBitvec();
BDD[] localPref = getLocalPref().getBitvec();
BDD[] ospfMet = getOspfMetric().getInteger().getBitvec();
BDD[] metric2 = other.getMetric().getBitvec();
BDD[] adminDist2 = other.getAdminDist().getBitvec();
BDD[] med2 = other.getMed().getBitvec();
BDD[] localPref2 = other.getLocalPref().getBitvec();
BDD[] ospfMet2 = other.getOspfMetric().getInteger().getBitvec();
for (int i = 0; i < 32; i++) {
metric[i].orWith(metric2[i]);
adminDist[i].orWith(adminDist2[i]);
med[i].orWith(med2[i]);
localPref[i].orWith(localPref2[i]);
}
for (int i = 0; i < ospfMet.length; i++) {
ospfMet[i].orWith(ospfMet2[i]);
}
getCommunities().forEach((cvar, bdd1) -> {
BDD bdd2 = other.getCommunities().get(cvar);
bdd1.orWith(bdd2);
});
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDAcl method computeIpProtocols.
/*
* Convert a set of ip protocols to a boolean expression on the symbolic packet
*/
private BDD computeIpProtocols(Set<IpProtocol> ipProtos) {
BDD acc = _factory.zero();
for (IpProtocol proto : ipProtos) {
BDD isValue = _pkt.getIpProtocol().value(proto.number());
acc = acc.or(isValue);
}
return acc;
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDInteger method sub.
/*
* Subtract one BDD from another bitwise to create a new BDD
*/
public BDDInteger sub(BDDInteger var1) {
if (this._bitvec.length != var1._bitvec.length) {
throw new BDDException();
} else {
BDD var3 = _factory.zero();
BDDInteger var4 = new BDDInteger(_factory, this._bitvec.length);
for (int var5 = var4._bitvec.length - 1; var5 >= 0; --var5) {
var4._bitvec[var5] = this._bitvec[var5].xor(var1._bitvec[var5]);
var4._bitvec[var5] = var4._bitvec[var5].xor(var3.id());
BDD var6 = var1._bitvec[var5].or(var3);
BDD var7 = this._bitvec[var5].apply(var6, BDDFactory.less);
var6.free();
var6 = this._bitvec[var5].and(var1._bitvec[var5]);
var6 = var6.and(var3);
var6 = var6.or(var7);
var3 = var6;
}
var3.free();
return var4;
}
}
use of net.sf.javabdd.BDD in project batfish by batfish.
the class BDDInteger method value.
/*
* Create a BDD representing the exact value
*/
public BDD value(int val) {
BDD bdd = _factory.one();
for (int i = this._bitvec.length - 1; i >= 0; i--) {
BDD b = this._bitvec[i];
if ((val & 1) != 0) {
bdd = bdd.and(b);
} else {
bdd = bdd.and(b.not());
}
val >>= 1;
}
return bdd;
}
Aggregations