libmemif: add support for buffer size 39/39139/2
authorMohsin Kazmi <sykazmi@cisco.com>
Thu, 27 Jul 2023 16:58:41 +0000 (16:58 +0000)
committerBeno�t Ganne <bganne@cisco.com>
Mon, 31 Jul 2023 09:55:41 +0000 (09:55 +0000)
Type: improvement

buffer size can be configurable:
./test_app -b 9216

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: Id77f6baac27d45dec3d5b7ea8a9a53acf2a302fc

extras/libmemif/examples/test_app/main.c

index 2293365..763ec6c 100644 (file)
@@ -102,7 +102,7 @@ on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
     {
       /* allocate tx buffers */
       err = memif_buffer_alloc (s->conn, s->tx_qid, s->tx_bufs, r->rx_buf_num,
-                               &s->tx_buf_num, 2048);
+                               &s->tx_buf_num, s->buffer_size);
       /* suppress full ring error MEMIF_ERR_NOBUF_RING */
       if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING)
        {
@@ -114,6 +114,7 @@ on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
       for (i = 0; i < s->tx_buf_num; i++)
        {
          memcpy (s->tx_bufs[i].data, r->rx_bufs[i].data, r->rx_bufs[i].len);
+         s->tx_bufs[i].flags = r->rx_bufs[i].flags;
          s->tx_bufs[i].len = r->rx_bufs[i].len;
        }
 
@@ -183,6 +184,7 @@ print_help ()
          "path. Default: /run/vpp/memif.sock\n");
   printf ("\t-i\tInterface id. Default: 0\n");
   printf ("\t-t\tInterface id2. Default: 1\n");
+  printf ("\t-b\tBuffer Size. Default: 2048\n");
   printf ("\t-h\tShow help and exit.\n");
   printf ("\t-v\tShow libmemif and memif version information and exit.\n");
 }
@@ -205,7 +207,7 @@ main (int argc, char *argv[])
   memset (&intf0, 0, sizeof (intf0));
   memset (&intf1, 0, sizeof (intf1));
 
-  while ((opt = getopt (argc, argv, "rsithv")) != -1)
+  while ((opt = getopt (argc, argv, "r:s:i:t:b:h:v")) != -1)
     {
       switch (opt)
        {
@@ -233,6 +235,9 @@ main (int argc, char *argv[])
        case 't':
          id1 = atoi (optarg);
          break;
+       case 'b':
+         intf1.buffer_size = intf0.buffer_size = atoi (optarg);
+         break;
        case 'h':
          print_help ();
          return 0;
@@ -274,6 +279,10 @@ main (int argc, char *argv[])
   strncpy (memif_conn_args.interface_name, IF_NAME0,
           sizeof (memif_conn_args.interface_name));
   memif_conn_args.is_master = is_master;
+  if (intf0.buffer_size)
+    memif_conn_args.buffer_size = intf0.buffer_size;
+  else
+    memif_conn_args.buffer_size = intf0.buffer_size = intf1.buffer_size = 2048;
 
   err = memif_create (&intf0.conn, &memif_conn_args, on_connect, on_disconnect,
                      on_interrupt, (void *) &intf0);