use of org.batfish.grammar.cisco.CiscoParser.Prefix_set_elemContext in project batfish by batfish.
the class CiscoControlPlaneExtractor method toRoutePolicyPrefixSet.
private RoutePolicyPrefixSet toRoutePolicyPrefixSet(Rp_prefix_setContext ctx) {
if (ctx.name != null) {
// named
String name = ctx.name.getText();
int expressionLine = ctx.name.getStart().getLine();
return new RoutePolicyPrefixSetName(name, expressionLine);
} else {
// inline
PrefixSpace prefixSpace = new PrefixSpace();
Prefix6Space prefix6Space = new Prefix6Space();
boolean ipv6 = false;
for (Prefix_set_elemContext pctxt : ctx.elems) {
int lower;
int upper;
Prefix prefix = null;
Prefix6 prefix6 = null;
if (pctxt.prefix != null) {
prefix = Prefix.parse(pctxt.prefix.getText());
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipa != null) {
prefix = new Prefix(toIp(pctxt.ipa), Prefix.MAX_PREFIX_LENGTH);
lower = prefix.getPrefixLength();
upper = Prefix.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6a != null) {
prefix6 = new Prefix6(toIp6(pctxt.ipv6a), Prefix6.MAX_PREFIX_LENGTH);
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else if (pctxt.ipv6_prefix != null) {
prefix6 = new Prefix6(pctxt.ipv6_prefix.getText());
lower = prefix6.getPrefixLength();
upper = Prefix6.MAX_PREFIX_LENGTH;
} else {
throw new BatfishException("Unhandled alternative");
}
if (pctxt.minpl != null) {
lower = toInteger(pctxt.minpl);
}
if (pctxt.maxpl != null) {
upper = toInteger(pctxt.maxpl);
}
if (pctxt.eqpl != null) {
lower = toInteger(pctxt.eqpl);
upper = lower;
}
if (prefix != null) {
prefixSpace.addPrefixRange(new PrefixRange(prefix, new SubRange(lower, upper)));
} else {
prefix6Space.addPrefix6Range(new Prefix6Range(prefix6, new SubRange(lower, upper)));
ipv6 = true;
}
}
if (ipv6) {
return new RoutePolicyInlinePrefix6Set(prefix6Space);
} else {
return new RoutePolicyInlinePrefixSet(prefixSpace);
}
}
}
Aggregations