Search in sources :

Example 6 with CommunityList

use of org.batfish.datamodel.CommunityList 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 7 with CommunityList

use of org.batfish.datamodel.CommunityList 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)

Example 8 with CommunityList

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

the class RouteMapSetAdditiveCommunityListLine method applyTo.

@Override
public void applyTo(List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) {
    SortedSet<Long> communities = new TreeSet<>();
    for (String communityListName : _communityLists) {
        CommunityList communityList = c.getCommunityLists().get(communityListName);
        if (communityList != null) {
            StandardCommunityList scl = cc.getStandardCommunityLists().get(communityListName);
            if (scl != null) {
                for (StandardCommunityListLine line : scl.getLines()) {
                    if (line.getAction() == LineAction.ACCEPT) {
                        communities.addAll(line.getCommunities());
                    } else {
                        w.redFlag("Expected only permit lines in standard community-list referred to by route-map " + "set community community-list line: \"" + communityListName + "\"");
                    }
                }
            } else {
                w.redFlag("Expected standard community list in route-map set community community-list line " + "but got expanded instead: \"" + communityListName + "\"");
            }
        } else {
            cc.undefined(CiscoStructureType.COMMUNITY_LIST, communityListName, CiscoStructureUsage.ROUTE_MAP_ADD_COMMUNITY, _statementLine);
        }
    }
    statements.add(new AddCommunity(new InlineCommunitySet(communities)));
}
Also used : AddCommunity(org.batfish.datamodel.routing_policy.statement.AddCommunity) TreeSet(java.util.TreeSet) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 9 with CommunityList

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

the class TransferSSA method matchCommunitySet.

/*
   * Converts a community set to a boolean expression
   */
private BoolExpr matchCommunitySet(Configuration conf, CommunitySetExpr e, SymbolicRoute other) {
    if (e instanceof InlineCommunitySet) {
        Set<CommunityVar> comms = _enc.getGraph().findAllCommunities(conf, e);
        BoolExpr acc = _enc.mkTrue();
        for (CommunityVar comm : comms) {
            BoolExpr c = other.getCommunities().get(comm);
            if (c == null) {
                throw new BatfishException("matchCommunitySet: should not be null");
            }
            acc = _enc.mkAnd(acc, c);
        }
        return acc;
    }
    if (e instanceof NamedCommunitySet) {
        NamedCommunitySet x = (NamedCommunitySet) e;
        CommunityList cl = conf.getCommunityLists().get(x.getName());
        return matchCommunityList(cl, other);
    }
    throw new BatfishException("TODO: match community set");
}
Also used : CommunityVar(org.batfish.symbolic.CommunityVar) BoolExpr(com.microsoft.z3.BoolExpr) BatfishException(org.batfish.common.BatfishException) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) CommunityList(org.batfish.datamodel.CommunityList) InlineCommunitySet(org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)

Example 10 with CommunityList

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

the class Graph method findNamedCommunities.

/*
   * Map named community sets that contain a single match
   * back to the community/regex value. This makes it
   * easier to provide intuitive counter examples.
   */
public Map<String, String> findNamedCommunities() {
    Map<String, String> comms = 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);
                comms.put(line.getRegex(), name);
            }
        }
    }
    return comms;
}
Also used : Configuration(org.batfish.datamodel.Configuration) CommunityListLine(org.batfish.datamodel.CommunityListLine) HashMap(java.util.HashMap) CommunityList(org.batfish.datamodel.CommunityList)

Aggregations

CommunityList (org.batfish.datamodel.CommunityList)13 CommunityListLine (org.batfish.datamodel.CommunityListLine)6 InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)5 NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)5 BatfishException (org.batfish.common.BatfishException)4 Configuration (org.batfish.datamodel.Configuration)4 ArrayList (java.util.ArrayList)3 CommunityVar (org.batfish.symbolic.CommunityVar)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 BoolExpr (com.microsoft.z3.BoolExpr)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 BDD (net.sf.javabdd.BDD)1 AsPathAccessList (org.batfish.datamodel.AsPathAccessList)1 AsPathAccessListLine (org.batfish.datamodel.AsPathAccessListLine)1 IkeGateway (org.batfish.datamodel.IkeGateway)1 Ip (org.batfish.datamodel.Ip)1 Ip6AccessList (org.batfish.datamodel.Ip6AccessList)1