Search in sources :

Example 1 with CommunitySetElem

use of org.batfish.datamodel.routing_policy.expr.CommunitySetElem 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 2 with CommunitySetElem

use of org.batfish.datamodel.routing_policy.expr.CommunitySetElem in project batfish by batfish.

the class CiscoControlPlaneExtractor method toCommunitySetElemExpr.

private CommunitySetElem toCommunitySetElemExpr(Rp_community_set_elemContext ctx) {
    if (ctx.prefix != null) {
        CommunitySetElemHalfExpr prefix = toCommunitySetElemHalfExpr(ctx.prefix);
        CommunitySetElemHalfExpr suffix = toCommunitySetElemHalfExpr(ctx.suffix);
        return new CommunitySetElem(prefix, suffix);
    } else if (ctx.community() != null) {
        long value = toLong(ctx.community());
        return new CommunitySetElem(value);
    } else {
        throw convError(CommunitySetElem.class, ctx);
    }
}
Also used : CommunitySetElem(org.batfish.datamodel.routing_policy.expr.CommunitySetElem) CommunitySetElemHalfExpr(org.batfish.datamodel.routing_policy.expr.CommunitySetElemHalfExpr)

Aggregations

CommunitySetElem (org.batfish.datamodel.routing_policy.expr.CommunitySetElem)2 HashSet (java.util.HashSet)1 BatfishException (org.batfish.common.BatfishException)1 CommunityList (org.batfish.datamodel.CommunityList)1 CommunityListLine (org.batfish.datamodel.CommunityListLine)1 CommunitySetElemHalfExpr (org.batfish.datamodel.routing_policy.expr.CommunitySetElemHalfExpr)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