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 AC44743B0C; Tue, 13 Feb 2024 17:58:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22BE742E17; Tue, 13 Feb 2024 17:58:50 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by mails.dpdk.org (Postfix) with ESMTP id DC93D42E0C for ; Tue, 13 Feb 2024 17:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707843527; x=1739379527; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=/l0n/L5llVkSlKWeij28Iq4THUaw0tbbb8J1j3ujWjc=; b=j3sq57OuMN/ptsvp3rEM+A5hbGQzasD++0o0eUcVuU75oJcbQQR/thTS LE332S35x6lpW1CZwXG9AYcysJW8BSaGvAGsRXDCbcAf6oj7uzmy4ydQt h014u1oGWUo815GgEZzWQDi7VUB22jzU+IPzNHPrWOnvxOJDSW0UNqEUk 3RFniF/QFx4ev2I5To2Gxcm61ZAkgfWFm9AbU7xp6m7JtwIYZIuvW7asa JxpFAF0MZ1xY3XBaDIIzMGzf2+cqzsT3A78bZ/CTTS0MmzMFkbZKBJrX+ qM6tCS79OgrTTs+ESAP+sSBCBwcMsq1kfd/PmpV+TG45b0Dm4/Um+IK19 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="2000500" X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="2000500" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 08:57:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="2855757" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.184]) by fmviesa007.fm.intel.com with ESMTP; 13 Feb 2024 08:57:41 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 3/3] examples/pipeline: add example for IPv6 address swap Date: Tue, 13 Feb 2024 16:57:37 +0000 Message-Id: <20240213165737.1534180-4-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213165737.1534180-1-cristian.dumitrescu@intel.com> References: <20240213165737.1534180-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 swapping the two halves of the IPv6 source address. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/examples/ipv6_addr_swap.cli | 35 ++++++++ .../pipeline/examples/ipv6_addr_swap.spec | 83 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 examples/pipeline/examples/ipv6_addr_swap.cli create mode 100644 examples/pipeline/examples/ipv6_addr_swap.spec diff --git a/examples/pipeline/examples/ipv6_addr_swap.cli b/examples/pipeline/examples/ipv6_addr_swap.cli new file mode 100644 index 0000000000..a8c9c77e00 --- /dev/null +++ b/examples/pipeline/examples/ipv6_addr_swap.cli @@ -0,0 +1,35 @@ +; SPDX-License-Identifier: BSD-3-Clause +; Copyright(c) 2022 Intel Corporation + +# Example command line: +# ./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/ipv6_addr_swap.cli +# +# Once the application has started, the command to get the CLI prompt is: +# telnet 0.0.0.0 8086 + +; +; Pipeline code generation & shared object library build. +; +pipeline codegen ./examples/pipeline/examples/ipv6_addr_swap.spec /tmp/ipv6_addr_swap.c +pipeline libbuild /tmp/ipv6_addr_swap.c /tmp/ipv6_addr_swap.so + +; +; List of DPDK devices. +; +; Note: Customize the parameters below to match your setup. +; +mempool MEMPOOL0 meta 0 pkt 2176 pool 32K cache 256 numa 0 +ethdev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +ethdev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +ethdev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on +ethdev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on + +; +; List of pipelines. +; +pipeline PIPELINE0 build lib /tmp/ipv6_addr_swap.so io ./examples/pipeline/examples/ethdev.io numa 0 + +; +; Pipelines-to-threads mapping. +; +pipeline PIPELINE0 enable thread 1 diff --git a/examples/pipeline/examples/ipv6_addr_swap.spec b/examples/pipeline/examples/ipv6_addr_swap.spec new file mode 100644 index 0000000000..42f8216463 --- /dev/null +++ b/examples/pipeline/examples/ipv6_addr_swap.spec @@ -0,0 +1,83 @@ +; SPDX-License-Identifier: BSD-3-Clause +; Copyright(c) 2022 Intel Corporation + +; This simple example swaps the two halves of the IPv6 source address. +; +; It demonstrates how to operate with 128-bit fields (used to represent IPv6 addresses) by using +; 64-bit operations. +; +; Notes: +; +; 1. The 128-bit fields are always stored in network byte order (NBO), even when these fields are +; meta-data fields, so the instructions like "mov" or "movh" that accept a 128-bit operand and +; a 64-bit (or lesser size) operand require the latter to be also stored in NBO, i.e. it must +; be a header field. Hence, the 64-bit upper_half and lower_half fields below are stored in a +; header, and not in meta-data. +; +; 2. To write a IPv6 address, the lower half (bits 63-0) must be written first using the mov +; instruction, as it also fills the upper half (bits 127-64) with zeros, and then the upper +; half must me written using the movh instruction, as the movh instruction does not change the +; lower half. + +// +// Headers. +// +struct ethernet_h { + bit<48> dst_addr + bit<48> src_addr + bit<16> ethertype +} + +struct ipv6_h { + bit<32> version_traffic_class_flow_label + bit<16> payload_length + bit<8> next_header + bit<8> hop_limit + bit<128> src_addr + bit<128> dst_addr +} + +struct sandbox_h { + bit<64> upper_half + bit<64> lower_half +} + +header ethernet instanceof ethernet_h +header ipv6 instanceof ipv6_h +header tmp instanceof sandbox_h + +// +// Meta-data. +// +struct metadata_t { + bit<32> port +} + +metadata instanceof metadata_t + +// +// Pipeline. +// +apply { + // + // RX and parse. + // + rx m.port + extract h.ethernet + extract h.ipv6 + + // + // Swap the two halves of the IPv6 source address. + // + movh h.tmp.upper_half h.ipv6.src_addr + mov h.tmp.lower_half h.ipv6.src_addr + mov h.ipv6.src_addr h.tmp.upper_half + movh h.ipv6.src_addr h.tmp.lower_half + + // + // De-parse and TX. + // + emit h.ethernet + emit h.ipv6 + tx m.port +} -- 2.34.1