create a mbuf with different sized segments * and fill with data [0x00 0x01 0x02 ...] */
| 2086 | * and fill with data [0x00 0x01 0x02 ...] |
| 2087 | */ |
| 2088 | static struct rte_mbuf * |
| 2089 | create_packet(struct rte_mempool *pktmbuf_pool, |
| 2090 | struct test_case *test_data) |
| 2091 | { |
| 2092 | uint16_t i, ret, seg, seg_len = 0; |
| 2093 | uint32_t last_index = 0; |
| 2094 | unsigned int seg_lengths[MBUF_MAX_SEG]; |
| 2095 | unsigned int hdr_len; |
| 2096 | struct rte_mbuf *pkt = NULL; |
| 2097 | struct rte_mbuf *pkt_seg = NULL; |
| 2098 | char *hdr = NULL; |
| 2099 | char *data = NULL; |
| 2100 | |
| 2101 | memcpy(seg_lengths, test_data->seg_lengths, |
| 2102 | sizeof(unsigned int)*test_data->seg_count); |
| 2103 | for (seg = 0; seg < test_data->seg_count; seg++) { |
| 2104 | hdr_len = 0; |
| 2105 | seg_len = seg_lengths[seg]; |
| 2106 | pkt_seg = rte_pktmbuf_alloc(pktmbuf_pool); |
| 2107 | if (pkt_seg == NULL) |
| 2108 | GOTO_FAIL("%s: mbuf allocation failed!\n", __func__); |
| 2109 | if (rte_pktmbuf_pkt_len(pkt_seg) != 0) |
| 2110 | GOTO_FAIL("%s: Bad packet length\n", __func__); |
| 2111 | rte_mbuf_sanity_check(pkt_seg, 0); |
| 2112 | /* Add header only for the first segment */ |
| 2113 | if (test_data->flags == MBUF_HEADER && seg == 0) { |
| 2114 | hdr_len = sizeof(struct rte_ether_hdr); |
| 2115 | /* prepend a header and fill with dummy data */ |
| 2116 | hdr = (char *)rte_pktmbuf_prepend(pkt_seg, hdr_len); |
| 2117 | if (hdr == NULL) |
| 2118 | GOTO_FAIL("%s: Cannot prepend header\n", |
| 2119 | __func__); |
| 2120 | if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len) |
| 2121 | GOTO_FAIL("%s: Bad pkt length", __func__); |
| 2122 | if (rte_pktmbuf_data_len(pkt_seg) != hdr_len) |
| 2123 | GOTO_FAIL("%s: Bad data length", __func__); |
| 2124 | for (i = 0; i < hdr_len; i++) |
| 2125 | hdr[i] = (last_index + i) % 0xffff; |
| 2126 | last_index += hdr_len; |
| 2127 | } |
| 2128 | /* skip appending segment with 0 length */ |
| 2129 | if (seg_len == 0) |
| 2130 | continue; |
| 2131 | data = rte_pktmbuf_append(pkt_seg, seg_len); |
| 2132 | if (data == NULL) |
| 2133 | GOTO_FAIL("%s: Cannot append data segment\n", __func__); |
| 2134 | if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len + seg_len) |
| 2135 | GOTO_FAIL("%s: Bad packet segment length: %d\n", |
| 2136 | __func__, rte_pktmbuf_pkt_len(pkt_seg)); |
| 2137 | if (rte_pktmbuf_data_len(pkt_seg) != hdr_len + seg_len) |
| 2138 | GOTO_FAIL("%s: Bad data length\n", __func__); |
| 2139 | for (i = 0; i < seg_len; i++) |
| 2140 | data[i] = (last_index + i) % 0xffff; |
| 2141 | /* to fill continuous data from one seg to another */ |
| 2142 | last_index += i; |
| 2143 | /* create chained mbufs */ |
| 2144 | if (seg == 0) |
| 2145 | pkt = pkt_seg; |
no test coverage detected