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