DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jananee Parthasarathy <jananeex.m.parthasarathy@intel.com>
To: dev@dpdk.org
Cc: remy.horton@intel.com, reshma.pattan@intel.com,
	Jananee Parthasarathy <jananeex.m.parthasarathy@intel.com>,
	Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com>
Subject: [dpdk-dev] [PATCH] add sample functions for packet forwarding
Date: Fri,  6 Jul 2018 18:07:15 +0100	[thread overview]
Message-ID: <1530896835-19629-1-git-send-email-jananeex.m.parthasarathy@intel.com> (raw)

From: Jananee Parthasarathy <jananeex.m.parthasarathy@intel.com> 

Add sample test functions for packet forwarding.
These can be used for unit test cases for
LatencyStats and BitrateStats libraries.

Signed-off-by: Chaitanya Babu Talluri <tallurix.chaitanya.babu@intel.com>
Reviewed-by: Reshma Pattan <reshma.pattan@intel.com>
---
 test/test/Makefile                |  1 +
 test/test/sample_packet_forward.c | 80 +++++++++++++++++++++++++++++++++++++++
 test/test/sample_packet_forward.h | 22 +++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 test/test/sample_packet_forward.c
 create mode 100644 test/test/sample_packet_forward.h

diff --git a/test/test/Makefile b/test/test/Makefile
index eccc8efcf..1e69f37a1 100644
--- a/test/test/Makefile
+++ b/test/test/Makefile
@@ -133,6 +133,7 @@ SRCS-y += test_version.c
 SRCS-y += test_func_reentrancy.c
 
 SRCS-y += test_service_cores.c
+SRCS-y += sample_packet_forward.c
 
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c
 SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c
diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c
new file mode 100644
index 000000000..6f66b83f8
--- /dev/null
+++ b/test/test/sample_packet_forward.c
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+
+#include <rte_memcpy.h>
+#include <rte_common.h>
+#include <rte_eth_ring.h>
+#include <rte_ethdev.h>
+
+#include "sample_packet_forward.h"
+#include "test.h"
+#include <rte_mbuf.h>
+
+#define NB_MBUF 512
+
+static struct rte_mempool *mp;
+uint16_t tx_portid, rx_portid;
+
+/* Sample test to create virtual rings and tx,rx portid from rings */
+int
+test_ring_setup(void)
+{
+	uint16_t socket_id = rte_socket_id();
+	struct rte_ring *rxtx[NUM_RINGS];
+	rxtx[0] = rte_ring_create("R0", RING_SIZE, socket_id,
+			RING_F_SP_ENQ|RING_F_SC_DEQ);
+	if (rxtx[0] == NULL) {
+		printf("%s() line %u: rte_ring_create R0 failed",
+				__func__, __LINE__);
+		return TEST_FAILED;
+	}
+	rxtx[1] = rte_ring_create("R1", RING_SIZE, socket_id,
+			RING_F_SP_ENQ|RING_F_SC_DEQ);
+	if (rxtx[1] == NULL) {
+		printf("%s() line %u: rte_ring_create R1 failed",
+				__func__, __LINE__);
+		return TEST_FAILED;
+	}
+	tx_portid = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx,
+			NUM_RINGS, SOCKET0);
+	rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx,
+			NUM_RINGS, SOCKET0);
+
+	return TEST_SUCCESS;
+}
+
+/* Sample test to forward packets using virtual portids */
+int
+test_packet_forward(void)
+{
+	struct rte_mbuf *pbuf[NUM_PACKETS];
+
+	mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32, 0,
+			RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
+	if (mp == NULL)
+		return -1;
+	if (rte_pktmbuf_alloc_bulk(mp, pbuf, NUM_PACKETS) != 0)
+		printf("%s() line %u: rte_pktmbuf_alloc_bulk failed"
+				, __func__, __LINE__);
+	/* send and receive packet and check for stats update */
+	if (rte_eth_tx_burst(tx_portid, 0, pbuf, NUM_PACKETS) !=
+			NUM_PACKETS) {
+		printf("%s() line %u: Error sending packet to"
+				" port %d\n", __func__, __LINE__,
+				tx_portid);
+		return TEST_FAILED;
+	}
+	if (rte_eth_rx_burst(rx_portid, 0, pbuf, NUM_PACKETS) !=
+			NUM_PACKETS) {
+		printf("%s() line %u: Error receiving packet from"
+				" port %d\n", __func__, __LINE__,
+				rx_portid);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h
new file mode 100644
index 000000000..464f97c33
--- /dev/null
+++ b/test/test/sample_packet_forward.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _SAMPLE_PACKET_FORWARD_H_
+#define _SAMPLE_PACKET_FORWARD_H_
+
+/* MACROS to support virtual ring creation */
+#define SOCKET0 0
+#define RING_SIZE 256
+#define NUM_RINGS 2
+
+#define NUM_PACKETS 10
+
+/* Sample test to create virtual rings and tx,rx portid from rings */
+int test_ring_setup(void);
+
+/* Sample test to forward packet using virtual port id */
+int test_packet_forward(void);
+
+#endif /* _SAMPLE_PACKET_FORWARD_H_ */
+
-- 
2.13.6

             reply	other threads:[~2018-07-06 17:07 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 17:07 Jananee Parthasarathy [this message]
2018-07-10  9:53 ` Pattan, Reshma
2018-07-12  8:53 ` [dpdk-dev] [PATCH v2] " Jananee Parthasarathy
2018-07-12 16:00   ` Pattan, Reshma
2018-07-16 16:00   ` [dpdk-dev] [PATCH v3] test: " Jananee Parthasarathy
2018-07-17  8:15     ` Pattan, Reshma
2018-07-17 10:00     ` [dpdk-dev] [PATCH v4] " Jananee Parthasarathy
2018-07-17 10:22       ` Burakov, Anatoly
2018-07-24 10:54       ` [dpdk-dev] [PATCH v5 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-07-24 10:54         ` [dpdk-dev] [PATCH v5 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu
2018-07-24 11:21           ` Burakov, Anatoly
2018-07-24 10:54         ` [dpdk-dev] [PATCH v5 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-07-24 10:54         ` [dpdk-dev] [PATCH v5 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-07-24 10:54         ` [dpdk-dev] [PATCH v5 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-07-24 12:27           ` Burakov, Anatoly
2018-07-25 17:05         ` [dpdk-dev] [PATCH v6 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-07-25 17:05           ` [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu
2018-07-26  9:59             ` Burakov, Anatoly
2018-07-25 17:05           ` [dpdk-dev] [PATCH v6 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-07-25 17:05           ` [dpdk-dev] [PATCH v6 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-07-25 17:06           ` [dpdk-dev] [PATCH v6 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-07-26 10:02             ` Burakov, Anatoly
2018-07-26 12:50           ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Naga Suresh Somarowthu
2018-07-26 12:50             ` [dpdk-dev] [PATCH v7 1/4] test: add ring pmd based packet rx/tx for UT Naga Suresh Somarowthu
2018-07-26 16:43               ` Pattan, Reshma
2018-07-27  7:40                 ` Burakov, Anatoly
2018-07-26 12:50             ` [dpdk-dev] [PATCH v7 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-07-26 12:50             ` [dpdk-dev] [PATCH v7 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-07-26 12:50             ` [dpdk-dev] [PATCH v7 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-07-26 16:04             ` [dpdk-dev] [PATCH v7 0/4] add unit tests for bitrate, latency and pdump libraries Pattan, Reshma
2018-07-27 14:26             ` [dpdk-dev] [PATCH v8 " Naga Suresh Somarowthu
2018-07-27 14:26               ` [dpdk-dev] [PATCH v8 1/4] test: add helper functions for tests using ring-PMD Rx/Tx Naga Suresh Somarowthu
2018-07-27 14:26               ` [dpdk-dev] [PATCH v8 2/4] test: add unit tests for bitrate library Naga Suresh Somarowthu
2018-07-27 14:26               ` [dpdk-dev] [PATCH v8 3/4] test: add unit tests for latencystats library Naga Suresh Somarowthu
2018-07-27 14:26               ` [dpdk-dev] [PATCH v8 4/4] test: add unit test for pdump library Naga Suresh Somarowthu
2018-07-31 14:57               ` [dpdk-dev] [PATCH v8 0/4] add unit tests for bitrate, latency and pdump libraries Thomas Monjalon
2018-07-31 16:43                 ` Pattan, Reshma

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=1530896835-19629-1-git-send-email-jananeex.m.parthasarathy@intel.com \
    --to=jananeex.m.parthasarathy@intel.com \
    --cc=dev@dpdk.org \
    --cc=remy.horton@intel.com \
    --cc=reshma.pattan@intel.com \
    --cc=tallurix.chaitanya.babu@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 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).