Search in sources :

Example 11 with LineAction

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

the class CiscoControlPlaneExtractor method exitIp_as_path_access_list_tail.

@Override
public void exitIp_as_path_access_list_tail(Ip_as_path_access_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.action);
    String regex = ctx.as_path_regex.getText().trim();
    IpAsPathAccessListLine line = new IpAsPathAccessListLine(action, regex);
    _currentAsPathAcl.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) IpAsPathAccessListLine(org.batfish.representation.cisco.IpAsPathAccessListLine)

Example 12 with LineAction

use of org.batfish.datamodel.LineAction 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 13 with LineAction

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

the class CiscoControlPlaneExtractor method enterRoute_map_stanza.

@Override
public void enterRoute_map_stanza(Route_map_stanzaContext ctx) {
    String name = ctx.name.getText();
    int definitionLine = ctx.name.getStart().getLine();
    RouteMap routeMap = _configuration.getRouteMaps().computeIfAbsent(name, n -> new RouteMap(n, definitionLine));
    _currentRouteMap = routeMap;
    int num = toInteger(ctx.num);
    LineAction action = toLineAction(ctx.rmt);
    RouteMapClause clause = _currentRouteMap.getClauses().get(num);
    if (clause == null) {
        clause = new RouteMapClause(action, name, num);
        routeMap.getClauses().put(num, clause);
    } else {
        _w.redFlag("Route map '" + _currentRouteMap.getName() + "' already contains clause numbered '" + num + "'. Duplicate clause will be merged with original clause.");
    }
    _currentRouteMapClause = clause;
}
Also used : LineAction(org.batfish.datamodel.LineAction) RouteMapClause(org.batfish.representation.cisco.RouteMapClause) RouteMap(org.batfish.representation.cisco.RouteMap)

Example 14 with LineAction

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

the class CiscoControlPlaneExtractor method exitExtended_access_list_tail.

@Override
public void exitExtended_access_list_tail(Extended_access_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.ala);
    IpProtocol protocol = toIpProtocol(ctx.prot);
    Ip srcIp = getIp(ctx.srcipr);
    Ip srcWildcard = getWildcard(ctx.srcipr);
    Ip dstIp = getIp(ctx.dstipr);
    Ip 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();
    ExtendedAccessListLine line = new ExtendedAccessListLine(name, action, protocol, new IpWildcard(srcIp, srcWildcard), srcAddressGroup, new IpWildcard(dstIp, dstWildcard), dstAddressGroup, srcPortRanges, dstPortRanges, dscps, ecns, icmpType, icmpCode, states, tcpFlags);
    _currentExtendedAcl.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) Ip(org.batfish.datamodel.Ip) RoutePolicyNextHopIp(org.batfish.representation.cisco.RoutePolicyNextHopIp) ExtendedAccessListLine(org.batfish.representation.cisco.ExtendedAccessListLine) ArrayList(java.util.ArrayList) IpWildcard(org.batfish.datamodel.IpWildcard) 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)

Example 15 with LineAction

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

the class CiscoControlPlaneExtractor method exitIpv6_prefix_list_tail.

@Override
public void exitIpv6_prefix_list_tail(Ipv6_prefix_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.action);
    Prefix6 prefix6 = new Prefix6(ctx.prefix6.getText());
    int prefixLength = prefix6.getPrefixLength();
    int minLen = prefixLength;
    int maxLen = prefixLength;
    if (ctx.minpl != null) {
        minLen = toInteger(ctx.minpl);
        maxLen = Prefix6.MAX_PREFIX_LENGTH;
    }
    if (ctx.maxpl != null) {
        maxLen = toInteger(ctx.maxpl);
    }
    if (ctx.eqpl != null) {
        minLen = toInteger(ctx.eqpl);
        maxLen = toInteger(ctx.eqpl);
    }
    SubRange lengthRange = new SubRange(minLen, maxLen);
    Prefix6ListLine line = new Prefix6ListLine(action, prefix6, lengthRange);
    _currentPrefix6List.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) Prefix6ListLine(org.batfish.representation.cisco.Prefix6ListLine) SubRange(org.batfish.datamodel.SubRange) Prefix6(org.batfish.datamodel.Prefix6)

Aggregations

LineAction (org.batfish.datamodel.LineAction)21 SubRange (org.batfish.datamodel.SubRange)9 Prefix (org.batfish.datamodel.Prefix)5 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 IpAccessList (org.batfish.datamodel.IpAccessList)4 IpWildcard (org.batfish.datamodel.IpWildcard)4 ImmutableList (com.google.common.collect.ImmutableList)3 Ip (org.batfish.datamodel.Ip)3 Ip6 (org.batfish.datamodel.Ip6)3 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)3 IpProtocol (org.batfish.datamodel.IpProtocol)3 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)3 List (java.util.List)2 Ip6Wildcard (org.batfish.datamodel.Ip6Wildcard)2 Prefix6 (org.batfish.datamodel.Prefix6)2 RouteFilterList (org.batfish.datamodel.RouteFilterList)2 State (org.batfish.datamodel.State)2 TcpFlags (org.batfish.datamodel.TcpFlags)2 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)2