libmemif: add support for custom buffer-size and headroom in icmp example app 67/36767/2
authorMohsin Kazmi <sykazmi@cisco.com>
Wed, 27 Jul 2022 15:04:01 +0000 (15:04 +0000)
committerBeno�t Ganne <bganne@cisco.com>
Mon, 29 Aug 2022 07:05:23 +0000 (07:05 +0000)
Type: improvement

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

extras/libmemif/examples/common/common.h
extras/libmemif/examples/common/responder.c
extras/libmemif/examples/icmp_responder/main.c

index ce4ead2..3538e39 100644 (file)
@@ -78,6 +78,10 @@ typedef struct memif_connection
   uint8_t ip_addr[4];
   /* interface hw address */
   uint8_t hw_addr[6];
+  /* buffer size */
+  uint16_t buffer_size;
+  /* headroom size */
+  uint16_t headroom_size;
 } memif_connection_t;
 
 void print_version ();
@@ -113,4 +117,4 @@ int basic_packet_handler (memif_connection_t *conn);
 /* ICMPv4 and ARP handler */
 int icmp_packet_handler (memif_connection_t *conn);
 
-#endif /* COMMON_H */
\ No newline at end of file
+#endif /* COMMON_H */
index e0fa9e3..3edf911 100644 (file)
@@ -19,7 +19,7 @@ responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
     {
       /* allocate tx buffers */
       err = memif_buffer_alloc (conn, qid, c->tx_bufs, c->rx_buf_num,
-                               &c->tx_buf_num, 2048);
+                               &c->tx_buf_num, c->buffer_size);
       /* suppress full ring error MEMIF_ERR_NOBUF_RING */
       if (err != MEMIF_ERR_SUCCESS && err != MEMIF_ERR_NOBUF_RING)
        {
@@ -42,7 +42,7 @@ responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
       /* Done processing packets */
 
       /* refill the queue */
-      err = memif_refill_queue (conn, qid, c->tx_buf_num, 0);
+      err = memif_refill_queue (conn, qid, c->tx_buf_num, c->headroom_size);
       if (err != MEMIF_ERR_SUCCESS)
        {
          INFO ("memif_refill_queue: %s", memif_strerror (err));
@@ -70,7 +70,7 @@ responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
   return 0;
 
 error:
-  err = memif_refill_queue (conn, qid, c->rx_buf_num, 0);
+  err = memif_refill_queue (conn, qid, c->rx_buf_num, c->headroom_size);
   if (err != MEMIF_ERR_SUCCESS)
     {
       INFO ("memif_refill_queue: %s", memif_strerror (err));
@@ -130,7 +130,7 @@ responder_zero_copy (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
        }
 
       /* refill the queue */
-      err = memif_refill_queue (conn, qid, tx, 0);
+      err = memif_refill_queue (conn, qid, tx, c->headroom_size);
       if (err != MEMIF_ERR_SUCCESS)
        {
          INFO ("memif_refill_queue: %s", memif_strerror (err));
@@ -160,7 +160,7 @@ responder_zero_copy (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
   return 0;
 
 error:
-  err = memif_refill_queue (conn, qid, c->rx_buf_num, 0);
+  err = memif_refill_queue (conn, qid, c->rx_buf_num, c->headroom_size);
   if (err != MEMIF_ERR_SUCCESS)
     {
       INFO ("memif_refill_queue: %s", memif_strerror (err));
@@ -169,4 +169,4 @@ error:
   c->rx_buf_num = 0;
 
   return -1;
-}
\ No newline at end of file
+}
index 32b8ed7..f89f579 100644 (file)
@@ -52,13 +52,15 @@ on_connect (memif_conn_handle_t conn, void *private_ctx)
   c->is_connected = 1;
   alloc_memif_buffers (c);
 
-  err = memif_refill_queue (conn, 0, -1, 0);
+  err = memif_refill_queue (conn, 0, -1, c->headroom_size);
   if (err != MEMIF_ERR_SUCCESS)
     {
       INFO ("memif_refill_queue: %s", memif_strerror (err));
       return err;
     }
 
+  print_memif_details (c);
+
   return 0;
 }
 
@@ -104,9 +106,11 @@ print_help ()
   printf ("\t-r\tInterface role <slave|master>. Default: slave\n");
   printf ("\t-s\tSocket path. Supports abstract socket using @ before the "
          "path. Default: /run/vpp/memif.sock\n");
+  printf ("\t-b\tBuffer Size. Default: 2048\n");
+  printf ("\t-h\tHeadroom Size. Default: 0\n");
   printf ("\t-i\tInterface id. Default: 0\n");
   printf ("\t-a\tIPv4 address. Default: 192.168.1.1\n");
-  printf ("\t-h\tMac address. Default: aa:aa:aa:aa:aa:aa\n");
+  printf ("\t-m\tMac address. Default: aa:aa:aa:aa:aa:aa\n");
   printf ("\t-?\tShow help and exit.\n");
   printf ("\t-v\tShow libmemif and memif version information and exit.\n");
 }
@@ -130,7 +134,7 @@ main (int argc, char *argv[])
   memcpy (intf.ip_addr, IP_ADDR, 4);
   memcpy (intf.hw_addr, HW_ADDR, 6);
 
-  while ((opt = getopt (argc, argv, "r:s:i:a:h:?v")) != -1)
+  while ((opt = getopt (argc, argv, "r:s:b:h:i:a:m:?v")) != -1)
     {
       switch (opt)
        {
@@ -152,6 +156,12 @@ main (int argc, char *argv[])
        case 's':
          sprintf (socket_path, "%s", optarg);
          break;
+       case 'b':
+         intf.buffer_size = atoi (optarg);
+         break;
+       case 'h':
+         intf.headroom_size = atoi (optarg);
+         break;
        case 'i':
          id = atoi (optarg);
          break;
@@ -162,7 +172,7 @@ main (int argc, char *argv[])
              return -1;
            }
          break;
-       case 'h':
+       case 'm':
          if (parse_mac (optarg, intf.hw_addr) != 0)
            {
              INFO ("Invalid mac address: %s", optarg);
@@ -207,6 +217,8 @@ main (int argc, char *argv[])
    * Both interaces are assigned the same socket and same id to create a
    * loopback.
    */
+  if (intf.buffer_size)
+    memif_conn_args.buffer_size = intf.buffer_size;
 
   memif_conn_args.socket = memif_socket;
   memif_conn_args.interface_id = id;