From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 25660A04B1; Wed, 9 Sep 2020 02:28:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AA12D1C0CE; Wed, 9 Sep 2020 02:28:34 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 5D45E1C0D0 for ; Wed, 9 Sep 2020 02:28:32 +0200 (CEST) IronPort-SDR: n2x4sUSb4TKiQedckb7HsHeRJgIE9TpXVOHot+KI0xgoeYczQ4eGG9J92RfkwEoWfyS+wCsXIQ W4iO1ZyL3y/g== X-IronPort-AV: E=McAfee;i="6000,8403,9738"; a="222453008" X-IronPort-AV: E=Sophos;i="5.76,407,1592895600"; d="scan'208";a="222453008" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2020 17:28:31 -0700 IronPort-SDR: 6eJCrl5Ltrt05oysoSnkX2D9vQoN0VfU2dxPeoFRleh5hW5DskErjcaneeilYlATThM2Nzl0eN R4fxo8y82ZyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,407,1592895600"; d="scan'208";a="286051353" Received: from npg-dpdk-patrickfu-casc2.sh.intel.com ([10.67.119.92]) by fmsmga008.fm.intel.com with ESMTP; 08 Sep 2020 17:28:28 -0700 From: Patrick Fu To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@intel.com, maxime.coquelin@redhat.com, bruce.richardson@intel.com, mm6021@att.com, zhihong.wang@intel.com, liang-min.wang@intel.com, konstantin.ananyev@intel.com, timothy.miskell@intel.com, cunming.liang@intel.com, patrick.fu@intel.com Date: Wed, 9 Sep 2020 08:22:46 +0800 Message-Id: <20200909002247.864844-3-patrick.fu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200909002247.864844-1-patrick.fu@intel.com> References: <20200909002247.864844-1-patrick.fu@intel.com> Subject: [dpdk-dev] [PATCH v1 2/3] lib/mirror: add port based mirroring X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch add port based mirroring support for the mirror lib. The port based mirroring is unconditional traffic mirroring between 2 ethdev ports. Signed-off-by: Liang-min Wang Signed-off-by: Patrick Fu Signed-off-by: Timothy Miskell --- lib/librte_mirror/rte_mirror.c | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/librte_mirror/rte_mirror.c b/lib/librte_mirror/rte_mirror.c index f2a85976a..d2c0d8eab 100644 --- a/lib/librte_mirror/rte_mirror.c +++ b/lib/librte_mirror/rte_mirror.c @@ -196,6 +196,57 @@ mirror_pkt_update(struct rte_mbuf *pkt, uint16_t dst_vlan_id) rte_mbuf_refcnt_update(pkt, 1); } +static inline uint16_t +mirror_port_cb(uint16_t qidx, struct rte_mbuf **pkts, + uint16_t nb_pkts, void *user_params) +{ + struct rte_mirror_param *data = user_params; + uint16_t i, dst_qidx; + uint16_t pkt_trans; + uint16_t dst_port_id = data->dst_port_id; + uint16_t dst_vlan_id = data->dst_vlan_id; + + if (nb_pkts == 0) + return 0; + + for (i = 0; i < nb_pkts; i++) + mirror_pkt_update(pkts[i], dst_vlan_id); + + dst_qidx = data->n_dst_queue > qidx ? qidx : data->n_dst_queue - 1; + + rte_spinlock_lock(&data->locks[dst_qidx]); + pkt_trans = rte_eth_tx_burst(dst_port_id, dst_qidx, pkts, nb_pkts); + rte_spinlock_unlock(&data->locks[dst_qidx]); + if (pkt_trans != nb_pkts) + RTE_ETHDEV_LOG(ERR, "%d packets for tapping but " + "only %d packet get through\n", nb_pkts, pkt_trans); + + for (i = 0; i < nb_pkts; i++) + pkts[i]->ol_flags &= ~VLAN_INSERT_FLAG; + + while (unlikely(pkt_trans < nb_pkts)) { + rte_pktmbuf_free(pkts[pkt_trans]); + pkt_trans++; + } + + return nb_pkts; +} + +static uint16_t +mirror_rx_port_cb(uint16_t port_id __rte_unused, uint16_t qidx, + struct rte_mbuf **pkts, uint16_t nb_pkts, + uint16_t max_pkts __rte_unused, void *user_params) +{ + return mirror_port_cb(qidx, pkts, nb_pkts, user_params); +} + +static uint16_t +mirror_tx_port_cb(uint16_t port_id __rte_unused, uint16_t qidx, + struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params) +{ + return mirror_port_cb(qidx, pkts, nb_pkts, user_params); +} + int rte_mirror_offload_register(uint16_t src_port, struct rte_mirror_param *param, int tx_cb) @@ -221,6 +272,12 @@ rte_mirror_offload_register(uint16_t src_port, } switch (data->mirror_type) { + case rte_mirror_type_port: + if (tx_cb) + tx_fn = mirror_tx_port_cb; + else + rx_fn = mirror_rx_port_cb; + break; default: MIRROR_LOG(ERR, "Un-supported mirror offloading type!!!\n"); return -ENOTSUP; -- 2.18.4