From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6971243AC2; Thu, 8 Feb 2024 10:10:21 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D78E442E50; Thu, 8 Feb 2024 10:10:10 +0100 (CET) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2056.outbound.protection.outlook.com [40.107.95.56]) by mails.dpdk.org (Postfix) with ESMTP id 4012242E4C for ; Thu, 8 Feb 2024 10:10:09 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hNPh9rVHWcJmwbFU7p1+n31JIlDmwNkeP6lw0AV83zSiUVu4gZ53DnpuJrSmbnY9DH0Qs8Ztp6gkn36WO3YfWaQUl0gdNST9O0m5Kn4V5S+AqcRljNnxQIGF5Ka7oOyL2CXpfWe8lMg7NosfDMx02a1VBRiCTW39dc40n38zXu+n8HdloMvAoMOLQ7okldqqn/AMQkDs9ff1W+xcM8/4T3ZsCjxudvGNg41+RznrJNzS6ok6EuZiYgh3qmWXSG9YrFT4p5o4hui3I6Mbx6Vp8lvCOxdDEelHbSyv3mEWgx4hQyLEYOK58czCmyGVPZS1NZNjuNv1DjcJgtg/h86eWQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=azy/qu8V+sB1Uzb0EcPj6GkRuRjJIpAAUF5vA6P+Jb0=; b=CLA1rAgEbPXxH917ziQ4tH5jR5Zj2fmJl7ut2rjweEeKXvoIZVBxvITYRXnDtLcMG7mbfJEbAk0shLSXC1E7+McOZV+ZUNmVg4vlrJ6C3xJcOnEu7Aft+AvnkZlCFEp2I0nCEoUbITwESgiRr89Df3co890wwRHobxkCIjFQgISTp6pR19tzUWK2Vr7VB0gy9bjpNSMFnzgJ2OhLJf5VMQbLdeclQOEvhPCUJvZXqyoizXIy1Sjda8FsWFKpRZnWnJLTruqaQRtTrC/n8M+s7jHWkpptEKYWOKjOdzIx6eJzqylGFewPy2UXjO2bI8ASPwjCOTVnp3avXg/lPFRzjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=amd.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=azy/qu8V+sB1Uzb0EcPj6GkRuRjJIpAAUF5vA6P+Jb0=; b=nMR/qJU2yXkSlnrnYN4t3X2uFrMToyELpav/V7W+9BuH70HPSL8Pn/9LYLvx+DCbf28bBCbNZNVZ5pgm/z3cSK0FtjriLecmsxifeM+22TaAjHEFOId4SyiFUEiVb1jwGmm8XhK7zXWK4pwi1M7CprYoLzKM+NbRhg9k64c94TgfamJcFL4etzZFbEFNQF40zoaZEDkz/+cm2gV47GoUmpO6HNJ/BbfBsO4Wj7kweL3m+L6R32guE3Cdz8ca5gZfHwFzdalWfHkZZw7r815G+03Pp9tTYeMXWsmQKYsRP1njqmUfpT1hBVO0r6ykp2DeGCyAWWYfgCVMP3wsBebgig== Received: from BN9PR03CA0576.namprd03.prod.outlook.com (2603:10b6:408:10d::11) by SA0PR12MB7076.namprd12.prod.outlook.com (2603:10b6:806:2d5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.14; Thu, 8 Feb 2024 09:10:06 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:10d:cafe::82) by BN9PR03CA0576.outlook.office365.com (2603:10b6:408:10d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.39 via Frontend Transport; Thu, 8 Feb 2024 09:10:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Thu, 8 Feb 2024 09:10:05 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 8 Feb 2024 01:09:54 -0800 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 8 Feb 2024 01:09:49 -0800 From: Ori Kam To: , , , , , Aman Singh , "Yuying Zhang" CC: , , Subject: [PATCH v2 4/4] app/testpmd: add encap hash calculation Date: Thu, 8 Feb 2024 11:09:19 +0200 Message-ID: <20240208090919.11565-4-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208090919.11565-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240208090919.11565-1-orika@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468C:EE_|SA0PR12MB7076:EE_ X-MS-Office365-Filtering-Correlation-Id: fe1ee9ef-be12-4a34-9747-08dc2885bdde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 49bQ+G/+e2dbGu5xm8wD/2c2OB+CnSL8arlcTAvL3MGfH0uMqaB39otKG7Mrnii+xJRyT4RIIYiv/Di6RnUuC7nKarj2I7qFc/i3vka1KEJdwQLx2dM90Kd5A0tw8zLLzFA+jqG+An5xiUCEK9LQCCWWmvWLyUSPow63NapXHLRi2KGjGqNSeX7qtitsrX4DShU02BsnF+gpKXLIzp916VtME6hEqG2fdhSiJC6bQZsb+v21c5n0Y+MOyeTw362ydHhdf52qxmsH0hyhNe29JJtGYNER09NIUitErel80BnAltIMoX7BpcK/6zEa56WVA6xPgPMWjnVYjJEBrktPRbs0DbxkmAUTWZTCgPClxO5NFr0pud3iNLqU/FoTfVhg0BfJ2ioV/pN20ayDup8JQ12D6nqcC8Np4ZALEQYJhfYw02aO5+UPoCsl1SNyQ481mz2WqJ4Or1E6gYuwJUyheykTI1eNqel174UPD+AgIAu3wpeSQ2c3bLCdkVnC7kOOruvzVu4Yx7kFaFGaHE5S3YKKVZxQPAjoRJoXCWEIbHfppxxmqWLYjKG9ST33Eu6tPU14YBwjX1SB2vVwRl1iEh+CHmNEbJjEAMQCwyWn0B8= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(82310400011)(46966006)(36840700001)(40470700004)(16526019)(1076003)(6286002)(336012)(26005)(83380400001)(7636003)(356005)(82740400003)(2616005)(107886003)(2906002)(8936002)(7696005)(70586007)(4326008)(5660300002)(6666004)(8676002)(316002)(110136005)(54906003)(70206006)(86362001)(36756003)(478600001)(426003)(41300700001)(55016003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2024 09:10:05.9135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe1ee9ef-be12-4a34-9747-08dc2885bdde X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7076 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commits add support for calculating the encap hash. Command structure: flow hash {port} encap {target field} pattern {item} [/ {item} [...] ] / end Example: calculate hash to be used by VXLAN encapsulation. flow hash 0 encap hash_field_sport pattern ipv4 dst is 7.7.7.7 src is 8.8.8.8 / udp dst is 5678 src is 1234 / end Signed-off-by: Ori Kam Acked-by: Dariusz Sosnowski --- app/test-pmd/cmdline_flow.c | 57 +++++++++++++++++++-- app/test-pmd/config.c | 30 +++++++++++ app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 +++++++- 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 4062879552..a42f07276d 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -219,6 +219,10 @@ enum index { HASH_CALC_TABLE, HASH_CALC_PATTERN_INDEX, HASH_CALC_PATTERN, + HASH_CALC_ENCAP, + HASH_CALC_DEST, + ENCAP_HASH_FIELD_SRC_PORT, + ENCAP_HASH_FIELD_GRE_FLOW_ID, /* Tunnel arguments. */ TUNNEL_CREATE, @@ -1192,6 +1196,8 @@ struct buffer { uint32_t pattern_n; uint32_t actions_n; uint8_t *data; + enum rte_flow_encap_hash_field field; + uint8_t encap_hash; } vc; /**< Validate/create arguments. */ struct { uint64_t *rule; @@ -2550,6 +2556,18 @@ static const enum index action_represented_port[] = { ZERO, }; +static const enum index next_hash_subcmd[] = { + HASH_CALC_TABLE, + HASH_CALC_ENCAP, + ZERO, +}; + +static const enum index next_hash_encap_dest_subcmd[] = { + ENCAP_HASH_FIELD_SRC_PORT, + ENCAP_HASH_FIELD_GRE_FLOW_ID, + ZERO, +}; + static int parse_set_raw_encap_decap(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -3789,7 +3807,7 @@ static const struct token token_list[] = { [HASH] = { .name = "hash", .help = "calculate hash for a given pattern in a given template table", - .next = NEXT(NEXT_ENTRY(HASH_CALC_TABLE), NEXT_ENTRY(COMMON_PORT_ID)), + .next = NEXT(next_hash_subcmd, NEXT_ENTRY(COMMON_PORT_ID)), .args = ARGS(ARGS_ENTRY(struct buffer, port)), .call = parse_hash, }, @@ -3803,6 +3821,12 @@ static const struct token token_list[] = { args.vc.table_id)), .call = parse_hash, }, + [HASH_CALC_ENCAP] = { + .name = "encap", + .help = "calculates encap hash", + .next = NEXT(next_hash_encap_dest_subcmd), + .call = parse_hash, + }, [HASH_CALC_PATTERN_INDEX] = { .name = "pattern_template", .help = "specify pattern template id", @@ -3812,6 +3836,18 @@ static const struct token token_list[] = { args.vc.pat_templ_id)), .call = parse_hash, }, + [ENCAP_HASH_FIELD_SRC_PORT] = { + .name = "hash_field_sport", + .help = "the encap hash field is src port", + .next = NEXT(NEXT_ENTRY(ITEM_PATTERN)), + .call = parse_hash, + }, + [ENCAP_HASH_FIELD_GRE_FLOW_ID] = { + .name = "hash_field_flow_id", + .help = "the encap hash field is NVGRE flow id", + .next = NEXT(NEXT_ENTRY(ITEM_PATTERN)), + .call = parse_hash, + }, /* Top-level command. */ [INDIRECT_ACTION] = { .name = "indirect_action", @@ -10691,6 +10727,15 @@ parse_hash(struct context *ctx, const struct token *token, ctx->object = out->args.vc.pattern; ctx->objmask = NULL; return len; + case HASH_CALC_ENCAP: + out->args.vc.encap_hash = 1; + return len; + case ENCAP_HASH_FIELD_SRC_PORT: + out->args.vc.field = RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT; + return len; + case ENCAP_HASH_FIELD_GRE_FLOW_ID: + out->args.vc.field = RTE_FLOW_ENCAP_HASH_FIELD_NVGRE_FLOW_ID; + return len; default: return -1; } @@ -12651,9 +12696,13 @@ cmd_flow_parsed(const struct buffer *in) port_queue_flow_pull(in->port, in->queue); break; case HASH: - port_flow_hash_calc(in->port, in->args.vc.table_id, - in->args.vc.pat_templ_id, - in->args.vc.pattern); + if (!in->args.vc.encap_hash) + port_flow_hash_calc(in->port, in->args.vc.table_id, + in->args.vc.pat_templ_id, + in->args.vc.pattern); + else + port_flow_hash_calc_encap(in->port, in->args.vc.field, + in->args.vc.pattern); break; case QUEUE_AGED: port_queue_flow_aged(in->port, in->queue, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index cad7537bc6..e26b5bd18d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3339,6 +3339,36 @@ port_flow_hash_calc(portid_t port_id, uint32_t table_id, return 0; } +/** Calculate the encap hash result for a given pattern. */ +int +port_flow_hash_calc_encap(portid_t port_id, + enum rte_flow_encap_hash_field encap_hash_field, + const struct rte_flow_item pattern[]) +{ + struct rte_flow_error error; + int ret = 0; + uint16_t hash = 0; + uint8_t len = encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ? 2 : 1; + + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) { + printf("Failed to calculate encap hash - not a valid port"); + return -EINVAL; + } + + ret = rte_flow_calc_encap_hash(port_id, pattern, encap_hash_field, len, + (uint8_t *)&hash, &error); + if (ret < 0) { + printf("Failed to calculate encap hash"); + return ret; + } + if (encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT) + printf("encap hash result %#x\n", hash); + else + printf("encap hash result %#x\n", *(uint8_t *)&hash); + return 0; +} + /** Pull queue operation results from the queue. */ static int port_queue_aged_flow_destroy(portid_t port_id, queueid_t queue_id, diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 9b10a9ea1c..e18546c46e 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -1016,6 +1016,9 @@ int port_queue_flow_push(portid_t port_id, queueid_t queue_id); int port_queue_flow_pull(portid_t port_id, queueid_t queue_id); int port_flow_hash_calc(portid_t port_id, uint32_t table_id, uint8_t pattern_template_index, const struct rte_flow_item pattern[]); +int port_flow_hash_calc_encap(portid_t port_id, + enum rte_flow_encap_hash_field encap_hash_field, + const struct rte_flow_item pattern[]); void port_queue_flow_aged(portid_t port_id, uint32_t queue_id, uint8_t destroy); int port_flow_validate(portid_t port_id, const struct rte_flow_attr *attr, diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 38ab421547..37a508c967 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3297,7 +3297,7 @@ The usual error message is shown when operations results cannot be pulled:: Calculating hash ~~~~~~~~~~~~~~~~ -``flow hash`` calculates the hash for a given pattern. +``flow hash {port_id} template_table`` calculates the hash for a given pattern. It is bound to ``rte_flow_calc_table_hash()``:: flow hash {port_id} template_table {table_id} @@ -3316,6 +3316,25 @@ Otherwise, it will show an error message of the form:: This command uses the same pattern items as ``flow create``, their format is described in `Creating flow rules`_. + +Simulate encap hash calculation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``flow hash {port_id} encap`` adds hash query, that returns the hash value +that the HW will calculate when encapsulating a packet. + + flow hash {port_id} encap {target field} pattern {item} [/ {item} [...]] / end + +If successful, it will show:: + + encap hash result #[...] + +The value will be shown as uint16_t without endian conversion. + +Otherwise it will show an error message of the form:: + + Failed to calculate encap hash - [...] + Creating a tunnel stub for offload ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 2.34.1