Search in sources :

Example 1 with CommunityListLine

use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.

the class Graph method initNamedCommunities.

/*
   * Map named community sets that contain a single match
   * back to the community/regex value. This makes it
   * easier to provide intuitive counter examples.
   */
private void initNamedCommunities() {
    _namedCommunities = new HashMap<>();
    for (Configuration conf : getConfigurations().values()) {
        for (Entry<String, CommunityList> entry : conf.getCommunityLists().entrySet()) {
            String name = entry.getKey();
            CommunityList cl = entry.getValue();
            if (cl != null && cl.getLines().size() == 1) {
                CommunityListLine line = cl.getLines().get(0);
                _namedCommunities.put(line.getRegex(), name);
            }
        }
    }
}
Also used : Configuration(org.batfish.datamodel.Configuration) CommunityListLine(org.batfish.datamodel.CommunityListLine) CommunityList(org.batfish.datamodel.CommunityList)

Example 2 with CommunityListLine

use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.

the class Graph method findAllCommunities.

/*
   * Final all uniquely mentioned community values for a particular
   * router configuration and community set expression.
   */
public Set<CommunityVar> findAllCommunities(Configuration conf, CommunitySetExpr ce) {
    Set<CommunityVar> comms = new HashSet<>();
    if (ce instanceof InlineCommunitySet) {
        InlineCommunitySet c = (InlineCommunitySet) ce;
        for (CommunitySetElem cse : c.getCommunities()) {
            if (cse.getPrefix() instanceof LiteralCommunitySetElemHalf && cse.getSuffix() instanceof LiteralCommunitySetElemHalf) {
                LiteralCommunitySetElemHalf x = (LiteralCommunitySetElemHalf) cse.getPrefix();
                LiteralCommunitySetElemHalf y = (LiteralCommunitySetElemHalf) cse.getSuffix();
                int prefixInt = x.getValue();
                int suffixInt = y.getValue();
                String val = prefixInt + ":" + suffixInt;
                Long l = (((long) prefixInt) << 16) | (suffixInt);
                CommunityVar var = new CommunityVar(CommunityVar.Type.EXACT, val, l);
                comms.add(var);
            } else {
                throw new BatfishException("TODO: community non literal: " + cse);
            }
        }
    }
    if (ce instanceof NamedCommunitySet) {
        NamedCommunitySet c = (NamedCommunitySet) ce;
        String cname = c.getName();
        CommunityList cl = conf.getCommunityLists().get(cname);
        if (cl != null) {
            for (CommunityListLine line : cl.getLines()) {
                CommunityVar var = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
                comms.add(var);
            }
        }
    }
    return comms;
}
Also used : BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) CommunityListLine(org.batfish.datamodel.CommunityListLine) CommunityList(org.batfish.datamodel.CommunityList) LiteralCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf) CommunitySetElem(org.batfish.datamodel.routing_policy.expr.CommunitySetElem) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet) HashSet(java.util.HashSet)

Example 3 with CommunityListLine

use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.

the class TransferBDD method matchCommunityList.

/*
   * Converts a community list to a boolean expression.
   */
private BDD matchCommunityList(TransferParam<BDDRoute> p, CommunityList cl, BDDRoute other) {
    List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
    Collections.reverse(lines);
    BDD acc = factory.zero();
    for (CommunityListLine line : lines) {
        boolean action = (line.getAction() == LineAction.ACCEPT);
        CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
        p.debug("Match Line: " + cvar);
        p.debug("Action: " + line.getAction());
        // Skip this match if it is irrelevant
        if (_policyQuotient.getCommsMatchedButNotAssigned().contains(cvar)) {
            continue;
        }
        List<CommunityVar> deps = _commDeps.get(cvar);
        for (CommunityVar dep : deps) {
            p.debug("Test for: " + dep);
            BDD c = other.getCommunities().get(dep);
            acc = ite(c, mkBDD(action), acc);
        }
    }
    return acc;
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BDD(net.sf.javabdd.BDD) CommunityListLine(org.batfish.datamodel.CommunityListLine) ArrayList(java.util.ArrayList)

Example 4 with CommunityListLine

use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.

the class TransferSSA method matchCommunityList.

/*
   * Converts a community list to a boolean expression.
   */
private BoolExpr matchCommunityList(CommunityList cl, SymbolicRoute other) {
    List<CommunityListLine> lines = new ArrayList<>(cl.getLines());
    Collections.reverse(lines);
    BoolExpr acc = _enc.mkFalse();
    for (CommunityListLine line : lines) {
        boolean action = (line.getAction() == LineAction.ACCEPT);
        CommunityVar cvar = new CommunityVar(CommunityVar.Type.REGEX, line.getRegex(), null);
        BoolExpr c = other.getCommunities().get(cvar);
        acc = _enc.mkIf(c, _enc.mkBool(action), acc);
    }
    return acc;
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr) CommunityListLine(org.batfish.datamodel.CommunityListLine) ArrayList(java.util.ArrayList)

Example 5 with CommunityListLine

use of org.batfish.datamodel.CommunityListLine in project batfish by batfish.

the class CiscoConfiguration method toCommunityList.

private CommunityList toCommunityList(ExpandedCommunityList ecList) {
    List<CommunityListLine> cllList = new ArrayList<>();
    for (ExpandedCommunityListLine ecll : ecList.getLines()) {
        cllList.add(toCommunityListLine(ecll));
    }
    CommunityList cList = new CommunityList(ecList.getName(), cllList);
    return cList;
}
Also used : CommunityListLine(org.batfish.datamodel.CommunityListLine) ArrayList(java.util.ArrayList) CommunityList(org.batfish.datamodel.CommunityList)

Aggregations

CommunityListLine (org.batfish.datamodel.CommunityListLine)7 CommunityList (org.batfish.datamodel.CommunityList)5 ArrayList (java.util.ArrayList)3 Configuration (org.batfish.datamodel.Configuration)2 CommunityVar (org.batfish.symbolic.CommunityVar)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 BoolExpr (com.microsoft.z3.BoolExpr)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BDD (net.sf.javabdd.BDD)1 BatfishException (org.batfish.common.BatfishException)1 CommunitySetElem (org.batfish.datamodel.routing_policy.expr.CommunitySetElem)1 InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)1 LiteralCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf)1 NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)1