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 7CA47A0509; Wed, 6 Apr 2022 20:49:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A5B04286C; Wed, 6 Apr 2022 20:48:46 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 28A6042852 for ; Wed, 6 Apr 2022 20:48:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649270922; x=1680806922; h=from:to:subject:date:message-id:in-reply-to:references; bh=U4Qlg0IWYbEdx/jU7CD9AxbwIaIdcPIzbDwiHRBva0k=; b=k6CfUAdzk1z32hZcbLhkFFq4RCUNS359TF9/yStHVWkOZiOpqPR6Kz7z JTtTKNx3rK8DmJotFDk1KJjEVMdCMfN0fAxYaFUEMG8uy5vGT5y7tTUe2 cDeuAc9gkatoFEShLlYAwt9IyZ+q026h8hihsx/aew49XdWbDezIRqSW3 r7Fbf2wMzKxUgjlKbFpc52Cv79m7oQ2REXYvfS4s16fH/3VZb7ei51dvN RZkzNJUXQuUKPPGxFwOuhlh1T+CQrz+MgkonvOqwFKCpH4BxFNXE3stOV +RjQXI4KW2trUNhXN7PsU2TxPY8B2VdwtwmmKwIYT0dZxdN1K1IPwA2fK Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="261121845" X-IronPort-AV: E=Sophos;i="5.90,240,1643702400"; d="scan'208";a="261121845" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2022 11:48:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,240,1643702400"; d="scan'208";a="642173087" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.223.107]) by FMSMGA003.fm.intel.com with ESMTP; 06 Apr 2022 11:48:40 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH V4 4/6] examples/pipeline: add packet mirroring example Date: Wed, 6 Apr 2022 19:48:34 +0100 Message-Id: <20220406184836.72784-4-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220406184836.72784-1-cristian.dumitrescu@intel.com> References: <20220405213632.48028-1-cristian.dumitrescu@intel.com> <20220406184836.72784-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 program to illustrate packet mirroring. Signed-off-by: Cristian Dumitrescu --- examples/pipeline/examples/mirroring.cli | 43 ++++++++++++ examples/pipeline/examples/mirroring.spec | 80 +++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 examples/pipeline/examples/mirroring.cli create mode 100644 examples/pipeline/examples/mirroring.spec diff --git a/examples/pipeline/examples/mirroring.cli b/examples/pipeline/examples/mirroring.cli new file mode 100644 index 0000000000..46d57db4ec --- /dev/null +++ b/examples/pipeline/examples/mirroring.cli @@ -0,0 +1,43 @@ +; 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/mirroring.spec + +; +; Packet mirroring sessions. +; +pipeline PIPELINE0 mirror session 0 port 1 clone fast truncate 0 +pipeline PIPELINE0 mirror session 1 port 2 clone slow truncate 0 +pipeline PIPELINE0 mirror session 2 port 3 clone slow truncate 64 +pipeline PIPELINE0 mirror session 3 port 0 clone slow truncate 128 + +; +; Pipelines-to-threads mapping. +; +thread 1 pipeline PIPELINE0 enable diff --git a/examples/pipeline/examples/mirroring.spec b/examples/pipeline/examples/mirroring.spec new file mode 100644 index 0000000000..faf5d60e96 --- /dev/null +++ b/examples/pipeline/examples/mirroring.spec @@ -0,0 +1,80 @@ +; SPDX-License-Identifier: BSD-3-Clause +; Copyright(c) 2022 Intel Corporation + +; This simple example illustrates how to perform packet mirroring. The "mirror" instruction is used +; to flag the current packet for mirroring, which means that at TX time, before the current packet +; is sent out, it will first be cloned (using either the fast or the slow/deep cloning method) and +; the clone packet sent out on the output port specified by the mirror session. +; +; In this example, the UDP packets with destination port 5000 are mirrored to the output port +; specified by the mirror session 0, while the rest of the packets are not mirrored. Therefore, for +; every UDP input packet with this specific destination port there will be two output packets (the +; current packet and its clone packet), while for every other input packet there will be a single +; output packet. + +// +// 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> mirror_slot + bit<32> mirror_session +} + +metadata instanceof metadata_t + +// +// Pipeline. +// +apply { + rx m.port + extract h.ethernet + extract h.ipv4 + extract h.udp + + // + // Mark for mirroring all packets with UDP destination port of 5000. + // + MIRROR_UDP_DST_PORT_5000 : jmpneq EMIT h.udp.dst_port 5000 + mov m.mirror_slot 0 + mov m.mirror_session 0 + mirror m.mirror_slot m.mirror_session + + EMIT : emit h.ethernet + emit h.ipv4 + emit h.udp + tx m.port +} -- 2.17.1