summaryrefslogtreecommitdiffstats
path: root/extras/libmemif/examples/common/sender.c
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2021-01-04 11:28:33 +0100
committerDamjan Marion <dmarion@me.com>2022-03-28 22:34:33 +0000
commite74c04fc9fb2600470fe79a69d3ec6b0db95faec (patch)
treecc85fb480afcbe74184a56162d3d06af67cc4eb5 /extras/libmemif/examples/common/sender.c
parent7d6f7d0d67face9889e43bdb5f71f352294b918a (diff)
libmemif: refactor examples
- icmp_responder: responds to ICMPv4 and ARP requests - loopback: connects two interfaces and sends a verification packet from master memif to slave memif where it is looped back - loopback (reverse path): reverses direction of packet in loopback application (slave memif to master memif) Type: refactor Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: Ie90aaa3367269408efb6c5d538ad5aa827432238 Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
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