DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 5/5] examples/pipeline: add variable size headers example
Date: Tue, 27 Jul 2021 17:36:09 +0100	[thread overview]
Message-ID: <20210727163609.97769-5-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20210727163609.97769-1-cristian.dumitrescu@intel.com>

Added the files to illustrate the variable size header usage.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/examples/varbit.cli  | 35 ++++++++++
 examples/pipeline/examples/varbit.spec | 95 ++++++++++++++++++++++++++
 2 files changed, 130 insertions(+)
 create mode 100644 examples/pipeline/examples/varbit.cli
 create mode 100644 examples/pipeline/examples/varbit.spec

diff --git a/examples/pipeline/examples/varbit.cli b/examples/pipeline/examples/varbit.cli
new file mode 100644
index 0000000000..0589e32c15
--- /dev/null
+++ b/examples/pipeline/examples/varbit.cli
@@ -0,0 +1,35 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 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 port out 4 sink none
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/varbit.spec
+
+;
+; Pipelines-to-threads mapping.
+;
+thread 1 pipeline PIPELINE0 enable
diff --git a/examples/pipeline/examples/varbit.spec b/examples/pipeline/examples/varbit.spec
new file mode 100644
index 0000000000..cd49403fa9
--- /dev/null
+++ b/examples/pipeline/examples/varbit.spec
@@ -0,0 +1,95 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; This simple example illustrates how to work with variable size headers. The assumed input packet
+; is Ethernet/IPv4/UDP, with the IPv4 header containing between 0 and 40 bytes of options. To locate
+; the start of the UDP header, the size of the IPv4 header needs to be detected first, which is done
+; by reading the first byte of the IPv4 header that carries the 4-bit Internet Header Length (IHL)
+; field; this read is done with the "lookahead" instruction, which does not advance the extract
+; pointer within the input packet buffer. Once the size of the IPv4 header options is known for the
+; current packet, the IPv4 header is extracted by using the two-argument "extract" instruction. Then
+; the UDP header is extracted and modified.
+
+//
+// Headers
+//
+struct ethernet_h {
+	bit<48> dst_addr
+	bit<48> src_addr
+	bit<16> ethertype
+}
+
+struct ipv4_top_h {
+	bit<8> ver_ihl
+}
+
+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
+	varbit<320> options
+}
+
+struct udp_h {
+	bit<16> src_port
+	bit<16> dst_port
+	bit<16> length
+	bit<16> checksum
+}
+
+header ethernet instanceof ethernet_h
+header ipv4_top instanceof ipv4_top_h
+header ipv4 instanceof ipv4_h
+header udp instanceof udp_h
+
+//
+// Meta-data
+//
+struct metadata_t {
+	bit<32> port
+	bit<32> options_size
+}
+
+metadata instanceof metadata_t
+
+//
+// Pipeline.
+//
+apply {
+	rx m.port
+
+	// Extract the fixed size Ethernet header.
+	extract h.ethernet
+
+	// Extract the variable size IPv4 header with up to 10 options.
+	lookahead h.ipv4_top
+	mov m.options_size h.ipv4_top.ver_ihl
+	and m.options_size 0xF
+	sub m.options_size 5
+	shl m.options_size 2
+	extract h.ipv4 m.options_size
+
+	// Extract the fixed size UDP header.
+	extract h.udp
+
+	// Modify the UDP header.
+	mov h.udp.src_port 0xAABB
+	mov h.udp.dst_port 0xCCDD
+
+	// Decide the output port.
+	xor m.port 1
+
+	// Emit the Ethernet, IPv4 and UDP headers.
+	emit h.ethernet
+	emit h.ipv4
+	emit h.udp
+
+	tx m.port
+}
-- 
2.17.1


  parent reply	other threads:[~2021-07-27 16:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 16:36 [dpdk-dev] [PATCH 1/5] pipeline: prepare for variable size headers Cristian Dumitrescu
2021-07-27 16:36 ` [dpdk-dev] [PATCH 2/5] pipeline: add support " Cristian Dumitrescu
2021-07-27 16:36 ` [dpdk-dev] [PATCH 3/5] pipeline: add variable size headers extract instruction Cristian Dumitrescu
2021-07-27 16:36 ` [dpdk-dev] [PATCH 4/5] pipeline: add header look-ahead instruction Cristian Dumitrescu
2021-07-27 16:36 ` Cristian Dumitrescu [this message]
2021-07-27 17:43 ` [dpdk-dev] [PATCH V2 1/5] pipeline: prepare for variable size headers Cristian Dumitrescu
2021-07-27 17:43   ` [dpdk-dev] [PATCH V2 2/5] pipeline: add support " Cristian Dumitrescu
2021-07-27 17:43   ` [dpdk-dev] [PATCH V2 3/5] pipeline: add variable size headers extract instruction Cristian Dumitrescu
2021-07-27 17:43   ` [dpdk-dev] [PATCH V2 4/5] pipeline: add header look-ahead instruction Cristian Dumitrescu
2021-07-27 17:43   ` [dpdk-dev] [PATCH V2 5/5] examples/pipeline: add variable size headers example Cristian Dumitrescu
2021-09-27  7:16   ` [dpdk-dev] [PATCH V2 1/5] pipeline: prepare for variable size headers 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=20210727163609.97769-5-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).