Search in sources :

Example 36 with SubRange

use of org.batfish.datamodel.SubRange in project batfish by batfish.

the class CiscoControlPlaneExtractor method toRange.

private static List<SubRange> toRange(RangeContext ctx) {
    List<SubRange> range = new ArrayList<>();
    for (SubrangeContext sc : ctx.range_list) {
        SubRange sr = toSubRange(sc);
        range.add(sr);
    }
    return range;
}
Also used : ArrayList(java.util.ArrayList) SubrangeContext(org.batfish.grammar.cisco.CiscoParser.SubrangeContext) SubRange(org.batfish.datamodel.SubRange)

Example 37 with SubRange

use of org.batfish.datamodel.SubRange in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitExtended_ipv6_access_list_tail.

@Override
public void exitExtended_ipv6_access_list_tail(Extended_ipv6_access_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.ala);
    IpProtocol protocol = toIpProtocol(ctx.prot);
    Ip6 srcIp = getIp(ctx.srcipr);
    Ip6 srcWildcard = getWildcard(ctx.srcipr);
    Ip6 dstIp = getIp(ctx.dstipr);
    Ip6 dstWildcard = getWildcard(ctx.dstipr);
    String srcAddressGroup = getAddressGroup(ctx.srcipr);
    String dstAddressGroup = getAddressGroup(ctx.dstipr);
    List<SubRange> srcPortRanges = ctx.alps_src != null ? toPortRanges(ctx.alps_src) : Collections.<SubRange>emptyList();
    List<SubRange> dstPortRanges = ctx.alps_dst != null ? toPortRanges(ctx.alps_dst) : Collections.<SubRange>emptyList();
    Integer icmpType = null;
    Integer icmpCode = null;
    List<TcpFlags> tcpFlags = new ArrayList<>();
    Set<Integer> dscps = new TreeSet<>();
    Set<Integer> ecns = new TreeSet<>();
    Set<State> states = EnumSet.noneOf(State.class);
    for (Extended_access_list_additional_featureContext feature : ctx.features) {
        if (feature.ACK() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseAck(true);
            alt.setAck(true);
            tcpFlags.add(alt);
        }
        if (feature.DSCP() != null) {
            int dscpType = toDscpType(feature.dscp_type());
            dscps.add(dscpType);
        }
        if (feature.ECE() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseEce(true);
            alt.setEce(true);
            tcpFlags.add(alt);
        }
        if (feature.ECHO_REPLY() != null) {
            icmpType = IcmpType.ECHO_REPLY;
            icmpCode = IcmpCode.ECHO_REPLY;
        }
        if (feature.ECHO() != null) {
            icmpType = IcmpType.ECHO_REQUEST;
            icmpCode = IcmpCode.ECHO_REQUEST;
        }
        if (feature.ECN() != null) {
            int ecn = toInteger(feature.ecn);
            ecns.add(ecn);
        }
        if (feature.ESTABLISHED() != null) {
            // must contain ACK or RST
            TcpFlags alt1 = new TcpFlags();
            TcpFlags alt2 = new TcpFlags();
            alt1.setUseAck(true);
            alt1.setAck(true);
            alt2.setUseRst(true);
            alt2.setRst(true);
            tcpFlags.add(alt1);
            tcpFlags.add(alt2);
        }
        if (feature.FIN() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseFin(true);
            alt.setFin(true);
            tcpFlags.add(alt);
        }
        if (feature.FRAGMENTS() != null) {
            todo(ctx, F_FRAGMENTS);
        }
        if (feature.HOST_UNKNOWN() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.DESTINATION_HOST_UNKNOWN;
        }
        if (feature.HOST_UNREACHABLE() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.DESTINATION_HOST_UNREACHABLE;
        }
        if (feature.NETWORK_UNKNOWN() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.DESTINATION_NETWORK_UNKNOWN;
        }
        if (feature.NET_UNREACHABLE() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.DESTINATION_NETWORK_UNREACHABLE;
        }
        if (feature.PACKET_TOO_BIG() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.PACKET_TOO_BIG;
        }
        if (feature.PARAMETER_PROBLEM() != null) {
            icmpType = IcmpType.PARAMETER_PROBLEM;
        }
        if (feature.PORT_UNREACHABLE() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
            icmpCode = IcmpCode.DESTINATION_PORT_UNREACHABLE;
        }
        if (feature.PSH() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUsePsh(true);
            alt.setPsh(true);
            tcpFlags.add(alt);
        }
        if (feature.REDIRECT() != null) {
            icmpType = IcmpType.REDIRECT_MESSAGE;
        }
        if (feature.RST() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseRst(true);
            alt.setRst(true);
            tcpFlags.add(alt);
        }
        if (feature.SOURCE_QUENCH() != null) {
            icmpType = IcmpType.SOURCE_QUENCH;
            icmpCode = IcmpCode.SOURCE_QUENCH;
        }
        if (feature.SYN() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseSyn(true);
            alt.setSyn(true);
            tcpFlags.add(alt);
        }
        if (feature.TIME_EXCEEDED() != null) {
            icmpType = IcmpType.TIME_EXCEEDED;
        }
        if (feature.TTL() != null) {
            todo(ctx, F_TTL);
        }
        if (feature.TTL_EXCEEDED() != null) {
            icmpType = IcmpType.TIME_EXCEEDED;
            icmpCode = IcmpCode.TTL_EXCEEDED;
        }
        if (feature.TRACEROUTE() != null) {
            icmpType = IcmpType.TRACEROUTE;
            icmpCode = IcmpCode.TRACEROUTE;
        }
        if (feature.TRACKED() != null) {
            states.add(State.ESTABLISHED);
        }
        if (feature.UNREACHABLE() != null) {
            icmpType = IcmpType.DESTINATION_UNREACHABLE;
        }
        if (feature.URG() != null) {
            TcpFlags alt = new TcpFlags();
            alt.setUseUrg(true);
            alt.setUrg(true);
            tcpFlags.add(alt);
        }
    }
    String name = getFullText(ctx).trim();
    ExtendedIpv6AccessListLine line = new ExtendedIpv6AccessListLine(name, action, protocol, new Ip6Wildcard(srcIp, srcWildcard), srcAddressGroup, new Ip6Wildcard(dstIp, dstWildcard), dstAddressGroup, srcPortRanges, dstPortRanges, dscps, ecns, icmpType, icmpCode, states, tcpFlags);
    _currentExtendedIpv6Acl.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) ArrayList(java.util.ArrayList) ExtendedIpv6AccessListLine(org.batfish.representation.cisco.ExtendedIpv6AccessListLine) Ip6(org.batfish.datamodel.Ip6) TcpFlags(org.batfish.datamodel.TcpFlags) TreeSet(java.util.TreeSet) State(org.batfish.datamodel.State) Extended_access_list_additional_featureContext(org.batfish.grammar.cisco.CiscoParser.Extended_access_list_additional_featureContext) IpProtocol(org.batfish.datamodel.IpProtocol) SubRange(org.batfish.datamodel.SubRange) Ip6Wildcard(org.batfish.datamodel.Ip6Wildcard)

Example 38 with SubRange

use of org.batfish.datamodel.SubRange in project batfish by batfish.

the class CiscoControlPlaneExtractor method enterS_interface.

@Override
public void enterS_interface(S_interfaceContext ctx) {
    String nameAlpha = ctx.iname.name_prefix_alpha.getText();
    String canonicalNamePrefix;
    try {
        canonicalNamePrefix = CiscoConfiguration.getCanonicalInterfaceNamePrefix(nameAlpha);
    } catch (BatfishException e) {
        _w.redFlag("Error fetching interface name at: " + getLocation(ctx) + getFullText(ctx) + " : " + e.getMessage());
        _currentInterfaces = ImmutableList.of();
        return;
    }
    String namePrefix = canonicalNamePrefix;
    for (Token part : ctx.iname.name_middle_parts) {
        namePrefix += part.getText();
    }
    _currentInterfaces = new ArrayList<>();
    if (ctx.iname.range() != null) {
        List<SubRange> ranges = toRange(ctx.iname.range());
        for (SubRange range : ranges) {
            for (int i = range.getStart(); i <= range.getEnd(); i++) {
                String name = namePrefix + i;
                addInterface(name, ctx.iname, true);
            }
        }
    } else {
        String name = namePrefix;
        addInterface(name, ctx.iname, true);
    }
    if (ctx.MULTIPOINT() != null) {
        todo(ctx, F_INTERFACE_MULTIPOINT);
    }
}
Also used : BatfishException(org.batfish.common.BatfishException) RedFlagBatfishException(org.batfish.common.RedFlagBatfishException) Token(org.antlr.v4.runtime.Token) SubRange(org.batfish.datamodel.SubRange)

Example 39 with SubRange

use of org.batfish.datamodel.SubRange 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);
    }
}
Also used : LiteralCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.LiteralCommunitySetElemHalf) RangeCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.RangeCommunitySetElemHalf) SubRange(org.batfish.datamodel.SubRange) VarCommunitySetElemHalf(org.batfish.datamodel.routing_policy.expr.VarCommunitySetElemHalf)

Example 40 with SubRange

use of org.batfish.datamodel.SubRange 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

SubRange (org.batfish.datamodel.SubRange)74 Prefix (org.batfish.datamodel.Prefix)18 IpWildcard (org.batfish.datamodel.IpWildcard)16 ArrayList (java.util.ArrayList)15 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)13 Ip (org.batfish.datamodel.Ip)11 FwFrom (org.batfish.representation.juniper.FwFrom)11 Test (org.junit.Test)11 BatfishException (org.batfish.common.BatfishException)9 LineAction (org.batfish.datamodel.LineAction)9 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)9 LinkedList (java.util.LinkedList)8 IpProtocol (org.batfish.datamodel.IpProtocol)8 RouteFilterList (org.batfish.datamodel.RouteFilterList)8 BoolExpr (com.microsoft.z3.BoolExpr)7 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)7 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)7 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)7 IpAccessList (org.batfish.datamodel.IpAccessList)6 PrefixRange (org.batfish.datamodel.PrefixRange)6