All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Fu <patrick.fu@intel.com>
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
Subject: [dpdk-dev] [PATCH v1 2/3] lib/mirror: add port based mirroring
Date: Wed,  9 Sep 2020 08:22:46 +0800	[thread overview]
Message-ID: <20200909002247.864844-3-patrick.fu@intel.com> (raw)
In-Reply-To: <20200909002247.864844-1-patrick.fu@intel.com>

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 <liang-min.wang@intel.com>
Signed-off-by: Patrick Fu <patrick.fu@intel.com>
Signed-off-by: Timothy Miskell <timothy.miskell@intel.com>
---
 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


  parent reply	other threads:[~2020-09-09  0:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09  0:22 [dpdk-dev] [PATCH v1 0/3] lib: introduce traffic mirroring lib Patrick Fu
2020-09-09  0:22 ` [dpdk-dev] [PATCH v1 1/3] lib/mirror: introduce traffic mirror API Patrick Fu
2020-09-09  1:09   ` Wang, Haiyue
2020-09-09  6:02     ` Fu, Patrick
2020-09-21 15:26   ` MEHAN, MUNISH
2020-09-09  0:22 ` Patrick Fu [this message]
2020-09-09  0:22 ` [dpdk-dev] [PATCH v1 3/3] lib/mirror: add flow based mirroring Patrick Fu
2020-09-22  7:40 ` [dpdk-dev] [PATCH v1 0/3] lib: introduce traffic mirroring lib 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=20200909002247.864844-3-patrick.fu@intel.com \
    --to=patrick.fu@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=cunming.liang@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=liang-min.wang@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=mm6021@att.com \
    --cc=thomas@monjalon.net \
    --cc=timothy.miskell@intel.com \
    --cc=zhihong.wang@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.