1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_eth_ring.h>
9 #include <rte_ethdev.h>
11 #include <rte_bus_vdev.h>
12 #include "rte_lcore.h"
13 #include "rte_mempool.h"
16 #include "sample_packet_forward.h"
18 /* Sample test to create virtual rings and tx,rx portid from rings */
20 test_ring_setup(struct rte_ring **ring, uint16_t *portid)
22 *ring = rte_ring_create("R0", RING_SIZE, rte_socket_id(),
23 RING_F_SP_ENQ | RING_F_SC_DEQ);
25 printf("%s() line %u: rte_ring_create R0 failed",
29 *portid = rte_eth_from_rings("net_ringa", ring, NUM_QUEUES,
30 ring, NUM_QUEUES, rte_socket_id());
35 /* Sample test to free the mempool */
37 test_mp_free(struct rte_mempool *mp)
42 /* Sample test to free the virtual rings */
44 test_ring_free(struct rte_ring *rxtx)
49 /* Sample test to release the vdev */
51 test_vdev_uninit(const char *vdev)
53 rte_vdev_uninit(vdev);
56 /* sample test to allocate the mempool */
58 test_get_mempool(struct rte_mempool **mp, char *poolname)
60 *mp = rte_pktmbuf_pool_create(poolname, NB_MBUF, 32, 0,
61 RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
67 /* sample test to allocate buffer for pkts */
69 test_get_mbuf_from_pool(struct rte_mempool **mp, struct rte_mbuf **pbuf,
74 ret = test_get_mempool(mp, poolname);
77 if (rte_pktmbuf_alloc_bulk(*mp, pbuf, NUM_PACKETS) != 0) {
78 printf("%s() line %u: rte_pktmbuf_alloc_bulk failed", __func__,
85 /* sample test to deallocate the allocated buffers and mempool */
87 test_put_mbuf_to_pool(struct rte_mempool *mp, struct rte_mbuf **pbuf)
91 for (itr = 0; itr < NUM_PACKETS; itr++)
92 rte_pktmbuf_free(pbuf[itr]);
96 /* Sample test to forward packets using virtual portids */
98 test_packet_forward(struct rte_mbuf **pbuf, uint16_t portid, uint16_t queue_id)
100 /* send and receive packet and check for stats update */
101 if (rte_eth_tx_burst(portid, queue_id, pbuf, NUM_PACKETS)
103 printf("%s() line %u: Error sending packet to"
104 " port %d\n", __func__, __LINE__, portid);
107 if (rte_eth_rx_burst(portid, queue_id, pbuf, NUM_PACKETS)
109 printf("%s() line %u: Error receiving packet from"
110 " port %d\n", __func__, __LINE__, portid);