Search in sources :

Example 1 with PortContext

use of org.batfish.grammar.cisco.CiscoParser.PortContext in project batfish by batfish.

the class CiscoControlPlaneExtractor method toPortRanges.

private List<SubRange> toPortRanges(Port_specifierContext ps) {
    List<SubRange> ranges = new ArrayList<>();
    if (ps.EQ() != null) {
        for (PortContext pc : ps.args) {
            int port = getPortNumber(pc);
            ranges.add(new SubRange(port, port));
        }
    } else if (ps.GT() != null) {
        int port = getPortNumber(ps.arg);
        ranges.add(new SubRange(port + 1, 65535));
    } else if (ps.NEQ() != null) {
        int port = getPortNumber(ps.arg);
        SubRange beforeRange = new SubRange(0, port - 1);
        SubRange afterRange = new SubRange(port + 1, 65535);
        ranges.add(beforeRange);
        ranges.add(afterRange);
    } else if (ps.LT() != null) {
        int port = getPortNumber(ps.arg);
        ranges.add(new SubRange(0, port - 1));
    } else if (ps.RANGE() != null) {
        int lowPort = getPortNumber(ps.arg1);
        int highPort = getPortNumber(ps.arg2);
        ranges.add(new SubRange(lowPort, highPort));
    } else {
        throw convError(List.class, ps);
    }
    return ranges;
}
Also used : ArrayList(java.util.ArrayList) SubRange(org.batfish.datamodel.SubRange) PortContext(org.batfish.grammar.cisco.CiscoParser.PortContext)

Aggregations

ArrayList (java.util.ArrayList)1 SubRange (org.batfish.datamodel.SubRange)1 PortContext (org.batfish.grammar.cisco.CiscoParser.PortContext)1