Search in sources :

Example 1 with RoutePolicyInlinePrefixSet

use of org.batfish.representation.cisco.RoutePolicyInlinePrefixSet 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);
        }
    }
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) PrefixRange(org.batfish.datamodel.PrefixRange) RoutePolicyInlinePrefixSet(org.batfish.representation.cisco.RoutePolicyInlinePrefixSet) RoutePolicyPrefixSetName(org.batfish.representation.cisco.RoutePolicyPrefixSetName) PrefixSpace(org.batfish.datamodel.PrefixSpace) Prefix_set_elemContext(org.batfish.grammar.cisco.CiscoParser.Prefix_set_elemContext) Prefix(org.batfish.datamodel.Prefix) Prefix6Space(org.batfish.datamodel.Prefix6Space) Prefix6Range(org.batfish.datamodel.Prefix6Range) RoutePolicyInlinePrefix6Set(org.batfish.representation.cisco.RoutePolicyInlinePrefix6Set) SubRange(org.batfish.datamodel.SubRange) Prefix6(org.batfish.datamodel.Prefix6)

Aggregations

BatfishException (org.batfish.common.BatfishException)1 RedFlagBatfishException (org.batfish.common.RedFlagBatfishException)1 Prefix (org.batfish.datamodel.Prefix)1 Prefix6 (org.batfish.datamodel.Prefix6)1 Prefix6Range (org.batfish.datamodel.Prefix6Range)1 Prefix6Space (org.batfish.datamodel.Prefix6Space)1 PrefixRange (org.batfish.datamodel.PrefixRange)1 PrefixSpace (org.batfish.datamodel.PrefixSpace)1 SubRange (org.batfish.datamodel.SubRange)1 Prefix_set_elemContext (org.batfish.grammar.cisco.CiscoParser.Prefix_set_elemContext)1 RoutePolicyInlinePrefix6Set (org.batfish.representation.cisco.RoutePolicyInlinePrefix6Set)1 RoutePolicyInlinePrefixSet (org.batfish.representation.cisco.RoutePolicyInlinePrefixSet)1 RoutePolicyPrefixSetName (org.batfish.representation.cisco.RoutePolicyPrefixSetName)1