Search in sources :

Example 1 with TcpFlags

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

the class ConfigurationBuilder method exitFftf_tcp_established.

@Override
public void exitFftf_tcp_established(Fftf_tcp_establishedContext ctx) {
    List<TcpFlags> tcpFlags = new ArrayList<>();
    TcpFlags alt1 = new TcpFlags();
    alt1.setUseAck(true);
    alt1.setAck(true);
    tcpFlags.add(alt1);
    TcpFlags alt2 = new TcpFlags();
    alt2.setUseRst(true);
    alt2.setRst(true);
    tcpFlags.add(alt2);
    FwFrom from = new FwFromTcpFlags(tcpFlags);
    _currentFwTerm.getFroms().add(from);
}
Also used : TcpFlags(org.batfish.datamodel.TcpFlags) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags) ArrayList(java.util.ArrayList) FwFrom(org.batfish.representation.juniper.FwFrom) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags)

Example 2 with TcpFlags

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

the class ConfigurationBuilder method toTcpFlags.

private static List<TcpFlags> toTcpFlags(Tcp_flagsContext ctx) {
    List<TcpFlags> tcpFlagsList = new ArrayList<>();
    for (Tcp_flags_alternativeContext alternativeCtx : ctx.alternatives) {
        TcpFlags tcpFlags = toTcpFlags(alternativeCtx);
        tcpFlagsList.add(tcpFlags);
    }
    return tcpFlagsList;
}
Also used : TcpFlags(org.batfish.datamodel.TcpFlags) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags) Tcp_flags_alternativeContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Tcp_flags_alternativeContext) ArrayList(java.util.ArrayList)

Example 3 with TcpFlags

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

the class ConfigurationBuilder method exitFftf_tcp_initial.

@Override
public void exitFftf_tcp_initial(Fftf_tcp_initialContext ctx) {
    List<TcpFlags> tcpFlags = new ArrayList<>();
    TcpFlags alt1 = new TcpFlags();
    alt1.setUseAck(true);
    alt1.setAck(false);
    alt1.setUseSyn(true);
    alt1.setSyn(true);
    tcpFlags.add(alt1);
    FwFrom from = new FwFromTcpFlags(tcpFlags);
    _currentFwTerm.getFroms().add(from);
}
Also used : TcpFlags(org.batfish.datamodel.TcpFlags) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags) ArrayList(java.util.ArrayList) FwFrom(org.batfish.representation.juniper.FwFrom) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags)

Example 4 with TcpFlags

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

the class ConfigurationBuilder method toTcpFlags.

private static TcpFlags toTcpFlags(Tcp_flags_alternativeContext ctx) {
    TcpFlags tcpFlags = new TcpFlags();
    for (Tcp_flags_literalContext literalCtx : ctx.literals) {
        boolean value = literalCtx.BANG() == null;
        Tcp_flags_atomContext atom = literalCtx.tcp_flags_atom();
        if (atom.ACK() != null) {
            tcpFlags.setUseAck(true);
            tcpFlags.setAck(value);
        } else if (atom.CWR() != null) {
            tcpFlags.setUseCwr(true);
            tcpFlags.setCwr(value);
        } else if (atom.ECE() != null) {
            tcpFlags.setUseEce(true);
            tcpFlags.setEce(value);
        } else if (atom.FIN() != null) {
            tcpFlags.setUseFin(true);
            tcpFlags.setFin(value);
        } else if (atom.PSH() != null) {
            tcpFlags.setUsePsh(true);
            tcpFlags.setPsh(value);
        } else if (atom.RST() != null) {
            tcpFlags.setUseRst(true);
            tcpFlags.setRst(value);
        } else if (atom.SYN() != null) {
            tcpFlags.setUseSyn(true);
            tcpFlags.setSyn(value);
        } else if (atom.URG() != null) {
            tcpFlags.setUseUrg(true);
            tcpFlags.setUrg(value);
        } else {
            throw new BatfishException("Invalid tcp-flags atom: " + atom.getText());
        }
    }
    return tcpFlags;
}
Also used : TcpFlags(org.batfish.datamodel.TcpFlags) FwFromTcpFlags(org.batfish.representation.juniper.FwFromTcpFlags) BatfishException(org.batfish.common.BatfishException) Tcp_flags_atomContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Tcp_flags_atomContext) Tcp_flags_literalContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Tcp_flags_literalContext)

Example 5 with TcpFlags

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

Aggregations

TcpFlags (org.batfish.datamodel.TcpFlags)9 ArrayList (java.util.ArrayList)7 FwFromTcpFlags (org.batfish.representation.juniper.FwFromTcpFlags)5 IpProtocol (org.batfish.datamodel.IpProtocol)4 State (org.batfish.datamodel.State)4 SubRange (org.batfish.datamodel.SubRange)4 FwFrom (org.batfish.representation.juniper.FwFrom)3 BigInteger (java.math.BigInteger)2 TreeSet (java.util.TreeSet)2 Ip6Wildcard (org.batfish.datamodel.Ip6Wildcard)2 IpWildcard (org.batfish.datamodel.IpWildcard)2 LineAction (org.batfish.datamodel.LineAction)2 Extended_access_list_additional_featureContext (org.batfish.grammar.cisco.CiscoParser.Extended_access_list_additional_featureContext)2 BatfishException (org.batfish.common.BatfishException)1 Ip (org.batfish.datamodel.Ip)1 Ip6 (org.batfish.datamodel.Ip6)1 Ip6AccessList (org.batfish.datamodel.Ip6AccessList)1 Ip6AccessListLine (org.batfish.datamodel.Ip6AccessListLine)1 IpAccessList (org.batfish.datamodel.IpAccessList)1 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)1