| #include <common.h> |
| |
| int |
| send_packets (memif_connection_t *c, uint16_t qid, |
| packet_generator_t *generator, uint32_t num_pkts, |
| uint16_t max_pkt_size) |
| { |
| int err, i; |
| uint16_t tx; |
| |
| do |
| { |
| err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, |
| num_pkts > MAX_MEMIF_BUFS ? MAX_MEMIF_BUFS : |
| num_pkts, |
| &c->tx_buf_num, max_pkt_size); |
| /* suppress full ring error MEMIF_ERR_NOBUF_RING */ |
| if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING) |
| { |
| INFO ("memif_buffer_alloc: %s", memif_strerror (err)); |
| goto error; |
| } |
| |
| /* generate packet inside allocated buffers */ |
| err = generator (c, num_pkts); |
| if (err != 0) |
| { |
| INFO ("paclet generator error: %d", err); |
| goto error; |
| } |
| |
| err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &tx); |
| if (err != MEMIF_ERR_SUCCESS) |
| { |
| INFO ("memif_tx_burst: %s", memif_strerror (err)); |
| goto error; |
| } |
| c->tx_buf_num -= tx; |
| |
| /* Should never happen... */ |
| if (c->tx_buf_num > 0) |
| { |
| INFO ("Failed to send allocated packets"); |
| goto error; |
| } |
| num_pkts -= tx; |
| } |
| while (num_pkts > 0); |
| |
| return 0; |
| |
| error: |
| /* TODO: free alloocated tx buffers */ |
| return -1; |
| } |