Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame^] | 1 | #include <common.h> |
| 2 | |
| 3 | int |
| 4 | send_packets (memif_connection_t *c, uint16_t qid, |
| 5 | packet_generator_t *generator, uint32_t num_pkts, |
| 6 | uint16_t max_pkt_size) |
| 7 | { |
| 8 | int err, i; |
| 9 | uint16_t tx; |
| 10 | |
| 11 | do |
| 12 | { |
| 13 | err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, |
| 14 | num_pkts > MAX_MEMIF_BUFS ? MAX_MEMIF_BUFS : |
| 15 | num_pkts, |
| 16 | &c->tx_buf_num, max_pkt_size); |
| 17 | /* suppress full ring error MEMIF_ERR_NOBUF_RING */ |
| 18 | if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING) |
| 19 | { |
| 20 | INFO ("memif_buffer_alloc: %s", memif_strerror (err)); |
| 21 | goto error; |
| 22 | } |
| 23 | |
| 24 | /* generate packet inside allocated buffers */ |
| 25 | err = generator (c, num_pkts); |
| 26 | if (err != 0) |
| 27 | { |
| 28 | INFO ("paclet generator error: %d", err); |
| 29 | goto error; |
| 30 | } |
| 31 | |
| 32 | err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &tx); |
| 33 | if (err != MEMIF_ERR_SUCCESS) |
| 34 | { |
| 35 | INFO ("memif_tx_burst: %s", memif_strerror (err)); |
| 36 | goto error; |
| 37 | } |
| 38 | c->tx_buf_num -= tx; |
| 39 | |
| 40 | /* Should never happen... */ |
| 41 | if (c->tx_buf_num > 0) |
| 42 | { |
| 43 | INFO ("Failed to send allocated packets"); |
| 44 | goto error; |
| 45 | } |
| 46 | num_pkts -= tx; |
| 47 | } |
| 48 | while (num_pkts > 0); |
| 49 | |
| 50 | return 0; |
| 51 | |
| 52 | error: |
| 53 | /* TODO: free alloocated tx buffers */ |
| 54 | return -1; |
| 55 | } |