From patchwork Fri Jul 6 17:07:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jananee Parthasarathy X-Patchwork-Id: 42537 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 C1EAA1BEA1; Fri, 6 Jul 2018 19:07:34 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id E216E1BE8B for ; Fri, 6 Jul 2018 19:07:33 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 10:07:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,317,1526367600"; d="scan'208";a="54943723" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga008.jf.intel.com with ESMTP; 06 Jul 2018 10:07:28 -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 w66H7Spi029934; Fri, 6 Jul 2018 18:07:28 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id w66H7RLF019708; Fri, 6 Jul 2018 18:07:27 +0100 Received: (from jmparthx@localhost) by wgcvswdev001.ir.intel.com with ? id w66H7RUH019704; Fri, 6 Jul 2018 18:07:27 +0100 From: Jananee Parthasarathy To: dev@dpdk.org Cc: remy.horton@intel.com, reshma.pattan@intel.com, Jananee Parthasarathy , Chaitanya Babu Talluri Date: Fri, 6 Jul 2018 18:07:15 +0100 Message-Id: <1530896835-19629-1-git-send-email-jananeex.m.parthasarathy@intel.com> X-Mailer: git-send-email 1.7.12.2 Subject: [dpdk-dev] [PATCH] add sample functions for packet forwarding 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" From: Jananee Parthasarathy 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 Reviewed-by: Reshma Pattan --- 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 +#include +#include + +#include +#include +#include +#include + +#include "sample_packet_forward.h" +#include "test.h" +#include + +#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_ */ +