[v2] add sample functions for packet forwarding
Checks
Commit Message
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>
---
v2: SOCKET0 is removed and NUM_QUEUES is used accordingly
---
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
Comments
Hi Jananee,
> -----Original Message-----
> From: Parthasarathy, JananeeX M
> Sent: Thursday, July 12, 2018 9:53 AM
> To: dev@dpdk.org
> Cc: Horton, Remy <remy.horton@intel.com>; Pattan, Reshma
> <reshma.pattan@intel.com>; Parthasarathy, JananeeX M
> <jananeex.m.parthasarathy@intel.com>; Chaitanya Babu, TalluriX
> <tallurix.chaitanya.babu@intel.com>
> Subject: [PATCH v2] add sample functions for packet forwarding
>
I could apply the patch succefully but there was a warning, just check is the white line can be removed.
git apply v2-add-sample-functions-for-packet-forwarding
v2-add-sample-functions-for-packet-forwarding:160: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
> + 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_QUEUES, rxtx,
> + NUM_QUEUES, socket_id);
> + rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_QUEUES, rxtx,
> + NUM_QUEUES, socket_id);
Also can you see if you can create only one port using rings instead of 2 and use it for
two ports rx_port id and tx_ports ids? And will that fit for all the UTs that you are writing.
Thanks,
Reshma
@@ -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
new file mode 100644
@@ -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_QUEUES, rxtx,
+ NUM_QUEUES, socket_id);
+ rx_portid = rte_eth_from_rings("net_ringb", rxtx, NUM_QUEUES, rxtx,
+ NUM_QUEUES, socket_id);
+
+ 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;
+}
new file mode 100644
@@ -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 RING_SIZE 256
+#define NUM_RINGS 2
+#define NUM_QUEUES 1
+
+#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_ */
+