From patchwork Thu Jul 2 15:16:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiri Kuzin X-Patchwork-Id: 72846 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 699D5A0520; Thu, 2 Jul 2020 17:16:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E0AEF1D736; Thu, 2 Jul 2020 17:16:30 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60066.outbound.protection.outlook.com [40.107.6.66]) by dpdk.org (Postfix) with ESMTP id A01101D451 for ; Thu, 2 Jul 2020 17:16:29 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=drEk6UTDnGREN8QuTaOzK9/9BVhR/l791Y+VplCMlRVa3nEUWHUFLZmeSSg/bpLNzqzyonx7uLsJjUJJ0y+fDqoqaO27Fd3WY9xJldlb6gBJaeo9NhPpRUL43SPHxnVJ6GEmF9hKvbnzaX71jVMJmXScJs4v6edxRUH4iZ7ALk9EOAU4yr0Skr05qPGDk+n2D/0ZfOR9pC2MWHdMUS00M+DMLS8U3oBtX0qXzjaaSyQqJW/OzNGMEP7Xf5YKNbko2LIG6uBHQ90JDWof8xkXmFvFdo8A1kS023JsAzP3P0ODZPcswMkFJTY3hnJK2dnVPfPUmCRXky2xyGh2YAd63Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hvb7qzMTVWhJWbjGMND+dx6YavQSoJ4qDcfeRcdgTYE=; b=aHy4byGyS45LXimyEEvEbERzz9Cs+B11UGZFoZY7yzwNeBQkcLn0mK2e6spompfwgvSD3CxsCGR6jNu0eQki0O9ixqq9S9RW+95TWgTyaYddTm5WaIMwAR2uANsyo61Mk28sXGgiB1MWsDildOijDhxMlSSG/1XYoauB07j2xs0URYyWQO7FPkbYpMO232rGXTyZXV94IfmJzPsJUnZRnFMsXwhaVEB0fp9YrtZp2uV7MXqU7XhuYZ2Or2UP/5o17oSgyR1qj6Edq3hhgOB8rN4SNt5hFu+SC+avwFX/3/jzatqVBOZTOWcqmFpLzVCmQFJWEMtC23HqyFkn2dXU+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hvb7qzMTVWhJWbjGMND+dx6YavQSoJ4qDcfeRcdgTYE=; b=c/Xqm2snGJa+VW7QIXGLdJ9YFCYNmoSrsG/lVlntbVRQtPjOJYOyRunMs+l586Yw3oZy1eajBcGIGKRnmReASI7UHeKPZ1PieTmAocg8vZuTAdiZGog4IznRbKcRYoO1kfT1fsc3+APT5eTGYm9jlYd8tbeeQay2F1avrXvMc8Q= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR0502MB3874.eurprd05.prod.outlook.com (2603:10a6:208:1a::29) by AM0PR05MB6819.eurprd05.prod.outlook.com (2603:10a6:20b:15c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.22; Thu, 2 Jul 2020 15:16:28 +0000 Received: from AM0PR0502MB3874.eurprd05.prod.outlook.com ([fe80::84e5:30fb:782e:5e60]) by AM0PR0502MB3874.eurprd05.prod.outlook.com ([fe80::84e5:30fb:782e:5e60%4]) with mapi id 15.20.3153.023; Thu, 2 Jul 2020 15:16:28 +0000 From: Shiri Kuzin To: dev@dpdk.org Cc: matan@mellanox.com, viacheslavo@mellanox.com Date: Thu, 2 Jul 2020 18:16:14 +0300 Message-Id: <1593702974-30927-1-git-send-email-shirik@mellanox.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: AM0PR10CA0043.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::23) To AM0PR0502MB3874.eurprd05.prod.outlook.com (2603:10a6:208:1a::29) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mellanox.com (94.188.199.18) by AM0PR10CA0043.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20 via Frontend Transport; Thu, 2 Jul 2020 15:16:28 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [94.188.199.18] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 012a203b-97f3-4a5c-0f16-08d81e9ae4b3 X-MS-TrafficTypeDiagnostic: AM0PR05MB6819: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:773; X-Forefront-PRVS: 0452022BE1 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VcKBzLhQf2YI1XAXI+oMtG119uku+rsRp23Zy3644fL5QKd0mGBlHwyjkqD8rdHRWxmgfmXdDEJ7Az6XEHpCUPoC+RtQ+jS4jNTX9m4vJSsaXED8EqWFYzjKZoP1T7ATwZCR1tuZQ7YA+jGWHQKf9EDyl5PKFZRUsR3qMIrfwjZ5XUsj/WwkS3UJsHMNs1ExQU6vNrIgkXrUpS0Z9CkMqXt5W4V14exJMrnbyurecYpLkBP/bh+/eW6mnREG28lwc+ivdn/1U4tF8SsnLAebKGtXFcz18xkbcJcYKIkR+psDR10OsnOSWv5UeuZyLqXB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR0502MB3874.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(396003)(346002)(376002)(366004)(136003)(66946007)(26005)(16526019)(66556008)(66476007)(186003)(6666004)(956004)(2616005)(8886007)(316002)(478600001)(8936002)(7696005)(52116002)(86362001)(2906002)(4326008)(6916009)(5660300002)(8676002)(83380400001)(36756003)(107886003)(30864003)(55016002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UtwAckOHK8eWPVEAuiiLR02g4AvKKMn7PHvCzjz5n4Gp2qaB2DbWoJ2TLeBOoog1jGY60wxSjJb07gmarwjr6ljOC+ichbB0bITgJv6LNZpwyGYhE9MFfVmQsG13B/S5j8OnpKzMDU0FUe3UuYMX/KSEvgq5WXtGW1v2GH3YVYWcZVgNanh4DbwK/ilgNKQV/UUNuf+kMOQQKMUIf0O8cj+debuzkFvw2VkDrrE6qYKt9Ldm6ufPv133rK3RVxDFB+yCoq2pO9RmORtF8GYAVGgSTSMKM62EcxMGzuIxMSkxrE24ERBNmOUEiTdNIkESK9eGt7jMgYHaG6+olYAbCR42A/UHIjIXwx9/qfoKqB+AXzpUra1XdgWoItHZTiaFwJvPRs6BeoohKAwWjNuOfDpxjmbC+wpn7w5Ix7fhBcJvn3tDOwCiDk099jkvxmZHAv5hqoTRRFX4T4Y6CxY/PgNImcMbTejn1QgJ6bG3LDo= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 012a203b-97f3-4a5c-0f16-08d81e9ae4b3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0502MB3874.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2020 15:16:28.5571 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iChO7Y2WKuEThAFAsKuTa0z3JeP9+Pl6N3vCz8i1FDh3MaTQgQcXR0ds/Br+ls4vTH11c/y4x59JtVh6/DGgcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6819 Subject: [dpdk-dev] [PATCH v1] app/testpmd: add 5tswap forwarding engine X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The new 5-tuple swap engine swaps: source and destination mac address, source and destination address in ipv4/ipv6, source and destination port in UDP/TCP. The forwarding engine will parse each layer and swap it, and will stop when the next layer doesn't match. The mentioned headers of ICMP/ARP/Multicast packets will be swapped as well according to matching layers. usage: --forward-mode=5tswap Signed-off-by: Shiri Kuzin Acked-by: Matan Azrad --- app/test-pmd/5tswap.c | 208 ++++++++++++++++++++++++++++ app/test-pmd/Makefile | 1 + app/test-pmd/meson.build | 3 +- app/test-pmd/parameters.c | 2 + app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 1 + doc/guides/rel_notes/release_20_08.rst | 6 + doc/guides/testpmd_app_ug/run_app.rst | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 10 +- 9 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 app/test-pmd/5tswap.c diff --git a/app/test-pmd/5tswap.c b/app/test-pmd/5tswap.c new file mode 100644 index 0000000..972f6b9 --- /dev/null +++ b/app/test-pmd/5tswap.c @@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2014-2020 Mellanox Technologies, Ltd + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "macswap_common.h" +#include "testpmd.h" + + +static inline void +swap_mac(struct rte_ether_hdr *eth_hdr) +{ + struct rte_ether_addr addr; + + /* Swap dest and src mac addresses. */ + rte_ether_addr_copy(ð_hdr->d_addr, &addr); + rte_ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr); + rte_ether_addr_copy(&addr, ð_hdr->s_addr); +} + +static inline void +swap_ipv4(struct rte_ipv4_hdr *ipv4_hdr) +{ + rte_be32_t addr; + + /* Swap dest and src ipv4 addresses. */ + addr = ipv4_hdr->src_addr; + ipv4_hdr->src_addr = ipv4_hdr->dst_addr; + ipv4_hdr->dst_addr = addr; +} + +static inline void +swap_ipv6(struct rte_ipv6_hdr *ipv6_hdr) +{ + uint8_t addr[16]; + + /* Swap dest and src ipv6 addresses. */ + memcpy(&addr, &ipv6_hdr->src_addr, 16); + memcpy(&ipv6_hdr->src_addr, &ipv6_hdr->dst_addr, 16); + memcpy(&ipv6_hdr->dst_addr, &addr, 16); +} + +static inline void +swap_tcp(struct rte_tcp_hdr *tcp_hdr) +{ + rte_be16_t port; + + /* Swap dest and src tcp port. */ + port = tcp_hdr->src_port; + tcp_hdr->src_port = tcp_hdr->dst_port; + tcp_hdr->dst_port = port; +} + +static inline void +swap_udp(struct rte_udp_hdr *udp_hdr) +{ + rte_be16_t port; + + /* Swap dest and src udp port */ + port = udp_hdr->src_port; + udp_hdr->src_port = udp_hdr->dst_port; + udp_hdr->dst_port = port; +} + +/* + * 5 tuple swap forwarding mode: Swap the source and the destination of layers + * 2,3,4. Swaps source and destination for MAC, IPv4/IPv6, UDP/TCP. + * Parses each layer and swaps it. When the next layer doesn't match it stops. + */ +static void +pkt_burst_5tuple_swap(struct fwd_stream *fs) +{ + struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_port *txp; + struct rte_mbuf *mb; + uint16_t next_proto; + uint64_t ol_flags; + uint16_t proto; + uint16_t nb_rx; + uint16_t nb_tx; + uint32_t retry; + + int i; + union { + struct rte_ether_hdr *eth; + struct rte_vlan_hdr *vlan; + struct rte_ipv4_hdr *ipv4; + struct rte_ipv6_hdr *ipv6; + struct rte_tcp_hdr *tcp; + struct rte_udp_hdr *udp; + uint8_t *byte; + } h; + +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + uint64_t start_tsc; + uint64_t end_tsc; + uint64_t core_cycles; +#endif + +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + start_tsc = rte_rdtsc(); +#endif + + /* + * Receive a burst of packets and forward them. + */ + nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst, + nb_pkt_per_burst); + if (unlikely(nb_rx == 0)) + return; + +#ifdef RTE_TEST_PMD_RECORD_BURST_STATS + fs->rx_burst_stats.pkt_burst_spread[nb_rx]++; +#endif + + fs->rx_packets += nb_rx; + txp = &ports[fs->tx_port]; + ol_flags = ol_flags_init(txp->dev_conf.txmode.offloads); + vlan_qinq_set(pkts_burst, nb_rx, ol_flags, + txp->tx_vlan_id, txp->tx_vlan_id_outer); + for (i = 0; i < nb_rx; i++) { + if (likely(i < nb_rx - 1)) + rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[i+1], + void *)); + mb = pkts_burst[i]; + h.eth = rte_pktmbuf_mtod(mb, struct rte_ether_hdr *); + proto = h.eth->ether_type; + swap_mac(h.eth); + mb->l2_len = sizeof(struct rte_ether_hdr); + h.eth++; + while (proto == RTE_BE16(RTE_ETHER_TYPE_VLAN) || + proto == RTE_BE16(RTE_ETHER_TYPE_QINQ)) { + proto = h.vlan->eth_proto; + h.vlan++; + mb->l2_len += sizeof(struct rte_vlan_hdr); + } + if (proto == RTE_BE16(RTE_ETHER_TYPE_IPV4)) { + swap_ipv4(h.ipv4); + next_proto = h.ipv4->next_proto_id; + mb->l3_len = (h.ipv4->version_ihl & 0x0f) * 4; + h.byte += mb->l3_len; + } else if (proto == RTE_BE16(RTE_ETHER_TYPE_IPV6)) { + swap_ipv6(h.ipv6); + next_proto = h.ipv6->proto; + h.ipv6++; + mb->l3_len = sizeof(struct rte_ipv6_hdr); + } else { + mbuf_field_set(mb, ol_flags); + continue; + } + if (next_proto == IPPROTO_UDP) { + swap_udp(h.udp); + mb->l4_len = sizeof(struct rte_udp_hdr); + } else if (next_proto == IPPROTO_TCP) { + swap_tcp(h.tcp); + mb->l4_len = (h.tcp->data_off & 0xf0) >> 2; + } + mbuf_field_set(mb, ol_flags); + } + nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx); + /* + * Retry if necessary + */ + if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) { + retry = 0; + while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) { + rte_delay_us(burst_tx_delay_time); + nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue, + &pkts_burst[nb_tx], nb_rx - nb_tx); + } + } + fs->tx_packets += nb_tx; +#ifdef RTE_TEST_PMD_RECORD_BURST_STATS + fs->tx_burst_stats.pkt_burst_spread[nb_tx]++; +#endif + if (unlikely(nb_tx < nb_rx)) { + fs->fwd_dropped += (nb_rx - nb_tx); + do { + rte_pktmbuf_free(pkts_burst[nb_tx]); + } while (++nb_tx < nb_rx); + } +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + end_tsc = rte_rdtsc(); + core_cycles = (end_tsc - start_tsc); + fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles); +#endif +} + +struct fwd_engine five_tuple_swap_fwd_engine = { + .fwd_mode_name = "5tswap", + .port_fwd_begin = NULL, + .port_fwd_end = NULL, + .packet_fwd = pkt_burst_5tuple_swap, +}; diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile index ea818de..b3ef205 100644 --- a/app/test-pmd/Makefile +++ b/app/test-pmd/Makefile @@ -33,6 +33,7 @@ SRCS-y += txonly.c SRCS-y += csumonly.c SRCS-y += icmpecho.c SRCS-y += noisy_vnf.c +SRCS-y += 5tswap.c SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ieee1588fwd.c SRCS-$(CONFIG_RTE_LIBRTE_BPF) += bpf_cmd.c SRCS-y += util.c diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build index 4872882..a47c7d1 100644 --- a/app/test-pmd/meson.build +++ b/app/test-pmd/meson.build @@ -4,7 +4,8 @@ # override default name to drop the hyphen name = 'testpmd' cflags += '-Wno-deprecated-declarations' -sources = files('cmdline.c', +sources = files('5tswap.c', + 'cmdline.c', 'cmdline_flow.c', 'cmdline_mtr.c', 'cmdline_tm.c', diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index f761e14..7cb0e3d 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -147,6 +147,8 @@ "is default).\n"); printf(" --forward-mode=N: set forwarding mode (N: %s).\n", list_pkt_forwarding_modes()); + printf(" --forward-mode=5tswap: set forwarding mode to " + "swap L2,L3,L4 for MAC, IPv4/IPv6 and TCP/UDP only.\n"); printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n"); printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n"); printf(" --rxq=N: set the number of RX queues per port to N.\n"); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 4989d22..4b23017 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -179,6 +179,7 @@ struct fwd_engine * fwd_engines[] = { &csum_fwd_engine, &icmp_echo_engine, &noisy_vnf_engine, + &five_tuple_swap_fwd_engine, #if defined RTE_LIBRTE_PMD_SOFTNIC &softnic_fwd_engine, #endif diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index a803750..3d8a9d5 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -266,6 +266,7 @@ struct fwd_engine { extern struct fwd_engine csum_fwd_engine; extern struct fwd_engine icmp_echo_engine; extern struct fwd_engine noisy_vnf_engine; +extern struct fwd_engine five_tuple_swap_fwd_engine; #ifdef SOFTNIC extern struct fwd_engine softnic_fwd_engine; #endif diff --git a/doc/guides/rel_notes/release_20_08.rst b/doc/guides/rel_notes/release_20_08.rst index 5cbc4ce..e403363 100644 --- a/doc/guides/rel_notes/release_20_08.rst +++ b/doc/guides/rel_notes/release_20_08.rst @@ -107,6 +107,12 @@ New Features * Dump ``rte_flow`` memory consumption. * Measure packet per second forwarding. +* **Added new testpmd forward mode.** + + Added new ``5tswap`` forward mode to testpmd. + the ``5tswap`` swaps source and destination in layers 2,3,4 + for ipv4 and ipv6 in L3 and UDP and TCP in L4. + Removed Items ------------- diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst index f169604..d1e4ee3 100644 --- a/doc/guides/testpmd_app_ug/run_app.rst +++ b/doc/guides/testpmd_app_ug/run_app.rst @@ -248,6 +248,7 @@ The command line options are: ieee1588 tm noisy + 5tswap * ``--rss-ip`` diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index a808b6a..73ac784 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -298,7 +298,7 @@ set fwd Set the packet forwarding mode:: testpmd> set fwd (io|mac|macswap|flowgen| \ - rxonly|txonly|csum|icmpecho|noisy) (""|retry) + rxonly|txonly|csum|icmpecho|noisy|5tswap) (""|retry) ``retry`` can be specified for forwarding engines except ``rx_only``. @@ -336,6 +336,14 @@ The available information categories are: Simulate more realistic behavior of a guest machine engaged in receiving and sending packets performing Virtual Network Function (VNF). +* ``5tswap``: Swap the source and destination of L2,L3,L4 if they exist. + + L2 swaps the source address and destination address of Ethernet, as same as ``macswap``. + + L3 swaps the source address and destination address of IP (v4 and v6). + + L4 swaps the source port and destination port of transport layer (TCP and UDP). + Example:: testpmd> set fwd rxonly