aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/examples/common/sender.c
diff options
context:
space:
mode:
Diffstat (limited to 'extras/libmemif/examples/common/sender.c')
-rw-r--r--extras/libmemif/examples/common/sender.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/extras/libmemif/examples/common/sender.c b/extras/libmemif/examples/common/sender.c
new file mode 100644
index 00000000000..bad926f7a16
--- /dev/null
+++ b/extras/libmemif/examples/common/sender.c
@@ -0,0 +1,55 @@
+#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;
+} \ No newline at end of file