Search in sources :

Example 21 with BDD

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

Example 22 with BDD

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

Example 23 with BDD

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");
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) BDD(net.sf.javabdd.BDD) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 24 with BDD

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

Example 25 with BDD

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());
}
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