get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/28013/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 28013,
    "url": "https://patches.dpdk.org/api/patches/28013/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1503677438-27591-6-git-send-email-bernard.iremonger@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1503677438-27591-6-git-send-email-bernard.iremonger@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1503677438-27591-6-git-send-email-bernard.iremonger@intel.com",
    "date": "2017-08-25T16:10:37",
    "name": "[dpdk-dev,v2,5/6] examples/flow_classify: flow classify sample application",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "1959bc9669eece1bf2ecf5ba30dc939ded8f8e6d",
    "submitter": {
        "id": 91,
        "url": "https://patches.dpdk.org/api/people/91/?format=api",
        "name": "Iremonger, Bernard",
        "email": "bernard.iremonger@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1503677438-27591-6-git-send-email-bernard.iremonger@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/28013/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/28013/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 7CEC67D8A;\n\tFri, 25 Aug 2017 18:11:01 +0200 (CEST)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id 902707D8A\n\tfor <dev@dpdk.org>; Fri, 25 Aug 2017 18:10:59 +0200 (CEST)",
            "from orsmga005.jf.intel.com ([10.7.209.41])\n\tby fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t25 Aug 2017 09:10:59 -0700",
            "from sivswdev01.ir.intel.com (HELO localhost.localdomain)\n\t([10.237.217.45])\n\tby orsmga005.jf.intel.com with ESMTP; 25 Aug 2017 09:10:57 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.41,426,1498546800\"; d=\"scan'208\";a=\"142009790\"",
        "From": "Bernard Iremonger <bernard.iremonger@intel.com>",
        "To": "dev@dpdk.org, ferruh.yigit@intel.com, konstantin.ananyev@intel.com,\n\tcristian.dumitrescu@intel.com, adrien.mazarguil@6wind.com",
        "Cc": "Bernard Iremonger <bernard.iremonger@intel.com>",
        "Date": "Fri, 25 Aug 2017 17:10:37 +0100",
        "Message-Id": "<1503677438-27591-6-git-send-email-bernard.iremonger@intel.com>",
        "X-Mailer": "git-send-email 1.7.0.7",
        "In-Reply-To": "<1503496275-27492-1-git-send-email-bernard.iremonger@intel.com>",
        "References": "<1503496275-27492-1-git-send-email-bernard.iremonger@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 5/6] examples/flow_classify: flow classify\n\tsample application",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The flow_classify sample application exercises the following\nlibrte_flow_classify API's:\n\nrte_flow_classify_create\nrte_flow_classify_validate\nrte_flow_classify_destroy\nrte_flow_classify_query\n\nIt sets up the IPv4 ACL field definitions.\nIt creates table_acl using the librte_table API.\n\nSigned-off-by: Bernard Iremonger <bernard.iremonger@intel.com>\n---\n examples/flow_classify/Makefile        |  57 +++\n examples/flow_classify/flow_classify.c | 634 +++++++++++++++++++++++++++++++++\n 2 files changed, 691 insertions(+)\n create mode 100644 examples/flow_classify/Makefile\n create mode 100644 examples/flow_classify/flow_classify.c",
    "diff": "diff --git a/examples/flow_classify/Makefile b/examples/flow_classify/Makefile\nnew file mode 100644\nindex 0000000..eecdde1\n--- /dev/null\n+++ b/examples/flow_classify/Makefile\n@@ -0,0 +1,57 @@\n+#   BSD LICENSE\n+#\n+#   Copyright(c) 2017 Intel Corporation. All rights reserved.\n+#   All rights reserved.\n+#\n+#   Redistribution and use in source and binary forms, with or without\n+#   modification, are permitted provided that the following conditions\n+#   are met:\n+#\n+#     * Redistributions of source code must retain the above copyright\n+#       notice, this list of conditions and the following disclaimer.\n+#     * Redistributions in binary form must reproduce the above copyright\n+#       notice, this list of conditions and the following disclaimer in\n+#       the documentation and/or other materials provided with the\n+#       distribution.\n+#     * Neither the name of Intel Corporation nor the names of its\n+#       contributors may be used to endorse or promote products derived\n+#       from this software without specific prior written permission.\n+#\n+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+#   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+ifeq ($(RTE_SDK),)\n+$(error \"Please define RTE_SDK environment variable\")\n+endif\n+\n+# Default target, can be overridden by command line or environment\n+RTE_TARGET ?= x86_64-native-linuxapp-gcc\n+\n+include $(RTE_SDK)/mk/rte.vars.mk\n+\n+# binary name\n+APP = flow_classify\n+\n+\n+# all source are stored in SRCS-y\n+SRCS-y := flow_classify.c\n+\n+CFLAGS += -O3\n+CFLAGS += $(WERROR_FLAGS)\n+\n+# workaround for a gcc bug with noreturn attribute\n+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603\n+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)\n+CFLAGS_main.o += -Wno-return-type\n+endif\n+\n+include $(RTE_SDK)/mk/rte.extapp.mk\ndiff --git a/examples/flow_classify/flow_classify.c b/examples/flow_classify/flow_classify.c\nnew file mode 100644\nindex 0000000..cc64e3d\n--- /dev/null\n+++ b/examples/flow_classify/flow_classify.c\n@@ -0,0 +1,634 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdint.h>\n+#include <inttypes.h>\n+#include <rte_eal.h>\n+#include <rte_ethdev.h>\n+#include <rte_cycles.h>\n+#include <rte_lcore.h>\n+#include <rte_mbuf.h>\n+#include <rte_flow.h>\n+#include <rte_flow_classify.h>\n+#include <rte_table_acl.h>\n+\n+#define RX_RING_SIZE 128\n+#define TX_RING_SIZE 512\n+\n+#define NUM_MBUFS 8191\n+#define MBUF_CACHE_SIZE 250\n+#define BURST_SIZE 32\n+#define MAX_NUM_CLASSIFY 5\n+#define FLOW_CLASSIFY_MAX_RULE_NUM 10\n+\n+static const struct rte_eth_conf port_conf_default = {\n+\t.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }\n+};\n+\n+static void *table_acl;\n+\n+/* ACL field definitions for IPv4 5 tuple rule */\n+\n+enum {\n+\tPROTO_FIELD_IPV4,\n+\tSRC_FIELD_IPV4,\n+\tDST_FIELD_IPV4,\n+\tSRCP_FIELD_IPV4,\n+\tDSTP_FIELD_IPV4,\n+\tNUM_FIELDS_IPV4\n+};\n+\n+enum {\n+\tPROTO_INPUT_IPV4,\n+\tSRC_INPUT_IPV4,\n+\tDST_INPUT_IPV4,\n+\tSRCP_DESTP_INPUT_IPV4\n+};\n+\n+static struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = {\n+\t/* first input field - always one byte long. */\n+\t{\n+\t\t.type = RTE_ACL_FIELD_TYPE_BITMASK,\n+\t\t.size = sizeof(uint8_t),\n+\t\t.field_index = PROTO_FIELD_IPV4,\n+\t\t.input_index = PROTO_INPUT_IPV4,\n+\t\t.offset = sizeof(struct ether_hdr) +\n+\t\t\toffsetof(struct ipv4_hdr, next_proto_id),\n+\t},\n+\t/* next input field (IPv4 source address) - 4 consecutive bytes. */\n+\t{\n+\t\t/* rte_flow uses a bit mask for IPv4 addresses */\n+\t\t.type = RTE_ACL_FIELD_TYPE_BITMASK,\n+\t\t.size = sizeof(uint32_t),\n+\t\t.field_index = SRC_FIELD_IPV4,\n+\t\t.input_index = SRC_INPUT_IPV4,\n+\t\t.offset = sizeof(struct ether_hdr) +\n+\t\t\toffsetof(struct ipv4_hdr, src_addr),\n+\t},\n+\t/* next input field (IPv4 destination address) - 4 consecutive bytes. */\n+\t{\n+\t\t/* rte_flow uses a bit mask for IPv4 addresses */\n+\t\t.type = RTE_ACL_FIELD_TYPE_BITMASK,\n+\t\t.size = sizeof(uint32_t),\n+\t\t.field_index = DST_FIELD_IPV4,\n+\t\t.input_index = DST_INPUT_IPV4,\n+\t\t.offset = sizeof(struct ether_hdr) +\n+\t\t\toffsetof(struct ipv4_hdr, dst_addr),\n+\t},\n+\t/*\n+\t * Next 2 fields (src & dst ports) form 4 consecutive bytes.\n+\t * They share the same input index.\n+\t */\n+\t{\n+\t\t/* rte_flow uses a bit mask for protocol ports */\n+\t\t.type = RTE_ACL_FIELD_TYPE_BITMASK,\n+\t\t.size = sizeof(uint16_t),\n+\t\t.field_index = SRCP_FIELD_IPV4,\n+\t\t.input_index = SRCP_DESTP_INPUT_IPV4,\n+\t\t.offset = sizeof(struct ether_hdr) +\n+\t\t\tsizeof(struct ipv4_hdr) +\n+\t\t\toffsetof(struct tcp_hdr, src_port),\n+\t},\n+\t{\n+\t\t/* rte_flow uses a bit mask for protocol ports */\n+\t\t.type = RTE_ACL_FIELD_TYPE_BITMASK,\n+\t\t.size = sizeof(uint16_t),\n+\t\t.field_index = DSTP_FIELD_IPV4,\n+\t\t.input_index = SRCP_DESTP_INPUT_IPV4,\n+\t\t.offset = sizeof(struct ether_hdr) +\n+\t\t\tsizeof(struct ipv4_hdr) +\n+\t\t\toffsetof(struct tcp_hdr, dst_port),\n+\t},\n+};\n+\n+/* flow classify data */\n+static struct rte_flow_classify *udp_flow_classify[MAX_NUM_CLASSIFY];\n+static struct rte_flow_classify *tcp_flow_classify[MAX_NUM_CLASSIFY];\n+static struct rte_flow_classify *sctp_flow_classify[MAX_NUM_CLASSIFY];\n+\n+static struct rte_flow_classify_5tuple_stats udp_ntuple_stats;\n+static struct rte_flow_classify_stats udp_classify_stats = {\n+\t\t.available_space = BURST_SIZE,\n+\t\t.used_space = 0,\n+\t\t.stats = (void **)&udp_ntuple_stats\n+};\n+\n+static struct rte_flow_classify_5tuple_stats tcp_ntuple_stats;\n+static struct rte_flow_classify_stats tcp_classify_stats = {\n+\t\t.available_space = BURST_SIZE,\n+\t\t.used_space = 0,\n+\t\t.stats = (void **)&tcp_ntuple_stats\n+};\n+\n+static struct rte_flow_classify_5tuple_stats sctp_ntuple_stats;\n+static struct rte_flow_classify_stats sctp_classify_stats = {\n+\t\t.available_space = BURST_SIZE,\n+\t\t.used_space = 0,\n+\t\t.stats = (void **)&sctp_ntuple_stats\n+};\n+\n+/* parameters for rte_flow_classify_validate and rte_flow_classify_create */\n+\n+/* first sample UDP pattern:\n+ * \"eth / ipv4 src spec 2.2.2.3 src mask 255.255.255.00 dst spec 2.2.2.7\n+ *  dst mask 255.255.255.00 / udp src is 32 dst is 33 / end\"\n+ */\n+static struct rte_flow_item_ipv4 ipv4_udp_spec_1 = {\n+\t{ 0, 0, 0, 0, 0, 0, 17, 0, IPv4(2, 2, 2, 3), IPv4(2, 2, 2, 7)}\n+};\n+static const struct rte_flow_item_ipv4 ipv4_mask_24 = {\n+\t.hdr = {\n+\t\t.next_proto_id = 0xff,\n+\t\t.src_addr = 0xffffff00,\n+\t\t.dst_addr = 0xffffff00,\n+\t},\n+};\n+static struct rte_flow_item_udp udp_spec_1 = {\n+\t{ 32, 33, 0, 0 }\n+};\n+\n+static struct rte_flow_item  eth_item = { RTE_FLOW_ITEM_TYPE_ETH,\n+\t0, 0, 0 };\n+static struct rte_flow_item  ipv4_udp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,\n+\t&ipv4_udp_spec_1, 0, &ipv4_mask_24};\n+static struct rte_flow_item  udp_item_1 = { RTE_FLOW_ITEM_TYPE_UDP,\n+\t&udp_spec_1, 0, &rte_flow_item_udp_mask};\n+static struct rte_flow_item  end_item = { RTE_FLOW_ITEM_TYPE_END,\n+\t0, 0, 0 };\n+static struct rte_flow_item  pattern_udp_1[4];\n+\n+/* second sample UDP pattern:\n+ * \"eth / ipv4 src is 9.9.9.3 dst is 9.9.9.7 / udp src is 32 dst is 33 / end\"\n+ */\n+static struct rte_flow_item_ipv4 ipv4_udp_spec_2 = {\n+\t{ 0, 0, 0, 0, 0, 0, 17, 0, IPv4(9, 9, 9, 3), IPv4(9, 9, 9, 7)}\n+};\n+static struct rte_flow_item_udp udp_spec_2 = {\n+\t{ 32, 33, 0, 0 }\n+};\n+\n+static struct rte_flow_item  ipv4_udp_item_2 = { RTE_FLOW_ITEM_TYPE_IPV4,\n+\t&ipv4_udp_spec_2, 0, &rte_flow_item_ipv4_mask};\n+static struct rte_flow_item  udp_item_2 = { RTE_FLOW_ITEM_TYPE_UDP,\n+\t&udp_spec_2, 0, &rte_flow_item_udp_mask};\n+static struct rte_flow_item  pattern_udp_2[4];\n+\n+/* first sample TCP pattern:\n+ * \"eth / ipv4 src spec 9.9.9.3 src mask 255.255.255.0 dst spec 9.9.9.7 dst\n+ * mask 255.255.255.0/ tcp src is 32 dst is 33 / end\"\n+ */\n+static struct rte_flow_item_ipv4 ipv4_tcp_spec_1 = {\n+\t{ 0, 0, 0, 0, 0, 0, 6, 0, IPv4(9, 9, 9, 3), IPv4(9, 9, 9, 7)}\n+};\n+static struct rte_flow_item_tcp tcp_spec_1 = {\n+\t{ 32, 33, 0, 0, 0, 0, 0, 0, 0 }\n+};\n+\n+static struct rte_flow_item  ipv4_tcp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,\n+\t&ipv4_tcp_spec_1, 0, &ipv4_mask_24};\n+static struct rte_flow_item  tcp_item_1 = { RTE_FLOW_ITEM_TYPE_TCP,\n+\t&tcp_spec_1, 0, &rte_flow_item_tcp_mask};\n+\n+static struct rte_flow_item  pattern_tcp_1[4];\n+\n+/* second sample TCP pattern:\n+ * \"eth / ipv4 src is 9.9.8.3 dst is 9.9.8.7 / tcp src is 32 dst is 33 / end\"\n+ */\n+static struct rte_flow_item_ipv4 ipv4_tcp_spec_2 = {\n+\t{ 0, 0, 0, 0, 0, 0, 6, 0, IPv4(9, 9, 8, 3), IPv4(9, 9, 8, 7)}\n+};\n+static struct rte_flow_item_tcp tcp_spec_2 = {\n+\t{ 32, 33, 0, 0, 0, 0, 0, 0, 0 }\n+};\n+\n+static struct rte_flow_item  ipv4_tcp_item_2 = { RTE_FLOW_ITEM_TYPE_IPV4,\n+\t&ipv4_tcp_spec_2, 0, &rte_flow_item_ipv4_mask};\n+static struct rte_flow_item  tcp_item_2 = { RTE_FLOW_ITEM_TYPE_TCP,\n+\t&tcp_spec_2, 0, &rte_flow_item_tcp_mask};\n+\n+static struct rte_flow_item  pattern_tcp_2[4];\n+\n+/* first sample SCTP pattern:\n+ * \"eth / ipv4 src is 6.7.8.9 dst is 2.3.4.5 / sctp src is 32 dst is 33 / end\"\n+ */\n+static struct rte_flow_item_ipv4 ipv4_sctp_spec_1 = {\n+\t{ 0, 0, 0, 0, 0, 0, 132, 0, IPv4(6, 7, 8, 9), IPv4(2, 3, 4, 5)}\n+};\n+static struct rte_flow_item_sctp sctp_spec_1 = {\n+\t{ 32, 33, 0, 0 }\n+};\n+\n+static struct rte_flow_item  ipv4_sctp_item_1 = { RTE_FLOW_ITEM_TYPE_IPV4,\n+\t&ipv4_sctp_spec_1, 0, &rte_flow_item_ipv4_mask};\n+static struct rte_flow_item  sctp_item_1 = { RTE_FLOW_ITEM_TYPE_SCTP,\n+\t&sctp_spec_1, 0, &rte_flow_item_sctp_mask};\n+\n+static struct rte_flow_item  pattern_sctp_1[4];\n+\n+\n+/* sample actions:\n+ * \"actions count / end\"\n+ */\n+static struct rte_flow_action count_action = { RTE_FLOW_ACTION_TYPE_COUNT, 0};\n+static struct rte_flow_action end_action = { RTE_FLOW_ACTION_TYPE_END, 0};\n+static struct rte_flow_action actions[2];\n+\n+/* sample attributes */\n+static struct rte_flow_attr attr;\n+\n+/* flow_classify.c:\n+ * Based on DPDK skeleton forwarding example.\n+ */\n+\n+/*\n+ * Initializes a given port using global settings and with the RX buffers\n+ * coming from the mbuf_pool passed as a parameter.\n+ */\n+static inline int\n+port_init(uint8_t port, struct rte_mempool *mbuf_pool)\n+{\n+\tstruct rte_eth_conf port_conf = port_conf_default;\n+\tstruct ether_addr addr;\n+\tconst uint16_t rx_rings = 1, tx_rings = 1;\n+\tint retval;\n+\tuint16_t q;\n+\n+\tif (port >= rte_eth_dev_count())\n+\t\treturn -1;\n+\n+\t/* Configure the Ethernet device. */\n+\tretval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);\n+\tif (retval != 0)\n+\t\treturn retval;\n+\n+\t/* Allocate and set up 1 RX queue per Ethernet port. */\n+\tfor (q = 0; q < rx_rings; q++) {\n+\t\tretval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), NULL, mbuf_pool);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Allocate and set up 1 TX queue per Ethernet port. */\n+\tfor (q = 0; q < tx_rings; q++) {\n+\t\tretval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE,\n+\t\t\t\trte_eth_dev_socket_id(port), NULL);\n+\t\tif (retval < 0)\n+\t\t\treturn retval;\n+\t}\n+\n+\t/* Start the Ethernet port. */\n+\tretval = rte_eth_dev_start(port);\n+\tif (retval < 0)\n+\t\treturn retval;\n+\n+\t/* Display the port MAC address. */\n+\trte_eth_macaddr_get(port, &addr);\n+\tprintf(\"Port %u MAC: %02\" PRIx8 \" %02\" PRIx8 \" %02\" PRIx8\n+\t\t\t   \" %02\" PRIx8 \" %02\" PRIx8 \" %02\" PRIx8 \"\\n\",\n+\t\t\tport,\n+\t\t\taddr.addr_bytes[0], addr.addr_bytes[1],\n+\t\t\taddr.addr_bytes[2], addr.addr_bytes[3],\n+\t\t\taddr.addr_bytes[4], addr.addr_bytes[5]);\n+\n+\t/* Enable RX in promiscuous mode for the Ethernet device. */\n+\trte_eth_promiscuous_enable(port);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * The lcore main. This is the main thread that does the work, reading from\n+ * an input port classifying the packets and writing to an output port.\n+ */\n+static __attribute__((noreturn)) void\n+lcore_main(void)\n+{\n+\tstruct rte_flow_error error;\n+\tconst uint8_t nb_ports = rte_eth_dev_count();\n+\tuint8_t port;\n+\tint ret;\n+\tint i;\n+\n+\t/*\n+\t * Check that the port is on the same NUMA node as the polling thread\n+\t * for best performance.\n+\t */\n+\tfor (port = 0; port < nb_ports; port++)\n+\t\tif (rte_eth_dev_socket_id(port) > 0 &&\n+\t\t\t\trte_eth_dev_socket_id(port) !=\n+\t\t\t\t\t\t(int)rte_socket_id())\n+\t\t\tprintf(\"\\n\\n\");\n+\t\t\tprintf(\"WARNING: port %u is on remote NUMA node\\n\",\n+\t\t\t       port);\n+\t\t\tprintf(\"to polling thread.\\n\");\n+\t\t\tprintf(\"Performance will not be optimal.\\n\");\n+\n+\tprintf(\"\\nCore %u forwarding packets. [Ctrl+C to quit]\\n\",\n+\t\t\trte_lcore_id());\n+\n+\t/* Run until the application is quit or killed. */\n+\tfor (;;) {\n+\t\t/*\n+\t\t * Receive packets on a port, classify them and forward them\n+\t\t * on the paired port.\n+\t\t * The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.\n+\t\t */\n+\t\tfor (port = 0; port < nb_ports; port++) {\n+\n+\t\t\t/* Get burst of RX packets, from first port of pair. */\n+\t\t\tstruct rte_mbuf *bufs[BURST_SIZE];\n+\t\t\tconst uint16_t nb_rx = rte_eth_rx_burst(port, 0,\n+\t\t\t\t\tbufs, BURST_SIZE);\n+\n+\t\t\tif (unlikely(nb_rx == 0))\n+\t\t\t\tcontinue;\n+\n+\t\t\tfor (i = 0; i < MAX_NUM_CLASSIFY; i++) {\n+\t\t\t\tif (udp_flow_classify[i]) {\n+\t\t\t\t\tret = rte_flow_classify_query(\n+\t\t\t\t\t\ttable_acl,\n+\t\t\t\t\t\tudp_flow_classify[i],\n+\t\t\t\t\t\tbufs, nb_rx,\n+\t\t\t\t\t\t&udp_classify_stats, &error);\n+\t\t\t\t\tif (ret)\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"udp flow classify[%d] query failed port=%u\\n\\n\",\n+\t\t\t\t\t\ti, port);\n+\t\t\t\t\telse\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"udp rule [%d] counter1=%lu used_space=%d\\n\\n\",\n+\t\t\t\t\t\ti, udp_ntuple_stats.counter1,\n+\t\t\t\t\t\tudp_classify_stats.used_space);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tfor (i = 0; i < MAX_NUM_CLASSIFY; i++) {\n+\t\t\t\tif (tcp_flow_classify[i]) {\n+\t\t\t\t\tret = rte_flow_classify_query(\n+\t\t\t\t\t\ttable_acl,\n+\t\t\t\t\t\ttcp_flow_classify[i],\n+\t\t\t\t\t\tbufs, nb_rx,\n+\t\t\t\t\t\t&tcp_classify_stats, &error);\n+\t\t\t\t\tif (ret)\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"tcp flow classify[%d] query failed port=%u\\n\\n\",\n+\t\t\t\t\t\ti, port);\n+\t\t\t\t\telse\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"tcp rule [%d] counter1=%lu used_space=%d\\n\\n\",\n+\t\t\t\t\t\ti, tcp_ntuple_stats.counter1,\n+\t\t\t\t\t\ttcp_classify_stats.used_space);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tfor (i = 0; i < MAX_NUM_CLASSIFY; i++) {\n+\t\t\t\tif (sctp_flow_classify[i]) {\n+\t\t\t\t\tret = rte_flow_classify_query(\n+\t\t\t\t\t\ttable_acl,\n+\t\t\t\t\t\tsctp_flow_classify[i],\n+\t\t\t\t\t\tbufs, nb_rx,\n+\t\t\t\t\t\t&sctp_classify_stats, &error);\n+\t\t\t\t\tif (ret)\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"sctp flow classify[%d] query failed port=%u\\n\\n\",\n+\t\t\t\t\t\ti, port);\n+\t\t\t\t\telse\n+\t\t\t\t\t\tprintf(\n+\t\t\t\t\t\t\"sctp rule [%d] counter1=%lu used_space=%d\\n\\n\",\n+\t\t\t\t\t\ti, sctp_ntuple_stats.counter1,\n+\t\t\t\t\t\tsctp_classify_stats.used_space);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* Send burst of TX packets, to second port of pair. */\n+\t\t\tconst uint16_t nb_tx = rte_eth_tx_burst(port ^ 1, 0,\n+\t\t\t\t\tbufs, nb_rx);\n+\n+\t\t\t/* Free any unsent packets. */\n+\t\t\tif (unlikely(nb_tx < nb_rx)) {\n+\t\t\t\tuint16_t buf;\n+\n+\t\t\t\tfor (buf = nb_tx; buf < nb_rx; buf++)\n+\t\t\t\t\trte_pktmbuf_free(bufs[buf]);\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * The main function, which does initialization and calls the per-lcore\n+ * functions.\n+ */\n+int\n+main(int argc, char *argv[])\n+{\n+\tstruct rte_mempool *mbuf_pool;\n+\tstruct rte_flow_error error;\n+\tuint8_t nb_ports;\n+\tuint8_t portid;\n+\tint ret;\n+\tint udp_num_classify = 0;\n+\tint tcp_num_classify = 0;\n+\tint sctp_num_classify = 0;\n+\tint socket_id;\n+\tstruct rte_table_acl_params table_acl_params;\n+\tuint32_t entry_size;\n+\n+\t/* Initialize the Environment Abstraction Layer (EAL). */\n+\tret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Error with EAL initialization\\n\");\n+\n+\targc -= ret;\n+\targv += ret;\n+\n+\t/* Check that there is an even number of ports to send/receive on. */\n+\tnb_ports = rte_eth_dev_count();\n+\tif (nb_ports < 2 || (nb_ports & 1))\n+\t\trte_exit(EXIT_FAILURE, \"Error: number of ports must be even\\n\");\n+\n+\t/* Creates a new mempool in memory to hold the mbufs. */\n+\tmbuf_pool = rte_pktmbuf_pool_create(\"MBUF_POOL\", NUM_MBUFS * nb_ports,\n+\t\tMBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());\n+\n+\tif (mbuf_pool == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Cannot create mbuf pool\\n\");\n+\n+\t/* Initialize all ports. */\n+\tfor (portid = 0; portid < nb_ports; portid++)\n+\t\tif (port_init(portid, mbuf_pool) != 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Cannot init port %\"PRIu8 \"\\n\",\n+\t\t\t\t\tportid);\n+\n+\tif (rte_lcore_count() > 1)\n+\t\tprintf(\"\\nWARNING: Too many lcores enabled. Only 1 used.\\n\");\n+\n+\tsocket_id = rte_eth_dev_socket_id(0);\n+\n+\t/* initialise ACL table params */\n+\ttable_acl_params.n_rule_fields = RTE_DIM(ipv4_defs);\n+\ttable_acl_params.name = \"table_acl_ipv4_5tuple\";\n+\ttable_acl_params.n_rules = FLOW_CLASSIFY_MAX_RULE_NUM;\n+\tmemcpy(table_acl_params.field_format, ipv4_defs, sizeof(ipv4_defs));\n+\tentry_size = RTE_ACL_RULE_SZ(RTE_DIM(ipv4_defs));\n+\n+\ttable_acl = rte_table_acl_ops.f_create(&table_acl_params, socket_id,\n+\t\t\t\t\t\tentry_size);\n+\tif (table_acl == NULL)\n+\t\treturn -1;\n+\n+\t/* set up parameters for rte_flow_classify_validate and\n+\t * rte_flow_classify_create\n+\t */\n+\n+\tattr.ingress = 1;\n+\tattr.priority = 1;\n+\tpattern_udp_1[0] = eth_item;\n+\tpattern_udp_1[1] = ipv4_udp_item_1;\n+\tpattern_udp_1[2] = udp_item_1;\n+\tpattern_udp_1[3] = end_item;\n+\tactions[0] = count_action;\n+\tactions[1] = end_action;\n+\n+\tret = rte_flow_classify_validate(table_acl, &attr,\n+\t\t\tpattern_udp_1, actions, &error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE, \"udp_1 flow classify validate failed\\n\");\n+\n+\tudp_flow_classify[udp_num_classify] = rte_flow_classify_create(\n+\t\t\ttable_acl, entry_size, &attr, pattern_udp_1, actions,\n+\t\t\t&error);\n+\tif (udp_flow_classify[udp_num_classify] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"udp_1 flow classify create failed\\n\");\n+\tudp_num_classify++;\n+\n+\tattr.ingress = 1;\n+\tattr.priority = 2;\n+\tpattern_udp_2[0] = eth_item;\n+\tpattern_udp_2[1] = ipv4_udp_item_2;\n+\tpattern_udp_2[2] = udp_item_2;\n+\tpattern_udp_2[3] = end_item;\n+\tactions[0] = count_action;\n+\tactions[1] = end_action;\n+\n+\tret = rte_flow_classify_validate(table_acl, &attr, pattern_udp_2,\n+\t\t\tactions, &error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE, \"udp_2 flow classify validate failed\\n\");\n+\n+\tudp_flow_classify[udp_num_classify] = rte_flow_classify_create(\n+\t\t\ttable_acl, entry_size, &attr, pattern_udp_2, actions,\n+\t\t\t&error);\n+\tif (udp_flow_classify[udp_num_classify] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"udp_2 flow classify create failed\\n\");\n+\tudp_num_classify++;\n+\n+\tattr.ingress = 1;\n+\tattr.priority = 3;\n+\tpattern_tcp_1[0] = eth_item;\n+\tpattern_tcp_1[1] = ipv4_tcp_item_1;\n+\tpattern_tcp_1[2] = tcp_item_1;\n+\tpattern_tcp_1[3] = end_item;\n+\tactions[0] = count_action;\n+\tactions[1] = end_action;\n+\n+\tret = rte_flow_classify_validate(table_acl, &attr, pattern_tcp_1,\n+\t\t\tactions, &error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE, \"tcp_1 flow classify validate failed\\n\");\n+\n+\ttcp_flow_classify[tcp_num_classify] = rte_flow_classify_create(\n+\t\t\ttable_acl, entry_size, &attr, pattern_tcp_1, actions,\n+\t\t\t&error);\n+\tif (tcp_flow_classify[tcp_num_classify] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"tcp_1 flow classify create failed\\n\");\n+\ttcp_num_classify++;\n+\n+\tattr.ingress = 1;\n+\tattr.priority = 4;\n+\tpattern_tcp_2[0] = eth_item;\n+\tpattern_tcp_2[1] = ipv4_tcp_item_2;\n+\tpattern_tcp_2[2] = tcp_item_2;\n+\tpattern_tcp_2[3] = end_item;\n+\tactions[0] = count_action;\n+\tactions[1] = end_action;\n+\n+\tret = rte_flow_classify_validate(table_acl, &attr, pattern_tcp_2,\n+\t\t\tactions, &error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE, \"tcp_2 flow classify validate failed\\n\");\n+\n+\ttcp_flow_classify[tcp_num_classify] = rte_flow_classify_create(\n+\t\t\ttable_acl, entry_size, &attr, pattern_tcp_2, actions,\n+\t\t\t&error);\n+\tif (tcp_flow_classify[tcp_num_classify] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"tcp_2 flow classify create failed\\n\");\n+\ttcp_num_classify++;\n+\n+\tattr.ingress = 1;\n+\tattr.priority = 5;\n+\tpattern_sctp_1[0] = eth_item;\n+\tpattern_sctp_1[1] = ipv4_sctp_item_1;\n+\tpattern_sctp_1[2] = sctp_item_1;\n+\tpattern_sctp_1[3] = end_item;\n+\tactions[0] = count_action;\n+\tactions[1] = end_action;\n+\n+\tret = rte_flow_classify_validate(table_acl, &attr, pattern_sctp_1,\n+\t\t\tactions, &error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t\"sctp_1 flow classify validate failed\\n\");\n+\n+\tsctp_flow_classify[sctp_num_classify] = rte_flow_classify_create(\n+\t\ttable_acl, entry_size, &attr, pattern_sctp_1, actions,\n+\t\t&error);\n+\tif (sctp_flow_classify[sctp_num_classify] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"sctp_1 flow classify create failed\\n\");\n+\tsctp_num_classify++;\n+\n+\tret = rte_flow_classify_destroy(table_acl, sctp_flow_classify[0],\n+\t\t\t&error);\n+\tif (ret)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t\"sctp_1 flow classify destroy failed\\n\");\n+\telse {\n+\t\tsctp_num_classify--;\n+\t\tsctp_flow_classify[0] = NULL;\n+\t}\n+\t/* Call lcore_main on the master core only. */\n+\tlcore_main();\n+\n+\treturn 0;\n+}\n",
    "prefixes": [
        "dpdk-dev",
        "v2",
        "5/6"
    ]
}