4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifdef RTE_LIBRTE_PMD_RING
39 #include <rte_eth_ring.h>
40 #include <rte_ethdev.h>
42 /* two test rings, r1 is used by two ports, r2 just by one */
43 static struct rte_ring *r1[2], *r2;
45 static struct rte_mempool *mp;
46 static uint8_t start_idx; /* will store the port id of the first of our new ports */
48 #define TX_PORT (uint8_t)(start_idx + 1)
49 #define RX_PORT (uint8_t)(start_idx + 2)
50 #define RXTX_PORT (uint8_t)(start_idx + 3)
51 #define RXTX_PORT2 (uint8_t)(start_idx + 4)
52 #define RXTX_PORT4 (uint8_t)(start_idx + 6)
53 #define RXTX_PORT5 (uint8_t)(start_idx + 7)
58 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
62 test_ethdev_configure(void)
64 struct rte_eth_conf null_conf;
65 struct rte_eth_link link;
67 memset(&null_conf, 0, sizeof(struct rte_eth_conf));
69 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
70 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
71 printf(" TX/RX port exceed max eth ports\n");
74 if (rte_eth_dev_configure(TX_PORT, 1, 2, &null_conf) < 0) {
75 printf("Configure failed for TX port\n");
79 /* Test queue release */
80 if (rte_eth_dev_configure(TX_PORT, 1, 1, &null_conf) < 0) {
81 printf("Configure failed for TX port\n");
84 if (rte_eth_dev_configure(RX_PORT, 1, 1, &null_conf) < 0) {
85 printf("Configure failed for RX port\n");
88 if (rte_eth_dev_configure(RXTX_PORT, 1, 1, &null_conf) < 0) {
89 printf("Configure failed for RX port\n");
93 if (rte_eth_tx_queue_setup(TX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
94 printf("TX queue setup failed\n");
97 if (rte_eth_rx_queue_setup(RX_PORT, 0, RING_SIZE, SOCKET0,
99 printf("RX queue setup failed\n");
102 if (rte_eth_tx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
103 printf("TX queue setup failed\n");
106 if (rte_eth_rx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0,
108 printf("RX queue setup failed\n");
112 if (rte_eth_dev_start(TX_PORT) < 0) {
113 printf("Error starting TX port\n");
116 if (rte_eth_dev_start(RX_PORT) < 0) {
117 printf("Error starting RX port\n");
120 if (rte_eth_dev_start(RXTX_PORT) < 0) {
121 printf("Error starting RX port\n");
125 rte_eth_link_get(TX_PORT, &link);
126 rte_eth_link_get(RX_PORT, &link);
127 rte_eth_link_get(RXTX_PORT, &link);
133 test_send_basic_packets(void)
135 struct rte_mbuf bufs[RING_SIZE];
136 struct rte_mbuf *pbufs[RING_SIZE];
139 printf("Testing ring pmd RX/TX\n");
141 for (i = 0; i < RING_SIZE/2; i++)
144 if (rte_eth_tx_burst(TX_PORT, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
145 printf("Failed to transmit packet burst\n");
149 if (rte_eth_rx_burst(RX_PORT, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
150 printf("Failed to receive packet burst\n");
154 for (i = 0; i < RING_SIZE/2; i++)
155 if (pbufs[i] != &bufs[i]) {
156 printf("Error: received data does not match that transmitted\n");
166 struct rte_eth_stats stats;
167 struct rte_mbuf buf, *pbuf = &buf;
169 printf("Testing ring PMD stats\n");
171 /* check stats of RXTX port, should all be zero */
172 rte_eth_stats_get(RXTX_PORT, &stats);
173 if (stats.ipackets != 0 || stats.opackets != 0 ||
174 stats.ibytes != 0 || stats.obytes != 0 ||
175 stats.ierrors != 0 || stats.oerrors != 0) {
176 printf("Error: RXTX port stats are not zero\n");
180 /* send and receive 1 packet and check for stats update */
181 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
182 printf("Error sending packet to RXTX port\n");
185 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
186 printf("Error receiving packet from RXTX port\n");
190 rte_eth_stats_get(RXTX_PORT, &stats);
191 if (stats.ipackets != 1 || stats.opackets != 1 ||
192 stats.ibytes != 0 || stats.obytes != 0 ||
193 stats.ierrors != 0 || stats.oerrors != 0) {
194 printf("Error: RXTX port stats are not as expected\n");
201 test_stats_reset(void)
203 struct rte_eth_stats stats;
204 struct rte_mbuf buf, *pbuf = &buf;
206 printf("Testing ring PMD stats reset\n");
208 rte_eth_stats_reset(RXTX_PORT);
210 /* check stats of RXTX port, should all be zero */
211 rte_eth_stats_get(RXTX_PORT, &stats);
212 if (stats.ipackets != 0 || stats.opackets != 0 ||
213 stats.ibytes != 0 || stats.obytes != 0 ||
214 stats.ierrors != 0 || stats.oerrors != 0) {
215 printf("Error: RXTX port stats are not zero\n");
219 /* send and receive 1 packet and check for stats update */
220 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
221 printf("Error sending packet to RXTX port\n");
225 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
226 printf("Error receiving packet from RXTX port\n");
230 rte_eth_stats_get(RXTX_PORT, &stats);
231 if (stats.ipackets != 1 || stats.opackets != 1 ||
232 stats.ibytes != 0 || stats.obytes != 0 ||
233 stats.ierrors != 0 || stats.oerrors != 0) {
234 printf("Error: RXTX port stats are not as expected\n");
238 rte_eth_stats_reset(RXTX_PORT);
240 /* check stats of RXTX port, should all be zero */
241 rte_eth_stats_get(RXTX_PORT, &stats);
242 if (stats.ipackets != 0 || stats.opackets != 0 ||
243 stats.ibytes != 0 || stats.obytes != 0 ||
244 stats.ierrors != 0 || stats.oerrors != 0) {
245 printf("Error: RXTX port stats are not zero\n");
253 test_pmd_ring_init(void)
255 struct rte_eth_stats stats;
256 struct rte_mbuf buf, *pbuf = &buf;
257 struct rte_eth_conf null_conf;
259 printf("Testing ring pmd init\n");
261 if (RXTX_PORT2 >= RTE_MAX_ETHPORTS) {
262 printf(" TX/RX port exceed max eth ports\n");
265 if (rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0) {
266 printf("Configure failed for RXTX port\n");
270 if (rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0) {
271 printf("TX queue setup failed\n");
275 if (rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0,
277 printf("RX queue setup failed\n");
281 if (rte_eth_dev_start(RXTX_PORT2) < 0) {
282 printf("Error starting RX port\n");
286 /* send and receive 1 packet and check for stats update */
287 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
288 printf("Error sending packet to RXTX port\n");
292 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
293 printf("Error receiving packet from RXTX port\n");
297 rte_eth_stats_get(RXTX_PORT2, &stats);
298 if (stats.ipackets != 1 || stats.opackets != 1 ||
299 stats.ibytes != 0 || stats.obytes != 0 ||
300 stats.ierrors != 0 || stats.oerrors != 0) {
301 printf("Error: RXTX port stats are not as expected\n");
305 rte_eth_dev_stop(RXTX_PORT2);
311 test_pmd_ring_pair_create(void)
313 struct rte_eth_stats stats, stats2;
314 struct rte_mbuf buf, *pbuf = &buf;
315 struct rte_eth_conf null_conf;
317 if ((RXTX_PORT4 >= RTE_MAX_ETHPORTS) || (RXTX_PORT5 >= RTE_MAX_ETHPORTS)) {
318 printf(" TX/RX port exceed max eth ports\n");
321 if ((rte_eth_dev_configure(RXTX_PORT4, 1, 1, &null_conf) < 0)
322 || (rte_eth_dev_configure(RXTX_PORT5, 1, 1, &null_conf) < 0)) {
323 printf("Configure failed for RXTX port\n");
327 if ((rte_eth_tx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL) < 0)
328 || (rte_eth_tx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
329 printf("TX queue setup failed\n");
333 if ((rte_eth_rx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
334 || (rte_eth_rx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
335 printf("RX queue setup failed\n");
339 if ((rte_eth_dev_start(RXTX_PORT4) < 0)
340 || (rte_eth_dev_start(RXTX_PORT5) < 0)) {
341 printf("Error starting RXTX port\n");
345 /* send and receive 1 packet and check for stats update */
346 if (rte_eth_tx_burst(RXTX_PORT4, 0, &pbuf, 1) != 1) {
347 printf("Error sending packet to RXTX port\n");
351 if (rte_eth_rx_burst(RXTX_PORT5, 0, &pbuf, 1) != 1) {
352 printf("Error receiving packet from RXTX port\n");
356 rte_eth_stats_get(RXTX_PORT4, &stats);
357 rte_eth_stats_get(RXTX_PORT5, &stats2);
358 if (stats.ipackets != 0 || stats.opackets != 1 ||
359 stats.ibytes != 0 || stats.obytes != 0 ||
360 stats.ierrors != 0 || stats.oerrors != 0) {
361 printf("Error: RXTX port stats are not as expected\n");
365 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
366 stats2.ibytes != 0 || stats2.obytes != 0 ||
367 stats2.ierrors != 0 || stats2.oerrors != 0) {
368 printf("Error: RXTX port stats are not as expected\n");
372 rte_eth_dev_stop(RXTX_PORT4);
373 rte_eth_dev_stop(RXTX_PORT5);
379 test_pmd_ring_pair_attach(void)
381 struct rte_eth_stats stats, stats2;
382 struct rte_mbuf buf, *pbuf = &buf;
383 struct rte_eth_conf null_conf;
385 if ((RXTX_PORT4 >= RTE_MAX_ETHPORTS) || (RXTX_PORT5 >= RTE_MAX_ETHPORTS)) {
386 printf(" TX/RX port exceed max eth ports\n");
389 if ((rte_eth_dev_configure(RXTX_PORT4, 1, 1, &null_conf) < 0)
390 || (rte_eth_dev_configure(RXTX_PORT5, 1, 1, &null_conf) < 0)) {
391 printf("Configure failed for RXTX port\n");
395 if ((rte_eth_tx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL) < 0)
396 || (rte_eth_tx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
397 printf("TX queue setup failed\n");
401 if ((rte_eth_rx_queue_setup(RXTX_PORT4, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
402 || (rte_eth_rx_queue_setup(RXTX_PORT5, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
403 printf("RX queue setup failed\n");
407 if ((rte_eth_dev_start(RXTX_PORT4) < 0)
408 || (rte_eth_dev_start(RXTX_PORT5) < 0)) {
409 printf("Error starting RXTX port\n");
413 rte_eth_stats_reset(RXTX_PORT4);
414 rte_eth_stats_reset(RXTX_PORT5);
416 /* send and receive 1 packet and check for stats update */
417 if (rte_eth_tx_burst(RXTX_PORT4, 0, &pbuf, 1) != 1) {
418 printf("Error sending packet to RXTX port\n");
421 if (rte_eth_rx_burst(RXTX_PORT5, 0, &pbuf, 1) != 1) {
422 printf("Error receiving packet from RXTX port\n");
426 rte_eth_stats_get(RXTX_PORT4, &stats);
427 rte_eth_stats_get(RXTX_PORT5, &stats2);
428 if (stats.ipackets != 0 || stats.opackets != 1 ||
429 stats.ibytes != 0 || stats.obytes != 0 ||
430 stats.ierrors != 0 || stats.oerrors != 0) {
431 printf("Error: RXTX port stats are not as expected\n");
435 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
436 stats2.ibytes != 0 || stats2.obytes != 0 ||
437 stats2.ierrors != 0 || stats2.oerrors != 0) {
438 printf("Error: RXTX port stats are not as expected\n");
442 rte_eth_dev_stop(RXTX_PORT4);
443 rte_eth_dev_stop(RXTX_PORT5);
451 r1[0] = rte_ring_create("R1", RING_SIZE, 0, 0);
452 r1[1] = rte_ring_create("R2", RING_SIZE, 0, 0);
453 if (r1[0] == NULL && (r1[0] = rte_ring_lookup("R1")) == NULL)
455 if (r1[1] == NULL && (r1[1] = rte_ring_lookup("R2")) == NULL)
458 r2 = rte_ring_create("R3", RING_SIZE, 0, RING_F_SP_ENQ|RING_F_SC_DEQ);
459 if (r2 == NULL && (r2 = rte_ring_lookup("R3")) == NULL)
462 mp = rte_mempool_create("mbuf_pool", NB_MBUF,
464 sizeof(struct rte_pktmbuf_pool_private),
465 rte_pktmbuf_pool_init, NULL,
466 rte_pktmbuf_init, NULL,
471 start_idx = rte_eth_dev_count();
473 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
474 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
475 printf(" TX/RX port exceed max eth ports\n");
479 if (test_ethdev_configure() < 0)
482 if (test_send_basic_packets() < 0)
485 if (test_get_stats() < 0)
488 if (test_stats_reset() < 0)
491 rte_eth_dev_stop(RX_PORT);
492 rte_eth_dev_stop(TX_PORT);
493 rte_eth_dev_stop(RXTX_PORT);
495 if (test_pmd_ring_init() < 0)
498 if (test_pmd_ring_pair_create() < 0)
501 if (test_pmd_ring_pair_attach() < 0)