<commit_before>/*
 * Copyright 2017-present Open Networking Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onosproject.pipelines.fabric;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.DeserializationException;
import org.onlab.packet.Ethernet;
import org.onlab.util.ImmutableByteSequence;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.packet.DefaultInboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.pi.model.PiMatchFieldId;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.model.PiTableId;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiPacketMetadata;
import org.onosproject.net.pi.runtime.PiPacketOperation;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.onlab.util.ImmutableByteSequence.copyFrom;
import static org.onosproject.net.PortNumber.CONTROLLER;
import static org.onosproject.net.PortNumber.FLOOD;
import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
import static org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT;

/**
 * Interpreter for fabric pipeline.
 */
public class FabricInterpreter extends AbstractFabricHandlerBehavior
        implements PiPipelineInterpreter {

    private static final int PORT_BITWIDTH = 9;

    // Group tables by control block.
    private static final Set<PiTableId> FILTERING_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN,
            FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER);
    private static final Set<PiTableId> FORWARDING_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_FORWARDING_MPLS,
            FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4,
            FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V6,
            FabricConstants.FABRIC_INGRESS_FORWARDING_BRIDGING);
    private static final Set<PiTableId> ACL_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_ACL_ACL);
    private static final Set<PiTableId> NEXT_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN,
            FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE,
            FabricConstants.FABRIC_INGRESS_NEXT_HASHED,
            FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT);
    private static final Set<PiTableId> E_NEXT_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN);

    private static final ImmutableMap<Criterion.Type, PiMatchFieldId> CRITERION_MAP =
            ImmutableMap.<Criterion.Type, PiMatchFieldId>builder()
                    .put(Criterion.Type.IN_PORT, FabricConstants.HDR_IG_PORT)
                    .put(Criterion.Type.ETH_DST, FabricConstants.HDR_ETH_DST)
                    .put(Criterion.Type.ETH_SRC, FabricConstants.HDR_ETH_SRC)
                    .put(Criterion.Type.ETH_DST_MASKED, FabricConstants.HDR_ETH_DST)
                    .put(Criterion.Type.ETH_SRC_MASKED, FabricConstants.HDR_ETH_SRC)
                    .put(Criterion.Type.ETH_TYPE, FabricConstants.HDR_ETH_TYPE)
                    .put(Criterion.Type.MPLS_LABEL, FabricConstants.HDR_MPLS_LABEL)
                    .put(Criterion.Type.VLAN_VID, FabricConstants.HDR_VLAN_ID)
                    .put(Criterion.Type.INNER_VLAN_VID, FabricConstants.HDR_INNER_VLAN_ID)
                    .put(Criterion.Type.IPV4_DST, FabricConstants.HDR_IPV4_DST)
                    .put(Criterion.Type.IPV4_SRC, FabricConstants.HDR_IPV4_SRC)
                    .put(Criterion.Type.IPV6_DST, FabricConstants.HDR_IPV6_DST)
                    .put(Criterion.Type.IP_PROTO, FabricConstants.HDR_IP_PROTO)
                    .put(Criterion.Type.ICMPV6_TYPE, FabricConstants.HDR_ICMP_TYPE)
                    .put(Criterion.Type.ICMPV6_CODE, FabricConstants.HDR_ICMP_CODE)
                    .build();

    private static final PiAction NOP = PiAction.builder()
            .withId(FabricConstants.NOP).build();

    private static final ImmutableMap<PiTableId, PiAction> DEFAULT_ACTIONS =
            ImmutableMap.<PiTableId, PiAction>builder()
                    .put(FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, NOP)
                    .build();<commit_msg>Added support for L4 ports as Criterion<commit_after>/*
 * Copyright 2017-present Open Networking Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onosproject.pipelines.fabric;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.DeserializationException;
import org.onlab.packet.Ethernet;
import org.onlab.util.ImmutableByteSequence;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.packet.DefaultInboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.pi.model.PiMatchFieldId;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import org.onosproject.net.pi.model.PiTableId;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiPacketMetadata;
import org.onosproject.net.pi.runtime.PiPacketOperation;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.onlab.util.ImmutableByteSequence.copyFrom;
import static org.onosproject.net.PortNumber.CONTROLLER;
import static org.onosproject.net.PortNumber.FLOOD;
import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
import static org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT;

/**
 * Interpreter for fabric pipeline.
 */
public class FabricInterpreter extends AbstractFabricHandlerBehavior
        implements PiPipelineInterpreter {

    private static final int PORT_BITWIDTH = 9;

    // Group tables by control block.
    private static final Set<PiTableId> FILTERING_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN,
            FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER);
    private static final Set<PiTableId> FORWARDING_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_FORWARDING_MPLS,
            FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4,
            FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V6,
            FabricConstants.FABRIC_INGRESS_FORWARDING_BRIDGING);
    private static final Set<PiTableId> ACL_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_ACL_ACL);
    private static final Set<PiTableId> NEXT_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN,
            FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE,
            FabricConstants.FABRIC_INGRESS_NEXT_HASHED,
            FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT);
    private static final Set<PiTableId> E_NEXT_CTRL_TBLS = ImmutableSet.of(
            FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN);

    private static final ImmutableMap<Criterion.Type, PiMatchFieldId> CRITERION_MAP =
            ImmutableMap.<Criterion.Type, PiMatchFieldId>builder()
                    .put(Criterion.Type.IN_PORT, FabricConstants.HDR_IG_PORT)
                    .put(Criterion.Type.ETH_DST, FabricConstants.HDR_ETH_DST)
                    .put(Criterion.Type.ETH_SRC, FabricConstants.HDR_ETH_SRC)
                    .put(Criterion.Type.ETH_DST_MASKED, FabricConstants.HDR_ETH_DST)
                    .put(Criterion.Type.ETH_SRC_MASKED, FabricConstants.HDR_ETH_SRC)
                    .put(Criterion.Type.ETH_TYPE, FabricConstants.HDR_ETH_TYPE)
                    .put(Criterion.Type.MPLS_LABEL, FabricConstants.HDR_MPLS_LABEL)
                    .put(Criterion.Type.VLAN_VID, FabricConstants.HDR_VLAN_ID)
                    .put(Criterion.Type.INNER_VLAN_VID, FabricConstants.HDR_INNER_VLAN_ID)
                    .put(Criterion.Type.IPV4_DST, FabricConstants.HDR_IPV4_DST)
                    .put(Criterion.Type.IPV4_SRC, FabricConstants.HDR_IPV4_SRC)
                    .put(Criterion.Type.IPV6_DST, FabricConstants.HDR_IPV6_DST)
                    .put(Criterion.Type.IP_PROTO, FabricConstants.HDR_IP_PROTO)
                    .put(Criterion.Type.ICMPV6_TYPE, FabricConstants.HDR_ICMP_TYPE)
                    .put(Criterion.Type.ICMPV6_CODE, FabricConstants.HDR_ICMP_CODE)
                    .put(Criterion.Type.UDP_DST, FabricConstants.HDR_L4_DPORT)
                    .put(Criterion.Type.UDP_SRC, FabricConstants.HDR_L4_SPORT)
                    .put(Criterion.Type.UDP_DST_MASKED, FabricConstants.HDR_L4_DPORT)
                    .put(Criterion.Type.UDP_SRC_MASKED, FabricConstants.HDR_L4_SPORT)
                    .put(Criterion.Type.TCP_DST, FabricConstants.HDR_L4_DPORT)
                    .put(Criterion.Type.TCP_SRC, FabricConstants.HDR_L4_SPORT)
                    .put(Criterion.Type.TCP_DST_MASKED, FabricConstants.HDR_L4_DPORT)
                    .put(Criterion.Type.TCP_SRC_MASKED, FabricConstants.HDR_L4_SPORT)
                    .build();

    private static final PiAction NOP = PiAction.builder()
            .withId(FabricConstants.NOP).build();

    private static final ImmutableMap<PiTableId, PiAction> DEFAULT_ACTIONS =
            ImmutableMap.<PiTableId, PiAction>builder()
                    .put(FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, NOP)
                    .build();
{'fraction_non_alphanumeric': 0.08, 'fraction_numerical': 0.004206008583690987, 'mean_word_length': 3.5352277150642273, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3755238', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3730, 'n_words': 589}