get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 7327,
    "url": "https://patches.dpdk.org/api/patches/7327/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1443623388-29104-4-git-send-email-ian.betts@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": "<1443623388-29104-4-git-send-email-ian.betts@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1443623388-29104-4-git-send-email-ian.betts@intel.com",
    "date": "2015-09-30T14:29:46",
    "name": "[dpdk-dev,v1,3/5] examples: add l3fwd-thread in performance-thread sample app",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "95db40ffd348ee9f9e6ad1028120e89bd6b99263",
    "submitter": {
        "id": 340,
        "url": "https://patches.dpdk.org/api/people/340/?format=api",
        "name": "ibetts",
        "email": "ian.betts@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1443623388-29104-4-git-send-email-ian.betts@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/7327/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/7327/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 1231D8E81;\n\tWed, 30 Sep 2015 16:30:16 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id AEB548DAD\n\tfor <dev@dpdk.org>; Wed, 30 Sep 2015 16:30:09 +0200 (CEST)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby fmsmga103.fm.intel.com with ESMTP; 30 Sep 2015 07:29:55 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga001.fm.intel.com with ESMTP; 30 Sep 2015 07:29:54 -0700",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tt8UETrFS003361; Wed, 30 Sep 2015 15:29:53 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id t8UETrXm029222;\n\tWed, 30 Sep 2015 15:29:53 +0100",
            "(from ibetts@localhost)\n\tby sivswdev01.ir.intel.com with  id t8UETrcp029218;\n\tWed, 30 Sep 2015 15:29:53 +0100"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.17,612,1437462000\"; d=\"scan'208\";a=\"800564743\"",
        "From": "ibetts <ian.betts@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Wed, 30 Sep 2015 15:29:46 +0100",
        "Message-Id": "<1443623388-29104-4-git-send-email-ian.betts@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1443623388-29104-1-git-send-email-ian.betts@intel.com>",
        "References": "<1443623388-29104-1-git-send-email-ian.betts@intel.com>",
        "Cc": "Ian Betts <ian.betts@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v1 3/5] examples: add l3fwd-thread in\n\tperformance-thread sample app",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <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": "From: Ian Betts <ian.betts@intel.com>\n\nThis commit adds an l3fwd derivative that allows multiple\nEAL threads to be run on a single physical core or multiple\nlightwieght threads to be run in an EAL thread.\n\nIts purpose is to facilitate characterization of performance\nwith different threading models.\n\nIt depends on a simple cooperative scheduler included in\nthis patchset.\n\nSigned-off-by: Ian Betts <ian.betts@intel.com>\n---\n examples/performance-thread/l3fwd-thread/Makefile |   57 +\n examples/performance-thread/l3fwd-thread/main.c   | 3355 +++++++++++++++++++++\n 2 files changed, 3412 insertions(+)\n create mode 100644 examples/performance-thread/l3fwd-thread/Makefile\n create mode 100644 examples/performance-thread/l3fwd-thread/main.c",
    "diff": "diff --git a/examples/performance-thread/l3fwd-thread/Makefile b/examples/performance-thread/l3fwd-thread/Makefile\nnew file mode 100644\nindex 0000000..d8fe5e6\n--- /dev/null\n+++ b/examples/performance-thread/l3fwd-thread/Makefile\n@@ -0,0 +1,57 @@\n+#   BSD LICENSE\n+#\n+#   Copyright(c) 2010-2015 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 = l3fwd-thread\n+\n+# all source are stored in SRCS-y\n+SRCS-y := main.c\n+\n+include $(RTE_SDK)/examples/performance-thread/common/common.mk\n+\n+CFLAGS += -O3 -g $(USER_FLAGS) $(INCLUDES) $(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/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c\nnew file mode 100644\nindex 0000000..2708ec6\n--- /dev/null\n+++ b/examples/performance-thread/l3fwd-thread/main.c\n@@ -0,0 +1,3355 @@\n+/*\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2015 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 <stdio.h>\n+#include <stdlib.h>\n+#include <stdint.h>\n+#include <inttypes.h>\n+#include <sys/types.h>\n+#include <string.h>\n+#include <sys/queue.h>\n+#include <stdarg.h>\n+#include <errno.h>\n+#include <getopt.h>\n+\n+#include <rte_common.h>\n+#include <rte_vect.h>\n+#include <rte_byteorder.h>\n+#include <rte_log.h>\n+#include <rte_memory.h>\n+#include <rte_memcpy.h>\n+#include <rte_memzone.h>\n+#include <rte_eal.h>\n+#include <rte_per_lcore.h>\n+#include <rte_launch.h>\n+#include <rte_atomic.h>\n+#include <rte_cycles.h>\n+#include <rte_prefetch.h>\n+#include <rte_lcore.h>\n+#include <rte_branch_prediction.h>\n+#include <rte_interrupts.h>\n+#include <rte_pci.h>\n+#include <rte_random.h>\n+#include <rte_debug.h>\n+#include <rte_ether.h>\n+#include <rte_ethdev.h>\n+#include <rte_ring.h>\n+#include <rte_mempool.h>\n+#include <rte_mbuf.h>\n+#include <rte_ip.h>\n+#include <rte_tcp.h>\n+#include <rte_udp.h>\n+#include <rte_string_fns.h>\n+#include <lthread_api.h>\n+\n+#include <cmdline_parse.h>\n+#include <cmdline_parse_etheraddr.h>\n+\n+#define APP_LOOKUP_EXACT_MATCH          0\n+#define APP_LOOKUP_LPM                  1\n+#define DO_RFC_1812_CHECKS\n+\n+#ifndef APP_LOOKUP_METHOD\n+#define APP_LOOKUP_METHOD             APP_LOOKUP_LPM\n+#endif\n+\n+/*\n+ *  When set to zero, simple forwarding path is enabled.\n+ *  When set to one, optimized forwarding path is enabled.\n+ *  Note that LPM optimization path uses SSE4.1 instructions.\n+ */\n+#if ((APP_LOOKUP_METHOD == APP_LOOKUP_LPM) && !defined(__SSE4_1__))\n+#define ENABLE_MULTI_BUFFER_OPTIMIZE\t0\n+#else\n+#define ENABLE_MULTI_BUFFER_OPTIMIZE\t1\n+#endif\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+#include <rte_hash.h>\n+#elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+#include <rte_lpm.h>\n+#include <rte_lpm6.h>\n+#else\n+#error \"APP_LOOKUP_METHOD set to incorrect value\"\n+#endif\n+\n+#ifndef IPv6_BYTES\n+#define IPv6_BYTES_FMT \"%02x%02x:%02x%02x:%02x%02x:%02x%02x:\"\\\n+\t\t\"%02x%02x:%02x%02x:%02x%02x:%02x%02x\"\n+#define IPv6_BYTES(addr) \\\n+\t\taddr[0], addr[1], addr[2], addr[3], \\\n+\t\taddr[4], addr[5], addr[6], addr[7], \\\n+\t\taddr[8], addr[9], addr[10], addr[11],\\\n+\t\taddr[12], addr[13], addr[14], addr[15]\n+#endif\n+\n+#define RTE_LOGTYPE_L3FWD RTE_LOGTYPE_USER1\n+#define MAX_JUMBO_PKT_LEN  9600\n+#define IPV6_ADDR_LEN 16\n+#define MEMPOOL_CACHE_SIZE 256\n+\n+/*\n+ * This expression is used to calculate the number of mbufs needed depending on\n+ * user input, taking into account memory for rx and tx hardware rings, cache\n+ * per lcore and mtable per port per lcore.\n+ * RTE_MAX is used to ensure that NB_MBUF never goes below a minimum value\n+ * of 8192\n+ */\n+\n+#define NB_MBUF RTE_MAX(                                     \\\n+\t\t(nb_ports * nb_rx_queue * RTE_TEST_RX_DESC_DEFAULT + \\\n+\t\tnb_ports * nb_lcores * MAX_PKT_BURST +               \\\n+\t\tnb_ports * n_tx_queue * RTE_TEST_TX_DESC_DEFAULT +   \\\n+\t\tnb_lcores * MEMPOOL_CACHE_SIZE),                     \\\n+\t\t(unsigned)8192)\n+\n+#define MAX_PKT_BURST      1024\n+#define BURST_TX_DRAIN_NS  100000 /* TX drain every ~100000ns */\n+\n+/*\n+ * Try to avoid TX buffering if we have at least MAX_TX_BURST packets to send.\n+ */\n+#define\tMAX_TX_BURST\t(MAX_PKT_BURST / 2)\n+\n+#define BURST_SIZE 512\n+\n+#define NB_SOCKETS 8\n+\n+/* Configure how many packets ahead to prefetch, when reading packets */\n+#define PREFETCH_OFFSET\t3\n+\n+/* Used to mark destination port as 'invalid'. */\n+#define\tBAD_PORT\t((uint16_t)-1)\n+\n+#define FWDSTEP\t4\n+\n+/*\n+ * Configurable number of RX/TX ring descriptors\n+ */\n+#define RTE_TEST_RX_DESC_DEFAULT 128\n+#define RTE_TEST_TX_DESC_DEFAULT 512\n+static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;\n+static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;\n+\n+/* ethernet addresses of ports */\n+static uint64_t dest_eth_addr[RTE_MAX_ETHPORTS];\n+static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];\n+\n+static __m128i val_eth[RTE_MAX_ETHPORTS];\n+\n+/* replace first 12B of the ethernet header. */\n+#define\tMASK_ETH\t0x3f\n+\n+/* mask of enabled ports */\n+static uint32_t enabled_port_mask;\n+static int promiscuous_on; /**< Ports set in promiscuous mode off by default. */\n+static int numa_on = 1; /**< NUMA is enabled by default. */\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+static int ipv6; /**< ipv6 is false by default. */\n+#endif\n+\n+struct mbuf_table {\n+\tuint16_t len;\n+\tstruct rte_mbuf *m_table[MAX_PKT_BURST];\n+};\n+\n+struct thread_rx_queue {\n+\tuint8_t port_id;\n+\tuint8_t queue_id;\n+} __rte_cache_aligned;\n+\n+#define MAX_RX_QUEUE_PER_THREAD 16\n+#define MAX_TX_PORT_PER_THREAD RTE_MAX_ETHPORTS\n+#define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS\n+#define MAX_RX_QUEUE_PER_PORT 128\n+\n+#define MAX_THREAD_PARAMS 1024\n+\n+/**\n+ * Rx params\n+ */\n+struct thread_rx_params {\n+\tuint8_t port_id;\n+\tuint8_t queue_id;\n+\tuint8_t lcore_id;\n+\tuint8_t thread_id;\n+} __rte_cache_aligned;\n+\n+static struct thread_rx_params thread_rx_params_array[MAX_THREAD_PARAMS];\n+static struct thread_rx_params thread_rx_params_array_default[] = {\n+\t{0, 0, 0, 0},\n+\t{1, 0, 1, 1},\n+};\n+\n+static struct thread_rx_params *thread_rx_params =\n+\t\tthread_rx_params_array_default;\n+static uint16_t nb_thread_rx_params = RTE_DIM(thread_rx_params_array_default);\n+\n+/**\n+ * Tx params\n+ */\n+struct thread_tx_params {\n+\tuint8_t port_id;    /**< Default port */\n+\tuint8_t lcore_id;   /**< Initial lcore */\n+\tuint8_t thread_id; /**< Tx thread index */\n+} __rte_cache_aligned;\n+\n+static struct thread_tx_params thread_tx_params_array[MAX_THREAD_PARAMS];\n+static struct thread_tx_params thread_tx_params_array_default[] = {\n+\t{0, 2, 0},\n+\t{1, 3, 1},\n+\t{0, 4, 2},\n+\t{1, 5, 3},\n+\t{0, 6, 4},\n+\t{1, 7, 5},\n+};\n+\n+static struct thread_tx_params *thread_tx_params =\n+\t\tthread_tx_params_array_default;\n+static uint16_t nb_thread_tx_params =\n+\t\tRTE_DIM(thread_tx_params_array_default);\n+\n+\n+static struct rte_eth_conf port_conf = {\n+\t.rxmode = {\n+\t\t.mq_mode = ETH_MQ_RX_RSS,\n+\t\t.max_rx_pkt_len = ETHER_MAX_LEN,\n+\t\t.split_hdr_size = 0,\n+\t\t.header_split   = 0, /**< Header Split disabled */\n+\t\t.hw_ip_checksum = 1, /**< IP checksum offload enabled */\n+\t\t.hw_vlan_filter = 0, /**< VLAN filtering disabled */\n+\t\t.jumbo_frame    = 0, /**< Jumbo Frame Support disabled */\n+\t\t.hw_strip_crc   = 0, /**< CRC stripped by hardware */\n+\t},\n+\t.rx_adv_conf = {\n+\t\t.rss_conf = {\n+\t\t\t.rss_key = NULL,\n+\t\t\t.rss_hf = ETH_RSS_IP,\n+\t\t},\n+\t},\n+\t.txmode = {\n+\t\t.mq_mode = ETH_MQ_TX_NONE,\n+\t},\n+};\n+\n+static struct rte_mempool *pktmbuf_pool[NB_SOCKETS];\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\n+#ifdef RTE_MACHINE_CPUFLAG_SSE4_2\n+#include <rte_hash_crc.h>\n+#define DEFAULT_HASH_FUNC       rte_hash_crc\n+#else\n+#include <rte_jhash.h>\n+#define DEFAULT_HASH_FUNC       rte_jhash\n+#endif\n+\n+struct ipv4_5tuple {\n+\tuint32_t ip_dst;\n+\tuint32_t ip_src;\n+\tuint16_t port_dst;\n+\tuint16_t port_src;\n+\tuint8_t  proto;\n+} __attribute__((__packed__));\n+\n+union ipv4_5tuple_host {\n+\tstruct {\n+\t\tuint8_t  pad0;\n+\t\tuint8_t  proto;\n+\t\tuint16_t pad1;\n+\t\tuint32_t ip_src;\n+\t\tuint32_t ip_dst;\n+\t\tuint16_t port_src;\n+\t\tuint16_t port_dst;\n+\t};\n+\t__m128i xmm;\n+};\n+\n+#define XMM_NUM_IN_IPV6_5TUPLE 3\n+\n+struct ipv6_5tuple {\n+\tuint8_t  ip_dst[IPV6_ADDR_LEN];\n+\tuint8_t  ip_src[IPV6_ADDR_LEN];\n+\tuint16_t port_dst;\n+\tuint16_t port_src;\n+\tuint8_t  proto;\n+} __attribute__((__packed__));\n+\n+union ipv6_5tuple_host {\n+\tstruct {\n+\t\tuint16_t pad0;\n+\t\tuint8_t  proto;\n+\t\tuint8_t  pad1;\n+\t\tuint8_t  ip_src[IPV6_ADDR_LEN];\n+\t\tuint8_t  ip_dst[IPV6_ADDR_LEN];\n+\t\tuint16_t port_src;\n+\t\tuint16_t port_dst;\n+\t\tuint64_t reserve;\n+\t};\n+\t__m128i xmm[XMM_NUM_IN_IPV6_5TUPLE];\n+};\n+\n+struct ipv4_l3fwd_route {\n+\tstruct ipv4_5tuple key;\n+\tuint8_t if_out;\n+};\n+\n+struct ipv6_l3fwd_route {\n+\tstruct ipv6_5tuple key;\n+\tuint8_t if_out;\n+};\n+\n+static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {\n+\t{{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1),  101, 11, IPPROTO_TCP}, 0},\n+\t{{IPv4(201, 0, 0, 0), IPv4(200, 20, 0, 1),  102, 12, IPPROTO_TCP}, 1},\n+\t{{IPv4(111, 0, 0, 0), IPv4(100, 30, 0, 1),  101, 11, IPPROTO_TCP}, 2},\n+\t{{IPv4(211, 0, 0, 0), IPv4(200, 40, 0, 1),  102, 12, IPPROTO_TCP}, 3},\n+};\n+\n+static struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {\n+\t{{\n+\t{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},\n+\t{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38,\n+\t\t\t0x05},\n+\t101, 11, IPPROTO_TCP}, 0},\n+\n+\t{{\n+\t{0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},\n+\t{0xfe, 0x90, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38,\n+\t\t\t0x05},\n+\t102, 12, IPPROTO_TCP}, 1},\n+\n+\t{{\n+\t{0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},\n+\t{0xfe, 0xa0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38,\n+\t\t\t0x05},\n+\t101, 11, IPPROTO_TCP}, 2},\n+\n+\t{{\n+\t{0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1e, 0x67, 0xff, 0xfe, 0, 0, 0},\n+\t{0xfe, 0xb0, 0, 0, 0, 0, 0, 0, 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38,\n+\t\t\t0x05},\n+\t102, 12, IPPROTO_TCP}, 3},\n+};\n+\n+typedef struct rte_hash lookup_struct_t;\n+static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];\n+static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];\n+\n+#ifdef RTE_ARCH_X86_64\n+/* default to 4 million hash entries (approx) */\n+#define L3FWD_HASH_ENTRIES\t\t(1024*1024*4)\n+#else\n+/* 32-bit has less address-space for hugepage memory, limit to 1M entries */\n+#define L3FWD_HASH_ENTRIES\t\t(1024*1024*1)\n+#endif\n+#define HASH_ENTRY_NUMBER_DEFAULT\t4\n+\n+static uint32_t hash_entry_number = HASH_ENTRY_NUMBER_DEFAULT;\n+\n+static inline uint32_t\n+ipv4_hash_crc(const void *data, __rte_unused uint32_t data_len,\n+\t\tuint32_t init_val)\n+{\n+\tconst union ipv4_5tuple_host *k;\n+\tuint32_t t;\n+\tconst uint32_t *p;\n+\n+\tk = data;\n+\tt = k->proto;\n+\tp = (const uint32_t *)&k->port_src;\n+\n+#ifdef RTE_MACHINE_CPUFLAG_SSE4_2\n+\tinit_val = rte_hash_crc_4byte(t, init_val);\n+\tinit_val = rte_hash_crc_4byte(k->ip_src, init_val);\n+\tinit_val = rte_hash_crc_4byte(k->ip_dst, init_val);\n+\tinit_val = rte_hash_crc_4byte(*p, init_val);\n+#else /* RTE_MACHINE_CPUFLAG_SSE4_2 */\n+\tinit_val = rte_jhash_1word(t, init_val);\n+\tinit_val = rte_jhash_1word(k->ip_src, init_val);\n+\tinit_val = rte_jhash_1word(k->ip_dst, init_val);\n+\tinit_val = rte_jhash_1word(*p, init_val);\n+#endif /* RTE_MACHINE_CPUFLAG_SSE4_2 */\n+\treturn init_val;\n+}\n+\n+static inline uint32_t\n+ipv6_hash_crc(const void *data, __rte_unused uint32_t data_len,\n+\t\tuint32_t init_val)\n+{\n+\tconst union ipv6_5tuple_host *k;\n+\tuint32_t t;\n+\tconst uint32_t *p;\n+#ifdef RTE_MACHINE_CPUFLAG_SSE4_2\n+\tconst uint32_t  *ip_src0, *ip_src1, *ip_src2, *ip_src3;\n+\tconst uint32_t  *ip_dst0, *ip_dst1, *ip_dst2, *ip_dst3;\n+#endif /* RTE_MACHINE_CPUFLAG_SSE4_2 */\n+\n+\tk = data;\n+\tt = k->proto;\n+\tp = (const uint32_t *)&k->port_src;\n+\n+#ifdef RTE_MACHINE_CPUFLAG_SSE4_2\n+\tip_src0 = (const uint32_t *) k->ip_src;\n+\tip_src1 = (const uint32_t *)(k->ip_src+4);\n+\tip_src2 = (const uint32_t *)(k->ip_src+8);\n+\tip_src3 = (const uint32_t *)(k->ip_src+12);\n+\tip_dst0 = (const uint32_t *) k->ip_dst;\n+\tip_dst1 = (const uint32_t *)(k->ip_dst+4);\n+\tip_dst2 = (const uint32_t *)(k->ip_dst+8);\n+\tip_dst3 = (const uint32_t *)(k->ip_dst+12);\n+\tinit_val = rte_hash_crc_4byte(t, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_src0, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_src1, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_src2, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_src3, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_dst0, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_dst1, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_dst2, init_val);\n+\tinit_val = rte_hash_crc_4byte(*ip_dst3, init_val);\n+\tinit_val = rte_hash_crc_4byte(*p, init_val);\n+#else /* RTE_MACHINE_CPUFLAG_SSE4_2 */\n+\tinit_val = rte_jhash_1word(t, init_val);\n+\tinit_val = rte_jhash(k->ip_src, sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);\n+\tinit_val = rte_jhash(k->ip_dst, sizeof(uint8_t) * IPV6_ADDR_LEN, init_val);\n+\tinit_val = rte_jhash_1word(*p, init_val);\n+#endif /* RTE_MACHINE_CPUFLAG_SSE4_2 */\n+\treturn init_val;\n+}\n+\n+#define IPV4_L3FWD_NUM_ROUTES RTE_DIM(ipv4_l3fwd_route_array)\n+#define IPV6_L3FWD_NUM_ROUTES RTE_DIM(ipv6_l3fwd_route_array)\n+\n+static uint8_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;\n+static uint8_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;\n+\n+#endif\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+struct ipv4_l3fwd_route {\n+\tuint32_t ip;\n+\tuint8_t  depth;\n+\tuint8_t  if_out;\n+};\n+\n+struct ipv6_l3fwd_route {\n+\tuint8_t ip[16];\n+\tuint8_t depth;\n+\tuint8_t if_out;\n+};\n+\n+static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {\n+\t{IPv4(1, 1, 1, 0), 24, 0},\n+\t{IPv4(2, 1, 1, 0), 24, 1},\n+\t{IPv4(3, 1, 1, 0), 24, 2},\n+\t{IPv4(4, 1, 1, 0), 24, 3},\n+\t{IPv4(5, 1, 1, 0), 24, 4},\n+\t{IPv4(6, 1, 1, 0), 24, 5},\n+\t{IPv4(7, 1, 1, 0), 24, 6},\n+\t{IPv4(8, 1, 1, 0), 24, 7},\n+};\n+\n+static struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {\n+\t{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 0},\n+\t{{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 1},\n+\t{{3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 2},\n+\t{{4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 3},\n+\t{{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 4},\n+\t{{6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 5},\n+\t{{7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 6},\n+\t{{8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 7},\n+};\n+\n+#define IPV4_L3FWD_NUM_ROUTES RTE_DIM(ipv4_l3fwd_route_array)\n+#define IPV6_L3FWD_NUM_ROUTES RTE_DIM(ipv6_l3fwd_route_array)\n+\n+#define IPV4_L3FWD_LPM_MAX_RULES         1024\n+#define IPV6_L3FWD_LPM_MAX_RULES         1024\n+#define IPV6_L3FWD_LPM_NUMBER_TBL8S (1 << 16)\n+\n+typedef struct rte_lpm lookup_struct_t;\n+typedef struct rte_lpm6 lookup6_struct_t;\n+static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];\n+static lookup6_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];\n+#endif\n+\n+#define MAX_RX_THREAD 8\n+#define MAX_TX_THREAD 8\n+#define MAX_THREAD    (MAX_RX_THREAD + MAX_TX_THREAD)\n+\n+/**\n+ * Producers and consumers threads configuration\n+ */\n+static int lthreads_on = 1; /**< Use lthreads for processing*/\n+\n+struct thread_rx_conf {\n+\tuint16_t lcore_id;      /**< Initial lcore for rx thread */\n+\tuint16_t thread_id;     /**< Rx thread index */\n+\n+\tuint16_t n_queue;       /**< Number of queues to read by one thread */\n+\tstruct thread_rx_queue queue[MAX_RX_QUEUE_PER_THREAD];\n+\n+\tuint16_t n_ring;        /**< Number of output rings */\n+\tstruct rte_ring *ring[RTE_MAX_LCORE];\n+\tstruct lthread_cond *ready[RTE_MAX_LCORE];\n+\n+} __rte_cache_aligned;\n+\n+struct thread_tx_conf {\n+\tuint16_t lcore_id;      /**< Initial lcore for tx thread*/\n+\tuint16_t thread_id;     /**< Tx thread index */\n+\n+\tuint16_t n_port_id;     /**< Number of output ports */\n+\tuint16_t port_id[MAX_TX_PORT_PER_THREAD];   /**< Default port_id */\n+\n+\tuint16_t n_ring;        /**< Number of input rings */\n+\tstruct rte_ring *ring[RTE_MAX_LCORE];\n+\tstruct lthread_cond **ready[RTE_MAX_LCORE];\n+\n+\tuint16_t queue_id[RTE_MAX_ETHPORTS];\n+\tstruct mbuf_table mbuf[RTE_MAX_ETHPORTS];\n+\n+} __rte_cache_aligned;\n+\n+struct thread_tx_ring_conf {\n+\tuint16_t ring_id;\n+\tstruct thread_tx_conf *tx_conf;\n+} __rte_cache_aligned;\n+\n+/**\n+ * lcore configuration\n+ */\n+struct lcore_conf {\n+\tvoid *data;\n+\tlookup_struct_t *ipv4_lookup_struct;\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+\tlookup6_struct_t *ipv6_lookup_struct;\n+#else\n+\tlookup_struct_t *ipv6_lookup_struct;\n+#endif\n+} __rte_cache_aligned;\n+\n+static struct lcore_conf lcore_conf[RTE_MAX_LCORE];\n+RTE_DEFINE_PER_LCORE(struct lcore_conf *, lcore_conf);\n+\n+uint16_t n_rx_thread;\n+struct thread_rx_conf rx_thread[MAX_RX_THREAD];\n+\n+uint16_t n_tx_thread;\n+struct thread_tx_conf tx_thread[MAX_TX_THREAD];\n+\n+/* Send burst of packets on an output interface */\n+static inline int\n+send_burst(struct thread_tx_conf *tx_conf, uint16_t n, uint8_t port)\n+{\n+\tstruct rte_mbuf **m_table;\n+\tint ret;\n+\tuint16_t queueid;\n+\n+\tqueueid = tx_conf->queue_id[port];\n+\tm_table = (struct rte_mbuf **)tx_conf->mbuf[port].m_table;\n+\n+\tret = rte_eth_tx_burst(port, queueid, m_table, n);\n+\tif (unlikely(ret < n))\n+\t\tdo {\n+\t\t\trte_pktmbuf_free(m_table[ret]);\n+\t\t} while (++ret < n);\n+\n+\treturn 0;\n+}\n+\n+/* Enqueue a single packet, and send burst if queue is filled */\n+static inline int\n+send_single_packet(struct rte_mbuf *m, uint8_t port)\n+{\n+\tuint16_t len;\n+\tstruct thread_tx_conf *tx_conf;\n+\n+\tif (lthreads_on)\n+\t\ttx_conf = (struct thread_tx_conf *)lthread_get_data();\n+\telse\n+\t\ttx_conf = (struct thread_tx_conf *)RTE_PER_LCORE(lcore_conf)->data;\n+\n+\tlen = tx_conf->mbuf[port].len;\n+\ttx_conf->mbuf[port].m_table[len] = m;\n+\tlen++;\n+\n+\t/* enough pkts to be sent */\n+\tif (unlikely(len == MAX_PKT_BURST)) {\n+\t\tsend_burst(tx_conf, MAX_PKT_BURST, port);\n+\t\tlen = 0;\n+\t}\n+\n+\ttx_conf->mbuf[port].len = len;\n+\treturn 0;\n+}\n+\n+static inline __attribute__((always_inline)) void\n+send_packetsx4(struct thread_tx_conf *tx_conf, uint8_t port,\n+\tstruct rte_mbuf *m[], uint32_t num)\n+{\n+\tuint32_t len, j, n;\n+\n+\tlen = tx_conf->mbuf[port].len;\n+\n+\t/*\n+\t * If TX buffer for that queue is empty, and we have enough packets,\n+\t * then send them straightway.\n+\t */\n+\tif (num >= MAX_TX_BURST && len == 0) {\n+\t\tn = rte_eth_tx_burst(port, tx_conf->queue_id[port], m, num);\n+\t\tif (unlikely(n < num)) {\n+\t\t\tdo {\n+\t\t\t\trte_pktmbuf_free(m[n]);\n+\t\t\t} while (++n < num);\n+\t\t}\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Put packets into TX buffer for that queue.\n+\t */\n+\n+\tn = len + num;\n+\tn = (n > MAX_PKT_BURST) ? MAX_PKT_BURST - len : num;\n+\n+\tj = 0;\n+\tswitch (n % FWDSTEP) {\n+\twhile (j < n) {\n+\tcase 0:\n+\t\ttx_conf->mbuf[port].m_table[len + j] = m[j];\n+\t\tj++;\n+\tcase 3:\n+\t\ttx_conf->mbuf[port].m_table[len + j] = m[j];\n+\t\tj++;\n+\tcase 2:\n+\t\ttx_conf->mbuf[port].m_table[len + j] = m[j];\n+\t\tj++;\n+\tcase 1:\n+\t\ttx_conf->mbuf[port].m_table[len + j] = m[j];\n+\t\tj++;\n+\t}\n+\t}\n+\n+\tlen += n;\n+\n+\t/* enough pkts to be sent */\n+\tif (unlikely(len == MAX_PKT_BURST)) {\n+\n+\t\tsend_burst(tx_conf, MAX_PKT_BURST, port);\n+\n+\t\t/* copy rest of the packets into the TX buffer. */\n+\t\tlen = num - n;\n+\t\tj = 0;\n+\t\tswitch (len % FWDSTEP) {\n+\t\twhile (j < len) {\n+\t\tcase 0:\n+\t\t\ttx_conf->mbuf[port].m_table[j] = m[n + j];\n+\t\t\tj++;\n+\t\tcase 3:\n+\t\t\ttx_conf->mbuf[port].m_table[j] = m[n + j];\n+\t\t\tj++;\n+\t\tcase 2:\n+\t\t\ttx_conf->mbuf[port].m_table[j] = m[n + j];\n+\t\t\tj++;\n+\t\tcase 1:\n+\t\t\ttx_conf->mbuf[port].m_table[j] = m[n + j];\n+\t\t\tj++;\n+\t\t}\n+\t\t}\n+\t}\n+\n+\ttx_conf->mbuf[port].len = len;\n+}\n+\n+#ifdef DO_RFC_1812_CHECKS\n+static inline int\n+is_valid_ipv4_pkt(struct ipv4_hdr *pkt, uint32_t link_len)\n+{\n+\t/* From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2 */\n+\t/*\n+\t * 1. The packet length reported by the Link Layer must be large\n+\t * enough to hold the minimum length legal IP datagram (20 bytes).\n+\t */\n+\tif (link_len < sizeof(struct ipv4_hdr))\n+\t\treturn -1;\n+\n+\t/* 2. The IP checksum must be correct. */\n+\t/* this is checked in H/W */\n+\n+\t/*\n+\t * 3. The IP version number must be 4. If the version number is not 4\n+\t * then the packet may be another version of IP, such as IPng or\n+\t * ST-II.\n+\t */\n+\tif (((pkt->version_ihl) >> 4) != 4)\n+\t\treturn -3;\n+\t/*\n+\t * 4. The IP header length field must be large enough to hold the\n+\t * minimum length legal IP datagram (20 bytes = 5 words).\n+\t */\n+\tif ((pkt->version_ihl & 0xf) < 5)\n+\t\treturn -4;\n+\n+\t/*\n+\t * 5. The IP total length field must be large enough to hold the IP\n+\t * datagram header, whose length is specified in the IP header length\n+\t * field.\n+\t */\n+\tif (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct ipv4_hdr))\n+\t\treturn -5;\n+\n+\treturn 0;\n+}\n+#endif\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\n+static __m128i mask0;\n+static __m128i mask1;\n+static __m128i mask2;\n+\n+static inline uint8_t\n+get_ipv4_dst_port(void *ipv4_hdr, uint8_t portid,\n+\t\tlookup_struct_t *ipv4_l3fwd_lookup_struct)\n+{\n+\tint ret = 0;\n+\tunion ipv4_5tuple_host key;\n+\n+\tipv4_hdr = (uint8_t *)ipv4_hdr + offsetof(struct ipv4_hdr, time_to_live);\n+\t__m128i data = _mm_loadu_si128((__m128i *)(ipv4_hdr));\n+\t/* Get 5 tuple: dst port, src port, dst IP address, src IP address and\n+\t   protocol */\n+\tkey.xmm = _mm_and_si128(data, mask0);\n+\t/* Find destination port */\n+\tret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);\n+\treturn (uint8_t)((ret < 0) ? portid : ipv4_l3fwd_out_if[ret]);\n+}\n+\n+static inline uint8_t\n+get_ipv6_dst_port(void *ipv6_hdr,  uint8_t portid,\n+\t\tlookup_struct_t *ipv6_l3fwd_lookup_struct)\n+{\n+\tint ret = 0;\n+\tunion ipv6_5tuple_host key;\n+\n+\tipv6_hdr = (uint8_t *)ipv6_hdr + offsetof(struct ipv6_hdr, payload_len);\n+\t__m128i data0 = _mm_loadu_si128((__m128i *)(ipv6_hdr));\n+\t__m128i data1 = _mm_loadu_si128((__m128i *)(((uint8_t *)ipv6_hdr) +\n+\t\t\tsizeof(__m128i)));\n+\t__m128i data2 = _mm_loadu_si128((__m128i *)(((uint8_t *)ipv6_hdr) +\n+\t\t\tsizeof(__m128i) + sizeof(__m128i)));\n+\t/* Get part of 5 tuple: src IP address lower 96 bits and protocol */\n+\tkey.xmm[0] = _mm_and_si128(data0, mask1);\n+\t/* Get part of 5 tuple: dst IP address lower 96 bits and src IP address\n+\t   higher 32 bits */\n+\tkey.xmm[1] = data1;\n+\t/* Get part of 5 tuple: dst port and src port and dst IP address higher\n+\t   32 bits */\n+\tkey.xmm[2] = _mm_and_si128(data2, mask2);\n+\n+\t/* Find destination port */\n+\tret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);\n+\treturn (uint8_t)((ret < 0) ? portid : ipv6_l3fwd_out_if[ret]);\n+}\n+#endif\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+\n+static inline uint8_t\n+get_ipv4_dst_port(void *ipv4_hdr, uint8_t portid,\n+\t\tlookup_struct_t *ipv4_l3fwd_lookup_struct)\n+{\n+\tuint8_t next_hop;\n+\n+\treturn (uint8_t) ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct,\n+\t\trte_be_to_cpu_32(((struct ipv4_hdr *)ipv4_hdr)->dst_addr),\n+\t\t&next_hop) == 0) ? next_hop : portid);\n+}\n+\n+static inline uint8_t\n+get_ipv6_dst_port(void *ipv6_hdr, uint8_t portid,\n+\t\tlookup6_struct_t *ipv6_l3fwd_lookup_struct)\n+{\n+\tuint8_t next_hop;\n+\n+\treturn (uint8_t) ((rte_lpm6_lookup(ipv6_l3fwd_lookup_struct,\n+\t\t\t((struct ipv6_hdr *)ipv6_hdr)->dst_addr, &next_hop) == 0) ?\n+\t\t\tnext_hop : portid);\n+}\n+#endif\n+\n+static inline void l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid)\n+\t\t__attribute__((unused));\n+\n+#if ((APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) && \\\n+\t(ENABLE_MULTI_BUFFER_OPTIMIZE == 1))\n+\n+#define MASK_ALL_PKTS    0xf\n+#define EXECLUDE_1ST_PKT 0xe\n+#define EXECLUDE_2ND_PKT 0xd\n+#define EXECLUDE_3RD_PKT 0xb\n+#define EXECLUDE_4TH_PKT 0x7\n+\n+static inline void\n+simple_ipv4_fwd_4pkts(struct rte_mbuf *m[4], uint8_t portid,\n+\t\tstruct thread_tx_conf *qconf)\n+{\n+\tstruct ether_hdr *eth_hdr[4];\n+\tstruct ipv4_hdr *ipv4_hdr[4];\n+\tuint8_t dst_port[4];\n+\tint32_t ret[4];\n+\tunion ipv4_5tuple_host key[4];\n+\t__m128i data[4];\n+\n+\teth_hdr[0] = rte_pktmbuf_mtod(m[0], struct ether_hdr *);\n+\teth_hdr[1] = rte_pktmbuf_mtod(m[1], struct ether_hdr *);\n+\teth_hdr[2] = rte_pktmbuf_mtod(m[2], struct ether_hdr *);\n+\teth_hdr[3] = rte_pktmbuf_mtod(m[3], struct ether_hdr *);\n+\n+\t/* Handle IPv4 headers.*/\n+\tipv4_hdr[0] = rte_pktmbuf_mtod_offset(m[0], struct ipv4_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv4_hdr[1] = rte_pktmbuf_mtod_offset(m[1], struct ipv4_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv4_hdr[2] = rte_pktmbuf_mtod_offset(m[2], struct ipv4_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv4_hdr[3] = rte_pktmbuf_mtod_offset(m[3], struct ipv4_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\n+#ifdef DO_RFC_1812_CHECKS\n+\t/* Check to make sure the packet is valid (RFC1812) */\n+\tuint8_t valid_mask = MASK_ALL_PKTS;\n+\n+\tif (is_valid_ipv4_pkt(ipv4_hdr[0], m[0]->pkt_len) < 0) {\n+\t\trte_pktmbuf_free(m[0]);\n+\t\tvalid_mask &= EXECLUDE_1ST_PKT;\n+\t}\n+\tif (is_valid_ipv4_pkt(ipv4_hdr[1], m[1]->pkt_len) < 0) {\n+\t\trte_pktmbuf_free(m[1]);\n+\t\tvalid_mask &= EXECLUDE_2ND_PKT;\n+\t}\n+\tif (is_valid_ipv4_pkt(ipv4_hdr[2], m[2]->pkt_len) < 0) {\n+\t\trte_pktmbuf_free(m[2]);\n+\t\tvalid_mask &= EXECLUDE_3RD_PKT;\n+\t}\n+\tif (is_valid_ipv4_pkt(ipv4_hdr[3], m[3]->pkt_len) < 0) {\n+\t\trte_pktmbuf_free(m[3]);\n+\t\tvalid_mask &= EXECLUDE_4TH_PKT;\n+\t}\n+\tif (unlikely(valid_mask != MASK_ALL_PKTS)) {\n+\t\tif (valid_mask == 0)\n+\t\t\treturn;\n+\n+\t\tuint8_t i = 0;\n+\n+\t\tfor (i = 0; i < 4; i++)\n+\t\t\tif ((0x1 << i) & valid_mask)\n+\t\t\t\tl3fwd_simple_forward(m[i], portid, qconf);\n+\n+\t\treturn;\n+\t}\n+#endif /* End of #ifdef DO_RFC_1812_CHECKS */\n+\n+\tdata[0] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[0], __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv4_hdr,\n+\t\t\ttime_to_live)));\n+\tdata[1] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[1], __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv4_hdr,\n+\t\t\ttime_to_live)));\n+\tdata[2] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[2], __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv4_hdr,\n+\t\t\ttime_to_live)));\n+\tdata[3] = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m[3], __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv4_hdr,\n+\t\t\ttime_to_live)));\n+\n+\tkey[0].xmm = _mm_and_si128(data[0], mask0);\n+\tkey[1].xmm = _mm_and_si128(data[1], mask0);\n+\tkey[2].xmm = _mm_and_si128(data[2], mask0);\n+\tkey[3].xmm = _mm_and_si128(data[3], mask0);\n+\n+\tconst void *key_array[4] = {&key[0], &key[1], &key[2], &key[3]};\n+\n+\trte_hash_lookup_multi(qconf->ipv4_lookup_struct, &key_array[0], 4, ret);\n+\tdst_port[0] = (uint8_t) ((ret[0] < 0) ? portid : ipv4_l3fwd_out_if[ret[0]]);\n+\tdst_port[1] = (uint8_t) ((ret[1] < 0) ? portid : ipv4_l3fwd_out_if[ret[1]]);\n+\tdst_port[2] = (uint8_t) ((ret[2] < 0) ? portid : ipv4_l3fwd_out_if[ret[2]]);\n+\tdst_port[3] = (uint8_t) ((ret[3] < 0) ? portid : ipv4_l3fwd_out_if[ret[3]]);\n+\n+\tif (dst_port[0] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[0]) == 0)\n+\t\tdst_port[0] = portid;\n+\tif (dst_port[1] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[1]) == 0)\n+\t\tdst_port[1] = portid;\n+\tif (dst_port[2] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[2]) == 0)\n+\t\tdst_port[2] = portid;\n+\tif (dst_port[3] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[3]) == 0)\n+\t\tdst_port[3] = portid;\n+\n+#ifdef DO_RFC_1812_CHECKS\n+\t/* Update time to live and header checksum */\n+\t--(ipv4_hdr[0]->time_to_live);\n+\t--(ipv4_hdr[1]->time_to_live);\n+\t--(ipv4_hdr[2]->time_to_live);\n+\t--(ipv4_hdr[3]->time_to_live);\n+\t++(ipv4_hdr[0]->hdr_checksum);\n+\t++(ipv4_hdr[1]->hdr_checksum);\n+\t++(ipv4_hdr[2]->hdr_checksum);\n+\t++(ipv4_hdr[3]->hdr_checksum);\n+#endif\n+\n+\t/* dst addr */\n+\t*(uint64_t *)&eth_hdr[0]->d_addr = dest_eth_addr[dst_port[0]];\n+\t*(uint64_t *)&eth_hdr[1]->d_addr = dest_eth_addr[dst_port[1]];\n+\t*(uint64_t *)&eth_hdr[2]->d_addr = dest_eth_addr[dst_port[2]];\n+\t*(uint64_t *)&eth_hdr[3]->d_addr = dest_eth_addr[dst_port[3]];\n+\n+\t/* src addr */\n+\tether_addr_copy(&ports_eth_addr[dst_port[0]], &eth_hdr[0]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[1]], &eth_hdr[1]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[2]], &eth_hdr[2]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[3]], &eth_hdr[3]->s_addr);\n+\n+\tsend_single_packet(m[0], (uint8_t)dst_port[0]);\n+\tsend_single_packet(m[1], (uint8_t)dst_port[1]);\n+\tsend_single_packet(m[2], (uint8_t)dst_port[2]);\n+\tsend_single_packet(m[3], (uint8_t)dst_port[3]);\n+\n+}\n+\n+static inline void get_ipv6_5tuple(struct rte_mbuf *m0, __m128i mask0,\n+\t\t__m128i mask1, union ipv6_5tuple_host *key)\n+{\n+\t__m128i tmpdata0 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len)));\n+\t__m128i tmpdata1 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) +\n+\t\t\tsizeof(__m128i)));\n+\t__m128i tmpdata2 = _mm_loadu_si128(rte_pktmbuf_mtod_offset(m0, __m128i *,\n+\t\t\tsizeof(struct ether_hdr) + offsetof(struct ipv6_hdr, payload_len) +\n+\t\t\tsizeof(__m128i) + sizeof(__m128i)));\n+\n+\tkey->xmm[0] = _mm_and_si128(tmpdata0, mask0);\n+\tkey->xmm[1] = tmpdata1;\n+\tkey->xmm[2] = _mm_and_si128(tmpdata2, mask1);\n+}\n+\n+static inline void\n+simple_ipv6_fwd_4pkts(struct rte_mbuf *m[4], uint8_t portid,\n+\t\tstruct thread_tx_conf *qconf)\n+{\n+\tstruct ether_hdr *eth_hdr[4];\n+\tuint8_t dst_port[4];\n+\tint32_t ret[4];\n+\tunion ipv6_5tuple_host key[4];\n+\n+\t__attribute__((unused)) struct ipv6_hdr *ipv6_hdr[4];\n+\n+\teth_hdr[0] = rte_pktmbuf_mtod(m[0], struct ether_hdr *);\n+\teth_hdr[1] = rte_pktmbuf_mtod(m[1], struct ether_hdr *);\n+\teth_hdr[2] = rte_pktmbuf_mtod(m[2], struct ether_hdr *);\n+\teth_hdr[3] = rte_pktmbuf_mtod(m[3], struct ether_hdr *);\n+\n+\t/* Handle IPv6 headers.*/\n+\tipv6_hdr[0] = rte_pktmbuf_mtod_offset(m[0], struct ipv6_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv6_hdr[1] = rte_pktmbuf_mtod_offset(m[1], struct ipv6_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv6_hdr[2] = rte_pktmbuf_mtod_offset(m[2], struct ipv6_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\tipv6_hdr[3] = rte_pktmbuf_mtod_offset(m[3], struct ipv6_hdr *,\n+\t\t\t\t\t      sizeof(struct ether_hdr));\n+\n+\tget_ipv6_5tuple(m[0], mask1, mask2, &key[0]);\n+\tget_ipv6_5tuple(m[1], mask1, mask2, &key[1]);\n+\tget_ipv6_5tuple(m[2], mask1, mask2, &key[2]);\n+\tget_ipv6_5tuple(m[3], mask1, mask2, &key[3]);\n+\n+\tconst void *key_array[4] = {&key[0], &key[1], &key[2], &key[3]};\n+\n+\trte_hash_lookup_multi(qconf->ipv6_lookup_struct, &key_array[0], 4, ret);\n+\tdst_port[0] = (uint8_t) ((ret[0] < 0) ? portid : ipv6_l3fwd_out_if[ret[0]]);\n+\tdst_port[1] = (uint8_t) ((ret[1] < 0) ? portid : ipv6_l3fwd_out_if[ret[1]]);\n+\tdst_port[2] = (uint8_t) ((ret[2] < 0) ? portid : ipv6_l3fwd_out_if[ret[2]]);\n+\tdst_port[3] = (uint8_t) ((ret[3] < 0) ? portid : ipv6_l3fwd_out_if[ret[3]]);\n+\n+\tif (dst_port[0] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[0]) == 0)\n+\t\tdst_port[0] = portid;\n+\tif (dst_port[1] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[1]) == 0)\n+\t\tdst_port[1] = portid;\n+\tif (dst_port[2] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[2]) == 0)\n+\t\tdst_port[2] = portid;\n+\tif (dst_port[3] >= RTE_MAX_ETHPORTS ||\n+\t\t\t(enabled_port_mask & 1 << dst_port[3]) == 0)\n+\t\tdst_port[3] = portid;\n+\n+\t/* dst addr */\n+\t*(uint64_t *)&eth_hdr[0]->d_addr = dest_eth_addr[dst_port[0]];\n+\t*(uint64_t *)&eth_hdr[1]->d_addr = dest_eth_addr[dst_port[1]];\n+\t*(uint64_t *)&eth_hdr[2]->d_addr = dest_eth_addr[dst_port[2]];\n+\t*(uint64_t *)&eth_hdr[3]->d_addr = dest_eth_addr[dst_port[3]];\n+\n+\t/* src addr */\n+\tether_addr_copy(&ports_eth_addr[dst_port[0]], &eth_hdr[0]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[1]], &eth_hdr[1]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[2]], &eth_hdr[2]->s_addr);\n+\tether_addr_copy(&ports_eth_addr[dst_port[3]], &eth_hdr[3]->s_addr);\n+\n+\tsend_single_packet(m[0], (uint8_t)dst_port[0]);\n+\tsend_single_packet(m[1], (uint8_t)dst_port[1]);\n+\tsend_single_packet(m[2], (uint8_t)dst_port[2]);\n+\tsend_single_packet(m[3], (uint8_t)dst_port[3]);\n+\n+}\n+#endif /* APP_LOOKUP_METHOD */\n+\n+static inline __attribute__((always_inline)) void\n+l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid)\n+{\n+\tstruct ether_hdr *eth_hdr;\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tuint8_t dst_port;\n+\n+\teth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n+\n+\tif (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {\n+\t\t/* Handle IPv4 headers.*/\n+\t\tipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,\n+\t\t\t\tsizeof(struct ether_hdr));\n+\n+#ifdef DO_RFC_1812_CHECKS\n+\t\t/* Check to make sure the packet is valid (RFC1812) */\n+\t\tif (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {\n+\t\t\trte_pktmbuf_free(m);\n+\t\t\treturn;\n+\t\t}\n+#endif\n+\n+\t\tdst_port = get_ipv4_dst_port(ipv4_hdr, portid,\n+\t\t\t\t RTE_PER_LCORE(lcore_conf)->ipv4_lookup_struct);\n+\t\tif (dst_port >= RTE_MAX_ETHPORTS ||\n+\t\t\t\t(enabled_port_mask & 1 << dst_port) == 0)\n+\t\t\tdst_port = portid;\n+\n+#ifdef DO_RFC_1812_CHECKS\n+\t\t/* Update time to live and header checksum */\n+\t\t--(ipv4_hdr->time_to_live);\n+\t\t++(ipv4_hdr->hdr_checksum);\n+#endif\n+\t\t/* dst addr */\n+\t\t*(uint64_t *)&eth_hdr->d_addr = dest_eth_addr[dst_port];\n+\n+\t\t/* src addr */\n+\t\tether_addr_copy(&ports_eth_addr[dst_port], &eth_hdr->s_addr);\n+\n+\t\tsend_single_packet(m, dst_port);\n+\t} else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {\n+\t\t/* Handle IPv6 headers.*/\n+\t\tstruct ipv6_hdr *ipv6_hdr;\n+\n+\t\tipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,\n+\t\t\t\t\t\t   sizeof(struct ether_hdr));\n+\n+\t\tdst_port = get_ipv6_dst_port(ipv6_hdr, portid,\n+\t\t\t\tRTE_PER_LCORE(lcore_conf)->ipv6_lookup_struct);\n+\n+\t\tif (dst_port >= RTE_MAX_ETHPORTS ||\n+\t\t\t\t(enabled_port_mask & 1 << dst_port) == 0)\n+\t\t\tdst_port = portid;\n+\n+\t\t/* dst addr */\n+\t\t*(uint64_t *)&eth_hdr->d_addr = dest_eth_addr[dst_port];\n+\n+\t\t/* src addr */\n+\t\tether_addr_copy(&ports_eth_addr[dst_port], &eth_hdr->s_addr);\n+\n+\t\tsend_single_packet(m, dst_port);\n+\t} else\n+\t\t/* Free the mbuf that contains non-IPV4/IPV6 packet */\n+\t\trte_pktmbuf_free(m);\n+}\n+\n+#ifdef DO_RFC_1812_CHECKS\n+\n+#define\tIPV4_MIN_VER_IHL      0x45\n+#define\tIPV4_MAX_VER_IHL      0x4f\n+#define\tIPV4_MAX_VER_IHL_DIFF (IPV4_MAX_VER_IHL - IPV4_MIN_VER_IHL)\n+\n+/* Minimum value of IPV4 total length (20B) in network byte order. */\n+#define\tIPV4_MIN_LEN_BE\t(sizeof(struct ipv4_hdr) << 8)\n+\n+/*\n+ * From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2:\n+ * - The IP version number must be 4.\n+ * - The IP header length field must be large enough to hold the\n+ *    minimum length legal IP datagram (20 bytes = 5 words).\n+ * - The IP total length field must be large enough to hold the IP\n+ *   datagram header, whose length is specified in the IP header length\n+ *   field.\n+ * If we encounter invalid IPV4 packet, then set destination port for it\n+ * to BAD_PORT value.\n+ */\n+static inline __attribute__((always_inline)) void\n+rfc1812_process(struct ipv4_hdr *ipv4_hdr, uint16_t *dp, uint32_t ptype)\n+{\n+\tuint8_t ihl;\n+\n+\tif (RTE_ETH_IS_IPV4_HDR(ptype)) {\n+\t\tihl = ipv4_hdr->version_ihl - IPV4_MIN_VER_IHL;\n+\n+\t\tipv4_hdr->time_to_live--;\n+\t\tipv4_hdr->hdr_checksum++;\n+\n+\t\tif (ihl > IPV4_MAX_VER_IHL_DIFF ||\n+\t\t\t\t((uint8_t)ipv4_hdr->total_length == 0 &&\n+\t\t\t\tipv4_hdr->total_length < IPV4_MIN_LEN_BE)) {\n+\t\t\tdp[0] = BAD_PORT;\n+\t\t}\n+\t}\n+}\n+\n+#else\n+#define\trfc1812_process(mb, dp)\tdo { } while (0)\n+#endif /* DO_RFC_1812_CHECKS */\n+\n+\n+#if ((APP_LOOKUP_METHOD == APP_LOOKUP_LPM) && \\\n+\t(ENABLE_MULTI_BUFFER_OPTIMIZE == 1))\n+\n+static inline __attribute__((always_inline)) uint16_t\n+get_dst_port(struct rte_mbuf *pkt, uint32_t dst_ipv4, uint8_t portid)\n+{\n+\tuint8_t next_hop;\n+\tstruct ipv6_hdr *ipv6_hdr;\n+\tstruct ether_hdr *eth_hdr;\n+\n+\tif (RTE_ETH_IS_IPV4_HDR(pkt->packet_type)) {\n+\t\tif (rte_lpm_lookup(RTE_PER_LCORE(lcore_conf)->ipv4_lookup_struct,\n+\t\t\t\tdst_ipv4, &next_hop) != 0)\n+\t\t\tnext_hop = portid;\n+\t} else if (RTE_ETH_IS_IPV6_HDR(pkt->packet_type)) {\n+\t\teth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);\n+\t\tipv6_hdr = (struct ipv6_hdr *)(eth_hdr + 1);\n+\t\tif (rte_lpm6_lookup(RTE_PER_LCORE(lcore_conf)->ipv6_lookup_struct,\n+\t\t\t\tipv6_hdr->dst_addr, &next_hop) != 0)\n+\t\t\tnext_hop = portid;\n+\t} else {\n+\t\tnext_hop = portid;\n+\t}\n+\n+\treturn next_hop;\n+}\n+\n+static inline void\n+process_packet(struct rte_mbuf *pkt, uint16_t *dst_port, uint8_t portid)\n+{\n+\tstruct ether_hdr *eth_hdr;\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tuint32_t dst_ipv4;\n+\tuint16_t dp;\n+\t__m128i te, ve;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);\n+\n+\tdst_ipv4 = ipv4_hdr->dst_addr;\n+\tdst_ipv4 = rte_be_to_cpu_32(dst_ipv4);\n+\tdp = get_dst_port(pkt, dst_ipv4, portid);\n+\n+\tte = _mm_load_si128((__m128i *)eth_hdr);\n+\tve = val_eth[dp];\n+\n+\tdst_port[0] = dp;\n+\trfc1812_process(ipv4_hdr, dst_port, pkt->packet_type);\n+\n+\tte =  _mm_blend_epi16(te, ve, MASK_ETH);\n+\t_mm_store_si128((__m128i *)eth_hdr, te);\n+}\n+\n+/*\n+ * Read packet_type and destination IPV4 addresses from 4 mbufs.\n+ */\n+static inline void\n+processx4_step1(struct rte_mbuf *pkt[FWDSTEP], __m128i *dip,\n+\t\tuint32_t *ipv4_flag)\n+{\n+\tstruct ipv4_hdr *ipv4_hdr;\n+\tstruct ether_hdr *eth_hdr;\n+\tuint32_t x0, x1, x2, x3;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt[0], struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);\n+\tx0 = ipv4_hdr->dst_addr;\n+\tipv4_flag[0] = pkt[0]->packet_type & RTE_PTYPE_L3_IPV4;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt[1], struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);\n+\tx1 = ipv4_hdr->dst_addr;\n+\tipv4_flag[0] &= pkt[1]->packet_type;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt[2], struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);\n+\tx2 = ipv4_hdr->dst_addr;\n+\tipv4_flag[0] &= pkt[2]->packet_type;\n+\n+\teth_hdr = rte_pktmbuf_mtod(pkt[3], struct ether_hdr *);\n+\tipv4_hdr = (struct ipv4_hdr *)(eth_hdr + 1);\n+\tx3 = ipv4_hdr->dst_addr;\n+\tipv4_flag[0] &= pkt[3]->packet_type;\n+\n+\tdip[0] = _mm_set_epi32(x3, x2, x1, x0);\n+}\n+\n+/*\n+ * Lookup into LPM for destination port.\n+ * If lookup fails, use incoming port (portid) as destination port.\n+ */\n+static inline void\n+processx4_step2(__m128i dip, uint32_t ipv4_flag, uint8_t portid,\n+\t\tstruct rte_mbuf *pkt[FWDSTEP], uint16_t dprt[FWDSTEP])\n+{\n+\trte_xmm_t dst;\n+\tconst  __m128i bswap_mask = _mm_set_epi8(12, 13, 14, 15, 8, 9, 10, 11,\n+\t\t\t\t\t\t4, 5, 6, 7, 0, 1, 2, 3);\n+\n+\t/* Byte swap 4 IPV4 addresses. */\n+\tdip = _mm_shuffle_epi8(dip, bswap_mask);\n+\n+\t/* if all 4 packets are IPV4. */\n+\tif (likely(ipv4_flag)) {\n+\t\trte_lpm_lookupx4(RTE_PER_LCORE(lcore_conf)->ipv4_lookup_struct, dip,\n+\t\t\t\tdprt, portid);\n+\t} else {\n+\t\tdst.x = dip;\n+\t\tdprt[0] = get_dst_port(pkt[0], dst.u32[0], portid);\n+\t\tdprt[1] = get_dst_port(pkt[1], dst.u32[1], portid);\n+\t\tdprt[2] = get_dst_port(pkt[2], dst.u32[2], portid);\n+\t\tdprt[3] = get_dst_port(pkt[3], dst.u32[3], portid);\n+\t}\n+}\n+\n+/*\n+ * Update source and destination MAC addresses in the ethernet header.\n+ * Perform RFC1812 checks and updates for IPV4 packets.\n+ */\n+static inline void\n+processx4_step3(struct rte_mbuf *pkt[FWDSTEP], uint16_t dst_port[FWDSTEP])\n+{\n+\t__m128i te[FWDSTEP];\n+\t__m128i ve[FWDSTEP];\n+\t__m128i *p[FWDSTEP];\n+\n+\tp[0] = rte_pktmbuf_mtod(pkt[0], __m128i *);\n+\tp[1] = rte_pktmbuf_mtod(pkt[1], __m128i *);\n+\tp[2] = rte_pktmbuf_mtod(pkt[2], __m128i *);\n+\tp[3] = rte_pktmbuf_mtod(pkt[3], __m128i *);\n+\n+\tve[0] = val_eth[dst_port[0]];\n+\tte[0] = _mm_load_si128(p[0]);\n+\n+\tve[1] = val_eth[dst_port[1]];\n+\tte[1] = _mm_load_si128(p[1]);\n+\n+\tve[2] = val_eth[dst_port[2]];\n+\tte[2] = _mm_load_si128(p[2]);\n+\n+\tve[3] = val_eth[dst_port[3]];\n+\tte[3] = _mm_load_si128(p[3]);\n+\n+\t/* Update first 12 bytes, keep rest bytes intact. */\n+\tte[0] =  _mm_blend_epi16(te[0], ve[0], MASK_ETH);\n+\tte[1] =  _mm_blend_epi16(te[1], ve[1], MASK_ETH);\n+\tte[2] =  _mm_blend_epi16(te[2], ve[2], MASK_ETH);\n+\tte[3] =  _mm_blend_epi16(te[3], ve[3], MASK_ETH);\n+\n+\t_mm_store_si128(p[0], te[0]);\n+\t_mm_store_si128(p[1], te[1]);\n+\t_mm_store_si128(p[2], te[2]);\n+\t_mm_store_si128(p[3], te[3]);\n+\n+\trfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[0] + 1),\n+\t\t&dst_port[0], pkt[0]->packet_type);\n+\trfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[1] + 1),\n+\t\t&dst_port[1], pkt[1]->packet_type);\n+\trfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[2] + 1),\n+\t\t&dst_port[2], pkt[2]->packet_type);\n+\trfc1812_process((struct ipv4_hdr *)((struct ether_hdr *)p[3] + 1),\n+\t\t&dst_port[3], pkt[3]->packet_type);\n+}\n+\n+/*\n+ * We group consecutive packets with the same destionation port into one burst.\n+ * To avoid extra latency this is done together with some other packet\n+ * processing, but after we made a final decision about packet's destination.\n+ * To do this we maintain:\n+ * pnum - array of number of consecutive packets with the same dest port for\n+ * each packet in the input burst.\n+ * lp - pointer to the last updated element in the pnum.\n+ * dlp - dest port value lp corresponds to.\n+ */\n+\n+#define\tGRPSZ  (1 << FWDSTEP)\n+#define\tGRPMSK (GRPSZ - 1)\n+\n+#define GROUP_PORT_STEP(dlp, dcp, lp, pn, idx)\tdo { \\\n+\tif (likely((dlp) == (dcp)[(idx)])) {             \\\n+\t\t(lp)[0]++;                                   \\\n+\t} else {                                         \\\n+\t\t(dlp) = (dcp)[idx];                          \\\n+\t\t(lp) = (pn) + (idx);                         \\\n+\t\t(lp)[0] = 1;                                 \\\n+\t}                                                \\\n+} while (0)\n+\n+/*\n+ * Group consecutive packets with the same destination port in bursts of 4.\n+ * Suppose we have array of destionation ports:\n+ * dst_port[] = {a, b, c, d,, e, ... }\n+ * dp1 should contain: <a, b, c, d>, dp2: <b, c, d, e>.\n+ * We doing 4 comparisions at once and the result is 4 bit mask.\n+ * This mask is used as an index into prebuild array of pnum values.\n+ */\n+static inline uint16_t *\n+port_groupx4(uint16_t pn[FWDSTEP + 1], uint16_t *lp, __m128i dp1, __m128i dp2)\n+{\n+\tstatic const struct {\n+\t\tuint64_t pnum; /* prebuild 4 values for pnum[]. */\n+\t\tint32_t  idx;  /* index for new last updated elemnet. */\n+\t\tuint16_t lpv;  /* add value to the last updated element. */\n+\t} gptbl[GRPSZ] = {\n+\t{\n+\t\t/* 0: a != b, b != c, c != d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000100010001),\n+\t\t.idx = 4,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 1: a == b, b != c, c != d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000100010002),\n+\t\t.idx = 4,\n+\t\t.lpv = 1,\n+\t},\n+\t{\n+\t\t/* 2: a != b, b == c, c != d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000100020001),\n+\t\t.idx = 4,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 3: a == b, b == c, c != d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000100020003),\n+\t\t.idx = 4,\n+\t\t.lpv = 2,\n+\t},\n+\t{\n+\t\t/* 4: a != b, b != c, c == d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000200010001),\n+\t\t.idx = 4,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 5: a == b, b != c, c == d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000200010002),\n+\t\t.idx = 4,\n+\t\t.lpv = 1,\n+\t},\n+\t{\n+\t\t/* 6: a != b, b == c, c == d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000200030001),\n+\t\t.idx = 4,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 7: a == b, b == c, c == d, d != e */\n+\t\t.pnum = UINT64_C(0x0001000200030004),\n+\t\t.idx = 4,\n+\t\t.lpv = 3,\n+\t},\n+\t{\n+\t\t/* 8: a != b, b != c, c != d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000100010001),\n+\t\t.idx = 3,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 9: a == b, b != c, c != d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000100010002),\n+\t\t.idx = 3,\n+\t\t.lpv = 1,\n+\t},\n+\t{\n+\t\t/* 0xa: a != b, b == c, c != d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000100020001),\n+\t\t.idx = 3,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 0xb: a == b, b == c, c != d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000100020003),\n+\t\t.idx = 3,\n+\t\t.lpv = 2,\n+\t},\n+\t{\n+\t\t/* 0xc: a != b, b != c, c == d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000300010001),\n+\t\t.idx = 2,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 0xd: a == b, b != c, c == d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000300010002),\n+\t\t.idx = 2,\n+\t\t.lpv = 1,\n+\t},\n+\t{\n+\t\t/* 0xe: a != b, b == c, c == d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000300040001),\n+\t\t.idx = 1,\n+\t\t.lpv = 0,\n+\t},\n+\t{\n+\t\t/* 0xf: a == b, b == c, c == d, d == e */\n+\t\t.pnum = UINT64_C(0x0002000300040005),\n+\t\t.idx = 0,\n+\t\t.lpv = 4,\n+\t},\n+\t};\n+\n+\tunion {\n+\t\tuint16_t u16[FWDSTEP + 1];\n+\t\tuint64_t u64;\n+\t} *pnum = (void *)pn;\n+\n+\tint32_t v;\n+\n+\tdp1 = _mm_cmpeq_epi16(dp1, dp2);\n+\tdp1 = _mm_unpacklo_epi16(dp1, dp1);\n+\tv = _mm_movemask_ps((__m128)dp1);\n+\n+\t/* update last port counter. */\n+\tlp[0] += gptbl[v].lpv;\n+\n+\t/* if dest port value has changed. */\n+\tif (v != GRPMSK) {\n+\t\tlp = pnum->u16 + gptbl[v].idx;\n+\t\tlp[0] = 1;\n+\t\tpnum->u64 = gptbl[v].pnum;\n+\t}\n+\n+\treturn lp;\n+}\n+\n+#endif /* APP_LOOKUP_METHOD */\n+\n+static inline void\n+process_burst(struct rte_mbuf *pkts_burst[MAX_PKT_BURST], int nb_rx,\n+\t\tstruct thread_tx_conf *tx_conf, uint8_t port_id)\n+{\n+\tint j;\n+\n+#if ((APP_LOOKUP_METHOD == APP_LOOKUP_LPM) && \\\n+\t(ENABLE_MULTI_BUFFER_OPTIMIZE == 1))\n+\tint32_t k;\n+\tuint16_t dlp;\n+\tuint16_t *lp;\n+\tuint16_t dst_port[MAX_PKT_BURST];\n+\t__m128i dip[MAX_PKT_BURST / FWDSTEP];\n+\tuint32_t ipv4_flag[MAX_PKT_BURST / FWDSTEP];\n+\tuint16_t pnum[MAX_PKT_BURST + 1];\n+#endif\n+\n+#if (ENABLE_MULTI_BUFFER_OPTIMIZE == 1)\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\t{\n+\t\t/*\n+\t\t * Send nb_rx - nb_rx%4 packets\n+\t\t * in groups of 4.\n+\t\t\t */\n+\t\t\tint32_t n = RTE_ALIGN_FLOOR(nb_rx, 4);\n+\n+\t\t\tfor (j = 0; j < n ; j += 4) {\n+\t\t\t\tuint32_t pkt_type =\n+\t\t\t\t\t\tpkts_burst[j]->packet_type &\n+\t\t\t\t\t\tpkts_burst[j+1]->packet_type &\n+\t\t\t\t\t\tpkts_burst[j+2]->packet_type &\n+\t\t\t\t\t\tpkts_burst[j+3]->packet_type;\n+\n+\t\t\t\tif (pkt_type & RTE_PTYPE_L3_IPV4) {\n+\t\t\t\t\tsimple_ipv4_fwd_4pkts(\n+\t\t\t\t\t\t\t&pkts_burst[j], port_id, tx_conf);\n+\t\t\t\t} else if (pkt_type &\n+\t\t\t\t\t\tRTE_PTYPE_L3_IPV6) {\n+\t\t\t\t\tsimple_ipv6_fwd_4pkts(&pkts_burst[j],\n+\t\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t\t} else {\n+\t\t\t\t\tl3fwd_simple_forward(pkts_burst[j],\n+\t\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t\t\tl3fwd_simple_forward(pkts_burst[j+1],\n+\t\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t\t\tl3fwd_simple_forward(pkts_burst[j+2],\n+\t\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t\t\tl3fwd_simple_forward(pkts_burst[j+3],\n+\t\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tfor (; j < nb_rx ; j++) {\n+\t\t\t\tl3fwd_simple_forward(pkts_burst[j],\n+\t\t\t\t\t\tport_id, tx_conf);\n+\t\t\t}\n+\t\t}\n+#elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+\n+\t\tk = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);\n+\t\tfor (j = 0; j != k; j += FWDSTEP) {\n+\t\t\tprocessx4_step1(&pkts_burst[j],\n+\t\t\t\t\t\t&dip[j / FWDSTEP],\n+\t\t\t\t\t\t&ipv4_flag[j / FWDSTEP]);\n+\t\t}\n+\n+\t\tk = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);\n+\t\tfor (j = 0; j != k; j += FWDSTEP)\n+\t\t\tprocessx4_step2(dip[j / FWDSTEP], ipv4_flag[j / FWDSTEP],\n+\t\t\t\t\tport_id, &pkts_burst[j], &dst_port[j]);\n+\n+\t\t/*\n+\t\t * Finish packet processing and group consecutive\n+\t\t * packets with the same destination port.\n+\t\t */\n+\t\tk = RTE_ALIGN_FLOOR(nb_rx, FWDSTEP);\n+\t\tif (k != 0) {\n+\t\t\t__m128i dp1, dp2;\n+\n+\t\t\tlp = pnum;\n+\t\t\tlp[0] = 1;\n+\n+\t\t\tprocessx4_step3(pkts_burst, dst_port);\n+\n+\t\t\t/* dp1: <d[0], d[1], d[2], d[3], ... > */\n+\t\t\tdp1 = _mm_loadu_si128((__m128i *)dst_port);\n+\n+\t\t\tfor (j = FWDSTEP; j != k; j += FWDSTEP) {\n+\t\t\t\tprocessx4_step3(&pkts_burst[j], &dst_port[j]);\n+\n+\t\t\t\t/*\n+\t\t\t\t * dp2:\n+\t\t\t\t * <d[j-3], d[j-2], d[j-1], d[j], ... >\n+\t\t\t\t */\n+\t\t\t\tdp2 = _mm_loadu_si128((__m128i *)&dst_port[j -\n+\t\t\t\t\t\tFWDSTEP + 1]);\n+\t\t\t\tlp  = port_groupx4(&pnum[j - FWDSTEP], lp, dp1, dp2);\n+\n+\t\t\t\t/*\n+\t\t\t\t * dp1:\n+\t\t\t\t * <d[j], d[j+1], d[j+2], d[j+3], ... >\n+\t\t\t\t */\n+\t\t\t\tdp1 = _mm_srli_si128(dp2, (FWDSTEP - 1) *\n+\t\t\t\t\t\tsizeof(dst_port[0]));\n+\t\t}\n+\n+\t\t/*\n+\t\t * dp2: <d[j-3], d[j-2], d[j-1], d[j-1], ... >\n+\t\t */\n+\t\tdp2 = _mm_shufflelo_epi16(dp1, 0xf9);\n+\t\tlp  = port_groupx4(&pnum[j - FWDSTEP], lp, dp1, dp2);\n+\n+\t\t/*\n+\t\t * remove values added by the last repeated\n+\t\t * dst port.\n+\t\t */\n+\t\tlp[0]--;\n+\t\tdlp = dst_port[j - 1];\n+\t} else {\n+\t\t/* set dlp and lp to the never used values. */\n+\t\tdlp = BAD_PORT - 1;\n+\t\tlp = pnum + MAX_PKT_BURST;\n+\t}\n+\n+\t/* Process up to last 3 packets one by one. */\n+\tswitch (nb_rx % FWDSTEP) {\n+\tcase 3:\n+\t\tprocess_packet(pkts_burst[j], dst_port + j, port_id);\n+\t\tGROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);\n+\t\tj++;\n+\tcase 2:\n+\t\tprocess_packet(pkts_burst[j], dst_port + j, port_id);\n+\t\tGROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);\n+\t\tj++;\n+\tcase 1:\n+\t\tprocess_packet(pkts_burst[j], dst_port + j, port_id);\n+\t\tGROUP_PORT_STEP(dlp, dst_port, lp, pnum, j);\n+\t\tj++;\n+\t}\n+\n+\t/*\n+\t * Send packets out, through destination port.\n+\t * Consecutive packets with the same destination port\n+\t * are already grouped together.\n+\t * If destination port for the packet equals BAD_PORT,\n+\t * then free the packet without sending it out.\n+\t */\n+\tfor (j = 0; j < nb_rx; j += k) {\n+\n+\t\tint32_t m;\n+\t\tuint16_t pn;\n+\n+\t\tpn = dst_port[j];\n+\t\tk = pnum[j];\n+\n+\t\tif (likely(pn != BAD_PORT)) {\n+\t\t\tsend_packetsx4(tx_conf, pn, pkts_burst + j, k);\n+\t\t} else {\n+\t\t\tfor (m = j; m != j + k; m++)\n+\t\t\t\trte_pktmbuf_free(pkts_burst[m]);\n+\t\t}\n+\t}\n+\n+#endif /* APP_LOOKUP_METHOD */\n+#else /* ENABLE_MULTI_BUFFER_OPTIMIZE == 0 */\n+\n+\t/* Prefetch first packets */\n+\tfor (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++)\n+\t\trte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j], void *));\n+\n+\t/* Prefetch and forward already prefetched packets */\n+\tfor (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {\n+\t\trte_prefetch0(rte_pktmbuf_mtod(pkts_burst[j +\n+\t\tPREFETCH_OFFSET], void *));\n+\t\t\tl3fwd_simple_forward(pkts_burst[j], port_id, tx_conf);\n+\t\t}\n+\n+\t\t/* Forward remaining prefetched packets */\n+\t\tfor (; j < nb_rx; j++)\n+\t\t\tl3fwd_simple_forward(pkts_burst[j], port_id, tx_conf);\n+\n+#endif /* ENABLE_MULTI_BUFFER_OPTIMIZE */\n+}\n+\n+\n+/*\n+ * lthread processing loops\n+ */\n+\n+\n+/*\n+ * Counter of spawned rx lthreads\n+ */\n+rte_atomic16_t rx_counter;\n+\n+\n+/*\n+ * Null processing lthread loop\n+ *\n+ * This loop is used to start empty scheduler on lcore.\n+ */\n+static void\n+main_lthread_null_loop(__rte_unused void *args)\n+{\n+\tint lcore_id = rte_lcore_id();\n+\n+\tRTE_LOG(INFO, L3FWD, \"Starting scheduler on lcore %d.\\n\", lcore_id);\n+\tlthread_exit(NULL);\n+}\n+\n+/*\n+ * Rx processing loop\n+ */\n+static void\n+main_lthread_rx_loop(void *args)\n+{\n+\tstruct rte_mbuf *pkts_burst[MAX_PKT_BURST];\n+\tint len[RTE_MAX_LCORE] = { 0 };\n+\n+\tunsigned lcore_id;\n+\tuint16_t i, nb_rx;\n+\n+\tuint16_t worker_id;\n+\n+\tuint8_t port_id, queue_id;\n+\tstruct thread_rx_conf *rx_conf;\n+\tint ret;\n+\n+\trx_conf = (struct thread_rx_conf *)args;\n+\n+\tlthread_set_data((void *)rx_conf);\n+\n+\t/*\n+\t * Move this lthread to lcore\n+\t */\n+\tlthread_set_affinity(rx_conf->lcore_id);\n+\n+\tlcore_id = rte_lcore_id();\n+\n+\tfor (i = 0; i < rx_conf->n_queue; i++) {\n+\t\tport_id = rx_conf->queue[i].port_id;\n+\t\tqueue_id = rx_conf->queue[i].queue_id;\n+\t\tRTE_LOG(INFO, L3FWD, \" -- lcoreid=%u portid=%hhu rxqueueid=%hhu\\n\",\n+\t\t\t\tlcore_id, port_id, queue_id);\n+\t}\n+\n+\tfor (i = 0; i < rx_conf->n_ring; i++)\n+\t\tlthread_cond_init(NULL, &rx_conf->ready[i], NULL);\n+\n+\trte_atomic16_inc(&rx_counter);\n+\n+\tRTE_LOG(INFO, L3FWD, \"Entering Rx loop on lcore %u\\n\", lcore_id);\n+\n+\tworker_id = 0;\n+\n+\twhile (1) {\n+\n+\t\t/*\n+\t\t * Read packet from RX queues\n+\t\t */\n+\t\tfor (i = 0; i < rx_conf->n_queue; ++i) {\n+\t\t\tlthread_yield();\n+\n+\t\t\tport_id = rx_conf->queue[i].port_id;\n+\t\t\tqueue_id = rx_conf->queue[i].queue_id;\n+\t\t\tnb_rx = rte_eth_rx_burst(port_id, queue_id, pkts_burst,\n+\t\t\t\t\tMAX_PKT_BURST);\n+\n+\t\t\tif (nb_rx == 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tworker_id = (worker_id + 1) % rx_conf->n_ring;\n+\n+\t\t\tret = rte_ring_sp_enqueue_burst(\n+\t\t\t\trx_conf->ring[worker_id],\n+\t\t\t\t(void **) pkts_burst,\n+\t\t\t\tnb_rx);\n+\n+\t\t\tlen[worker_id] += nb_rx;\n+\t\t\tif (len[worker_id] >= BURST_SIZE) {\n+\t\t\t\tlthread_cond_signal(rx_conf->ready[worker_id]);\n+\t\t\t\tlen[worker_id] = 0;\n+\t\t\t}\n+\n+\t\t\tif (unlikely(ret == -ENOBUFS)) {\n+\t\t\t\tuint32_t k;\n+\n+\t\t\t\tfor (k = 0; k < nb_rx; k++) {\n+\t\t\t\t\tstruct rte_mbuf *m = pkts_burst[k];\n+\n+\t\t\t\t\trte_pktmbuf_free(m);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * Tx processing loop (one per ring)\n+ *\n+ * This lthread waits for data from producer on condition variable \"ready\", and\n+ * then process incomming packets.\n+ */\n+static void\n+main_lthread_tx_loop(void *args)\n+{\n+\tstruct rte_mbuf *pkts_burst[MAX_PKT_BURST];\n+\tuint8_t port_id;\n+\tstruct thread_tx_ring_conf *tx_ring_conf;\n+\tstruct thread_tx_conf *tx_conf;\n+\tuint16_t n, nb_rx;\n+\tuint16_t ring_id;\n+\n+\ttx_ring_conf = (struct thread_tx_ring_conf *)args;\n+\ttx_conf = tx_ring_conf->tx_conf;\n+\tring_id = tx_ring_conf->ring_id;\n+\tstruct rte_ring *ring = tx_conf->ring[ring_id];\n+\tstruct lthread_cond *ready = *tx_conf->ready[ring_id];\n+\n+\tlthread_set_data((void *)tx_conf);\n+\n+\tnb_rx = 0;\n+\n+\twhile (1) {\n+\t\t/*\n+\t\t * Read packet from RX rings\n+\t\t */\n+\t\tfor (n = 0; n < tx_conf->n_port_id; n++) {\n+\n+\t\t\t/*\n+\t\t\t * Wait for signal only if needed\n+\t\t\t */\n+\t\t\tif (nb_rx < BURST_SIZE)\n+\t\t\t\tlthread_cond_wait(ready, 0);\n+\n+\t\t\tnb_rx = rte_ring_sc_dequeue_burst(ring, (void **)pkts_burst,\n+\t\t\t\t\tBURST_SIZE);\n+\n+\t\t\tif (likely(nb_rx != 0)) {\n+\t\t\t\tport_id = tx_conf->port_id[n];\n+\t\t\t\tprocess_burst(pkts_burst, nb_rx, tx_conf, port_id);\n+\t\t\t}\n+\n+\t\t\tlthread_yield();\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * Main tx-lthreads spawner lthread.\n+ *\n+ * This lthread is used to spawn one new lthread per ring from producers.\n+ *\n+ */\n+static void\n+main_lthread_tx_main_loop(void *args)\n+{\n+\tstruct lthread *lt[MAX_TX_THREAD];\n+\tstruct thread_tx_ring_conf tx_ring_conf[RTE_MAX_LCORE];\n+\n+\tunsigned lcore_id;\n+\tuint8_t portid;\n+\tstruct thread_tx_conf *tx_conf;\n+\tuint16_t i;\n+\n+\ttx_conf = (struct thread_tx_conf *)args;\n+\tlthread_set_data((void *)tx_conf);\n+\n+\t/*\n+\t * Move this lthread to the selected lcore\n+\t */\n+\tlthread_set_affinity(tx_conf->lcore_id);\n+\n+\t/*\n+\t * Spawn tx readers (one per input ring)\n+\t */\n+\tfor (i = 0; i < tx_conf->n_ring; ++i) {\n+\t\ttx_ring_conf[i].tx_conf = tx_conf;\n+\t\ttx_ring_conf[i].ring_id = i;\n+\t\tlthread_create(&lt[i], tx_conf->lcore_id, main_lthread_tx_loop,\n+\t\t\t\t(void *)&tx_ring_conf[i]);\n+\t}\n+\n+\tlcore_id = rte_lcore_id();\n+\tRTE_LOG(INFO, L3FWD, \"Entering Tx main loop on lcore %u\\n\", lcore_id);\n+\n+\twhile (1) {\n+\n+\t\tlthread_sleep(BURST_TX_DRAIN_NS);\n+\n+\t\t/*\n+\t\t * TX burst queue drain\n+\t\t */\n+\t\tfor (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {\n+\t\t\tif (tx_conf->mbuf[portid].len == 0)\n+\t\t\t\tcontinue;\n+\t\t\tsend_burst(tx_conf, tx_conf->mbuf[portid].len, portid);\n+\t\t\ttx_conf->mbuf[portid].len = 0;\n+\t\t}\n+\n+\t}\n+}\n+\n+/*\n+ * Start scheduler with initial lthread on lcore\n+ *\n+ * This lthread loop spawns all rx and tx lthreads on master lcore\n+ */\n+static void\n+main_lthread_master_loop(__rte_unused void *arg) {\n+\tstruct lthread *lt[MAX_THREAD];\n+\tint i;\n+\tint n_thread = 0;\n+\n+\t/*\n+\t * Create producers (rx threads) on default lcore\n+\t */\n+\tfor (i = 0; i < n_rx_thread; i++) {\n+\t\trx_thread[i].thread_id = i;\n+\t\tlthread_create(&lt[n_thread], -1, main_lthread_rx_loop,\n+\t\t\t\t(void *)&rx_thread[i]);\n+\t\tn_thread++;\n+\t}\n+\n+\t/*\n+\t * Wait for all producers. Until some producers can be started on the same\n+\t * scheduler as this lthread, yielding is required to let them to run and\n+\t * prevent deadlock here.\n+\t */\n+\twhile (rte_atomic16_read(&rx_counter) < n_rx_thread)\n+\t\tlthread_sleep(100000);\n+\n+\t/*\n+\t * Create consumers (tx threads) on default lcore_id\n+\t */\n+\tfor (i = 0; i < n_tx_thread; i++) {\n+\t\ttx_thread[i].thread_id = i;\n+\t\tlthread_create(&lt[n_thread], -1, main_lthread_tx_main_loop,\n+\t\t\t\t(void *)&tx_thread[i]);\n+\t\tn_thread++;\n+\t}\n+\n+\t/*\n+\t * Wait for all threads finished\n+\t */\n+\tfor (i = 0; i < n_thread; i++)\n+\t\tlthread_join(lt[i], NULL);\n+\n+}\n+\n+\n+/*\n+ * Rx processing loop for pthreads\n+ */\n+static void\n+main_pthread_rx_loop(void *args)\n+{\n+\tstruct rte_mbuf *pkts_burst[MAX_PKT_BURST];\n+\n+\tunsigned lcore_id;\n+\tuint16_t i, nb_rx;\n+\n+\tuint16_t worker_id = 0;\n+\n+\tuint8_t portid, queueid;\n+\tstruct thread_rx_conf *rx_conf;\n+\tint ret;\n+\n+\trx_conf = (struct thread_rx_conf *)args;\n+\n+\tlcore_id = rte_lcore_id();\n+\n+\tfor (i = 0; i < rx_conf->n_queue; i++) {\n+\t\tportid = rx_conf->queue[i].port_id;\n+\t\tqueueid = rx_conf->queue[i].queue_id;\n+\t\tRTE_LOG(INFO, L3FWD, \" -- lcoreid=%u portid=%hhu rxqueueid=%hhu\\n\",\n+\t\t\t\tlcore_id, portid, queueid);\n+\t}\n+\n+\trte_atomic16_inc(&rx_counter);\n+\n+\tRTE_LOG(INFO, L3FWD, \"Entering Rx loop on lcore %u\\n\", lcore_id);\n+\n+\twhile (1) {\n+\n+\t\t/*\n+\t\t * Read packet from RX queues\n+\t\t */\n+\t\tfor (i = 0; i < rx_conf->n_queue; ++i) {\n+\n+\t\t\tportid = rx_conf->queue[i].port_id;\n+\t\t\tqueueid = rx_conf->queue[i].queue_id;\n+\t\t\tnb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,\n+\t\t\t\tMAX_PKT_BURST);\n+\n+\t\t\tif (nb_rx == 0) {\n+\t\t\t\tsched_yield();\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tworker_id = (worker_id + 1) % rx_conf->n_ring;\n+\n+\t\t\tret = rte_ring_sp_enqueue_burst(\n+\t\t\t\trx_conf->ring[worker_id],\n+\t\t\t\t(void **) pkts_burst,\n+\t\t\t\tnb_rx);\n+\n+\t\t\tif (unlikely(ret == -ENOBUFS)) {\n+\t\t\t\tuint32_t k;\n+\n+\t\t\t\tfor (k = 0; k < nb_rx; k++) {\n+\t\t\t\t\tstruct rte_mbuf *m = pkts_burst[k];\n+\n+\t\t\t\t\trte_pktmbuf_free(m);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * Tx processing loop for pthreads\n+ */\n+static void\n+main_pthread_tx_loop(void *args)\n+{\n+\tstruct rte_mbuf *pkts_burst[MAX_PKT_BURST];\n+\tuint8_t port_id;\n+\tstruct thread_tx_conf *tx_conf;\n+\tuint16_t nb_rx;\n+\tuint16_t ring_id;\n+\n+\tuint64_t prev_tsc, diff_tsc, cur_tsc;\n+\tstruct rte_ring *ring;\n+\tconst uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /\n+\t\tUS_PER_S * BURST_TX_DRAIN_NS / 1000;\n+\n+\tnb_rx = 0;\n+\tprev_tsc = 0;\n+\ttx_conf = (struct thread_tx_conf *)args;\n+\n+\tRTE_LOG(INFO, L3FWD, \"Entering Tx loop on lcore %u\\n\", rte_lcore_id());\n+\n+\twhile (1) {\n+\n+\t\tcur_tsc = rte_rdtsc();\n+\n+\t\t/*\n+\t\t * TX burst queue drain\n+\t\t */\n+\t\tdiff_tsc = cur_tsc - prev_tsc;\n+\t\tif (unlikely(diff_tsc > drain_tsc)) {\n+\n+\t\t\tfor (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {\n+\t\t\t\tif (tx_conf->mbuf[port_id].len == 0)\n+\t\t\t\t\tcontinue;\n+\t\t\t\tsend_burst(tx_conf, tx_conf->mbuf[port_id].len, port_id);\n+\t\t\t\ttx_conf->mbuf[port_id].len = 0;\n+\t\t\t}\n+\n+\t\t\tprev_tsc = cur_tsc;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Read packet from RX rings\n+\t\t */\n+\t\tfor (ring_id = 0; ring_id < tx_conf->n_ring; ring_id++) {\n+\n+\t\t\tring = tx_conf->ring[ring_id];\n+\n+\t\t\tnb_rx = rte_ring_sc_dequeue_burst(ring, (void **)pkts_burst,\n+\t\t\t\t\tBURST_SIZE);\n+\n+\t\t\tif (nb_rx == 0) {\n+\t\t\t\tsched_yield();\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\t/** For p-threads we have one port per lcore */\n+\t\t\tport_id = tx_conf->port_id[0];\n+\t\t\tprocess_burst(pkts_burst, nb_rx, tx_conf, port_id);\n+\n+\t\t}\n+\t}\n+}\n+\n+\n+/*\n+ * Initialize and configure application\n+ */\n+\n+static int\n+check_lcore_params(void)\n+{\n+\tuint8_t queue, lcore;\n+\tuint16_t i;\n+\tint socketid;\n+\n+\tfor (i = 0; i < nb_thread_rx_params; ++i) {\n+\t\tqueue = thread_rx_params[i].queue_id;\n+\t\tif (queue >= MAX_RX_QUEUE_PER_PORT) {\n+\t\t\tprintf(\"invalid queue number: %hhu\\n\", queue);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tlcore = thread_rx_params[i].lcore_id;\n+\t\tif (!rte_lcore_is_enabled(lcore)) {\n+\t\t\tprintf(\"error: lcore %hhu is not enabled in lcore mask\\n\", lcore);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tsocketid = rte_lcore_to_socket_id(lcore);\n+\t\tif ((socketid != 0) && (numa_on == 0))\n+\t\t\tprintf(\"warning: lcore %hhu is on socket %d with numa off\\n\",\n+\t\t\t\t\tlcore, socketid);\n+\t}\n+\treturn 0;\n+}\n+\n+static int\n+check_port_config(const unsigned nb_ports)\n+{\n+\tunsigned portid;\n+\tuint16_t i;\n+\n+\tfor (i = 0; i < nb_thread_rx_params; ++i) {\n+\t\tportid = thread_rx_params[i].port_id;\n+\t\tif ((enabled_port_mask & (1 << portid)) == 0) {\n+\t\t\tprintf(\"port %u is not enabled in port mask\\n\", portid);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tif (portid >= nb_ports) {\n+\t\t\tprintf(\"port %u is not present on the board\\n\", portid);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+static uint8_t\n+get_port_n_rx_queues(const uint8_t port)\n+{\n+\tint queue = -1;\n+\tuint16_t i;\n+\n+\tfor (i = 0; i < nb_thread_rx_params; ++i)\n+\t\tif (thread_rx_params[i].port_id == port &&\n+\t\t\t\tthread_rx_params[i].queue_id > queue)\n+\t\t\tqueue = thread_rx_params[i].queue_id;\n+\n+\treturn (uint8_t)(++queue);\n+}\n+\n+static int\n+init_lcore_rx_rings(void)\n+{\n+\tunsigned rx_thread_id, tx_thread_id;\n+\n+\tstruct thread_rx_conf *rx_conf;\n+\tstruct thread_tx_conf *tx_conf;\n+\n+\t/* Initialize the rings for the RX side */\n+\tfor (rx_thread_id = 0; rx_thread_id < n_rx_thread; rx_thread_id++) {\n+\t\tunsigned socket_io;\n+\n+\t\trx_conf = &rx_thread[rx_thread_id];\n+\n+\t\t/* use socket from initial lcore for rx_thread */\n+\t\tsocket_io = rte_lcore_to_socket_id(rx_conf->lcore_id);\n+\n+\t\tfor (tx_thread_id = 0; tx_thread_id < n_tx_thread; tx_thread_id++) {\n+\t\t\tchar name[32];\n+\t\t\tstruct rte_ring *ring = NULL;\n+\n+\t\t\ttx_conf = &tx_thread[tx_thread_id];\n+\n+\t\t\tprintf(\"Creating ring to connect rx-lthread %u (socket %u) with \"\n+\t\t\t\t\t\"tx-lthread %u ...\\n\", rx_thread_id, socket_io,\n+\t\t\t\t\ttx_thread_id);\n+\n+\t\t\tsnprintf(name, sizeof(name), \"app_ring_rx_s%u_rx%u_tx%u\",\n+\t\t\t\tsocket_io, rx_thread_id, tx_thread_id);\n+\n+\t\t\tring = rte_ring_create(name, 1024 * 1024 * 2, socket_io,\n+\t\t\t\t\tRING_F_SP_ENQ | RING_F_SC_DEQ);\n+\n+\t\t\tif (ring == NULL) {\n+\t\t\t\trte_panic(\"Cannot create ring to connect rx-lthread %u with \"\n+\t\t\t\t\t\t\"tx-thread %u\\n\", rx_thread_id, tx_thread_id);\n+\t\t\t}\n+\n+\t\t\trx_conf->ring[rx_conf->n_ring] = ring;\n+\n+\t\t\ttx_conf->ring[tx_conf->n_ring] = ring;\n+\t\t\ttx_conf->ready[tx_conf->n_ring] = &rx_conf->ready[rx_conf->n_ring];\n+\n+\t\t\trx_conf->n_ring++;\n+\t\t\ttx_conf->n_ring++;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+static int\n+init_lcore_rx_queues(void)\n+{\n+\tuint16_t i, nb_rx_queue;\n+\tuint8_t lcore_id, thread_id;\n+\tstruct thread_rx_conf *rx_conf;\n+\n+\tn_rx_thread = 0;\n+\tfor (i = 0; i < nb_thread_rx_params; ++i) {\n+\t\tlcore_id = thread_rx_params[i].lcore_id;\n+\t\tthread_id = thread_rx_params[i].thread_id;\n+\n+\t\trx_conf = &rx_thread[thread_id];\n+\t\trx_conf->lcore_id = lcore_id;\n+\n+\t\tnb_rx_queue = rx_conf->n_queue;\n+\t\tif (nb_rx_queue >= MAX_RX_QUEUE_PER_THREAD) {\n+\t\t\tprintf(\"error: too many queues (%u) for lcore: %u\\n\",\n+\t\t\t\t(unsigned)nb_rx_queue + 1, (unsigned)lcore_id);\n+\t\t\treturn -1;\n+\t\t}\n+\t\trx_conf->queue[nb_rx_queue].port_id = thread_rx_params[i].port_id;\n+\t\trx_conf->queue[nb_rx_queue].queue_id = thread_rx_params[i].queue_id;\n+\n+\t\trx_conf->n_queue++;\n+\t\tif (thread_rx_params[i].thread_id >= n_rx_thread)\n+\t\t\tn_rx_thread = thread_rx_params[i].thread_id + 1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int\n+init_lcore_tx_queues(void)\n+{\n+\tuint16_t i;\n+\tuint8_t tid;\n+\tunsigned cid;\n+\tstruct thread_tx_conf *tx_conf;\n+\n+\tn_tx_thread = 0;\n+\tfor (i = 0; i < nb_thread_tx_params; ++i) {\n+\t\tcid = thread_tx_params[i].lcore_id;\n+\t\ttid = thread_tx_params[i].thread_id;\n+\n+\t\ttx_conf = &tx_thread[tid];\n+\t\ttx_conf->lcore_id = cid;\n+\t\ttx_conf->port_id[tx_conf->n_port_id++] = thread_tx_params[i].port_id;\n+\n+\t\tif (thread_tx_params[i].thread_id >= n_tx_thread)\n+\t\t\tn_tx_thread = thread_tx_params[i].thread_id + 1;\n+\n+\t}\n+\treturn 0;\n+}\n+\n+/* display usage */\n+static void\n+print_usage(const char *prgname)\n+{\n+\tprintf(\"%s [EAL options] -- -p PORTMASK -P\"\n+\t\t\"  [--rx (port,queue,lcore,thread)[,(port,queue,lcore,thread]]\"\n+\t\t\"  [--tx (port,lcore,thread)[,(port,lcore,thread]]\"\n+\t\t\"  [--enable-jumbo [--max-pkt-len PKTLEN]]\\n\"\n+\t\t\"  -p PORTMASK: hexadecimal bitmask of ports to configure\\n\"\n+\t\t\"  -P : enable promiscuous mode\\n\"\n+\t\t\"  --rx (port,queue,lcore,thread): rx queues configuration\\n\"\n+\t\t\"  --tx (port,lcore,thread): tx configuration\\n\"\n+\t\t\"  --eth-dest=X,MM:MM:MM:MM:MM:MM: optional, ethernet destination for port X\\n\"\n+\t\t\"  --no-numa: optional, disable numa awareness\\n\"\n+\t\t\"  --ipv6: optional, specify it if running ipv6 packets\\n\"\n+\t\t\"  --enable-jumbo: enable jumbo frame\"\n+\t\t\" which max packet len is PKTLEN in decimal (64-9600)\\n\"\n+\t\t\"  --hash-entry-num: specify the hash entry number in hexadecimal to be setup\\n\"\n+\t\t\"  --no-lthreads: optional, disable lthread model\\n\",\n+\t\tprgname);\n+}\n+\n+static int\n+parse_max_pkt_len(const char *pktlen)\n+{\n+\tchar *end = NULL;\n+\tunsigned long len;\n+\n+\t/* parse decimal string */\n+\tlen = strtoul(pktlen, &end, 10);\n+\tif ((pktlen[0] == '\\0') || (end == NULL) || (*end != '\\0'))\n+\t\treturn -1;\n+\n+\tif (len == 0)\n+\t\treturn -1;\n+\n+\treturn len;\n+}\n+\n+static int\n+parse_portmask(const char *portmask)\n+{\n+\tchar *end = NULL;\n+\tunsigned long pm;\n+\n+\t/* parse hexadecimal string */\n+\tpm = strtoul(portmask, &end, 16);\n+\tif ((portmask[0] == '\\0') || (end == NULL) || (*end != '\\0'))\n+\t\treturn -1;\n+\n+\tif (pm == 0)\n+\t\treturn -1;\n+\n+\treturn pm;\n+}\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+static int\n+parse_hash_entry_number(const char *hash_entry_num)\n+{\n+\tchar *end = NULL;\n+\tunsigned long hash_en;\n+\n+\t/* parse hexadecimal string */\n+\thash_en = strtoul(hash_entry_num, &end, 16);\n+\tif ((hash_entry_num[0] == '\\0') || (end == NULL) || (*end != '\\0'))\n+\t\treturn -1;\n+\n+\tif (hash_en == 0)\n+\t\treturn -1;\n+\n+\treturn hash_en;\n+}\n+#endif\n+\n+static int\n+parse_rx_config(const char *q_arg)\n+{\n+\tchar s[256];\n+\tconst char *p, *p0 = q_arg;\n+\tchar *end;\n+\tenum fieldnames {\n+\t\tFLD_PORT = 0,\n+\t\tFLD_QUEUE,\n+\t\tFLD_LCORE,\n+\t\tFLD_THREAD,\n+\t\t_NUM_FLD\n+\t};\n+\tunsigned long int_fld[_NUM_FLD];\n+\tchar *str_fld[_NUM_FLD];\n+\tint i;\n+\tunsigned size;\n+\n+\tnb_thread_rx_params = 0;\n+\n+\twhile ((p = strchr(p0, '(')) != NULL) {\n+\t\t++p;\n+\t\tp0 = strchr(p, ')');\n+\t\tif (p0 == NULL)\n+\t\t\treturn -1;\n+\n+\t\tsize = p0 - p;\n+\t\tif (size >= sizeof(s))\n+\t\t\treturn -1;\n+\n+\t\tsnprintf(s, sizeof(s), \"%.*s\", size, p);\n+\t\tif (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)\n+\t\t\treturn -1;\n+\t\tfor (i = 0; i < _NUM_FLD; i++) {\n+\t\t\terrno = 0;\n+\t\t\tint_fld[i] = strtoul(str_fld[i], &end, 0);\n+\t\t\tif (errno != 0 || end == str_fld[i] || int_fld[i] > 255)\n+\t\t\t\treturn -1;\n+\t\t}\n+\t\tif (nb_thread_rx_params >= MAX_THREAD_PARAMS) {\n+\t\t\tprintf(\"exceeded max number of lcore params: %hu\\n\",\n+\t\t\t\t\tnb_thread_rx_params);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tthread_rx_params_array[nb_thread_rx_params].port_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_PORT];\n+\t\tthread_rx_params_array[nb_thread_rx_params].queue_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_QUEUE];\n+\t\tthread_rx_params_array[nb_thread_rx_params].lcore_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_LCORE];\n+\t\tthread_rx_params_array[nb_thread_rx_params].thread_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_THREAD];\n+\n+\t\t++nb_thread_rx_params;\n+\t}\n+\tthread_rx_params = thread_rx_params_array;\n+\treturn 0;\n+}\n+\n+static int\n+parse_tx_config(const char *q_arg)\n+{\n+\tchar s[256];\n+\tconst char *p, *p0 = q_arg;\n+\tchar *end;\n+\tenum fieldnames {\n+\t\tFLD_PORT = 0,\n+\t\tFLD_LCORE,\n+\t\tFLD_THREAD,\n+\t\t_NUM_FLD\n+\t};\n+\tunsigned long int_fld[_NUM_FLD];\n+\tchar *str_fld[_NUM_FLD];\n+\tint i;\n+\tunsigned size;\n+\n+\tnb_thread_tx_params = 0;\n+\n+\twhile ((p = strchr(p0, '(')) != NULL) {\n+\t\t++p;\n+\t\tp0 = strchr(p, ')');\n+\t\tif (p0 == NULL)\n+\t\t\treturn -1;\n+\n+\t\tsize = p0 - p;\n+\t\tif (size >= sizeof(s))\n+\t\t\treturn -1;\n+\n+\t\tsnprintf(s, sizeof(s), \"%.*s\", size, p);\n+\t\tif (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)\n+\t\t\treturn -1;\n+\t\tfor (i = 0; i < _NUM_FLD; i++) {\n+\t\t\terrno = 0;\n+\t\t\tint_fld[i] = strtoul(str_fld[i], &end, 0);\n+\t\t\tif (errno != 0 || end == str_fld[i] || int_fld[i] > 255)\n+\t\t\t\treturn -1;\n+\t\t}\n+\t\tif (nb_thread_rx_params >= MAX_THREAD_PARAMS) {\n+\t\t\tprintf(\"exceeded max number of lcore params: %hu\\n\",\n+\t\t\t\tnb_thread_rx_params);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tthread_tx_params_array[nb_thread_tx_params].port_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_PORT];\n+\t\tthread_tx_params_array[nb_thread_tx_params].lcore_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_LCORE];\n+\t\tthread_tx_params_array[nb_thread_tx_params].thread_id =\n+\t\t\t\t(uint8_t)int_fld[FLD_THREAD];\n+\n+\t\t++nb_thread_tx_params;\n+\t}\n+\tthread_tx_params = thread_tx_params_array;\n+\treturn 0;\n+}\n+\n+static void\n+parse_eth_dest(const char *optarg)\n+{\n+\tuint8_t portid;\n+\tchar *port_end;\n+\tuint8_t c, *dest, peer_addr[6];\n+\n+\terrno = 0;\n+\tportid = strtoul(optarg, &port_end, 10);\n+\tif (errno != 0 || port_end == optarg || *port_end++ != ',')\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\"Invalid eth-dest: %s\", optarg);\n+\tif (portid >= RTE_MAX_ETHPORTS)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\"eth-dest: port %d >= RTE_MAX_ETHPORTS(%d)\\n\",\n+\t\tportid, RTE_MAX_ETHPORTS);\n+\n+\tif (cmdline_parse_etheraddr(NULL, port_end,\n+\t\t&peer_addr, sizeof(peer_addr)) < 0)\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\"Invalid ethernet address: %s\\n\",\n+\t\tport_end);\n+\tdest = (uint8_t *)&dest_eth_addr[portid];\n+\tfor (c = 0; c < 6; c++)\n+\t\tdest[c] = peer_addr[c];\n+\t*(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];\n+}\n+\n+#define CMD_LINE_OPT_RX_CONFIG \"rx\"\n+#define CMD_LINE_OPT_TX_CONFIG \"tx\"\n+#define CMD_LINE_OPT_ETH_DEST \"eth-dest\"\n+#define CMD_LINE_OPT_NO_NUMA \"no-numa\"\n+#define CMD_LINE_OPT_IPV6 \"ipv6\"\n+#define CMD_LINE_OPT_ENABLE_JUMBO \"enable-jumbo\"\n+#define CMD_LINE_OPT_HASH_ENTRY_NUM \"hash-entry-num\"\n+#define CMD_LINE_OPT_NO_LTHREADS \"no-lthreads\"\n+\n+/* Parse the argument given in the command line of the application */\n+static int\n+parse_args(int argc, char **argv)\n+{\n+\tint opt, ret;\n+\tchar **argvopt;\n+\tint option_index;\n+\tchar *prgname = argv[0];\n+\tstatic struct option lgopts[] = {\n+\t\t{CMD_LINE_OPT_RX_CONFIG, 1, 0, 0},\n+\t\t{CMD_LINE_OPT_TX_CONFIG, 1, 0, 0},\n+\t\t{CMD_LINE_OPT_ETH_DEST, 1, 0, 0},\n+\t\t{CMD_LINE_OPT_NO_NUMA, 0, 0, 0},\n+\t\t{CMD_LINE_OPT_IPV6, 0, 0, 0},\n+\t\t{CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0},\n+\t\t{CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0},\n+\t\t{CMD_LINE_OPT_NO_LTHREADS, 0, 0, 0},\n+\t\t{NULL, 0, 0, 0}\n+\t};\n+\n+\targvopt = argv;\n+\n+\twhile ((opt = getopt_long(argc, argvopt, \"p:P\",\n+\t\t\t\tlgopts, &option_index)) != EOF) {\n+\n+\t\tswitch (opt) {\n+\t\t/* portmask */\n+\t\tcase 'p':\n+\t\t\tenabled_port_mask = parse_portmask(optarg);\n+\t\t\tif (enabled_port_mask == 0) {\n+\t\t\t\tprintf(\"invalid portmask\\n\");\n+\t\t\t\tprint_usage(prgname);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tcase 'P':\n+\t\t\tprintf(\"Promiscuous mode selected\\n\");\n+\t\t\tpromiscuous_on = 1;\n+\t\t\tbreak;\n+\n+\t\t/* long options */\n+\t\tcase 0:\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_RX_CONFIG,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_RX_CONFIG))) {\n+\t\t\t\tret = parse_rx_config(optarg);\n+\t\t\t\tif (ret) {\n+\t\t\t\t\tprintf(\"invalid rx config\\n\");\n+\t\t\t\t\tprint_usage(prgname);\n+\t\t\t\t\treturn -1;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_TX_CONFIG,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_TX_CONFIG))) {\n+\t\t\t\tret = parse_tx_config(optarg);\n+\t\t\t\tif (ret) {\n+\t\t\t\t\tprintf(\"invalid tx config\\n\");\n+\t\t\t\t\tprint_usage(prgname);\n+\t\t\t\t\treturn -1;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ETH_DEST,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_ETH_DEST)))\n+\t\t\t\tparse_eth_dest(optarg);\n+\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_NO_NUMA))) {\n+\t\t\t\tprintf(\"numa is disabled\\n\");\n+\t\t\t\tnuma_on = 0;\n+\t\t\t}\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_IPV6,\n+\t\t\t\tsizeof(CMD_LINE_OPT_IPV6))) {\n+\t\t\t\tprintf(\"ipv6 is specified\\n\");\n+\t\t\t\tipv6 = 1;\n+\t\t\t}\n+#endif\n+\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_LTHREADS,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_NO_LTHREADS))) {\n+\t\t\t\tprintf(\"l-threads model is disabled\\n\");\n+\t\t\t\tlthreads_on = 0;\n+\t\t\t}\n+\n+\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_JUMBO,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_ENABLE_JUMBO))) {\n+\t\t\t\tstruct option lenopts = {\"max-pkt-len\", required_argument, 0,\n+\t\t\t\t\t\t0};\n+\n+\t\t\t\tprintf(\"jumbo frame is enabled - disabling simple TX path\\n\");\n+\t\t\t\tport_conf.rxmode.jumbo_frame = 1;\n+\n+\t\t\t\t/* if no max-pkt-len set, use the default value ETHER_MAX_LEN */\n+\t\t\t\tif (0 == getopt_long(argc, argvopt, \"\", &lenopts,\n+\t\t\t\t\t\t&option_index)) {\n+\t\t\t\t\tret = parse_max_pkt_len(optarg);\n+\t\t\t\t\tif ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) {\n+\t\t\t\t\t\tprintf(\"invalid packet length\\n\");\n+\t\t\t\t\t\tprint_usage(prgname);\n+\t\t\t\t\t\treturn -1;\n+\t\t\t\t\t}\n+\t\t\t\t\tport_conf.rxmode.max_rx_pkt_len = ret;\n+\t\t\t\t}\n+\t\t\t\tprintf(\"set jumbo frame max packet length to %u\\n\",\n+\t\t\t\t\t\t(unsigned int)port_conf.rxmode.max_rx_pkt_len);\n+\t\t\t}\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\t\t\tif (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_HASH_ENTRY_NUM,\n+\t\t\t\t\tsizeof(CMD_LINE_OPT_HASH_ENTRY_NUM))) {\n+\t\t\t\tret = parse_hash_entry_number(optarg);\n+\t\t\t\tif ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) {\n+\t\t\t\t\thash_entry_number = ret;\n+\t\t\t\t} else {\n+\t\t\t\t\tprintf(\"invalid hash entry number\\n\");\n+\t\t\t\t\tprint_usage(prgname);\n+\t\t\t\t\treturn -1;\n+\t\t\t\t}\n+\t\t\t}\n+#endif\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tprint_usage(prgname);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tif (optind >= 0)\n+\t\targv[optind-1] = prgname;\n+\n+\tret = optind-1;\n+\toptind = 0; /* reset getopt lib */\n+\treturn ret;\n+}\n+\n+static void\n+print_ethaddr(const char *name, const struct ether_addr *eth_addr)\n+{\n+\tchar buf[ETHER_ADDR_FMT_SIZE];\n+\n+\tether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);\n+\tprintf(\"%s%s\", name, buf);\n+}\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)\n+\n+static void convert_ipv4_5tuple(struct ipv4_5tuple *key1,\n+\t\tunion ipv4_5tuple_host *key2)\n+{\n+\tkey2->ip_dst = rte_cpu_to_be_32(key1->ip_dst);\n+\tkey2->ip_src = rte_cpu_to_be_32(key1->ip_src);\n+\tkey2->port_dst = rte_cpu_to_be_16(key1->port_dst);\n+\tkey2->port_src = rte_cpu_to_be_16(key1->port_src);\n+\tkey2->proto = key1->proto;\n+\tkey2->pad0 = 0;\n+\tkey2->pad1 = 0;\n+}\n+\n+static void convert_ipv6_5tuple(struct ipv6_5tuple *key1,\n+\t\tunion ipv6_5tuple_host *key2)\n+{\n+\tuint32_t i;\n+\n+\tfor (i = 0; i < 16; i++) {\n+\t\tkey2->ip_dst[i] = key1->ip_dst[i];\n+\t\tkey2->ip_src[i] = key1->ip_src[i];\n+\t}\n+\tkey2->port_dst = rte_cpu_to_be_16(key1->port_dst);\n+\tkey2->port_src = rte_cpu_to_be_16(key1->port_src);\n+\tkey2->proto = key1->proto;\n+\tkey2->pad0 = 0;\n+\tkey2->pad1 = 0;\n+\tkey2->reserve = 0;\n+}\n+\n+#define BYTE_VALUE_MAX 256\n+#define ALL_32_BITS 0xffffffff\n+#define BIT_8_TO_15 0x0000ff00\n+\n+static inline void\n+populate_ipv4_few_flow_into_table(const struct rte_hash *h)\n+{\n+\tuint32_t i;\n+\tint32_t ret;\n+\tuint32_t array_len = RTE_DIM(ipv4_l3fwd_route_array);\n+\n+\tmask0 = _mm_set_epi32(ALL_32_BITS, ALL_32_BITS, ALL_32_BITS, BIT_8_TO_15);\n+\tfor (i = 0; i < array_len; i++) {\n+\t\tstruct ipv4_l3fwd_route  entry;\n+\t\tunion ipv4_5tuple_host newkey;\n+\n+\t\tentry = ipv4_l3fwd_route_array[i];\n+\t\tconvert_ipv4_5tuple(&entry.key, &newkey);\n+\t\tret = rte_hash_add_key(h, (void *) &newkey);\n+\t\tif (ret < 0) {\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %\" PRIu32\n+\t\t\t\t\" to the l3fwd hash.\\n\", i);\n+\t\t}\n+\t\tipv4_l3fwd_out_if[ret] = entry.if_out;\n+\t}\n+\tprintf(\"Hash: Adding 0x%\" PRIx32 \" keys\\n\", array_len);\n+}\n+\n+#define BIT_16_TO_23 0x00ff0000\n+static inline void\n+populate_ipv6_few_flow_into_table(const struct rte_hash *h)\n+{\n+\tuint32_t i;\n+\tint32_t ret;\n+\tuint32_t array_len = RTE_DIM(ipv6_l3fwd_route_array);\n+\n+\tmask1 = _mm_set_epi32(ALL_32_BITS, ALL_32_BITS, ALL_32_BITS, BIT_16_TO_23);\n+\tmask2 = _mm_set_epi32(0, 0, ALL_32_BITS, ALL_32_BITS);\n+\n+\tfor (i = 0; i < array_len; i++) {\n+\t\tstruct ipv6_l3fwd_route entry;\n+\t\tunion ipv6_5tuple_host newkey;\n+\n+\t\tentry = ipv6_l3fwd_route_array[i];\n+\t\tconvert_ipv6_5tuple(&entry.key, &newkey);\n+\n+\t\tret = rte_hash_add_key(h, (void *)&newkey);\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %\" PRIu32\n+\t\t\t\t\" to the l3fwd hash.\\n\", i);\n+\n+\t\tipv6_l3fwd_out_if[ret] = entry.if_out;\n+\t}\n+\tprintf(\"Hash: Adding 0x%\" PRIx32 \"keys\\n\", array_len);\n+}\n+\n+#define NUMBER_PORT_USED 4\n+static inline void\n+populate_ipv4_many_flow_into_table(const struct rte_hash *h,\n+\t\tunsigned int nr_flow)\n+{\n+\tunsigned i;\n+\n+\tmask0 = _mm_set_epi32(ALL_32_BITS, ALL_32_BITS, ALL_32_BITS, BIT_8_TO_15);\n+\tfor (i = 0; i < nr_flow; i++) {\n+\t\tstruct ipv4_l3fwd_route entry;\n+\t\tunion ipv4_5tuple_host newkey;\n+\t\tuint8_t a = (uint8_t) ((i / NUMBER_PORT_USED) % BYTE_VALUE_MAX);\n+\t\tuint8_t b = (uint8_t) (((i / NUMBER_PORT_USED) / BYTE_VALUE_MAX) %\n+\t\t\t\tBYTE_VALUE_MAX);\n+\t\tuint8_t c = (uint8_t) ((i / NUMBER_PORT_USED) / (BYTE_VALUE_MAX *\n+\t\t\t\tBYTE_VALUE_MAX));\n+\n+\t\t/* Create the ipv4 exact match flow */\n+\t\tmemset(&entry, 0, sizeof(entry));\n+\t\tswitch (i & (NUMBER_PORT_USED - 1)) {\n+\t\tcase 0:\n+\t\t\tentry = ipv4_l3fwd_route_array[0];\n+\t\t\tentry.key.ip_dst = IPv4(101, c, b, a);\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\tentry = ipv4_l3fwd_route_array[1];\n+\t\t\tentry.key.ip_dst = IPv4(201, c, b, a);\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tentry = ipv4_l3fwd_route_array[2];\n+\t\t\tentry.key.ip_dst = IPv4(111, c, b, a);\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\tentry = ipv4_l3fwd_route_array[3];\n+\t\t\tentry.key.ip_dst = IPv4(211, c, b, a);\n+\t\t\tbreak;\n+\t\t};\n+\t\tconvert_ipv4_5tuple(&entry.key, &newkey);\n+\n+\t\tint32_t ret = rte_hash_add_key(h, (void *) &newkey);\n+\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %u\\n\", i);\n+\n+\t\tipv4_l3fwd_out_if[ret] = (uint8_t) entry.if_out;\n+\n+\t}\n+\tprintf(\"Hash: Adding 0x%x keys\\n\", nr_flow);\n+}\n+\n+static inline void\n+populate_ipv6_many_flow_into_table(const struct rte_hash *h,\n+\t\tunsigned int nr_flow)\n+{\n+\tunsigned i;\n+\n+\tmask1 = _mm_set_epi32(ALL_32_BITS, ALL_32_BITS, ALL_32_BITS, BIT_16_TO_23);\n+\tmask2 = _mm_set_epi32(0, 0, ALL_32_BITS, ALL_32_BITS);\n+\n+\tfor (i = 0; i < nr_flow; i++) {\n+\t\tstruct ipv6_l3fwd_route entry;\n+\t\tunion ipv6_5tuple_host newkey;\n+\t\tuint8_t a = (uint8_t) ((i / NUMBER_PORT_USED) % BYTE_VALUE_MAX);\n+\t\tuint8_t b = (uint8_t) (((i / NUMBER_PORT_USED) / BYTE_VALUE_MAX) %\n+\t\t\t\tBYTE_VALUE_MAX);\n+\t\tuint8_t c = (uint8_t) ((i / NUMBER_PORT_USED) / (BYTE_VALUE_MAX *\n+\t\t\t\tBYTE_VALUE_MAX));\n+\n+\t\t/* Create the ipv6 exact match flow */\n+\t\tmemset(&entry, 0, sizeof(entry));\n+\t\tswitch (i & (NUMBER_PORT_USED - 1)) {\n+\t\tcase 0:\n+\t\t\tentry = ipv6_l3fwd_route_array[0];\n+\t\t\tbreak;\n+\t\tcase 1:\n+\t\t\tentry = ipv6_l3fwd_route_array[1];\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tentry = ipv6_l3fwd_route_array[2];\n+\t\t\tbreak;\n+\t\tcase 3:\n+\t\t\tentry = ipv6_l3fwd_route_array[3];\n+\t\t\tbreak;\n+\t\t};\n+\t\tentry.key.ip_dst[13] = c;\n+\t\tentry.key.ip_dst[14] = b;\n+\t\tentry.key.ip_dst[15] = a;\n+\t\tconvert_ipv6_5tuple(&entry.key, &newkey);\n+\n+\t\tint32_t ret = rte_hash_add_key(h, (void *) &newkey);\n+\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %u\\n\", i);\n+\n+\t\tipv6_l3fwd_out_if[ret] = (uint8_t) entry.if_out;\n+\n+\t}\n+\tprintf(\"Hash: Adding 0x%x keys\\n\", nr_flow);\n+}\n+\n+static void\n+setup_hash(int socketid)\n+{\n+\tstruct rte_hash_parameters ipv4_l3fwd_hash_params = {\n+\t\t.name = NULL,\n+\t\t.entries = L3FWD_HASH_ENTRIES,\n+\t\t.key_len = sizeof(union ipv4_5tuple_host),\n+\t\t.hash_func = ipv4_hash_crc,\n+\t\t.hash_func_init_val = 0,\n+\t};\n+\n+\tstruct rte_hash_parameters ipv6_l3fwd_hash_params = {\n+\t\t.name = NULL,\n+\t\t.entries = L3FWD_HASH_ENTRIES,\n+\t\t.key_len = sizeof(union ipv6_5tuple_host),\n+\t\t.hash_func = ipv6_hash_crc,\n+\t\t.hash_func_init_val = 0,\n+\t};\n+\n+\tchar s[64];\n+\n+\t/* create ipv4 hash */\n+\tsnprintf(s, sizeof(s), \"ipv4_l3fwd_hash_%d\", socketid);\n+\tipv4_l3fwd_hash_params.name = s;\n+\tipv4_l3fwd_hash_params.socket_id = socketid;\n+\tipv4_l3fwd_lookup_struct[socketid] =\n+\t\t\trte_hash_create(&ipv4_l3fwd_hash_params);\n+\tif (ipv4_l3fwd_lookup_struct[socketid] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Unable to create the l3fwd hash on socket %d\\n\",\n+\t\t\t\tsocketid);\n+\n+\t/* create ipv6 hash */\n+\tsnprintf(s, sizeof(s), \"ipv6_l3fwd_hash_%d\", socketid);\n+\tipv6_l3fwd_hash_params.name = s;\n+\tipv6_l3fwd_hash_params.socket_id = socketid;\n+\tipv6_l3fwd_lookup_struct[socketid] =\n+\t\t\trte_hash_create(&ipv6_l3fwd_hash_params);\n+\tif (ipv6_l3fwd_lookup_struct[socketid] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Unable to create the l3fwd hash on socket %d\\n\",\n+\t\t\t\tsocketid);\n+\n+\tif (hash_entry_number != HASH_ENTRY_NUMBER_DEFAULT) {\n+\t\t/* For testing hash matching with a large number of flows we\n+\t\t * generate millions of IP 5-tuples with an incremented dst\n+\t\t * address to initialize the hash table. */\n+\t\tif (ipv6 == 0) {\n+\t\t\t/* populate the ipv4 hash */\n+\t\t\tpopulate_ipv4_many_flow_into_table(\n+\t\t\t\tipv4_l3fwd_lookup_struct[socketid], hash_entry_number);\n+\t\t} else {\n+\t\t\t/* populate the ipv6 hash */\n+\t\t\tpopulate_ipv6_many_flow_into_table(\n+\t\t\t\tipv6_l3fwd_lookup_struct[socketid], hash_entry_number);\n+\t\t}\n+\t} else {\n+\t\t/* Use data in ipv4/ipv6 l3fwd lookup table directly to initialize\n+\t\t   the hash table */\n+\t\tif (ipv6 == 0) {\n+\t\t\t/* populate the ipv4 hash */\n+\t\t\tpopulate_ipv4_few_flow_into_table(\n+\t\t\t\t\tipv4_l3fwd_lookup_struct[socketid]);\n+\t\t} else {\n+\t\t\t/* populate the ipv6 hash */\n+\t\t\tpopulate_ipv6_few_flow_into_table(\n+\t\t\t\t\tipv6_l3fwd_lookup_struct[socketid]);\n+\t\t}\n+\t}\n+}\n+#endif\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+static void\n+setup_lpm(int socketid)\n+{\n+\tstruct rte_lpm6_config config;\n+\tunsigned i;\n+\tint ret;\n+\tchar s[64];\n+\n+\t/* create the LPM table */\n+\tsnprintf(s, sizeof(s), \"IPV4_L3FWD_LPM_%d\", socketid);\n+\tipv4_l3fwd_lookup_struct[socketid] = rte_lpm_create(s, socketid,\n+\t\t\t\tIPV4_L3FWD_LPM_MAX_RULES, 0);\n+\tif (ipv4_l3fwd_lookup_struct[socketid] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Unable to create the l3fwd LPM table \"\n+\t\t\t\t\"on socket %d\\n\", socketid);\n+\n+\t/* populate the LPM table */\n+\tfor (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {\n+\n+\t\t/* skip unused ports */\n+\t\tif ((1 << ipv4_l3fwd_route_array[i].if_out &\n+\t\t\t\tenabled_port_mask) == 0)\n+\t\t\tcontinue;\n+\n+\t\tret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],\n+\t\t\tipv4_l3fwd_route_array[i].ip,\n+\t\t\tipv4_l3fwd_route_array[i].depth,\n+\t\t\tipv4_l3fwd_route_array[i].if_out);\n+\n+\t\tif (ret < 0) {\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %u to the \"\n+\t\t\t\t\"l3fwd LPM table on socket %d\\n\",\n+\t\t\t\ti, socketid);\n+\t\t}\n+\n+\t\tprintf(\"LPM: Adding route 0x%08x / %d (%d)\\n\",\n+\t\t\t(unsigned)ipv4_l3fwd_route_array[i].ip,\n+\t\t\tipv4_l3fwd_route_array[i].depth,\n+\t\t\tipv4_l3fwd_route_array[i].if_out);\n+\t}\n+\n+\t/* create the LPM6 table */\n+\tsnprintf(s, sizeof(s), \"IPV6_L3FWD_LPM_%d\", socketid);\n+\n+\tconfig.max_rules = IPV6_L3FWD_LPM_MAX_RULES;\n+\tconfig.number_tbl8s = IPV6_L3FWD_LPM_NUMBER_TBL8S;\n+\tconfig.flags = 0;\n+\tipv6_l3fwd_lookup_struct[socketid] = rte_lpm6_create(s, socketid,\n+\t\t\t\t&config);\n+\tif (ipv6_l3fwd_lookup_struct[socketid] == NULL)\n+\t\trte_exit(EXIT_FAILURE, \"Unable to create the l3fwd LPM table\"\n+\t\t\t\t\" on socket %d\\n\", socketid);\n+\n+\t/* populate the LPM table */\n+\tfor (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {\n+\n+\t\t/* skip unused ports */\n+\t\tif ((1 << ipv6_l3fwd_route_array[i].if_out &\n+\t\t\t\tenabled_port_mask) == 0)\n+\t\t\tcontinue;\n+\n+\t\tret = rte_lpm6_add(ipv6_l3fwd_lookup_struct[socketid],\n+\t\t\tipv6_l3fwd_route_array[i].ip,\n+\t\t\tipv6_l3fwd_route_array[i].depth,\n+\t\t\tipv6_l3fwd_route_array[i].if_out);\n+\n+\t\tif (ret < 0) {\n+\t\t\trte_exit(EXIT_FAILURE, \"Unable to add entry %u to the \"\n+\t\t\t\t\"l3fwd LPM table on socket %d\\n\",\n+\t\t\t\ti, socketid);\n+\t\t}\n+\n+\t\tprintf(\"LPM: Adding route %s / %d (%d)\\n\",\n+\t\t\t\"IPV6\",\n+\t\t\tipv6_l3fwd_route_array[i].depth,\n+\t\t\tipv6_l3fwd_route_array[i].if_out);\n+\t}\n+}\n+#endif\n+\n+static int\n+init_mem(unsigned nb_mbuf)\n+{\n+\tstruct lcore_conf *qconf;\n+\tint socketid;\n+\tunsigned lcore_id;\n+\tchar s[64];\n+\n+\tfor (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {\n+\t\tif (rte_lcore_is_enabled(lcore_id) == 0)\n+\t\t\tcontinue;\n+\n+\t\tif (numa_on)\n+\t\t\tsocketid = rte_lcore_to_socket_id(lcore_id);\n+\t\telse\n+\t\t\tsocketid = 0;\n+\n+\t\tif (socketid >= NB_SOCKETS) {\n+\t\t\trte_exit(EXIT_FAILURE, \"Socket %d of lcore %u is out of range %d\\n\",\n+\t\t\t\tsocketid, lcore_id, NB_SOCKETS);\n+\t\t}\n+\t\tif (pktmbuf_pool[socketid] == NULL) {\n+\t\t\tsnprintf(s, sizeof(s), \"mbuf_pool_%d\", socketid);\n+\t\t\tpktmbuf_pool[socketid] =\n+\t\t\t\trte_pktmbuf_pool_create(s, nb_mbuf,\n+\t\t\t\t\tMEMPOOL_CACHE_SIZE, 0,\n+\t\t\t\t\tRTE_MBUF_DEFAULT_BUF_SIZE, socketid);\n+\t\t\tif (pktmbuf_pool[socketid] == NULL)\n+\t\t\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t\t\t\"Cannot init mbuf pool on socket %d\\n\", socketid);\n+\t\t\telse\n+\t\t\t\tprintf(\"Allocated mbuf pool on socket %d\\n\", socketid);\n+\n+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)\n+\t\t\tsetup_lpm(socketid);\n+#else\n+\t\t\tsetup_hash(socketid);\n+#endif\n+\t\t}\n+\t\tqconf = &lcore_conf[lcore_id];\n+\t\tqconf->ipv4_lookup_struct =\n+\t\t\t\tipv4_l3fwd_lookup_struct[socketid];\n+\t\tqconf->ipv6_lookup_struct =\n+\t\t\t\tipv6_l3fwd_lookup_struct[socketid];\n+\t}\n+\treturn 0;\n+}\n+\n+/* Check the link status of all ports in up to 9s, and print them finally */\n+static void\n+check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)\n+{\n+#define CHECK_INTERVAL 100 /* 100ms */\n+#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */\n+\tuint8_t portid, count, all_ports_up, print_flag = 0;\n+\tstruct rte_eth_link link;\n+\n+\tprintf(\"\\nChecking link status\");\n+\tfflush(stdout);\n+\tfor (count = 0; count <= MAX_CHECK_TIME; count++) {\n+\t\tall_ports_up = 1;\n+\t\tfor (portid = 0; portid < port_num; portid++) {\n+\t\t\tif ((port_mask & (1 << portid)) == 0)\n+\t\t\t\tcontinue;\n+\t\t\tmemset(&link, 0, sizeof(link));\n+\t\t\trte_eth_link_get_nowait(portid, &link);\n+\t\t\t/* print link status if flag set */\n+\t\t\tif (print_flag == 1) {\n+\t\t\t\tif (link.link_status)\n+\t\t\t\t\tprintf(\"Port %d Link Up - speed %u \"\n+\t\t\t\t\t\t\"Mbps - %s\\n\", (uint8_t)portid,\n+\t\t\t\t\t\t(unsigned)link.link_speed,\n+\t\t\t\t(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?\n+\t\t\t\t\t(\"full-duplex\") : (\"half-duplex\\n\"));\n+\t\t\t\telse\n+\t\t\t\t\tprintf(\"Port %d Link Down\\n\",\n+\t\t\t\t\t\t(uint8_t)portid);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\t/* clear all_ports_up flag if any link down */\n+\t\t\tif (link.link_status == 0) {\n+\t\t\t\tall_ports_up = 0;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\t/* after finally printing all link status, get out */\n+\t\tif (print_flag == 1)\n+\t\t\tbreak;\n+\n+\t\tif (all_ports_up == 0) {\n+\t\t\tprintf(\".\");\n+\t\t\tfflush(stdout);\n+\t\t\trte_delay_ms(CHECK_INTERVAL);\n+\t\t}\n+\n+\t\t/* set the print_flag if all ports up or timeout */\n+\t\tif (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {\n+\t\t\tprint_flag = 1;\n+\t\t\tprintf(\"done\\n\");\n+\t\t}\n+\t}\n+}\n+\n+/*\n+ * Start scheduler on lcore.\n+ */\n+static int\n+lthread_slave_spawner(__rte_unused void *arg) {\n+\tstruct lthread *lt;\n+\tint lcore_id = rte_lcore_id();\n+\n+\tRTE_PER_LCORE(lcore_conf) = &lcore_conf[lcore_id];\n+\tlthread_create(&lt, -1, main_lthread_null_loop, NULL);\n+\tlthread_run();\n+\treturn 0;\n+}\n+\n+/*\n+ * Start master scheduler with initial lthread spawning rx and tx lthreads\n+ * (main_lthread_master).\n+ */\n+static int\n+lthread_master_spawner(__rte_unused void *arg) {\n+\tstruct lthread *lt;\n+\tint lcore_id = rte_lcore_id();\n+\n+\tRTE_PER_LCORE(lcore_conf) = &lcore_conf[lcore_id];\n+\tlthread_create(&lt, -1, main_lthread_master_loop, NULL);\n+\tlthread_run();\n+\treturn 0;\n+}\n+\n+/*\n+ * Start rx/tx threads on lcore.\n+ */\n+static int\n+pthread_spawner(__rte_unused void *arg) {\n+\tint lcore_id = rte_lcore_id();\n+\tint i;\n+\n+\tRTE_PER_LCORE(lcore_conf) = &lcore_conf[lcore_id];\n+\n+\tfor (i = 0; i < n_rx_thread; i++)\n+\t\tif (rx_thread[i].lcore_id == lcore_id) {\n+\t\t\tRTE_PER_LCORE(lcore_conf)->data = (void *)&rx_thread[i];\n+\t\t\tmain_pthread_rx_loop((void *)&rx_thread[i]);\n+\t\t\treturn 0;\n+\t\t}\n+\n+\tfor (i = 0; i < n_tx_thread; i++)\n+\t\tif (tx_thread[i].lcore_id == lcore_id) {\n+\t\t\tRTE_PER_LCORE(lcore_conf)->data = (void *)&tx_thread[i];\n+\t\t\tmain_pthread_tx_loop((void *)&tx_thread[i]);\n+\t\t\treturn 0;\n+\t\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Dump current configuration\n+ */\n+static void\n+print_config(void)\n+{\n+\tunsigned rx, tx;\n+\tunsigned i;\n+\tstruct thread_rx_conf *rx_conf;\n+\tstruct thread_tx_conf *tx_conf;\n+\n+\tprintf(\"\\n\\n--- Configuration ---\\n\\n\");\n+\n+\tprintf(\"rx lthreads: %d\\n\", n_rx_thread);\n+\tfor (rx = 0; rx < n_rx_thread; rx++) {\n+\t\trx_conf = &rx_thread[rx];\n+\t\tprintf(\"  %2d. lcore=%d, %d queue(s):\\n\", rx, rx_conf->lcore_id,\n+\t\t\t\trx_conf->n_queue);\n+\t\tfor (i = 0; i < rx_conf->n_queue; i++)\n+\t\t\tprintf(\"     %2d. Rx-port %d, queue %d\\n\", i,\n+\t\t\t\t\trx_conf->queue[i].port_id, rx_conf->queue[i].queue_id);\n+\t}\n+\n+\tprintf(\"tx lthreads: %d\\n\", n_tx_thread);\n+\tfor (tx = 0; tx < n_tx_thread; tx++) {\n+\t\ttx_conf = &tx_thread[tx];\n+\t\tprintf(\"  %2d. lcore %d, lthread %d\\n\", tx, tx_conf->lcore_id,\n+\t\t\t\ttx_conf->thread_id);\n+\t\tfor (i = 0; i < tx_conf->n_port_id; i++)\n+\t\t\tprintf(\"     %2d. Tx-port %d\\n\", i, tx_conf->port_id[i]);\n+\t}\n+\n+}\n+\n+int\n+main(int argc, char **argv)\n+{\n+\tstruct rte_eth_dev_info dev_info;\n+\tstruct rte_eth_txconf *txconf;\n+\tint ret;\n+\tunsigned nb_ports;\n+\tuint16_t queueid;\n+\tunsigned lcore_id, lthread_id;\n+\tuint32_t n_tx_queue, nb_lcores;\n+\tuint8_t portid, nb_rx_queue, queue, socketid;\n+\n+\t/* init EAL */\n+\tret = rte_eal_init(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Invalid EAL parameters\\n\");\n+\targc -= ret;\n+\targv += ret;\n+\n+\t/* pre-init dst MACs for all ports to 02:00:00:00:00:xx */\n+\tfor (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {\n+\t\tdest_eth_addr[portid] = ETHER_LOCAL_ADMIN_ADDR + ((uint64_t)portid <<\n+\t\t\t\t40);\n+\t\t*(uint64_t *)(val_eth + portid) = dest_eth_addr[portid];\n+\t}\n+\n+\t/* parse application arguments (after the EAL ones) */\n+\tret = parse_args(argc, argv);\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"Invalid L3FWD parameters\\n\");\n+\n+\tif (check_lcore_params() < 0)\n+\t\trte_exit(EXIT_FAILURE, \"check_lcore_params failed\\n\");\n+\n+\tret = init_lcore_rx_queues();\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"init_lcore_rx_queues failed\\n\");\n+\n+\tret = init_lcore_tx_queues();\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"init_lcore_tx_queues failed\\n\");\n+\n+\tret = init_lcore_rx_rings();\n+\tif (ret < 0)\n+\t\trte_exit(EXIT_FAILURE, \"init_lcore_rx_rings failed\\n\");\n+\n+\tnb_ports = rte_eth_dev_count();\n+\tif (nb_ports > RTE_MAX_ETHPORTS)\n+\t\tnb_ports = RTE_MAX_ETHPORTS;\n+\n+\tif (check_port_config(nb_ports) < 0)\n+\t\trte_exit(EXIT_FAILURE, \"check_port_config failed\\n\");\n+\n+\tnb_lcores = rte_lcore_count();\n+\n+\t/* initialize all ports */\n+\tfor (portid = 0; portid < nb_ports; portid++) {\n+\t\t/* skip ports that are not enabled */\n+\t\tif ((enabled_port_mask & (1 << portid)) == 0) {\n+\t\t\tprintf(\"\\nSkipping disabled port %d\\n\", portid);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* init port */\n+\t\tprintf(\"Initializing port %d ... \", portid);\n+\t\tfflush(stdout);\n+\n+\t\tnb_rx_queue = get_port_n_rx_queues(portid);\n+\t\tn_tx_queue = nb_lcores;\n+\n+\t\tif (n_tx_queue > MAX_TX_QUEUE_PER_PORT)\n+\t\t\tn_tx_queue = MAX_TX_QUEUE_PER_PORT;\n+\n+\t\tprintf(\"Creating queues: nb_rxq=%d nb_txq=%u... \", nb_rx_queue,\n+\t\t\t\t(unsigned)n_tx_queue);\n+\n+\t\tret = rte_eth_dev_configure(portid, nb_rx_queue, (uint16_t)n_tx_queue,\n+\t\t\t\t&port_conf);\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"Cannot configure device: err=%d, port=%d\\n\",\n+\t\t\t\tret, portid);\n+\n+\t\trte_eth_macaddr_get(portid, &ports_eth_addr[portid]);\n+\t\tprint_ethaddr(\" Address:\", &ports_eth_addr[portid]);\n+\t\tprintf(\", \");\n+\t\tprint_ethaddr(\"Destination:\",\n+\t\t\t(const struct ether_addr *)&dest_eth_addr[portid]);\n+\t\tprintf(\", \");\n+\n+\t\t/*\n+\t\t * prepare src MACs for each port.\n+\t\t */\n+\t\tether_addr_copy(&ports_eth_addr[portid],\n+\t\t\t(struct ether_addr *)(val_eth + portid) + 1);\n+\n+\t\t/* init memory */\n+\t\tret = init_mem(NB_MBUF);\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"init_mem failed\\n\");\n+\n+\t\t/* init one TX queue per couple (lcore,port) */\n+\t\tqueueid = 0;\n+\t\tfor (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {\n+\t\t\tif (rte_lcore_is_enabled(lcore_id) == 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (numa_on)\n+\t\t\t\tsocketid = (uint8_t)rte_lcore_to_socket_id(lcore_id);\n+\t\t\telse\n+\t\t\t\tsocketid = 0;\n+\n+\t\t\tprintf(\"txq=%u,%d,%d \", lcore_id, queueid, socketid);\n+\t\t\tfflush(stdout);\n+\n+\t\t\trte_eth_dev_info_get(portid, &dev_info);\n+\t\t\ttxconf = &dev_info.default_txconf;\n+\t\t\tif (port_conf.rxmode.jumbo_frame)\n+\t\t\t\ttxconf->txq_flags = 0;\n+\t\t\tret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,\n+\t\t\t\t\t\t     socketid, txconf);\n+\t\t\tif (ret < 0)\n+\t\t\t\trte_exit(EXIT_FAILURE, \"rte_eth_tx_queue_setup: err=%d, \"\n+\t\t\t\t\t\"port=%d\\n\", ret, portid);\n+\n+\t\t\tqueueid++;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Set other tx queue number for every thread\n+\t\t */\n+\t\tfor (lthread_id = 0; lthread_id < n_tx_thread; lthread_id++)\n+\t\t\ttx_thread[lthread_id].queue_id[portid] = lthread_id;\n+\n+\n+\t\tprintf(\"\\n\");\n+\t}\n+\n+\tfor (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {\n+\t\tif (rte_lcore_is_enabled(lcore_id) == 0)\n+\t\t\tcontinue;\n+\n+\t\t/* init RX queues */\n+\t\tfor (lthread_id = 0; lthread_id < n_rx_thread; lthread_id++)\n+\t\t\tfor (queue = 0; queue < rx_thread[lthread_id].n_queue; ++queue) {\n+\n+\t\t\t\tportid = rx_thread[lthread_id].queue[queue].port_id;\n+\t\t\t\tqueueid = rx_thread[lthread_id].queue[queue].queue_id;\n+\n+\t\t\t\tif (numa_on)\n+\t\t\t\t\tsocketid = (uint8_t)rte_lcore_to_socket_id(lcore_id);\n+\t\t\t\telse\n+\t\t\t\t\tsocketid = 0;\n+\n+\t\t\t\tprintf(\"rxq=%d,%d,%d \", portid, queueid, socketid);\n+\t\t\t\tfflush(stdout);\n+\n+\t\t\t\tret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd, socketid,\n+\t\t\t\t\t\tNULL, pktmbuf_pool[socketid]);\n+\t\t\t\tif (ret < 0)\n+\t\t\t\t\trte_exit(EXIT_FAILURE, \"rte_eth_rx_queue_setup: err=%d,\"\n+\t\t\t\t\t\t\t\"port=%d\\n\", ret, portid);\n+\t\t\t}\n+\t}\n+\n+\tprintf(\"\\n\");\n+\n+\t/* start ports */\n+\tfor (portid = 0; portid < nb_ports; portid++) {\n+\t\tif ((enabled_port_mask & (1 << portid)) == 0)\n+\t\t\tcontinue;\n+\n+\t\t/* Start device */\n+\t\tret = rte_eth_dev_start(portid);\n+\t\tif (ret < 0)\n+\t\t\trte_exit(EXIT_FAILURE, \"rte_eth_dev_start: err=%d, port=%d\\n\",\n+\t\t\t\tret, portid);\n+\n+\t\t/*\n+\t\t * If enabled, put device in promiscuous mode.\n+\t\t * This allows IO forwarding mode to forward packets\n+\t\t * to itself through 2 cross-connected  ports of the\n+\t\t * target machine.\n+\t\t */\n+\t\tif (promiscuous_on)\n+\t\t\trte_eth_promiscuous_enable(portid);\n+\t}\n+\n+\t/*\n+\t * Dump rx/tx lthreads configuration\n+\t */\n+\tprint_config();\n+\n+\tcheck_all_ports_link_status((uint8_t)nb_ports, enabled_port_mask);\n+\n+\t/*\n+\t * Set number of schedulers to wait for all schedulers\n+\t */\n+\tif (lthreads_on) {\n+\t\tprintf(\"Starting L-Threading Model\\n\");\n+\t\tlthread_num_schedulers_set(nb_lcores);\n+\t\trte_eal_mp_remote_launch(lthread_slave_spawner, NULL, SKIP_MASTER);\n+\t\tlthread_master_spawner(NULL);\n+\t} else {\n+\t\tprintf(\"Starting P-Threading Model\");\n+\t\trte_eal_mp_remote_launch(pthread_spawner, NULL, CALL_MASTER);\n+\t}\n+\n+\tRTE_LCORE_FOREACH_SLAVE(lcore_id) {\n+\t\tif (rte_eal_wait_lcore(lcore_id) < 0)\n+\t\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n",
    "prefixes": [
        "dpdk-dev",
        "v1",
        "3/5"
    ]
}