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