From patchwork Wed Jul 25 17:05:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naga Suresh Somarowthu X-Patchwork-Id: 43365 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B33212BAC; Wed, 25 Jul 2018 19:06:12 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C60441C01 for ; Wed, 25 Jul 2018 19:06:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2018 10:06:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,401,1526367600"; d="scan'208";a="57830398" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga008.fm.intel.com with ESMTP; 25 Jul 2018 10:06:09 -0700 Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com [10.102.246.100]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w6PH68di019263; Wed, 25 Jul 2018 18:06:08 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w6PH66QY008999; Wed, 25 Jul 2018 18:06:06 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with ? id w6PH66xq008995; Wed, 25 Jul 2018 18:06:06 +0100 From: Naga Suresh Somarowthu To: dev@dpdk.org Cc: remy.horton@intel.com, reshma.pattan@intel.com, Naga Suresh Somarowthu Date: Wed, 25 Jul 2018 18:05:57 +0100 Message-Id: <1532538360-8773-2-git-send-email-naga.sureshx.somarowthu@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1532538360-8773-1-git-send-email-naga.sureshx.somarowthu@intel.com> References: <1532429671-1606-1-git-send-email-naga.sureshx.somarowthu@intel.com> <1532538360-8773-1-git-send-email-naga.sureshx.somarowthu@intel.com> Subject: [dpdk-dev] [PATCH v6 1/4] test: add ring pmd based packet rx/tx for UT 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" Added ring pmd based packet rx/tx helper functions for verifying Latency, Bitrate and pdump lib UTs. Signed-off-by: Naga Suresh Somarowthu Reviewed-by: Reshma Pattan Reviewed-by: Anatoly Burakov --- test/test/Makefile | 1 + test/test/sample_packet_forward.c | 115 ++++++++++++++++++++++++++++++++++++++ test/test/sample_packet_forward.h | 40 +++++++++++++ 3 files changed, 156 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 e6967bab6..9f7d398e4 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -165,6 +165,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_REORDER) += test_reorder.c SRCS-y += virtual_pmd.c SRCS-y += packet_burst_generator.c +SRCS-y += sample_packet_forward.c SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y) diff --git a/test/test/sample_packet_forward.c b/test/test/sample_packet_forward.c new file mode 100644 index 000000000..467735264 --- /dev/null +++ b/test/test/sample_packet_forward.c @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "sample_packet_forward.h" +#include "test.h" + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int +test_ring_setup(struct rte_ring **ring, uint16_t *portid) +{ + *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ); + if (*ring == NULL) { + printf("%s() line %u: rte_ring_create R0 failed", + __func__, __LINE__); + return -1; + } + *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES, + ring, NUM_QUEUES, rte_socket_id()); + + return 0; +} + +/* Sample test to free the mempool */ +void +test_mp_free(struct rte_mempool *mp) +{ + rte_mempool_free(mp); +} + +/* Sample test to free the virtual rings */ +void +test_ring_free(struct rte_ring *rxtx) +{ + rte_ring_free(rxtx); +} + +/* Sample test to release the vdev */ +void +test_vdev_uninit(const char *vdev) +{ + rte_vdev_uninit(vdev); +} + +/* sample test to deallocate the allocated buffers */ +int +test_get_mempool(struct rte_mempool **mp, char *poolname) +{ + *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0, + RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); + if (*mp == NULL) + return -1; + return 0; +} + +/* sample test to allocate buffer for pkts */ +int +test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname) +{ + int ret = 0; + + ret = test_get_mempool(mp, poolname); + if (ret < 0) + return -1; + if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) { + printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__, + __LINE__); + return -1; + } + return 0; +} + +/* sample test to deallocate the allocated buffers */ +void +test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf) +{ + int itr = 0; + + for (itr = 0; itr < NUM_PACKETS; itr++) + rte_pktmbuf_free(pbuf[itr]); + rte_mempool_free(mp); +} + +/* Sample test to forward packets using virtual portids */ +int +test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id) +{ + /* send and receive packet and check for stats update */ + if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error sending packet to" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS) + < NUM_PACKETS) { + printf("%s() line %u: Error receiving packet from" + " port %d\n", __func__, __LINE__, portid); + return -1; + } + return 0; +} diff --git a/test/test/sample_packet_forward.h b/test/test/sample_packet_forward.h new file mode 100644 index 000000000..0f0ecf877 --- /dev/null +++ b/test/test/sample_packet_forward.h @@ -0,0 +1,40 @@ +/* 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_QUEUES 1 +#define NB_MBUF 512 + +#define NUM_PACKETS 10 + +/* Sample test to create virtual rings and tx,rx portid from rings */ +int test_ring_setup(struct rte_ring **ring, uint16_t *portid); + +/* Sample test to free the virtual rings */ +void test_ring_free(struct rte_ring *rxtx); + +/* Sample test to forward packet using virtual port id */ +int test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, + uint16_t queue_id); + +/* sample test to allocate buffer for pkts */ +int test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf, + char *poolname); + +/* Sample test to create the mempool */ +int test_get_mempool(struct rte_mempool **mp, char *poolname); + +/* sample test to deallocate the allocated buffers */ +void test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf); + +/* Sample test to free the mempool */ +void test_mp_free(struct rte_mempool *mp); + +/* Sample test to release the vdev */ +void test_vdev_uninit(const char *vdev); +#endif /* _SAMPLE_PACKET_FORWARD_H_ */