Search in sources :

Example 41 with SubRange

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

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

Example 43 with SubRange

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

the class CiscoControlPlaneExtractor method exitIp_prefix_list_tail.

@Override
public void exitIp_prefix_list_tail(Ip_prefix_list_tailContext ctx) {
    LineAction action = toLineAction(ctx.action);
    Prefix prefix = Prefix.parse(ctx.prefix.getText());
    int prefixLength = prefix.getPrefixLength();
    int minLen = prefixLength;
    int maxLen = prefixLength;
    if (ctx.minpl != null) {
        minLen = toInteger(ctx.minpl);
        maxLen = Prefix.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);
    PrefixListLine line = new PrefixListLine(action, prefix, lengthRange);
    _currentPrefixList.addLine(line);
}
Also used : LineAction(org.batfish.datamodel.LineAction) PrefixListLine(org.batfish.representation.cisco.PrefixListLine) RouteMapMatchIpPrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpPrefixListLine) RouteMapMatchIpv6PrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpv6PrefixListLine) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange)

Example 44 with SubRange

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

the class CiscoControlPlaneExtractor method exitPrefix_set_elem.

@Override
public void exitPrefix_set_elem(Prefix_set_elemContext ctx) {
    String name = _currentPrefixSetName;
    if (name != null) {
        if (ctx.ipa != null || ctx.prefix != null) {
            PrefixList pl = _configuration.getPrefixLists().computeIfAbsent(name, n -> new PrefixList(n, _currentPrefixSetDefinitionLine));
            Prefix prefix;
            if (ctx.ipa != null) {
                prefix = new Prefix(toIp(ctx.ipa), Prefix.MAX_PREFIX_LENGTH);
            } else {
                prefix = Prefix.parse(ctx.prefix.getText());
            }
            int prefixLength = prefix.getPrefixLength();
            int minLen = prefixLength;
            int maxLen = prefixLength;
            if (ctx.minpl != null) {
                minLen = toInteger(ctx.minpl);
                maxLen = Prefix.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);
            PrefixListLine line = new PrefixListLine(LineAction.ACCEPT, prefix, lengthRange);
            pl.addLine(line);
        } else {
            Prefix6List pl = _configuration.getPrefix6Lists().computeIfAbsent(name, n -> new Prefix6List(n, _currentPrefixSetDefinitionLine));
            Prefix6 prefix6;
            if (ctx.ipv6a != null) {
                prefix6 = new Prefix6(toIp6(ctx.ipv6a), Prefix6.MAX_PREFIX_LENGTH);
            } else {
                prefix6 = new Prefix6(ctx.ipv6_prefix.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(LineAction.ACCEPT, prefix6, lengthRange);
            pl.addLine(line);
        }
    }
}
Also used : Prefix6ListLine(org.batfish.representation.cisco.Prefix6ListLine) Prefix6List(org.batfish.representation.cisco.Prefix6List) PrefixListLine(org.batfish.representation.cisco.PrefixListLine) RouteMapMatchIpPrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpPrefixListLine) RouteMapMatchIpv6PrefixListLine(org.batfish.representation.cisco.RouteMapMatchIpv6PrefixListLine) PrefixList(org.batfish.representation.cisco.PrefixList) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) Prefix6(org.batfish.datamodel.Prefix6)

Example 45 with SubRange

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

the class ConfigurationBuilder method exitFftf_packet_length.

@Override
public void exitFftf_packet_length(Fftf_packet_lengthContext ctx) {
    List<SubRange> range = toRange(ctx.range());
    FwFrom from = new FwFromPacketLength(range, false);
    _currentFwTerm.getFroms().add(from);
}
Also used : FwFromPacketLength(org.batfish.representation.juniper.FwFromPacketLength) FwFrom(org.batfish.representation.juniper.FwFrom) SubRange(org.batfish.datamodel.SubRange)

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