1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #include <rte_common.h>
15 #include <rte_errno.h>
16 #include <rte_debug.h>
18 #include <rte_memory.h>
19 #include <rte_memcpy.h>
20 #include <rte_launch.h>
22 #include <rte_per_lcore.h>
23 #include <rte_lcore.h>
24 #include <rte_atomic.h>
25 #include <rte_branch_prediction.h>
27 #include <rte_mempool.h>
29 #include <rte_random.h>
30 #include <rte_cycles.h>
31 #include <rte_malloc.h>
32 #include <rte_ether.h>
35 #include <rte_mbuf_dyn.h>
39 #define MEMPOOL_CACHE_SIZE 32
40 #define MBUF_DATA_SIZE 2048
42 #define MBUF_TEST_DATA_LEN 1464
43 #define MBUF_TEST_DATA_LEN2 50
44 #define MBUF_TEST_DATA_LEN3 256
45 #define MBUF_TEST_HDR1_LEN 20
46 #define MBUF_TEST_HDR2_LEN 30
47 #define MBUF_TEST_ALL_HDRS_LEN (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN)
48 #define MBUF_TEST_SEG_SIZE 64
49 #define MBUF_TEST_BURST 8
50 #define EXT_BUF_TEST_DATA_LEN 1024
51 #define MBUF_MAX_SEG 16
52 #define MBUF_NO_HEADER 0
54 #define MBUF_NEG_TEST_READ 2
55 #define VAL_NAME(flag) { flag, #flag }
57 /* chain length in bulk test */
60 /* size of private data for mbuf in pktmbuf_pool2 */
61 #define MBUF2_PRIV_SIZE 128
63 #define REFCNT_MAX_ITER 64
64 #define REFCNT_MAX_TIMEOUT 10
65 #define REFCNT_MAX_REF (RTE_MAX_LCORE)
66 #define REFCNT_MBUF_NUM 64
67 #define REFCNT_RING_SIZE (REFCNT_MBUF_NUM * REFCNT_MAX_REF)
69 #define MAGIC_DATA 0x42424242
71 #define MAKE_STRING(x) # x
73 #ifdef RTE_MBUF_REFCNT_ATOMIC
75 static volatile uint32_t refcnt_stop_workers;
76 static unsigned refcnt_lcore[RTE_MAX_LCORE];
84 * #. Allocate a mbuf pool.
86 * - The pool contains NB_MBUF elements, where each mbuf is MBUF_SIZE
89 * #. Test multiple allocations of mbufs from this pool.
91 * - Allocate NB_MBUF and store pointers in a table.
92 * - If an allocation fails, return an error.
93 * - Free all these mbufs.
94 * - Repeat the same test to check that mbufs were freed correctly.
96 * #. Test data manipulation in pktmbuf.
99 * - Append data using rte_pktmbuf_append().
100 * - Test for error in rte_pktmbuf_append() when len is too large.
101 * - Trim data at the end of mbuf using rte_pktmbuf_trim().
102 * - Test for error in rte_pktmbuf_trim() when len is too large.
103 * - Prepend a header using rte_pktmbuf_prepend().
104 * - Test for error in rte_pktmbuf_prepend() when len is too large.
105 * - Remove data at the beginning of mbuf using rte_pktmbuf_adj().
106 * - Test for error in rte_pktmbuf_adj() when len is too large.
107 * - Check that appended data is not corrupt.
109 * - Between all these tests, check data_len and pkt_len, and
110 * that the mbuf is contiguous.
111 * - Repeat the test to check that allocation operations
112 * reinitialize the mbuf correctly.
114 * #. Test packet cloning
115 * - Clone a mbuf and verify the data
116 * - Clone the cloned mbuf and verify the data
117 * - Attach a mbuf to another that does not have the same priv_size.
120 #define GOTO_FAIL(str, ...) do { \
121 printf("mbuf test FAILED (l.%d): <" str ">\n", \
122 __LINE__, ##__VA_ARGS__); \
127 * test data manipulation in mbuf with non-ascii data
130 test_pktmbuf_with_non_ascii_data(struct rte_mempool *pktmbuf_pool)
132 struct rte_mbuf *m = NULL;
135 m = rte_pktmbuf_alloc(pktmbuf_pool);
137 GOTO_FAIL("Cannot allocate mbuf");
138 if (rte_pktmbuf_pkt_len(m) != 0)
139 GOTO_FAIL("Bad length");
141 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
143 GOTO_FAIL("Cannot append data");
144 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
145 GOTO_FAIL("Bad pkt length");
146 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
147 GOTO_FAIL("Bad data length");
148 memset(data, 0xff, rte_pktmbuf_pkt_len(m));
149 if (!rte_pktmbuf_is_contiguous(m))
150 GOTO_FAIL("Buffer should be continuous");
151 rte_pktmbuf_dump(stdout, m, MBUF_TEST_DATA_LEN);
165 * test data manipulation in mbuf
168 test_one_pktmbuf(struct rte_mempool *pktmbuf_pool)
170 struct rte_mbuf *m = NULL;
171 char *data, *data2, *hdr;
174 printf("Test pktmbuf API\n");
178 m = rte_pktmbuf_alloc(pktmbuf_pool);
180 GOTO_FAIL("Cannot allocate mbuf");
181 if (rte_pktmbuf_pkt_len(m) != 0)
182 GOTO_FAIL("Bad length");
184 rte_pktmbuf_dump(stdout, m, 0);
188 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
190 GOTO_FAIL("Cannot append data");
191 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
192 GOTO_FAIL("Bad pkt length");
193 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
194 GOTO_FAIL("Bad data length");
195 memset(data, 0x66, rte_pktmbuf_pkt_len(m));
196 if (!rte_pktmbuf_is_contiguous(m))
197 GOTO_FAIL("Buffer should be continuous");
198 rte_pktmbuf_dump(stdout, m, MBUF_TEST_DATA_LEN);
199 rte_pktmbuf_dump(stdout, m, 2*MBUF_TEST_DATA_LEN);
201 /* this append should fail */
203 data2 = rte_pktmbuf_append(m, (uint16_t)(rte_pktmbuf_tailroom(m) + 1));
205 GOTO_FAIL("Append should not succeed");
207 /* append some more data */
209 data2 = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
211 GOTO_FAIL("Cannot append data");
212 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
213 GOTO_FAIL("Bad pkt length");
214 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
215 GOTO_FAIL("Bad data length");
216 if (!rte_pktmbuf_is_contiguous(m))
217 GOTO_FAIL("Buffer should be continuous");
219 /* trim data at the end of mbuf */
221 if (rte_pktmbuf_trim(m, MBUF_TEST_DATA_LEN2) < 0)
222 GOTO_FAIL("Cannot trim data");
223 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
224 GOTO_FAIL("Bad pkt length");
225 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
226 GOTO_FAIL("Bad data length");
227 if (!rte_pktmbuf_is_contiguous(m))
228 GOTO_FAIL("Buffer should be continuous");
230 /* this trim should fail */
232 if (rte_pktmbuf_trim(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) == 0)
233 GOTO_FAIL("trim should not succeed");
235 /* prepend one header */
237 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR1_LEN);
239 GOTO_FAIL("Cannot prepend");
240 if (data - hdr != MBUF_TEST_HDR1_LEN)
241 GOTO_FAIL("Prepend failed");
242 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
243 GOTO_FAIL("Bad pkt length");
244 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
245 GOTO_FAIL("Bad data length");
246 if (!rte_pktmbuf_is_contiguous(m))
247 GOTO_FAIL("Buffer should be continuous");
248 memset(hdr, 0x55, MBUF_TEST_HDR1_LEN);
250 /* prepend another header */
252 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR2_LEN);
254 GOTO_FAIL("Cannot prepend");
255 if (data - hdr != MBUF_TEST_ALL_HDRS_LEN)
256 GOTO_FAIL("Prepend failed");
257 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
258 GOTO_FAIL("Bad pkt length");
259 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
260 GOTO_FAIL("Bad data length");
261 if (!rte_pktmbuf_is_contiguous(m))
262 GOTO_FAIL("Buffer should be continuous");
263 memset(hdr, 0x55, MBUF_TEST_HDR2_LEN);
265 rte_mbuf_sanity_check(m, 1);
266 rte_mbuf_sanity_check(m, 0);
267 rte_pktmbuf_dump(stdout, m, 0);
269 /* this prepend should fail */
271 hdr = rte_pktmbuf_prepend(m, (uint16_t)(rte_pktmbuf_headroom(m) + 1));
273 GOTO_FAIL("prepend should not succeed");
275 /* remove data at beginning of mbuf (adj) */
277 if (data != rte_pktmbuf_adj(m, MBUF_TEST_ALL_HDRS_LEN))
278 GOTO_FAIL("rte_pktmbuf_adj failed");
279 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
280 GOTO_FAIL("Bad pkt length");
281 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
282 GOTO_FAIL("Bad data length");
283 if (!rte_pktmbuf_is_contiguous(m))
284 GOTO_FAIL("Buffer should be continuous");
286 /* this adj should fail */
288 if (rte_pktmbuf_adj(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) != NULL)
289 GOTO_FAIL("rte_pktmbuf_adj should not succeed");
293 if (!rte_pktmbuf_is_contiguous(m))
294 GOTO_FAIL("Buffer should be continuous");
296 for (i=0; i<MBUF_TEST_DATA_LEN; i++) {
298 GOTO_FAIL("Data corrupted at offset %u", i);
314 testclone_refcnt_read(struct rte_mbuf *m)
316 return RTE_MBUF_HAS_PINNED_EXTBUF(m) ?
317 rte_mbuf_ext_refcnt_read(m->shinfo) :
318 rte_mbuf_refcnt_read(m);
322 testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool,
323 struct rte_mempool *clone_pool)
325 struct rte_mbuf *m = NULL;
326 struct rte_mbuf *clone = NULL;
327 struct rte_mbuf *clone2 = NULL;
328 unaligned_uint32_t *data;
331 m = rte_pktmbuf_alloc(pktmbuf_pool);
333 GOTO_FAIL("ooops not allocating mbuf");
335 if (rte_pktmbuf_pkt_len(m) != 0)
336 GOTO_FAIL("Bad length");
338 rte_pktmbuf_append(m, sizeof(uint32_t));
339 data = rte_pktmbuf_mtod(m, unaligned_uint32_t *);
342 /* clone the allocated mbuf */
343 clone = rte_pktmbuf_clone(m, clone_pool);
345 GOTO_FAIL("cannot clone data\n");
347 data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *);
348 if (*data != MAGIC_DATA)
349 GOTO_FAIL("invalid data in clone\n");
351 if (testclone_refcnt_read(m) != 2)
352 GOTO_FAIL("invalid refcnt in m\n");
355 rte_pktmbuf_free(clone);
358 /* same test with a chained mbuf */
359 m->next = rte_pktmbuf_alloc(pktmbuf_pool);
361 GOTO_FAIL("Next Pkt Null\n");
364 rte_pktmbuf_append(m->next, sizeof(uint32_t));
365 m->pkt_len = 2 * sizeof(uint32_t);
367 data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *);
370 clone = rte_pktmbuf_clone(m, clone_pool);
372 GOTO_FAIL("cannot clone data\n");
374 data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *);
375 if (*data != MAGIC_DATA)
376 GOTO_FAIL("invalid data in clone\n");
378 data = rte_pktmbuf_mtod(clone->next, unaligned_uint32_t *);
379 if (*data != MAGIC_DATA)
380 GOTO_FAIL("invalid data in clone->next\n");
382 if (testclone_refcnt_read(m) != 2)
383 GOTO_FAIL("invalid refcnt in m\n");
385 if (testclone_refcnt_read(m->next) != 2)
386 GOTO_FAIL("invalid refcnt in m->next\n");
388 /* try to clone the clone */
390 clone2 = rte_pktmbuf_clone(clone, clone_pool);
392 GOTO_FAIL("cannot clone the clone\n");
394 data = rte_pktmbuf_mtod(clone2, unaligned_uint32_t *);
395 if (*data != MAGIC_DATA)
396 GOTO_FAIL("invalid data in clone2\n");
398 data = rte_pktmbuf_mtod(clone2->next, unaligned_uint32_t *);
399 if (*data != MAGIC_DATA)
400 GOTO_FAIL("invalid data in clone2->next\n");
402 if (testclone_refcnt_read(m) != 3)
403 GOTO_FAIL("invalid refcnt in m\n");
405 if (testclone_refcnt_read(m->next) != 3)
406 GOTO_FAIL("invalid refcnt in m->next\n");
410 rte_pktmbuf_free(clone);
411 rte_pktmbuf_free(clone2);
416 printf("%s ok\n", __func__);
423 rte_pktmbuf_free(clone);
425 rte_pktmbuf_free(clone2);
430 test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool,
431 struct rte_mempool *clone_pool)
433 struct rte_mbuf *m = NULL;
434 struct rte_mbuf *copy = NULL;
435 struct rte_mbuf *copy2 = NULL;
436 struct rte_mbuf *clone = NULL;
437 unaligned_uint32_t *data;
440 m = rte_pktmbuf_alloc(pktmbuf_pool);
442 GOTO_FAIL("ooops not allocating mbuf");
444 if (rte_pktmbuf_pkt_len(m) != 0)
445 GOTO_FAIL("Bad length");
447 rte_pktmbuf_append(m, sizeof(uint32_t));
448 data = rte_pktmbuf_mtod(m, unaligned_uint32_t *);
451 /* copy the allocated mbuf */
452 copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX);
454 GOTO_FAIL("cannot copy data\n");
456 if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t))
457 GOTO_FAIL("copy length incorrect\n");
459 if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t))
460 GOTO_FAIL("copy data length incorrect\n");
462 data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
463 if (*data != MAGIC_DATA)
464 GOTO_FAIL("invalid data in copy\n");
467 rte_pktmbuf_free(copy);
470 /* same test with a cloned mbuf */
471 clone = rte_pktmbuf_clone(m, clone_pool);
473 GOTO_FAIL("cannot clone data\n");
475 if ((!RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
476 !RTE_MBUF_CLONED(clone)) ||
477 (RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
478 !RTE_MBUF_HAS_EXTBUF(clone)))
479 GOTO_FAIL("clone did not give a cloned mbuf\n");
481 copy = rte_pktmbuf_copy(clone, pktmbuf_pool, 0, UINT32_MAX);
483 GOTO_FAIL("cannot copy cloned mbuf\n");
485 if (RTE_MBUF_CLONED(copy))
486 GOTO_FAIL("copy of clone is cloned?\n");
488 if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t))
489 GOTO_FAIL("copy clone length incorrect\n");
491 if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t))
492 GOTO_FAIL("copy clone data length incorrect\n");
494 data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
495 if (*data != MAGIC_DATA)
496 GOTO_FAIL("invalid data in clone copy\n");
497 rte_pktmbuf_free(clone);
498 rte_pktmbuf_free(copy);
503 /* same test with a chained mbuf */
504 m->next = rte_pktmbuf_alloc(pktmbuf_pool);
506 GOTO_FAIL("Next Pkt Null\n");
509 rte_pktmbuf_append(m->next, sizeof(uint32_t));
510 m->pkt_len = 2 * sizeof(uint32_t);
511 data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *);
512 *data = MAGIC_DATA + 1;
514 copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX);
516 GOTO_FAIL("cannot copy data\n");
518 if (rte_pktmbuf_pkt_len(copy) != 2 * sizeof(uint32_t))
519 GOTO_FAIL("chain copy length incorrect\n");
521 if (rte_pktmbuf_data_len(copy) != 2 * sizeof(uint32_t))
522 GOTO_FAIL("chain copy data length incorrect\n");
524 data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
525 if (data[0] != MAGIC_DATA || data[1] != MAGIC_DATA + 1)
526 GOTO_FAIL("invalid data in copy\n");
528 rte_pktmbuf_free(copy2);
530 /* test offset copy */
531 copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool,
532 sizeof(uint32_t), UINT32_MAX);
534 GOTO_FAIL("cannot copy the copy\n");
536 if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t))
537 GOTO_FAIL("copy with offset, length incorrect\n");
539 if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t))
540 GOTO_FAIL("copy with offset, data length incorrect\n");
542 data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *);
543 if (data[0] != MAGIC_DATA + 1)
544 GOTO_FAIL("copy with offset, invalid data\n");
546 rte_pktmbuf_free(copy2);
548 /* test truncation copy */
549 copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool,
550 0, sizeof(uint32_t));
552 GOTO_FAIL("cannot copy the copy\n");
554 if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t))
555 GOTO_FAIL("copy with truncate, length incorrect\n");
557 if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t))
558 GOTO_FAIL("copy with truncate, data length incorrect\n");
560 data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *);
561 if (data[0] != MAGIC_DATA)
562 GOTO_FAIL("copy with truncate, invalid data\n");
566 rte_pktmbuf_free(copy);
567 rte_pktmbuf_free(copy2);
572 printf("%s ok\n", __func__);
579 rte_pktmbuf_free(copy);
581 rte_pktmbuf_free(copy2);
586 test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool,
587 struct rte_mempool *pktmbuf_pool2)
589 struct rte_mbuf *m = NULL;
590 struct rte_mbuf *clone = NULL;
591 struct rte_mbuf *clone2 = NULL;
592 char *data, *c_data, *c_data2;
595 m = rte_pktmbuf_alloc(pktmbuf_pool);
597 GOTO_FAIL("cannot allocate mbuf");
599 if (rte_pktmbuf_pkt_len(m) != 0)
600 GOTO_FAIL("Bad length");
602 data = rte_pktmbuf_mtod(m, char *);
604 /* allocate a new mbuf from the second pool, and attach it to the first
606 clone = rte_pktmbuf_alloc(pktmbuf_pool2);
608 GOTO_FAIL("cannot allocate mbuf from second pool\n");
610 /* check data room size and priv size, and erase priv */
611 if (rte_pktmbuf_data_room_size(clone->pool) != 0)
612 GOTO_FAIL("data room size should be 0\n");
613 if (rte_pktmbuf_priv_size(clone->pool) != MBUF2_PRIV_SIZE)
614 GOTO_FAIL("data room size should be %d\n", MBUF2_PRIV_SIZE);
615 memset(clone + 1, 0, MBUF2_PRIV_SIZE);
617 /* save data pointer to compare it after detach() */
618 c_data = rte_pktmbuf_mtod(clone, char *);
619 if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE)
620 GOTO_FAIL("bad data pointer in clone");
621 if (rte_pktmbuf_headroom(clone) != 0)
622 GOTO_FAIL("bad headroom in clone");
624 rte_pktmbuf_attach(clone, m);
626 if (rte_pktmbuf_mtod(clone, char *) != data)
627 GOTO_FAIL("clone was not attached properly\n");
628 if (rte_pktmbuf_headroom(clone) != RTE_PKTMBUF_HEADROOM)
629 GOTO_FAIL("bad headroom in clone after attach");
630 if (rte_mbuf_refcnt_read(m) != 2)
631 GOTO_FAIL("invalid refcnt in m\n");
633 /* allocate a new mbuf from the second pool, and attach it to the first
635 clone2 = rte_pktmbuf_alloc(pktmbuf_pool2);
637 GOTO_FAIL("cannot allocate clone2 from second pool\n");
639 /* check data room size and priv size, and erase priv */
640 if (rte_pktmbuf_data_room_size(clone2->pool) != 0)
641 GOTO_FAIL("data room size should be 0\n");
642 if (rte_pktmbuf_priv_size(clone2->pool) != MBUF2_PRIV_SIZE)
643 GOTO_FAIL("data room size should be %d\n", MBUF2_PRIV_SIZE);
644 memset(clone2 + 1, 0, MBUF2_PRIV_SIZE);
646 /* save data pointer to compare it after detach() */
647 c_data2 = rte_pktmbuf_mtod(clone2, char *);
648 if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE)
649 GOTO_FAIL("bad data pointer in clone2");
650 if (rte_pktmbuf_headroom(clone2) != 0)
651 GOTO_FAIL("bad headroom in clone2");
653 rte_pktmbuf_attach(clone2, clone);
655 if (rte_pktmbuf_mtod(clone2, char *) != data)
656 GOTO_FAIL("clone2 was not attached properly\n");
657 if (rte_pktmbuf_headroom(clone2) != RTE_PKTMBUF_HEADROOM)
658 GOTO_FAIL("bad headroom in clone2 after attach");
659 if (rte_mbuf_refcnt_read(m) != 3)
660 GOTO_FAIL("invalid refcnt in m\n");
662 /* detach the clones */
663 rte_pktmbuf_detach(clone);
664 if (c_data != rte_pktmbuf_mtod(clone, char *))
665 GOTO_FAIL("clone was not detached properly\n");
666 if (rte_mbuf_refcnt_read(m) != 2)
667 GOTO_FAIL("invalid refcnt in m\n");
669 rte_pktmbuf_detach(clone2);
670 if (c_data2 != rte_pktmbuf_mtod(clone2, char *))
671 GOTO_FAIL("clone2 was not detached properly\n");
672 if (rte_mbuf_refcnt_read(m) != 1)
673 GOTO_FAIL("invalid refcnt in m\n");
675 /* free the clones and the initial mbuf */
676 rte_pktmbuf_free(clone2);
677 rte_pktmbuf_free(clone);
679 printf("%s ok\n", __func__);
686 rte_pktmbuf_free(clone);
688 rte_pktmbuf_free(clone2);
693 * test allocation and free of mbufs
696 test_pktmbuf_pool(struct rte_mempool *pktmbuf_pool)
699 struct rte_mbuf *m[NB_MBUF];
702 for (i=0; i<NB_MBUF; i++)
705 /* alloc NB_MBUF mbufs */
706 for (i=0; i<NB_MBUF; i++) {
707 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
709 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
713 struct rte_mbuf *extra = NULL;
714 extra = rte_pktmbuf_alloc(pktmbuf_pool);
716 printf("Error pool not empty");
719 extra = rte_pktmbuf_clone(m[0], pktmbuf_pool);
721 printf("Error pool not empty");
725 for (i=0; i<NB_MBUF; i++) {
727 rte_pktmbuf_free(m[i]);
734 * test bulk allocation and bulk free of mbufs
737 test_pktmbuf_pool_bulk(void)
739 struct rte_mempool *pool = NULL;
740 struct rte_mempool *pool2 = NULL;
743 struct rte_mbuf *mbufs[NB_MBUF];
746 /* We cannot use the preallocated mbuf pools because their caches
747 * prevent us from bulk allocating all objects in them.
748 * So we create our own mbuf pools without caches.
750 printf("Create mbuf pools for bulk allocation.\n");
751 pool = rte_pktmbuf_pool_create("test_pktmbuf_bulk",
752 NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
754 printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n",
758 pool2 = rte_pktmbuf_pool_create("test_pktmbuf_bulk2",
759 NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
761 printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n",
766 /* Preconditions: Mempools must be full. */
767 if (!(rte_mempool_full(pool) && rte_mempool_full(pool2))) {
768 printf("Test precondition failed: mempools not full\n");
771 if (!(rte_mempool_avail_count(pool) == NB_MBUF &&
772 rte_mempool_avail_count(pool2) == NB_MBUF)) {
773 printf("Test precondition failed: mempools: %u+%u != %u+%u",
774 rte_mempool_avail_count(pool),
775 rte_mempool_avail_count(pool2),
780 printf("Test single bulk alloc, followed by multiple bulk free.\n");
782 /* Bulk allocate all mbufs in the pool, in one go. */
783 ret = rte_pktmbuf_alloc_bulk(pool, mbufs, NB_MBUF);
785 printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
788 /* Test that they have been removed from the pool. */
789 if (!rte_mempool_empty(pool)) {
790 printf("mempool not empty\n");
793 /* Bulk free all mbufs, in four steps. */
794 RTE_BUILD_BUG_ON(NB_MBUF % 4 != 0);
795 for (i = 0; i < NB_MBUF; i += NB_MBUF / 4) {
796 rte_pktmbuf_free_bulk(&mbufs[i], NB_MBUF / 4);
797 /* Test that they have been returned to the pool. */
798 if (rte_mempool_avail_count(pool) != i + NB_MBUF / 4) {
799 printf("mempool avail count incorrect\n");
804 printf("Test multiple bulk alloc, followed by single bulk free.\n");
806 /* Bulk allocate all mbufs in the pool, in four steps. */
807 for (i = 0; i < NB_MBUF; i += NB_MBUF / 4) {
808 ret = rte_pktmbuf_alloc_bulk(pool, &mbufs[i], NB_MBUF / 4);
810 printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
814 /* Test that they have been removed from the pool. */
815 if (!rte_mempool_empty(pool)) {
816 printf("mempool not empty\n");
819 /* Bulk free all mbufs, in one go. */
820 rte_pktmbuf_free_bulk(mbufs, NB_MBUF);
821 /* Test that they have been returned to the pool. */
822 if (!rte_mempool_full(pool)) {
823 printf("mempool not full\n");
827 printf("Test bulk free of single long chain.\n");
829 /* Bulk allocate all mbufs in the pool, in one go. */
830 ret = rte_pktmbuf_alloc_bulk(pool, mbufs, NB_MBUF);
832 printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
835 /* Create a long mbuf chain. */
836 for (i = 1; i < NB_MBUF; i++) {
837 ret = rte_pktmbuf_chain(mbufs[0], mbufs[i]);
839 printf("rte_pktmbuf_chain() failed: %d\n", ret);
844 /* Free the mbuf chain containing all the mbufs. */
845 rte_pktmbuf_free_bulk(mbufs, 1);
846 /* Test that they have been returned to the pool. */
847 if (!rte_mempool_full(pool)) {
848 printf("mempool not full\n");
852 printf("Test bulk free of multiple chains using multiple pools.\n");
854 /* Create mbuf chains containing mbufs from different pools. */
855 RTE_BUILD_BUG_ON(CHAIN_LEN % 2 != 0);
856 RTE_BUILD_BUG_ON(NB_MBUF % (CHAIN_LEN / 2) != 0);
857 for (i = 0; i < NB_MBUF * 2; i++) {
858 m = rte_pktmbuf_alloc((i & 4) ? pool2 : pool);
860 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
863 if ((i % CHAIN_LEN) == 0)
864 mbufs[i / CHAIN_LEN] = m;
866 rte_pktmbuf_chain(mbufs[i / CHAIN_LEN], m);
868 /* Test that both pools have been emptied. */
869 if (!(rte_mempool_empty(pool) && rte_mempool_empty(pool2))) {
870 printf("mempools not empty\n");
873 /* Free one mbuf chain. */
874 rte_pktmbuf_free_bulk(mbufs, 1);
875 /* Test that the segments have been returned to the pools. */
876 if (!(rte_mempool_avail_count(pool) == CHAIN_LEN / 2 &&
877 rte_mempool_avail_count(pool2) == CHAIN_LEN / 2)) {
878 printf("all segments of first mbuf have not been returned\n");
881 /* Free the remaining mbuf chains. */
882 rte_pktmbuf_free_bulk(&mbufs[1], NB_MBUF * 2 / CHAIN_LEN - 1);
883 /* Test that they have been returned to the pools. */
884 if (!(rte_mempool_full(pool) && rte_mempool_full(pool2))) {
885 printf("mempools not full\n");
896 printf("Free mbuf pools for bulk allocation.\n");
897 rte_mempool_free(pool);
898 rte_mempool_free(pool2);
903 * test that the pointer to the data on a packet mbuf is set properly
906 test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool)
909 struct rte_mbuf *m[NB_MBUF];
912 for (i=0; i<NB_MBUF; i++)
915 /* alloc NB_MBUF mbufs */
916 for (i=0; i<NB_MBUF; i++) {
917 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
919 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
923 m[i]->data_off += 64;
927 for (i=0; i<NB_MBUF; i++) {
929 rte_pktmbuf_free(m[i]);
932 for (i=0; i<NB_MBUF; i++)
935 /* alloc NB_MBUF mbufs */
936 for (i=0; i<NB_MBUF; i++) {
937 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
939 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
943 if (m[i]->data_off != RTE_PKTMBUF_HEADROOM) {
944 printf("invalid data_off\n");
950 for (i=0; i<NB_MBUF; i++) {
952 rte_pktmbuf_free(m[i]);
959 test_pktmbuf_free_segment(struct rte_mempool *pktmbuf_pool)
962 struct rte_mbuf *m[NB_MBUF];
965 for (i=0; i<NB_MBUF; i++)
968 /* alloc NB_MBUF mbufs */
969 for (i=0; i<NB_MBUF; i++) {
970 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
972 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
978 for (i=0; i<NB_MBUF; i++) {
980 struct rte_mbuf *mb, *mt;
986 rte_pktmbuf_free_seg(mt);
995 * Stress test for rte_mbuf atomic refcnt.
996 * Implies that RTE_MBUF_REFCNT_ATOMIC is defined.
997 * For more efficiency, recommended to run with RTE_LIBRTE_MBUF_DEBUG defined.
1000 #ifdef RTE_MBUF_REFCNT_ATOMIC
1003 test_refcnt_worker(void *arg)
1005 unsigned lcore, free;
1007 struct rte_ring *refcnt_mbuf_ring = arg;
1009 lcore = rte_lcore_id();
1010 printf("%s started at lcore %u\n", __func__, lcore);
1013 while (refcnt_stop_workers == 0) {
1014 if (rte_ring_dequeue(refcnt_mbuf_ring, &mp) == 0) {
1016 rte_pktmbuf_free(mp);
1020 refcnt_lcore[lcore] += free;
1021 printf("%s finished at lcore %u, "
1022 "number of freed mbufs: %u\n",
1023 __func__, lcore, free);
1028 test_refcnt_iter(unsigned int lcore, unsigned int iter,
1029 struct rte_mempool *refcnt_pool,
1030 struct rte_ring *refcnt_mbuf_ring)
1033 unsigned i, n, tref, wn;
1038 /* For each mbuf in the pool:
1040 * - increment it's reference up to N+1,
1041 * - enqueue it N times into the ring for worker cores to free.
1043 for (i = 0, n = rte_mempool_avail_count(refcnt_pool);
1044 i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
1046 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
1048 if ((ref & 1) != 0) {
1049 rte_pktmbuf_refcnt_update(m, ref);
1051 rte_ring_enqueue(refcnt_mbuf_ring, m);
1053 while (ref-- != 0) {
1054 rte_pktmbuf_refcnt_update(m, 1);
1055 rte_ring_enqueue(refcnt_mbuf_ring, m);
1058 rte_pktmbuf_free(m);
1062 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
1063 "%u from %u mbufs\n", lcore, iter, i, n);
1065 /* wait till worker lcores will consume all mbufs */
1066 while (!rte_ring_empty(refcnt_mbuf_ring))
1069 /* check that all mbufs are back into mempool by now */
1070 for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
1071 if ((i = rte_mempool_avail_count(refcnt_pool)) == n) {
1072 refcnt_lcore[lcore] += tref;
1073 printf("%s(lcore=%u, iter=%u) completed, "
1074 "%u references processed\n",
1075 __func__, lcore, iter, tref);
1081 rte_panic("(lcore=%u, iter=%u): after %us only "
1082 "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
1086 test_refcnt_main(struct rte_mempool *refcnt_pool,
1087 struct rte_ring *refcnt_mbuf_ring)
1091 lcore = rte_lcore_id();
1092 printf("%s started at lcore %u\n", __func__, lcore);
1094 for (i = 0; i != REFCNT_MAX_ITER; i++)
1095 test_refcnt_iter(lcore, i, refcnt_pool, refcnt_mbuf_ring);
1097 refcnt_stop_workers = 1;
1100 printf("%s finished at lcore %u\n", __func__, lcore);
1107 test_refcnt_mbuf(void)
1109 #ifdef RTE_MBUF_REFCNT_ATOMIC
1110 unsigned int main_lcore, worker, tref;
1112 struct rte_mempool *refcnt_pool = NULL;
1113 struct rte_ring *refcnt_mbuf_ring = NULL;
1115 if (rte_lcore_count() < 2) {
1116 printf("Not enough cores for test_refcnt_mbuf, expecting at least 2\n");
1117 return TEST_SKIPPED;
1120 printf("starting %s, at %u lcores\n", __func__, rte_lcore_count());
1122 /* create refcnt pool & ring if they don't exist */
1124 refcnt_pool = rte_pktmbuf_pool_create(MAKE_STRING(refcnt_pool),
1125 REFCNT_MBUF_NUM, 0, 0, 0,
1127 if (refcnt_pool == NULL) {
1128 printf("%s: cannot allocate " MAKE_STRING(refcnt_pool) "\n",
1133 refcnt_mbuf_ring = rte_ring_create("refcnt_mbuf_ring",
1134 rte_align32pow2(REFCNT_RING_SIZE), SOCKET_ID_ANY,
1136 if (refcnt_mbuf_ring == NULL) {
1137 printf("%s: cannot allocate " MAKE_STRING(refcnt_mbuf_ring)
1142 refcnt_stop_workers = 0;
1143 memset(refcnt_lcore, 0, sizeof (refcnt_lcore));
1145 rte_eal_mp_remote_launch(test_refcnt_worker, refcnt_mbuf_ring, SKIP_MAIN);
1147 test_refcnt_main(refcnt_pool, refcnt_mbuf_ring);
1149 rte_eal_mp_wait_lcore();
1151 /* check that we porcessed all references */
1153 main_lcore = rte_get_main_lcore();
1155 RTE_LCORE_FOREACH_WORKER(worker)
1156 tref += refcnt_lcore[worker];
1158 if (tref != refcnt_lcore[main_lcore])
1159 rte_panic("referenced mbufs: %u, freed mbufs: %u\n",
1160 tref, refcnt_lcore[main_lcore]);
1162 rte_mempool_dump(stdout, refcnt_pool);
1163 rte_ring_dump(stdout, refcnt_mbuf_ring);
1168 rte_mempool_free(refcnt_pool);
1169 rte_ring_free(refcnt_mbuf_ring);
1177 #include <sys/wait.h>
1179 /* use fork() to test mbuf errors panic */
1181 verify_mbuf_check_panics(struct rte_mbuf *buf)
1189 rte_mbuf_sanity_check(buf, 1); /* should panic */
1190 exit(0); /* return normally if it doesn't panic */
1191 } else if (pid < 0){
1192 printf("Fork Failed\n");
1203 test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
1205 struct rte_mbuf *buf;
1206 struct rte_mbuf badbuf;
1208 printf("Checking rte_mbuf_sanity_check for failure conditions\n");
1210 /* get a good mbuf to use to make copies */
1211 buf = rte_pktmbuf_alloc(pktmbuf_pool);
1215 printf("Checking good mbuf initially\n");
1216 if (verify_mbuf_check_panics(buf) != -1)
1219 printf("Now checking for error conditions\n");
1221 if (verify_mbuf_check_panics(NULL)) {
1222 printf("Error with NULL mbuf test\n");
1228 if (verify_mbuf_check_panics(&badbuf)) {
1229 printf("Error with bad-pool mbuf test\n");
1234 badbuf.buf_iova = 0;
1235 if (verify_mbuf_check_panics(&badbuf)) {
1236 printf("Error with bad-physaddr mbuf test\n");
1241 badbuf.buf_addr = NULL;
1242 if (verify_mbuf_check_panics(&badbuf)) {
1243 printf("Error with bad-addr mbuf test\n");
1249 if (verify_mbuf_check_panics(&badbuf)) {
1250 printf("Error with bad-refcnt(0) mbuf test\n");
1255 badbuf.refcnt = UINT16_MAX;
1256 if (verify_mbuf_check_panics(&badbuf)) {
1257 printf("Error with bad-refcnt(MAX) mbuf test\n");
1265 test_mbuf_linearize(struct rte_mempool *pktmbuf_pool, int pkt_len,
1269 struct rte_mbuf *m = NULL, *mbuf = NULL;
1277 printf("Packet size must be 1 or more (is %d)\n", pkt_len);
1282 printf("Number of segments must be 1 or more (is %d)\n",
1287 seg_len = pkt_len / nb_segs;
1293 /* Create chained mbuf_src and fill it generated data */
1294 for (seg = 0; remain > 0; seg++) {
1296 m = rte_pktmbuf_alloc(pktmbuf_pool);
1298 printf("Cannot create segment for source mbuf");
1302 /* Make sure if tailroom is zeroed */
1303 memset(rte_pktmbuf_mtod(m, uint8_t *), 0,
1304 rte_pktmbuf_tailroom(m));
1307 if (data_len > seg_len)
1310 data = (uint8_t *)rte_pktmbuf_append(m, data_len);
1312 printf("Cannot append %d bytes to the mbuf\n",
1317 for (i = 0; i < data_len; i++)
1318 data[i] = (seg * seg_len + i) % 0x0ff;
1323 rte_pktmbuf_chain(mbuf, m);
1328 /* Create destination buffer to store coalesced data */
1329 if (rte_pktmbuf_linearize(mbuf)) {
1330 printf("Mbuf linearization failed\n");
1334 if (!rte_pktmbuf_is_contiguous(mbuf)) {
1335 printf("Source buffer should be contiguous after "
1340 data = rte_pktmbuf_mtod(mbuf, uint8_t *);
1342 for (i = 0; i < pkt_len; i++)
1343 if (data[i] != (i % 0x0ff)) {
1344 printf("Incorrect data in linearized mbuf\n");
1348 rte_pktmbuf_free(mbuf);
1353 rte_pktmbuf_free(mbuf);
1358 test_mbuf_linearize_check(struct rte_mempool *pktmbuf_pool)
1360 struct test_mbuf_array {
1372 printf("Test mbuf linearize API\n");
1374 for (i = 0; i < RTE_DIM(mbuf_array); i++)
1375 if (test_mbuf_linearize(pktmbuf_pool, mbuf_array[i].size,
1376 mbuf_array[i].nb_segs)) {
1377 printf("Test failed for %d, %d\n", mbuf_array[i].size,
1378 mbuf_array[i].nb_segs);
1386 * Helper function for test_tx_ofload
1389 set_tx_offload(struct rte_mbuf *mb, uint64_t il2, uint64_t il3, uint64_t il4,
1390 uint64_t tso, uint64_t ol3, uint64_t ol2)
1395 mb->tso_segsz = tso;
1396 mb->outer_l3_len = ol3;
1397 mb->outer_l2_len = ol2;
1401 test_tx_offload(void)
1403 struct rte_mbuf *mb;
1404 uint64_t tm, v1, v2;
1408 static volatile struct {
1415 const uint32_t num = 0x10000;
1417 txof.l2 = rte_rand() % (1 << RTE_MBUF_L2_LEN_BITS);
1418 txof.l3 = rte_rand() % (1 << RTE_MBUF_L3_LEN_BITS);
1419 txof.l4 = rte_rand() % (1 << RTE_MBUF_L4_LEN_BITS);
1420 txof.tso = rte_rand() % (1 << RTE_MBUF_TSO_SEGSZ_BITS);
1422 printf("%s started, tx_offload = {\n"
1426 "\ttso_segsz=%#hx,\n"
1427 "\touter_l3_len=%#x,\n"
1428 "\touter_l2_len=%#x,\n"
1431 txof.l2, txof.l3, txof.l4, txof.tso, txof.l3, txof.l2);
1433 sz = sizeof(*mb) * num;
1434 mb = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
1436 printf("%s failed, out of memory\n", __func__);
1441 tm = rte_rdtsc_precise();
1443 for (i = 0; i != num; i++)
1444 set_tx_offload(mb + i, txof.l2, txof.l3, txof.l4,
1445 txof.tso, txof.l3, txof.l2);
1447 tm = rte_rdtsc_precise() - tm;
1448 printf("%s set tx_offload by bit-fields: %u iterations, %"
1449 PRIu64 " cycles, %#Lf cycles/iter\n",
1450 __func__, num, tm, (long double)tm / num);
1452 v1 = mb[rte_rand() % num].tx_offload;
1455 tm = rte_rdtsc_precise();
1457 for (i = 0; i != num; i++)
1458 mb[i].tx_offload = rte_mbuf_tx_offload(txof.l2, txof.l3,
1459 txof.l4, txof.tso, txof.l3, txof.l2, 0);
1461 tm = rte_rdtsc_precise() - tm;
1462 printf("%s set raw tx_offload: %u iterations, %"
1463 PRIu64 " cycles, %#Lf cycles/iter\n",
1464 __func__, num, tm, (long double)tm / num);
1466 v2 = mb[rte_rand() % num].tx_offload;
1470 printf("%s finished\n"
1471 "expected tx_offload value: 0x%" PRIx64 ";\n"
1472 "rte_mbuf_tx_offload value: 0x%" PRIx64 ";\n",
1475 return (v1 == v2) ? 0 : -EINVAL;
1479 test_get_rx_ol_flag_list(void)
1481 int len = 6, ret = 0;
1485 /* Test case to check with null buffer */
1486 ret = rte_get_rx_ol_flag_list(0, NULL, 0);
1488 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1490 /* Test case to check with zero buffer len */
1491 ret = rte_get_rx_ol_flag_list(PKT_RX_L4_CKSUM_MASK, buf, 0);
1493 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1495 buflen = strlen(buf);
1497 GOTO_FAIL("%s buffer should be empty, received = %d\n",
1500 /* Test case to check with reduced buffer len */
1501 ret = rte_get_rx_ol_flag_list(0, buf, len);
1503 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1505 buflen = strlen(buf);
1506 if (buflen != (len - 1))
1507 GOTO_FAIL("%s invalid buffer length retrieved, expected: %d,"
1508 "received = %d\n", __func__,
1511 /* Test case to check with zero mask value */
1512 ret = rte_get_rx_ol_flag_list(0, buf, sizeof(buf));
1514 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
1516 buflen = strlen(buf);
1518 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
1519 "non-zero, buffer should not be empty");
1521 /* Test case to check with valid mask value */
1522 ret = rte_get_rx_ol_flag_list(PKT_RX_SEC_OFFLOAD, buf, sizeof(buf));
1524 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
1526 buflen = strlen(buf);
1528 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
1529 "non-zero, buffer should not be empty");
1537 test_get_tx_ol_flag_list(void)
1539 int len = 6, ret = 0;
1543 /* Test case to check with null buffer */
1544 ret = rte_get_tx_ol_flag_list(0, NULL, 0);
1546 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1548 /* Test case to check with zero buffer len */
1549 ret = rte_get_tx_ol_flag_list(PKT_TX_IP_CKSUM, buf, 0);
1551 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1553 buflen = strlen(buf);
1555 GOTO_FAIL("%s buffer should be empty, received = %d\n",
1559 /* Test case to check with reduced buffer len */
1560 ret = rte_get_tx_ol_flag_list(0, buf, len);
1562 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
1564 buflen = strlen(buf);
1565 if (buflen != (len - 1))
1566 GOTO_FAIL("%s invalid buffer length retrieved, expected: %d,"
1567 "received = %d\n", __func__,
1570 /* Test case to check with zero mask value */
1571 ret = rte_get_tx_ol_flag_list(0, buf, sizeof(buf));
1573 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
1575 buflen = strlen(buf);
1577 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
1578 "non-zero, buffer should not be empty");
1580 /* Test case to check with valid mask value */
1581 ret = rte_get_tx_ol_flag_list(PKT_TX_UDP_CKSUM, buf, sizeof(buf));
1583 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
1585 buflen = strlen(buf);
1587 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
1588 "non-zero, buffer should not be empty");
1602 test_get_rx_ol_flag_name(void)
1605 const char *flag_str = NULL;
1606 const struct flag_name rx_flags[] = {
1607 VAL_NAME(PKT_RX_VLAN),
1608 VAL_NAME(PKT_RX_RSS_HASH),
1609 VAL_NAME(PKT_RX_FDIR),
1610 VAL_NAME(PKT_RX_L4_CKSUM_BAD),
1611 VAL_NAME(PKT_RX_L4_CKSUM_GOOD),
1612 VAL_NAME(PKT_RX_L4_CKSUM_NONE),
1613 VAL_NAME(PKT_RX_IP_CKSUM_BAD),
1614 VAL_NAME(PKT_RX_IP_CKSUM_GOOD),
1615 VAL_NAME(PKT_RX_IP_CKSUM_NONE),
1616 VAL_NAME(PKT_RX_EIP_CKSUM_BAD),
1617 VAL_NAME(PKT_RX_VLAN_STRIPPED),
1618 VAL_NAME(PKT_RX_IEEE1588_PTP),
1619 VAL_NAME(PKT_RX_IEEE1588_TMST),
1620 VAL_NAME(PKT_RX_FDIR_ID),
1621 VAL_NAME(PKT_RX_FDIR_FLX),
1622 VAL_NAME(PKT_RX_QINQ_STRIPPED),
1623 VAL_NAME(PKT_RX_LRO),
1624 VAL_NAME(PKT_RX_TIMESTAMP),
1625 VAL_NAME(PKT_RX_SEC_OFFLOAD),
1626 VAL_NAME(PKT_RX_SEC_OFFLOAD_FAILED),
1627 VAL_NAME(PKT_RX_OUTER_L4_CKSUM_BAD),
1628 VAL_NAME(PKT_RX_OUTER_L4_CKSUM_GOOD),
1629 VAL_NAME(PKT_RX_OUTER_L4_CKSUM_INVALID),
1632 /* Test case to check with valid flag */
1633 for (i = 0; i < RTE_DIM(rx_flags); i++) {
1634 flag_str = rte_get_rx_ol_flag_name(rx_flags[i].flag);
1635 if (flag_str == NULL)
1636 GOTO_FAIL("%s: Expected flagname = %s; received null\n",
1637 __func__, rx_flags[i].name);
1638 if (strcmp(flag_str, rx_flags[i].name) != 0)
1639 GOTO_FAIL("%s: Expected flagname = %s; received = %s\n",
1640 __func__, rx_flags[i].name, flag_str);
1642 /* Test case to check with invalid flag */
1643 flag_str = rte_get_rx_ol_flag_name(0);
1644 if (flag_str != NULL) {
1645 GOTO_FAIL("%s: Expected flag name = null; received = %s\n",
1646 __func__, flag_str);
1655 test_get_tx_ol_flag_name(void)
1658 const char *flag_str = NULL;
1659 const struct flag_name tx_flags[] = {
1660 VAL_NAME(PKT_TX_VLAN),
1661 VAL_NAME(PKT_TX_IP_CKSUM),
1662 VAL_NAME(PKT_TX_TCP_CKSUM),
1663 VAL_NAME(PKT_TX_SCTP_CKSUM),
1664 VAL_NAME(PKT_TX_UDP_CKSUM),
1665 VAL_NAME(PKT_TX_IEEE1588_TMST),
1666 VAL_NAME(PKT_TX_TCP_SEG),
1667 VAL_NAME(PKT_TX_IPV4),
1668 VAL_NAME(PKT_TX_IPV6),
1669 VAL_NAME(PKT_TX_OUTER_IP_CKSUM),
1670 VAL_NAME(PKT_TX_OUTER_IPV4),
1671 VAL_NAME(PKT_TX_OUTER_IPV6),
1672 VAL_NAME(PKT_TX_TUNNEL_VXLAN),
1673 VAL_NAME(PKT_TX_TUNNEL_GRE),
1674 VAL_NAME(PKT_TX_TUNNEL_IPIP),
1675 VAL_NAME(PKT_TX_TUNNEL_GENEVE),
1676 VAL_NAME(PKT_TX_TUNNEL_MPLSINUDP),
1677 VAL_NAME(PKT_TX_TUNNEL_VXLAN_GPE),
1678 VAL_NAME(PKT_TX_TUNNEL_IP),
1679 VAL_NAME(PKT_TX_TUNNEL_UDP),
1680 VAL_NAME(PKT_TX_QINQ),
1681 VAL_NAME(PKT_TX_MACSEC),
1682 VAL_NAME(PKT_TX_SEC_OFFLOAD),
1683 VAL_NAME(PKT_TX_UDP_SEG),
1684 VAL_NAME(PKT_TX_OUTER_UDP_CKSUM),
1687 /* Test case to check with valid flag */
1688 for (i = 0; i < RTE_DIM(tx_flags); i++) {
1689 flag_str = rte_get_tx_ol_flag_name(tx_flags[i].flag);
1690 if (flag_str == NULL)
1691 GOTO_FAIL("%s: Expected flagname = %s; received null\n",
1692 __func__, tx_flags[i].name);
1693 if (strcmp(flag_str, tx_flags[i].name) != 0)
1694 GOTO_FAIL("%s: Expected flagname = %s; received = %s\n",
1695 __func__, tx_flags[i].name, flag_str);
1697 /* Test case to check with invalid flag */
1698 flag_str = rte_get_tx_ol_flag_name(0);
1699 if (flag_str != NULL) {
1700 GOTO_FAIL("%s: Expected flag name = null; received = %s\n",
1701 __func__, flag_str);
1711 test_mbuf_validate_tx_offload(const char *test_name,
1712 struct rte_mempool *pktmbuf_pool,
1715 int expected_retval)
1717 struct rte_mbuf *m = NULL;
1720 /* alloc a mbuf and do sanity check */
1721 m = rte_pktmbuf_alloc(pktmbuf_pool);
1723 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
1724 if (rte_pktmbuf_pkt_len(m) != 0)
1725 GOTO_FAIL("%s: Bad packet length\n", __func__);
1726 rte_mbuf_sanity_check(m, 0);
1727 m->ol_flags = ol_flags;
1728 m->tso_segsz = segsize;
1729 ret = rte_validate_tx_offload(m);
1730 if (ret != expected_retval)
1731 GOTO_FAIL("%s(%s): expected ret val: %d; received: %d\n",
1732 __func__, test_name, expected_retval, ret);
1733 rte_pktmbuf_free(m);
1738 rte_pktmbuf_free(m);
1745 test_mbuf_validate_tx_offload_one(struct rte_mempool *pktmbuf_pool)
1747 /* test to validate tx offload flags */
1748 uint64_t ol_flags = 0;
1750 /* test to validate if IP checksum is counted only for IPV4 packet */
1751 /* set both IP checksum and IPV6 flags */
1752 ol_flags |= PKT_TX_IP_CKSUM;
1753 ol_flags |= PKT_TX_IPV6;
1754 if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_CKSUM_IPV6_SET",
1756 ol_flags, 0, -EINVAL) < 0)
1757 GOTO_FAIL("%s failed: IP cksum is set incorrect.\n", __func__);
1758 /* resetting ol_flags for next testcase */
1761 /* test to validate if IP type is set when required */
1762 ol_flags |= PKT_TX_L4_MASK;
1763 if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_NOT_SET",
1765 ol_flags, 0, -EINVAL) < 0)
1766 GOTO_FAIL("%s failed: IP type is not set.\n", __func__);
1768 /* test if IP type is set when TCP SEG is on */
1769 ol_flags |= PKT_TX_TCP_SEG;
1770 if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_NOT_SET",
1772 ol_flags, 0, -EINVAL) < 0)
1773 GOTO_FAIL("%s failed: IP type is not set.\n", __func__);
1776 /* test to confirm IP type (IPV4/IPV6) is set */
1777 ol_flags = PKT_TX_L4_MASK;
1778 ol_flags |= PKT_TX_IPV6;
1779 if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_SET",
1781 ol_flags, 0, 0) < 0)
1782 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
1785 /* test to check TSO segment size is non-zero */
1786 ol_flags |= PKT_TX_IPV4;
1787 ol_flags |= PKT_TX_TCP_SEG;
1788 /* set 0 tso segment size */
1789 if (test_mbuf_validate_tx_offload("MBUF_TEST_NULL_TSO_SEGSZ",
1791 ol_flags, 0, -EINVAL) < 0)
1792 GOTO_FAIL("%s failed: tso segment size is null.\n", __func__);
1794 /* retain IPV4 and PKT_TX_TCP_SEG mask */
1795 /* set valid tso segment size but IP CKSUM not set */
1796 if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IP_CKSUM_NOT_SET",
1798 ol_flags, 512, -EINVAL) < 0)
1799 GOTO_FAIL("%s failed: IP CKSUM is not set.\n", __func__);
1801 /* test to validate if IP checksum is set for TSO capability */
1802 /* retain IPV4, TCP_SEG, tso_seg size */
1803 ol_flags |= PKT_TX_IP_CKSUM;
1804 if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IP_CKSUM_SET",
1806 ol_flags, 512, 0) < 0)
1807 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
1809 /* test to confirm TSO for IPV6 type */
1811 ol_flags |= PKT_TX_IPV6;
1812 ol_flags |= PKT_TX_TCP_SEG;
1813 if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IPV6_SET",
1815 ol_flags, 512, 0) < 0)
1816 GOTO_FAIL("%s failed: TSO req not met.\n", __func__);
1819 /* test if outer IP checksum set for non outer IPv4 packet */
1820 ol_flags |= PKT_TX_IPV6;
1821 ol_flags |= PKT_TX_OUTER_IP_CKSUM;
1822 if (test_mbuf_validate_tx_offload("MBUF_TEST_OUTER_IPV4_NOT_SET",
1824 ol_flags, 512, -EINVAL) < 0)
1825 GOTO_FAIL("%s failed: Outer IP cksum set.\n", __func__);
1828 /* test to confirm outer IP checksum is set for outer IPV4 packet */
1829 ol_flags |= PKT_TX_OUTER_IP_CKSUM;
1830 ol_flags |= PKT_TX_OUTER_IPV4;
1831 if (test_mbuf_validate_tx_offload("MBUF_TEST_OUTER_IPV4_SET",
1833 ol_flags, 512, 0) < 0)
1834 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
1837 /* test to confirm if packets with no TX_OFFLOAD_MASK are skipped */
1838 if (test_mbuf_validate_tx_offload("MBUF_TEST_OL_MASK_NOT_SET",
1840 ol_flags, 512, 0) < 0)
1841 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
1848 * Test for allocating a bulk of mbufs
1849 * define an array with positive sizes for mbufs allocations.
1852 test_pktmbuf_alloc_bulk(struct rte_mempool *pktmbuf_pool)
1855 unsigned int idx, loop;
1856 unsigned int alloc_counts[] = {
1858 MEMPOOL_CACHE_SIZE - 1,
1859 MEMPOOL_CACHE_SIZE + 1,
1860 MEMPOOL_CACHE_SIZE * 1.5,
1861 MEMPOOL_CACHE_SIZE * 2,
1862 MEMPOOL_CACHE_SIZE * 2 - 1,
1863 MEMPOOL_CACHE_SIZE * 2 + 1,
1867 /* allocate a large array of mbuf pointers */
1868 struct rte_mbuf *mbufs[NB_MBUF] = { 0 };
1869 for (idx = 0; idx < RTE_DIM(alloc_counts); idx++) {
1870 ret = rte_pktmbuf_alloc_bulk(pktmbuf_pool, mbufs,
1873 for (loop = 0; loop < alloc_counts[idx] &&
1874 mbufs[loop] != NULL; loop++)
1875 rte_pktmbuf_free(mbufs[loop]);
1876 } else if (ret != 0) {
1877 printf("%s: Bulk alloc failed count(%u); ret val(%d)\n",
1878 __func__, alloc_counts[idx], ret);
1886 * Negative testing for allocating a bulk of mbufs
1889 test_neg_pktmbuf_alloc_bulk(struct rte_mempool *pktmbuf_pool)
1892 unsigned int idx, loop;
1893 unsigned int neg_alloc_counts[] = {
1894 MEMPOOL_CACHE_SIZE - NB_MBUF,
1899 struct rte_mbuf *mbufs[NB_MBUF * 8] = { 0 };
1901 for (idx = 0; idx < RTE_DIM(neg_alloc_counts); idx++) {
1902 ret = rte_pktmbuf_alloc_bulk(pktmbuf_pool, mbufs,
1903 neg_alloc_counts[idx]);
1905 printf("%s: Bulk alloc must fail! count(%u); ret(%d)\n",
1906 __func__, neg_alloc_counts[idx], ret);
1907 for (loop = 0; loop < neg_alloc_counts[idx] &&
1908 mbufs[loop] != NULL; loop++)
1909 rte_pktmbuf_free(mbufs[loop]);
1917 * Test to read mbuf packet using rte_pktmbuf_read
1920 test_pktmbuf_read(struct rte_mempool *pktmbuf_pool)
1922 struct rte_mbuf *m = NULL;
1924 const char *data_copy = NULL;
1928 m = rte_pktmbuf_alloc(pktmbuf_pool);
1930 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
1931 if (rte_pktmbuf_pkt_len(m) != 0)
1932 GOTO_FAIL("%s: Bad packet length\n", __func__);
1933 rte_mbuf_sanity_check(m, 0);
1935 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
1937 GOTO_FAIL("%s: Cannot append data\n", __func__);
1938 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN2)
1939 GOTO_FAIL("%s: Bad packet length\n", __func__);
1940 memset(data, 0xfe, MBUF_TEST_DATA_LEN2);
1942 /* read the data from mbuf */
1943 data_copy = rte_pktmbuf_read(m, 0, MBUF_TEST_DATA_LEN2, NULL);
1944 if (data_copy == NULL)
1945 GOTO_FAIL("%s: Error in reading data!\n", __func__);
1946 for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
1947 if (data_copy[off] != (char)0xfe)
1948 GOTO_FAIL("Data corrupted at offset %u", off);
1950 rte_pktmbuf_free(m);
1956 rte_pktmbuf_free(m);
1963 * Test to read mbuf packet data from offset
1966 test_pktmbuf_read_from_offset(struct rte_mempool *pktmbuf_pool)
1968 struct rte_mbuf *m = NULL;
1969 struct ether_hdr *hdr = NULL;
1971 const char *data_copy = NULL;
1973 unsigned int hdr_len = sizeof(struct rte_ether_hdr);
1976 m = rte_pktmbuf_alloc(pktmbuf_pool);
1978 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
1980 if (rte_pktmbuf_pkt_len(m) != 0)
1981 GOTO_FAIL("%s: Bad packet length\n", __func__);
1982 rte_mbuf_sanity_check(m, 0);
1984 /* prepend an ethernet header */
1985 hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m, hdr_len);
1987 GOTO_FAIL("%s: Cannot prepend header\n", __func__);
1988 if (rte_pktmbuf_pkt_len(m) != hdr_len)
1989 GOTO_FAIL("%s: Bad pkt length", __func__);
1990 if (rte_pktmbuf_data_len(m) != hdr_len)
1991 GOTO_FAIL("%s: Bad data length", __func__);
1992 memset(hdr, 0xde, hdr_len);
1994 /* read mbuf header info from 0 offset */
1995 data_copy = rte_pktmbuf_read(m, 0, hdr_len, NULL);
1996 if (data_copy == NULL)
1997 GOTO_FAIL("%s: Error in reading header!\n", __func__);
1998 for (off = 0; off < hdr_len; off++) {
1999 if (data_copy[off] != (char)0xde)
2000 GOTO_FAIL("Header info corrupted at offset %u", off);
2003 /* append sample data after ethernet header */
2004 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
2006 GOTO_FAIL("%s: Cannot append data\n", __func__);
2007 if (rte_pktmbuf_pkt_len(m) != hdr_len + MBUF_TEST_DATA_LEN2)
2008 GOTO_FAIL("%s: Bad packet length\n", __func__);
2009 if (rte_pktmbuf_data_len(m) != hdr_len + MBUF_TEST_DATA_LEN2)
2010 GOTO_FAIL("%s: Bad data length\n", __func__);
2011 memset(data, 0xcc, MBUF_TEST_DATA_LEN2);
2013 /* read mbuf data after header info */
2014 data_copy = rte_pktmbuf_read(m, hdr_len, MBUF_TEST_DATA_LEN2, NULL);
2015 if (data_copy == NULL)
2016 GOTO_FAIL("%s: Error in reading header data!\n", __func__);
2017 for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
2018 if (data_copy[off] != (char)0xcc)
2019 GOTO_FAIL("Data corrupted at offset %u", off);
2022 /* partial reading of mbuf data */
2023 data_copy = rte_pktmbuf_read(m, hdr_len + 5, MBUF_TEST_DATA_LEN2 - 5,
2025 if (data_copy == NULL)
2026 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2027 if (strlen(data_copy) != MBUF_TEST_DATA_LEN2 - 5)
2028 GOTO_FAIL("%s: Incorrect data length!\n", __func__);
2029 for (off = 0; off < MBUF_TEST_DATA_LEN2 - 5; off++) {
2030 if (data_copy[off] != (char)0xcc)
2031 GOTO_FAIL("Data corrupted at offset %u", off);
2034 /* read length greater than mbuf data_len */
2035 if (rte_pktmbuf_read(m, hdr_len, rte_pktmbuf_data_len(m) + 1,
2037 GOTO_FAIL("%s: Requested len is larger than mbuf data len!\n",
2040 /* read length greater than mbuf pkt_len */
2041 if (rte_pktmbuf_read(m, hdr_len, rte_pktmbuf_pkt_len(m) + 1,
2043 GOTO_FAIL("%s: Requested len is larger than mbuf pkt len!\n",
2046 /* read data of zero len from valid offset */
2047 data_copy = rte_pktmbuf_read(m, hdr_len, 0, NULL);
2048 if (data_copy == NULL)
2049 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2050 if (strlen(data_copy) != MBUF_TEST_DATA_LEN2)
2051 GOTO_FAIL("%s: Corrupted data content!\n", __func__);
2052 for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
2053 if (data_copy[off] != (char)0xcc)
2054 GOTO_FAIL("Data corrupted at offset %u", off);
2057 /* read data of zero length from zero offset */
2058 data_copy = rte_pktmbuf_read(m, 0, 0, NULL);
2059 if (data_copy == NULL)
2060 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2061 /* check if the received address is the beginning of header info */
2062 if (hdr != (const struct ether_hdr *)data_copy)
2063 GOTO_FAIL("%s: Corrupted data address!\n", __func__);
2065 /* read data of max length from valid offset */
2066 data_copy = rte_pktmbuf_read(m, hdr_len, UINT_MAX, NULL);
2067 if (data_copy == NULL)
2068 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2069 /* check if the received address is the beginning of data segment */
2070 if (data_copy != data)
2071 GOTO_FAIL("%s: Corrupted data address!\n", __func__);
2073 /* try to read from mbuf with max size offset */
2074 data_copy = rte_pktmbuf_read(m, UINT_MAX, 0, NULL);
2075 if (data_copy != NULL)
2076 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2078 /* try to read from mbuf with max size offset and len */
2079 data_copy = rte_pktmbuf_read(m, UINT_MAX, UINT_MAX, NULL);
2080 if (data_copy != NULL)
2081 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
2083 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
2085 rte_pktmbuf_free(m);
2091 rte_pktmbuf_free(m);
2098 unsigned int seg_count;
2102 unsigned int seg_lengths[MBUF_MAX_SEG];
2105 /* create a mbuf with different sized segments
2106 * and fill with data [0x00 0x01 0x02 ...]
2108 static struct rte_mbuf *
2109 create_packet(struct rte_mempool *pktmbuf_pool,
2110 struct test_case *test_data)
2112 uint16_t i, ret, seg, seg_len = 0;
2113 uint32_t last_index = 0;
2114 unsigned int seg_lengths[MBUF_MAX_SEG];
2115 unsigned int hdr_len;
2116 struct rte_mbuf *pkt = NULL;
2117 struct rte_mbuf *pkt_seg = NULL;
2121 memcpy(seg_lengths, test_data->seg_lengths,
2122 sizeof(unsigned int)*test_data->seg_count);
2123 for (seg = 0; seg < test_data->seg_count; seg++) {
2125 seg_len = seg_lengths[seg];
2126 pkt_seg = rte_pktmbuf_alloc(pktmbuf_pool);
2127 if (pkt_seg == NULL)
2128 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
2129 if (rte_pktmbuf_pkt_len(pkt_seg) != 0)
2130 GOTO_FAIL("%s: Bad packet length\n", __func__);
2131 rte_mbuf_sanity_check(pkt_seg, 0);
2132 /* Add header only for the first segment */
2133 if (test_data->flags == MBUF_HEADER && seg == 0) {
2134 hdr_len = sizeof(struct rte_ether_hdr);
2135 /* prepend a header and fill with dummy data */
2136 hdr = (char *)rte_pktmbuf_prepend(pkt_seg, hdr_len);
2138 GOTO_FAIL("%s: Cannot prepend header\n",
2140 if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len)
2141 GOTO_FAIL("%s: Bad pkt length", __func__);
2142 if (rte_pktmbuf_data_len(pkt_seg) != hdr_len)
2143 GOTO_FAIL("%s: Bad data length", __func__);
2144 for (i = 0; i < hdr_len; i++)
2145 hdr[i] = (last_index + i) % 0xffff;
2146 last_index += hdr_len;
2148 /* skip appending segment with 0 length */
2151 data = rte_pktmbuf_append(pkt_seg, seg_len);
2153 GOTO_FAIL("%s: Cannot append data segment\n", __func__);
2154 if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len + seg_len)
2155 GOTO_FAIL("%s: Bad packet segment length: %d\n",
2156 __func__, rte_pktmbuf_pkt_len(pkt_seg));
2157 if (rte_pktmbuf_data_len(pkt_seg) != hdr_len + seg_len)
2158 GOTO_FAIL("%s: Bad data length\n", __func__);
2159 for (i = 0; i < seg_len; i++)
2160 data[i] = (last_index + i) % 0xffff;
2161 /* to fill continuous data from one seg to another */
2163 /* create chained mbufs */
2167 ret = rte_pktmbuf_chain(pkt, pkt_seg);
2169 GOTO_FAIL("%s:FAIL: Chained mbuf creation %d\n",
2173 pkt_seg = pkt_seg->next;
2178 rte_pktmbuf_free(pkt);
2181 if (pkt_seg != NULL) {
2182 rte_pktmbuf_free(pkt_seg);
2189 test_pktmbuf_read_from_chain(struct rte_mempool *pktmbuf_pool)
2192 struct test_case test_cases[] = {
2194 .seg_lengths = { 100, 100, 100 },
2196 .flags = MBUF_NO_HEADER,
2201 .seg_lengths = { 100, 125, 150 },
2203 .flags = MBUF_NO_HEADER,
2208 .seg_lengths = { 100, 100 },
2210 .flags = MBUF_NO_HEADER,
2215 .seg_lengths = { 100, 200 },
2217 .flags = MBUF_HEADER,
2218 .read_off = sizeof(struct rte_ether_hdr),
2222 .seg_lengths = { 1000, 100 },
2224 .flags = MBUF_NO_HEADER,
2229 .seg_lengths = { 1024, 0, 100 },
2231 .flags = MBUF_NO_HEADER,
2236 .seg_lengths = { 1000, 1, 1000 },
2238 .flags = MBUF_NO_HEADER,
2243 .seg_lengths = { MBUF_TEST_DATA_LEN,
2244 MBUF_TEST_DATA_LEN2,
2245 MBUF_TEST_DATA_LEN3, 800, 10 },
2247 .flags = MBUF_NEG_TEST_READ,
2249 .read_len = MBUF_DATA_SIZE
2254 const char *data_copy = NULL;
2255 char data_buf[MBUF_DATA_SIZE];
2257 memset(data_buf, 0, MBUF_DATA_SIZE);
2259 for (i = 0; i < RTE_DIM(test_cases); i++) {
2260 m = create_packet(pktmbuf_pool, &test_cases[i]);
2262 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
2264 data_copy = rte_pktmbuf_read(m, test_cases[i].read_off,
2265 test_cases[i].read_len, data_buf);
2266 if (test_cases[i].flags == MBUF_NEG_TEST_READ) {
2267 if (data_copy != NULL)
2268 GOTO_FAIL("%s: mbuf data read should fail!\n",
2271 rte_pktmbuf_free(m);
2276 if (data_copy == NULL)
2277 GOTO_FAIL("%s: Error in reading packet data!\n",
2279 for (pos = 0; pos < test_cases[i].read_len; pos++) {
2280 if (data_copy[pos] !=
2281 (char)((test_cases[i].read_off + pos)
2283 GOTO_FAIL("Data corrupted at offset %u is %2X",
2284 pos, data_copy[pos]);
2286 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
2287 rte_pktmbuf_free(m);
2294 rte_pktmbuf_free(m);
2300 /* Define a free call back function to be used for external buffer */
2302 ext_buf_free_callback_fn(void *addr __rte_unused, void *opaque)
2304 void *ext_buf_addr = opaque;
2306 if (ext_buf_addr == NULL) {
2307 printf("External buffer address is invalid\n");
2310 rte_free(ext_buf_addr);
2311 ext_buf_addr = NULL;
2312 printf("External buffer freed via callback\n");
2316 * Test to initialize shared data in external buffer before attaching to mbuf
2317 * - Allocate mbuf with no data.
2318 * - Allocate external buffer with size should be large enough to accommodate
2319 * rte_mbuf_ext_shared_info.
2320 * - Invoke pktmbuf_ext_shinfo_init_helper to initialize shared data.
2321 * - Invoke rte_pktmbuf_attach_extbuf to attach external buffer to the mbuf.
2322 * - Clone another mbuf and attach the same external buffer to it.
2323 * - Invoke rte_pktmbuf_detach_extbuf to detach the external buffer from mbuf.
2326 test_pktmbuf_ext_shinfo_init_helper(struct rte_mempool *pktmbuf_pool)
2328 struct rte_mbuf *m = NULL;
2329 struct rte_mbuf *clone = NULL;
2330 struct rte_mbuf_ext_shared_info *ret_shinfo = NULL;
2331 rte_iova_t buf_iova;
2332 void *ext_buf_addr = NULL;
2333 uint16_t buf_len = EXT_BUF_TEST_DATA_LEN +
2334 sizeof(struct rte_mbuf_ext_shared_info);
2337 m = rte_pktmbuf_alloc(pktmbuf_pool);
2339 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
2340 if (rte_pktmbuf_pkt_len(m) != 0)
2341 GOTO_FAIL("%s: Bad packet length\n", __func__);
2342 rte_mbuf_sanity_check(m, 0);
2344 ext_buf_addr = rte_malloc("External buffer", buf_len,
2345 RTE_CACHE_LINE_SIZE);
2346 if (ext_buf_addr == NULL)
2347 GOTO_FAIL("%s: External buffer allocation failed\n", __func__);
2349 ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len,
2350 ext_buf_free_callback_fn, ext_buf_addr);
2351 if (ret_shinfo == NULL)
2352 GOTO_FAIL("%s: Shared info initialization failed!\n", __func__);
2354 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 1)
2355 GOTO_FAIL("%s: External refcount is not 1\n", __func__);
2357 if (rte_mbuf_refcnt_read(m) != 1)
2358 GOTO_FAIL("%s: Invalid refcnt in mbuf\n", __func__);
2360 buf_iova = rte_mempool_virt2iova(ext_buf_addr);
2361 rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len,
2363 if (m->ol_flags != EXT_ATTACHED_MBUF)
2364 GOTO_FAIL("%s: External buffer is not attached to mbuf\n",
2367 /* allocate one more mbuf */
2368 clone = rte_pktmbuf_clone(m, pktmbuf_pool);
2370 GOTO_FAIL("%s: mbuf clone allocation failed!\n", __func__);
2371 if (rte_pktmbuf_pkt_len(clone) != 0)
2372 GOTO_FAIL("%s: Bad packet length\n", __func__);
2374 /* attach the same external buffer to the cloned mbuf */
2375 rte_pktmbuf_attach_extbuf(clone, ext_buf_addr, buf_iova, buf_len,
2377 if (clone->ol_flags != EXT_ATTACHED_MBUF)
2378 GOTO_FAIL("%s: External buffer is not attached to mbuf\n",
2381 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 2)
2382 GOTO_FAIL("%s: Invalid ext_buf ref_cnt\n", __func__);
2384 /* test to manually update ext_buf_ref_cnt from 2 to 3*/
2385 rte_mbuf_ext_refcnt_update(ret_shinfo, 1);
2386 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 3)
2387 GOTO_FAIL("%s: Update ext_buf ref_cnt failed\n", __func__);
2389 /* reset the ext_refcnt before freeing the external buffer */
2390 rte_mbuf_ext_refcnt_set(ret_shinfo, 2);
2391 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 2)
2392 GOTO_FAIL("%s: set ext_buf ref_cnt failed\n", __func__);
2394 /* detach the external buffer from mbufs */
2395 rte_pktmbuf_detach_extbuf(m);
2396 /* check if ref cnt is decremented */
2397 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 1)
2398 GOTO_FAIL("%s: Invalid ext_buf ref_cnt\n", __func__);
2400 rte_pktmbuf_detach_extbuf(clone);
2401 if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 0)
2402 GOTO_FAIL("%s: Invalid ext_buf ref_cnt\n", __func__);
2404 rte_pktmbuf_free(m);
2406 rte_pktmbuf_free(clone);
2413 rte_pktmbuf_free(m);
2417 rte_pktmbuf_free(clone);
2420 if (ext_buf_addr != NULL) {
2421 rte_free(ext_buf_addr);
2422 ext_buf_addr = NULL;
2428 * Test the mbuf pool with pinned external data buffers
2429 * - Allocate memory zone for external buffer
2430 * - Create the mbuf pool with pinned external buffer
2431 * - Check the created pool with relevant mbuf pool unit tests
2434 test_pktmbuf_ext_pinned_buffer(struct rte_mempool *std_pool)
2437 struct rte_pktmbuf_extmem ext_mem;
2438 struct rte_mempool *pinned_pool = NULL;
2439 const struct rte_memzone *mz = NULL;
2441 printf("Test mbuf pool with external pinned data buffers\n");
2443 /* Allocate memzone for the external data buffer */
2444 mz = rte_memzone_reserve("pinned_pool",
2445 NB_MBUF * MBUF_DATA_SIZE,
2447 RTE_MEMZONE_2MB | RTE_MEMZONE_SIZE_HINT_ONLY);
2449 GOTO_FAIL("%s: Memzone allocation failed\n", __func__);
2451 /* Create the mbuf pool with pinned external data buffer */
2452 ext_mem.buf_ptr = mz->addr;
2453 ext_mem.buf_iova = mz->iova;
2454 ext_mem.buf_len = mz->len;
2455 ext_mem.elt_size = MBUF_DATA_SIZE;
2457 pinned_pool = rte_pktmbuf_pool_create_extbuf("test_pinned_pool",
2458 NB_MBUF, MEMPOOL_CACHE_SIZE, 0,
2459 MBUF_DATA_SIZE, SOCKET_ID_ANY,
2461 if (pinned_pool == NULL)
2462 GOTO_FAIL("%s: Mbuf pool with pinned external"
2463 " buffer creation failed\n", __func__);
2464 /* test multiple mbuf alloc */
2465 if (test_pktmbuf_pool(pinned_pool) < 0)
2466 GOTO_FAIL("%s: test_mbuf_pool(pinned) failed\n",
2469 /* do it another time to check that all mbufs were freed */
2470 if (test_pktmbuf_pool(pinned_pool) < 0)
2471 GOTO_FAIL("%s: test_mbuf_pool(pinned) failed (2)\n",
2474 /* test that the data pointer on a packet mbuf is set properly */
2475 if (test_pktmbuf_pool_ptr(pinned_pool) < 0)
2476 GOTO_FAIL("%s: test_pktmbuf_pool_ptr(pinned) failed\n",
2479 /* test data manipulation in mbuf with non-ascii data */
2480 if (test_pktmbuf_with_non_ascii_data(pinned_pool) < 0)
2481 GOTO_FAIL("%s: test_pktmbuf_with_non_ascii_data(pinned)"
2482 " failed\n", __func__);
2484 /* test free pktmbuf segment one by one */
2485 if (test_pktmbuf_free_segment(pinned_pool) < 0)
2486 GOTO_FAIL("%s: test_pktmbuf_free_segment(pinned) failed\n",
2489 if (testclone_testupdate_testdetach(pinned_pool, std_pool) < 0)
2490 GOTO_FAIL("%s: testclone_and_testupdate(pinned) failed\n",
2493 if (test_pktmbuf_copy(pinned_pool, std_pool) < 0)
2494 GOTO_FAIL("%s: test_pktmbuf_copy(pinned) failed\n",
2497 if (test_failing_mbuf_sanity_check(pinned_pool) < 0)
2498 GOTO_FAIL("%s: test_failing_mbuf_sanity_check(pinned)"
2499 " failed\n", __func__);
2501 if (test_mbuf_linearize_check(pinned_pool) < 0)
2502 GOTO_FAIL("%s: test_mbuf_linearize_check(pinned) failed\n",
2505 /* test for allocating a bulk of mbufs with various sizes */
2506 if (test_pktmbuf_alloc_bulk(pinned_pool) < 0)
2507 GOTO_FAIL("%s: test_rte_pktmbuf_alloc_bulk(pinned) failed\n",
2510 /* test for allocating a bulk of mbufs with various sizes */
2511 if (test_neg_pktmbuf_alloc_bulk(pinned_pool) < 0)
2512 GOTO_FAIL("%s: test_neg_rte_pktmbuf_alloc_bulk(pinned)"
2513 " failed\n", __func__);
2515 /* test to read mbuf packet */
2516 if (test_pktmbuf_read(pinned_pool) < 0)
2517 GOTO_FAIL("%s: test_rte_pktmbuf_read(pinned) failed\n",
2520 /* test to read mbuf packet from offset */
2521 if (test_pktmbuf_read_from_offset(pinned_pool) < 0)
2522 GOTO_FAIL("%s: test_rte_pktmbuf_read_from_offset(pinned)"
2523 " failed\n", __func__);
2525 /* test to read data from chain of mbufs with data segments */
2526 if (test_pktmbuf_read_from_chain(pinned_pool) < 0)
2527 GOTO_FAIL("%s: test_rte_pktmbuf_read_from_chain(pinned)"
2528 " failed\n", __func__);
2530 RTE_SET_USED(std_pool);
2531 rte_mempool_free(pinned_pool);
2532 rte_memzone_free(mz);
2536 rte_mempool_free(pinned_pool);
2537 rte_memzone_free(mz);
2542 test_mbuf_dyn(struct rte_mempool *pktmbuf_pool)
2544 const struct rte_mbuf_dynfield dynfield = {
2545 .name = "test-dynfield",
2546 .size = sizeof(uint8_t),
2547 .align = __alignof__(uint8_t),
2550 const struct rte_mbuf_dynfield dynfield2 = {
2551 .name = "test-dynfield2",
2552 .size = sizeof(uint16_t),
2553 .align = __alignof__(uint16_t),
2556 const struct rte_mbuf_dynfield dynfield3 = {
2557 .name = "test-dynfield3",
2558 .size = sizeof(uint8_t),
2559 .align = __alignof__(uint8_t),
2562 const struct rte_mbuf_dynfield dynfield_fail_big = {
2563 .name = "test-dynfield-fail-big",
2568 const struct rte_mbuf_dynfield dynfield_fail_align = {
2569 .name = "test-dynfield-fail-align",
2574 const struct rte_mbuf_dynflag dynflag = {
2575 .name = "test-dynflag",
2578 const struct rte_mbuf_dynflag dynflag2 = {
2579 .name = "test-dynflag2",
2582 const struct rte_mbuf_dynflag dynflag3 = {
2583 .name = "test-dynflag3",
2586 struct rte_mbuf *m = NULL;
2587 int offset, offset2, offset3;
2588 int flag, flag2, flag3;
2591 printf("Test mbuf dynamic fields and flags\n");
2592 rte_mbuf_dyn_dump(stdout);
2594 offset = rte_mbuf_dynfield_register(&dynfield);
2596 GOTO_FAIL("failed to register dynamic field, offset=%d: %s",
2597 offset, strerror(errno));
2599 ret = rte_mbuf_dynfield_register(&dynfield);
2601 GOTO_FAIL("failed to lookup dynamic field, ret=%d: %s",
2602 ret, strerror(errno));
2604 offset2 = rte_mbuf_dynfield_register(&dynfield2);
2605 if (offset2 == -1 || offset2 == offset || (offset2 & 1))
2606 GOTO_FAIL("failed to register dynamic field 2, offset2=%d: %s",
2607 offset2, strerror(errno));
2609 offset3 = rte_mbuf_dynfield_register_offset(&dynfield3,
2610 offsetof(struct rte_mbuf, dynfield1[1]));
2611 if (offset3 != offsetof(struct rte_mbuf, dynfield1[1])) {
2612 if (rte_errno == EBUSY)
2613 printf("mbuf test error skipped: dynfield is busy\n");
2615 GOTO_FAIL("failed to register dynamic field 3, offset="
2616 "%d: %s", offset3, strerror(errno));
2619 printf("dynfield: offset=%d, offset2=%d, offset3=%d\n",
2620 offset, offset2, offset3);
2622 ret = rte_mbuf_dynfield_register(&dynfield_fail_big);
2624 GOTO_FAIL("dynamic field creation should fail (too big)");
2626 ret = rte_mbuf_dynfield_register(&dynfield_fail_align);
2628 GOTO_FAIL("dynamic field creation should fail (bad alignment)");
2630 ret = rte_mbuf_dynfield_register_offset(&dynfield_fail_align,
2631 offsetof(struct rte_mbuf, ol_flags));
2633 GOTO_FAIL("dynamic field creation should fail (not avail)");
2635 flag = rte_mbuf_dynflag_register(&dynflag);
2637 GOTO_FAIL("failed to register dynamic flag, flag=%d: %s",
2638 flag, strerror(errno));
2640 ret = rte_mbuf_dynflag_register(&dynflag);
2642 GOTO_FAIL("failed to lookup dynamic flag, ret=%d: %s",
2643 ret, strerror(errno));
2645 flag2 = rte_mbuf_dynflag_register(&dynflag2);
2646 if (flag2 == -1 || flag2 == flag)
2647 GOTO_FAIL("failed to register dynamic flag 2, flag2=%d: %s",
2648 flag2, strerror(errno));
2650 flag3 = rte_mbuf_dynflag_register_bitnum(&dynflag3,
2651 rte_bsf64(PKT_LAST_FREE));
2652 if (flag3 != rte_bsf64(PKT_LAST_FREE))
2653 GOTO_FAIL("failed to register dynamic flag 3, flag3=%d: %s",
2654 flag3, strerror(errno));
2656 printf("dynflag: flag=%d, flag2=%d, flag3=%d\n", flag, flag2, flag3);
2658 /* set, get dynamic field */
2659 m = rte_pktmbuf_alloc(pktmbuf_pool);
2661 GOTO_FAIL("Cannot allocate mbuf");
2663 *RTE_MBUF_DYNFIELD(m, offset, uint8_t *) = 1;
2664 if (*RTE_MBUF_DYNFIELD(m, offset, uint8_t *) != 1)
2665 GOTO_FAIL("failed to read dynamic field");
2666 *RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) = 1000;
2667 if (*RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) != 1000)
2668 GOTO_FAIL("failed to read dynamic field");
2670 /* set a dynamic flag */
2671 m->ol_flags |= (1ULL << flag);
2673 rte_mbuf_dyn_dump(stdout);
2674 rte_pktmbuf_free(m);
2677 rte_pktmbuf_free(m);
2685 struct rte_mempool *pktmbuf_pool = NULL;
2686 struct rte_mempool *pktmbuf_pool2 = NULL;
2689 RTE_BUILD_BUG_ON(sizeof(struct rte_mbuf) != RTE_CACHE_LINE_MIN_SIZE * 2);
2691 /* create pktmbuf pool if it does not exist */
2692 pktmbuf_pool = rte_pktmbuf_pool_create("test_pktmbuf_pool",
2693 NB_MBUF, MEMPOOL_CACHE_SIZE, 0, MBUF_DATA_SIZE,
2696 if (pktmbuf_pool == NULL) {
2697 printf("cannot allocate mbuf pool\n");
2701 /* test registration of dynamic fields and flags */
2702 if (test_mbuf_dyn(pktmbuf_pool) < 0) {
2703 printf("mbuf dynflag test failed\n");
2707 /* create a specific pktmbuf pool with a priv_size != 0 and no data
2709 pktmbuf_pool2 = rte_pktmbuf_pool_create("test_pktmbuf_pool2",
2710 NB_MBUF, MEMPOOL_CACHE_SIZE, MBUF2_PRIV_SIZE, 0,
2713 if (pktmbuf_pool2 == NULL) {
2714 printf("cannot allocate mbuf pool\n");
2718 /* test multiple mbuf alloc */
2719 if (test_pktmbuf_pool(pktmbuf_pool) < 0) {
2720 printf("test_mbuf_pool() failed\n");
2724 /* do it another time to check that all mbufs were freed */
2725 if (test_pktmbuf_pool(pktmbuf_pool) < 0) {
2726 printf("test_mbuf_pool() failed (2)\n");
2730 /* test bulk mbuf alloc and free */
2731 if (test_pktmbuf_pool_bulk() < 0) {
2732 printf("test_pktmbuf_pool_bulk() failed\n");
2736 /* test that the pointer to the data on a packet mbuf is set properly */
2737 if (test_pktmbuf_pool_ptr(pktmbuf_pool) < 0) {
2738 printf("test_pktmbuf_pool_ptr() failed\n");
2742 /* test data manipulation in mbuf */
2743 if (test_one_pktmbuf(pktmbuf_pool) < 0) {
2744 printf("test_one_mbuf() failed\n");
2750 * do it another time, to check that allocation reinitialize
2751 * the mbuf correctly
2753 if (test_one_pktmbuf(pktmbuf_pool) < 0) {
2754 printf("test_one_mbuf() failed (2)\n");
2758 if (test_pktmbuf_with_non_ascii_data(pktmbuf_pool) < 0) {
2759 printf("test_pktmbuf_with_non_ascii_data() failed\n");
2763 /* test free pktmbuf segment one by one */
2764 if (test_pktmbuf_free_segment(pktmbuf_pool) < 0) {
2765 printf("test_pktmbuf_free_segment() failed.\n");
2769 if (testclone_testupdate_testdetach(pktmbuf_pool, pktmbuf_pool) < 0) {
2770 printf("testclone_and_testupdate() failed \n");
2774 if (test_pktmbuf_copy(pktmbuf_pool, pktmbuf_pool) < 0) {
2775 printf("test_pktmbuf_copy() failed\n");
2779 if (test_attach_from_different_pool(pktmbuf_pool, pktmbuf_pool2) < 0) {
2780 printf("test_attach_from_different_pool() failed\n");
2784 if (test_refcnt_mbuf() < 0) {
2785 printf("test_refcnt_mbuf() failed \n");
2789 if (test_failing_mbuf_sanity_check(pktmbuf_pool) < 0) {
2790 printf("test_failing_mbuf_sanity_check() failed\n");
2794 if (test_mbuf_linearize_check(pktmbuf_pool) < 0) {
2795 printf("test_mbuf_linearize_check() failed\n");
2799 if (test_tx_offload() < 0) {
2800 printf("test_tx_offload() failed\n");
2804 if (test_get_rx_ol_flag_list() < 0) {
2805 printf("test_rte_get_rx_ol_flag_list() failed\n");
2809 if (test_get_tx_ol_flag_list() < 0) {
2810 printf("test_rte_get_tx_ol_flag_list() failed\n");
2814 if (test_get_rx_ol_flag_name() < 0) {
2815 printf("test_rte_get_rx_ol_flag_name() failed\n");
2819 if (test_get_tx_ol_flag_name() < 0) {
2820 printf("test_rte_get_tx_ol_flag_name() failed\n");
2824 if (test_mbuf_validate_tx_offload_one(pktmbuf_pool) < 0) {
2825 printf("test_mbuf_validate_tx_offload_one() failed\n");
2829 /* test for allocating a bulk of mbufs with various sizes */
2830 if (test_pktmbuf_alloc_bulk(pktmbuf_pool) < 0) {
2831 printf("test_rte_pktmbuf_alloc_bulk() failed\n");
2835 /* test for allocating a bulk of mbufs with various sizes */
2836 if (test_neg_pktmbuf_alloc_bulk(pktmbuf_pool) < 0) {
2837 printf("test_neg_rte_pktmbuf_alloc_bulk() failed\n");
2841 /* test to read mbuf packet */
2842 if (test_pktmbuf_read(pktmbuf_pool) < 0) {
2843 printf("test_rte_pktmbuf_read() failed\n");
2847 /* test to read mbuf packet from offset */
2848 if (test_pktmbuf_read_from_offset(pktmbuf_pool) < 0) {
2849 printf("test_rte_pktmbuf_read_from_offset() failed\n");
2853 /* test to read data from chain of mbufs with data segments */
2854 if (test_pktmbuf_read_from_chain(pktmbuf_pool) < 0) {
2855 printf("test_rte_pktmbuf_read_from_chain() failed\n");
2859 /* test to initialize shared info. at the end of external buffer */
2860 if (test_pktmbuf_ext_shinfo_init_helper(pktmbuf_pool) < 0) {
2861 printf("test_pktmbuf_ext_shinfo_init_helper() failed\n");
2865 /* test the mbuf pool with pinned external data buffers */
2866 if (test_pktmbuf_ext_pinned_buffer(pktmbuf_pool) < 0) {
2867 printf("test_pktmbuf_ext_pinned_buffer() failed\n");
2874 rte_mempool_free(pktmbuf_pool);
2875 rte_mempool_free(pktmbuf_pool2);
2880 REGISTER_TEST_COMMAND(mbuf_autotest, test_mbuf);