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 10105A0507; Sat, 30 Apr 2022 15:34:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F440410E6; Sat, 30 Apr 2022 15:33:55 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 8BC5C4069D for ; Sat, 30 Apr 2022 15:33:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651325633; x=1682861633; h=from:to:subject:date:message-id:in-reply-to:references; bh=LW2rvRnIbEG748B3X1gxMmKEh76nSL5fhqyN5vCwykM=; b=iQRpgU/V1wisECVPPXaEmLzSEMCY0O/8T0iLhZJi6PWJLNep+ILJ502z S4/aXhD4n4D5BT0S9Eigclx6i/gdZyxiCtLoHtB0o1xdvRLidxgU4lNhh qzdJ1bOsStf40zVX5Vc93PjkzD+UaXJ58IdpQoBtxfPNJOLIFqkC5NRUg ZW+/btRbvsesFi6mw9HB6eFZnoAGQmpFvRNhJUq/SKf7s5L3YomgX/AIH NInhagqXC2cyx65HM1K1vXjdXTHZQfIpvUfHb03GVw8da8OeVxWnrFqtq /zA5UAkTfjJM1BhCUjXTsqcueVi4yfs2R8gEAtVueaWzqc+eY3c8amdFU g==; X-IronPort-AV: E=McAfee;i="6400,9594,10332"; a="267043030" X-IronPort-AV: E=Sophos;i="5.91,188,1647327600"; d="scan'208";a="267043030" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2022 06:33:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,188,1647327600"; d="scan'208";a="597823108" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by orsmga001.jf.intel.com with ESMTP; 30 Apr 2022 06:33:51 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V2 2/2] examples/pipeline: support hash functions Date: Sat, 30 Apr 2022 14:33:49 +0100 Message-Id: <20220430133349.80152-2-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220430133349.80152-1-cristian.dumitrescu@intel.com> References: <20220430131837.79733-1-cristian.dumitrescu@intel.com> <20220430133349.80152-1-cristian.dumitrescu@intel.com> 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 Add example for hash function operation. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/examples/hash_func.cli | 35 +++++++ examples/pipeline/examples/hash_func.spec | 107 ++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 examples/pipeline/examples/hash_func.cli create mode 100644 examples/pipeline/examples/hash_func.spec diff --git a/examples/pipeline/examples/hash_func.cli b/examples/pipeline/examples/hash_func.cli new file mode 100644 index 0000000000..df6e6e6205 --- /dev/null +++ b/examples/pipeline/examples/hash_func.cli @@ -0,0 +1,35 @@ +; SPDX-License-Identifier: BSD-3-Clause +; Copyright(c) 2022 Intel Corporation + +; +; Customize the LINK parameters to match your setup. +; +mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0 + +link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on + +; +; PIPELINE0 setup. +; +pipeline PIPELINE0 create 0 +pipeline PIPELINE0 mirror slots 4 sessions 16 + +pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32 +pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32 +pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32 +pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32 + +pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32 +pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32 +pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32 +pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32 + +pipeline PIPELINE0 build ./examples/pipeline/examples/hash_func.spec + +; +; Pipelines-to-threads mapping. +; +thread 1 pipeline PIPELINE0 enable diff --git a/examples/pipeline/examples/hash_func.spec b/examples/pipeline/examples/hash_func.spec new file mode 100644 index 0000000000..22c9e13411 --- /dev/null +++ b/examples/pipeline/examples/hash_func.spec @@ -0,0 +1,107 @@ +; SPDX-License-Identifier: BSD-3-Clause +; Copyright(c) 2022 Intel Corporation + +; This simple example illustrates how to compute a hash signature over an n-tuple set of fields read +; from the packet headers and/or the packet meta-data by using the "hash" instruction. In this +; specific example, the n-tuple is the classical DiffServ 5-tuple. + +// +// Headers +// +struct ethernet_h { + bit<48> dst_addr + bit<48> src_addr + bit<16> ethertype +} + +struct ipv4_h { + bit<8> ver_ihl + bit<8> diffserv + bit<16> total_len + bit<16> identification + bit<16> flags_offset + bit<8> ttl + bit<8> protocol + bit<16> hdr_checksum + bit<32> src_addr + bit<32> dst_addr +} + +struct udp_h { + bit<16> src_port + bit<16> dst_port + bit<16> length + bit<16> checksum +} + +header ethernet instanceof ethernet_h +header ipv4 instanceof ipv4_h +header udp instanceof udp_h + +// +// Meta-data. +// +struct metadata_t { + bit<32> port + bit<32> src_addr + bit<32> dst_addr + bit<8> protocol + bit<16> src_port + bit<16> dst_port + bit<32> hash +} + +metadata instanceof metadata_t + +// +// Pipeline. +// +apply { + // + // RX and parse. + // + rx m.port + extract h.ethernet + extract h.ipv4 + extract h.udp + + // + // Prepare the n-tuple to be hashed in meta-data. + // + // This is required when: + // a) The n-tuple fields are part of different headers; + // b) Some n-tuple fields come from headers and some from meta-data. + // + mov m.src_addr h.ipv4.src_addr + mov m.dst_addr h.ipv4.dst_addr + mov m.protocol h.ipv4.protocol + mov m.src_port h.udp.src_port + mov m.dst_port h.udp.dst_port + + // + // Compute the hash over the n-tuple. + // + // Details: + // a) Hash function: jhash; + // b) Destination (i.e. hash result): m.hash; + // c) Source (i.e. n-tuple to be hashed): The 5-tuple formed by the meta-data fields + // (m.src_addr, m.dst_addr, m.protocol, m.src_port, m.dst_port). Only the first and + // the last n-tuple fields are specified in the hash instruction, but all the fields + // in between are part of the n-tuple to be hashed. + // + hash jhash m.hash m.src_addr m.dst_port + + // + // Use the computed hash to create a uniform distribution of pkts across the 4 output ports. + // + and m.hash 3 + mov m.port m.hash + + // + // De-parse and TX. + // + emit h.ethernet + emit h.ipv4 + emit h.udp + tx m.port +} -- 2.17.1