Search in sources :

Example 1 with LiteralCommunitySetElemHalf

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

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

the class CiscoControlPlaneExtractor method toCommunitySetElemHalfExpr.

private CommunitySetElemHalfExpr toCommunitySetElemHalfExpr(Rp_community_set_elem_halfContext ctx) {
    if (ctx.value != null) {
        int value = toInteger(ctx.value);
        return new LiteralCommunitySetElemHalf(value);
    } else if (ctx.var != null) {
        String var = ctx.var.getText();
        return new VarCommunitySetElemHalf(var);
    } else if (ctx.first != null) {
        int first = toInteger(ctx.first);
        int last = toInteger(ctx.last);
        SubRange range = new SubRange(first, last);
        return new RangeCommunitySetElemHalf(range);
    } else {
        throw convError(CommunitySetElem.class, ctx);
    }
}
Also used : LiteralCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf) RangeCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.RangeCommunitySetElemHalf) SubRange(org.batfish.datamodel.SubRange) VarCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.VarCommunitySetElemHalf)

Aggregations

LiteralCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf)2 HashSet (java.util.HashSet)1 BatfishException (org.batfish.common.BatfishException)1 CommunityList (org.batfish.datamodel.CommunityList)1 CommunityListLine (org.batfish.datamodel.CommunityListLine)1 SubRange (org.batfish.datamodel.SubRange)1 CommunitySetElem (org.batfish.datamodel.routing_policy.expr.CommunitySetElem)1 InlineCommunitySet (org.batfish.datamodel.routing_policy.expr.InlineCommunitySet)1 NamedCommunitySet (org.batfish.datamodel.routing_policy.expr.NamedCommunitySet)1 RangeCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.RangeCommunitySetElemHalf)1 VarCommunitySetElemHalf (org.batfish.datamodel.routing_policy.expr.VarCommunitySetElemHalf)1