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 static struct rte_mempool *mp;
53 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
57 test_ethdev_configure(void)
59 struct rte_eth_conf null_conf;
60 struct rte_eth_link link;
62 memset(&null_conf, 0, sizeof(struct rte_eth_conf));
64 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
65 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
66 printf(" TX/RX port exceed max eth ports\n");
69 if (rte_eth_dev_configure(TX_PORT, 1, 2, &null_conf) < 0) {
70 printf("Configure failed for TX port\n");
74 /* Test queue release */
75 if (rte_eth_dev_configure(TX_PORT, 1, 1, &null_conf) < 0) {
76 printf("Configure failed for TX port\n");
79 if (rte_eth_dev_configure(RX_PORT, 1, 1, &null_conf) < 0) {
80 printf("Configure failed for RX port\n");
83 if (rte_eth_dev_configure(RXTX_PORT, 1, 1, &null_conf) < 0) {
84 printf("Configure failed for RXTX port\n");
88 if (rte_eth_tx_queue_setup(TX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
89 printf("TX queue setup failed\n");
92 if (rte_eth_rx_queue_setup(RX_PORT, 0, RING_SIZE, SOCKET0,
94 printf("RX queue setup failed\n");
97 if (rte_eth_tx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0, NULL) < 0) {
98 printf("TX queue setup failed\n");
101 if (rte_eth_rx_queue_setup(RXTX_PORT, 0, RING_SIZE, SOCKET0,
103 printf("RX queue setup failed\n");
107 if (rte_eth_dev_start(TX_PORT) < 0) {
108 printf("Error starting TX port\n");
111 if (rte_eth_dev_start(RX_PORT) < 0) {
112 printf("Error starting RX port\n");
115 if (rte_eth_dev_start(RXTX_PORT) < 0) {
116 printf("Error starting RX port\n");
120 rte_eth_link_get(TX_PORT, &link);
121 rte_eth_link_get(RX_PORT, &link);
122 rte_eth_link_get(RXTX_PORT, &link);
128 test_send_basic_packets(void)
130 struct rte_mbuf bufs[RING_SIZE];
131 struct rte_mbuf *pbufs[RING_SIZE];
134 printf("Testing ring pmd RX/TX\n");
136 for (i = 0; i < RING_SIZE/2; i++)
139 if (rte_eth_tx_burst(TX_PORT, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
140 printf("Failed to transmit packet burst\n");
144 if (rte_eth_rx_burst(RX_PORT, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
145 printf("Failed to receive packet burst\n");
149 for (i = 0; i < RING_SIZE/2; i++)
150 if (pbufs[i] != &bufs[i]) {
151 printf("Error: received data does not match that transmitted\n");
161 struct rte_eth_stats stats;
162 struct rte_mbuf buf, *pbuf = &buf;
164 printf("Testing ring PMD stats\n");
166 /* check stats of RXTX port, should all be zero */
167 rte_eth_stats_get(RXTX_PORT, &stats);
168 if (stats.ipackets != 0 || stats.opackets != 0 ||
169 stats.ibytes != 0 || stats.obytes != 0 ||
170 stats.ierrors != 0 || stats.oerrors != 0) {
171 printf("Error: RXTX port stats are not zero\n");
175 /* send and receive 1 packet and check for stats update */
176 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
177 printf("Error sending packet to RXTX port\n");
180 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
181 printf("Error receiving packet from RXTX port\n");
185 rte_eth_stats_get(RXTX_PORT, &stats);
186 if (stats.ipackets != 1 || stats.opackets != 1 ||
187 stats.ibytes != 0 || stats.obytes != 0 ||
188 stats.ierrors != 0 || stats.oerrors != 0) {
189 printf("Error: RXTX port stats are not as expected\n");
196 test_stats_reset(void)
198 struct rte_eth_stats stats;
199 struct rte_mbuf buf, *pbuf = &buf;
201 printf("Testing ring PMD stats reset\n");
203 rte_eth_stats_reset(RXTX_PORT);
205 /* check stats of RXTX port, should all be zero */
206 rte_eth_stats_get(RXTX_PORT, &stats);
207 if (stats.ipackets != 0 || stats.opackets != 0 ||
208 stats.ibytes != 0 || stats.obytes != 0 ||
209 stats.ierrors != 0 || stats.oerrors != 0) {
210 printf("Error: RXTX port stats are not zero\n");
214 /* send and receive 1 packet and check for stats update */
215 if (rte_eth_tx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
216 printf("Error sending packet to RXTX port\n");
220 if (rte_eth_rx_burst(RXTX_PORT, 0, &pbuf, 1) != 1) {
221 printf("Error receiving packet from RXTX port\n");
225 rte_eth_stats_get(RXTX_PORT, &stats);
226 if (stats.ipackets != 1 || stats.opackets != 1 ||
227 stats.ibytes != 0 || stats.obytes != 0 ||
228 stats.ierrors != 0 || stats.oerrors != 0) {
229 printf("Error: RXTX port stats are not as expected\n");
233 rte_eth_stats_reset(RXTX_PORT);
235 /* check stats of RXTX port, should all be zero */
236 rte_eth_stats_get(RXTX_PORT, &stats);
237 if (stats.ipackets != 0 || stats.opackets != 0 ||
238 stats.ibytes != 0 || stats.obytes != 0 ||
239 stats.ierrors != 0 || stats.oerrors != 0) {
240 printf("Error: RXTX port stats are not zero\n");
248 test_pmd_ring_pair_create_attach(void)
250 struct rte_eth_stats stats, stats2;
251 struct rte_mbuf buf, *pbuf = &buf;
252 struct rte_eth_conf null_conf;
254 if ((RXTX_PORT2 >= RTE_MAX_ETHPORTS) || (RXTX_PORT3 >= RTE_MAX_ETHPORTS)) {
255 printf(" TX/RX port exceed max eth ports\n");
258 if ((rte_eth_dev_configure(RXTX_PORT2, 1, 1, &null_conf) < 0)
259 || (rte_eth_dev_configure(RXTX_PORT3, 1, 1, &null_conf) < 0)) {
260 printf("Configure failed for RXTX port\n");
264 if ((rte_eth_tx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL) < 0)
265 || (rte_eth_tx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL) < 0)) {
266 printf("TX queue setup failed\n");
270 if ((rte_eth_rx_queue_setup(RXTX_PORT2, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)
271 || (rte_eth_rx_queue_setup(RXTX_PORT3, 0, RING_SIZE, SOCKET0, NULL, mp) < 0)) {
272 printf("RX queue setup failed\n");
276 if ((rte_eth_dev_start(RXTX_PORT2) < 0)
277 || (rte_eth_dev_start(RXTX_PORT3) < 0)) {
278 printf("Error starting RXTX port\n");
283 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT3)
284 * and check for stats update
286 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
287 printf("Error sending packet to RXTX port\n");
291 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
292 printf("Error receiving packet from RXTX port\n");
296 rte_eth_stats_get(RXTX_PORT2, &stats);
297 rte_eth_stats_get(RXTX_PORT3, &stats2);
298 if (stats.ipackets != 0 || 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 if (stats2.ipackets != 1 || stats2.opackets != 0 ||
306 stats2.ibytes != 0 || stats2.obytes != 0 ||
307 stats2.ierrors != 0 || stats2.oerrors != 0) {
308 printf("Error: RXTX port stats are not as expected\n");
313 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT2)
314 * and check for stats update
316 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
317 printf("Error sending packet to RXTX port\n");
321 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
322 printf("Error receiving packet from RXTX port\n");
326 rte_eth_stats_get(RXTX_PORT2, &stats);
327 rte_eth_stats_get(RXTX_PORT3, &stats2);
328 if (stats.ipackets != 1 || stats.opackets != 1 ||
329 stats.ibytes != 0 || stats.obytes != 0 ||
330 stats.ierrors != 0 || stats.oerrors != 0) {
331 printf("Error: RXTX port stats are not as expected\n");
335 if (stats2.ipackets != 1 || stats2.opackets != 1 ||
336 stats2.ibytes != 0 || stats2.obytes != 0 ||
337 stats2.ierrors != 0 || stats2.oerrors != 0) {
338 printf("Error: RXTX port stats are not as expected\n");
343 * send and receive 1 packet (RXTX_PORT2 -> RXTX_PORT2)
344 * and check for stats update
346 if (rte_eth_tx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
347 printf("Error sending packet to RXTX port\n");
351 if (rte_eth_rx_burst(RXTX_PORT2, 0, &pbuf, 1) != 1) {
352 printf("Error receiving packet from RXTX port\n");
356 rte_eth_stats_get(RXTX_PORT2, &stats);
357 rte_eth_stats_get(RXTX_PORT3, &stats2);
358 if (stats.ipackets != 2 || stats.opackets != 2 ||
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 != 1 ||
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");
373 * send and receive 1 packet (RXTX_PORT3 -> RXTX_PORT3)
374 * and check for stats update
376 if (rte_eth_tx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
377 printf("Error sending packet to RXTX port\n");
381 if (rte_eth_rx_burst(RXTX_PORT3, 0, &pbuf, 1) != 1) {
382 printf("Error receiving packet from RXTX port\n");
386 rte_eth_stats_get(RXTX_PORT2, &stats);
387 rte_eth_stats_get(RXTX_PORT3, &stats2);
388 if (stats.ipackets != 2 || stats.opackets != 2 ||
389 stats.ibytes != 0 || stats.obytes != 0 ||
390 stats.ierrors != 0 || stats.oerrors != 0) {
391 printf("Error: RXTX port stats are not as expected\n");
395 if (stats2.ipackets != 2 || stats2.opackets != 2 ||
396 stats2.ibytes != 0 || stats2.obytes != 0 ||
397 stats2.ierrors != 0 || stats2.oerrors != 0) {
398 printf("Error: RXTX port stats are not as expected\n");
402 rte_eth_dev_stop(RXTX_PORT2);
403 rte_eth_dev_stop(RXTX_PORT3);
411 mp = rte_mempool_create("mbuf_pool", NB_MBUF,
413 sizeof(struct rte_pktmbuf_pool_private),
414 rte_pktmbuf_pool_init, NULL,
415 rte_pktmbuf_init, NULL,
420 if ((TX_PORT >= RTE_MAX_ETHPORTS) || (RX_PORT >= RTE_MAX_ETHPORTS)\
421 || (RXTX_PORT >= RTE_MAX_ETHPORTS)) {
422 printf(" TX/RX port exceed max eth ports\n");
426 if (test_ethdev_configure() < 0)
429 if (test_send_basic_packets() < 0)
432 if (test_get_stats() < 0)
435 if (test_stats_reset() < 0)
438 rte_eth_dev_stop(RX_PORT);
439 rte_eth_dev_stop(TX_PORT);
440 rte_eth_dev_stop(RXTX_PORT);
442 if (test_pmd_ring_pair_create_attach() < 0)