DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [PATCH V4 2/2] examples/pipeline: support hash functions
Date: Wed,  4 May 2022 12:23:43 +0100	[thread overview]
Message-ID: <20220504112343.21723-2-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20220504112343.21723-1-cristian.dumitrescu@intel.com>

Add example for hash function operation.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
Change log:

V4:
-Removed redundant line in the CLI file.
-Added comment on the crc32 hash function in the .spec file.

 examples/pipeline/examples/hash_func.cli  |  34 +++++++
 examples/pipeline/examples/hash_func.spec | 107 ++++++++++++++++++++++
 2 files changed, 141 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..d65cd62d17
--- /dev/null
+++ b/examples/pipeline/examples/hash_func.cli
@@ -0,0 +1,34 @@
+; 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 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..a3275a17da
--- /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. Another available option is crc32.
+	//    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


  reply	other threads:[~2022-05-04 11:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-30 13:18 [PATCH 1/2] pipeline: " Cristian Dumitrescu
2022-04-30 13:18 ` [PATCH 2/2] examples/pipeline: " Cristian Dumitrescu
2022-04-30 13:33 ` [PATCH V2 1/2] pipeline: " Cristian Dumitrescu
2022-04-30 13:33   ` [PATCH V2 2/2] examples/pipeline: " Cristian Dumitrescu
2022-04-30 13:40   ` [PATCH V3 1/2] pipeline: " Cristian Dumitrescu
2022-04-30 13:40     ` [PATCH V3 2/2] examples/pipeline: " Cristian Dumitrescu
2022-05-04 11:23     ` [PATCH V4 1/2] pipeline: " Cristian Dumitrescu
2022-05-04 11:23       ` Cristian Dumitrescu [this message]
2022-05-20 22:31       ` [PATCH V5 " Cristian Dumitrescu
2022-05-20 22:31         ` [PATCH V5 2/2] examples/pipeline: " Cristian Dumitrescu
2022-06-01 14:24         ` [PATCH V5 1/2] pipeline: " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504112343.21723-2-cristian.dumitrescu@intel.com \
    --to=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).