Search in sources :

Example 16 with BDD

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);
}
Also used : BDD(net.sf.javabdd.BDD)

Example 17 with BDD

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);
    });
}
Also used : BDD(net.sf.javabdd.BDD)

Example 18 with BDD

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;
}
Also used : BDD(net.sf.javabdd.BDD) IpProtocol(org.batfish.datamodel.IpProtocol)

Example 19 with BDD

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;
    }
}
Also used : BDD(net.sf.javabdd.BDD) BDDException(net.sf.javabdd.BDDException)

Example 20 with BDD

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;
}
Also used : BDD(net.sf.javabdd.BDD)

Aggregations

BDD (net.sf.javabdd.BDD)26 BatfishException (org.batfish.common.BatfishException)7 ArrayList (java.util.ArrayList)5 Prefix (org.batfish.datamodel.Prefix)4 SubRange (org.batfish.datamodel.SubRange)3 CommunityVar (org.batfish.symbolic.CommunityVar)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 BDDException (net.sf.javabdd.BDDException)2 PrefixRange (org.batfish.datamodel.PrefixRange)2 ExplicitPrefixSet (org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet)2 InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)2 MatchCommunitySet (org.batfish.datamodel.routing_policy.expr.MatchCommunitySet)2 MatchPrefix6Set (org.batfish.datamodel.routing_policy.expr.MatchPrefix6Set)2 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)2 NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)2 NamedPrefixSet (org.batfish.datamodel.routing_policy.expr.NamedPrefixSet)2 TransferResult (org.batfish.symbolic.TransferResult)2 HashMap (java.util.HashMap)1 List (java.util.List)1