vppapigen: enable codegen for stream message types 21/36721/4
authorStanislav Zaikin <zstaseg@gmail.com>
Thu, 21 Jul 2022 17:06:26 +0000 (19:06 +0200)
committerStanislav Zaikin <zstaseg@gmail.com>
Mon, 23 Jan 2023 20:01:06 +0000 (21:01 +0100)
Enable codegen for C type from 'rpc A returns B stream C' notation

Type: improvement

Change-Id: I05cfce71c385d414d7b177a080009628bc8c8fad
Signed-off-by: Stanislav Zaikin <zstaseg@gmail.com>
src/plugins/linux-cp/lcp.api
src/plugins/linux-cp/lcp_api.c
src/tools/vppapigen/vppapigen_c.py [changed mode: 0644->0755]
src/vnet/interface_api.c

index 1e9db3d..ca36fe5 100644 (file)
@@ -105,13 +105,13 @@ define lcp_itf_pair_add_del_v2_reply
     @param context - sender context, to match reply w/ request
     @param sw_if_index - interface to use as filter (~0 == "all")
 */
-define lcp_itf_pair_get
+autoendian define lcp_itf_pair_get
 {
   u32 client_index;
   u32 context;
   u32 cursor;
 };
-define lcp_itf_pair_get_reply
+autoendian define lcp_itf_pair_get_reply
 {
   u32 context;
   i32 retval;
index e7edf55..638d9f7 100644 (file)
@@ -133,11 +133,11 @@ send_lcp_itf_pair_details (index_t lipi, vl_api_registration_t *rp,
   vl_api_lcp_itf_pair_details_t *rmp;
   lcp_itf_pair_t *lcp_pair = lcp_itf_pair_get (lipi);
 
-  REPLY_MACRO_DETAILS4 (
+  REPLY_MACRO_DETAILS4_END (
     VL_API_LCP_ITF_PAIR_DETAILS, rp, context, ({
-      rmp->phy_sw_if_index = ntohl (lcp_pair->lip_phy_sw_if_index);
-      rmp->host_sw_if_index = ntohl (lcp_pair->lip_host_sw_if_index);
-      rmp->vif_index = ntohl (lcp_pair->lip_vif_index);
+      rmp->phy_sw_if_index = lcp_pair->lip_phy_sw_if_index;
+      rmp->host_sw_if_index = lcp_pair->lip_host_sw_if_index;
+      rmp->vif_index = lcp_pair->lip_vif_index;
       rmp->host_if_type = api_encode_host_type (lcp_pair->lip_host_type);
 
       memcpy_s (rmp->host_if_name, sizeof (rmp->host_if_name),
@@ -156,7 +156,7 @@ vl_api_lcp_itf_pair_get_t_handler (vl_api_lcp_itf_pair_get_t *mp)
   vl_api_lcp_itf_pair_get_reply_t *rmp;
   i32 rv = 0;
 
-  REPLY_AND_DETAILS_MACRO (
+  REPLY_AND_DETAILS_MACRO_END (
     VL_API_LCP_ITF_PAIR_GET_REPLY, lcp_itf_pair_pool,
     ({ send_lcp_itf_pair_details (cursor, rp, mp->context); }));
 }
old mode 100644 (file)
new mode 100755 (executable)
index 5ca2ed5..26a348f
@@ -1250,6 +1250,11 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a)
 
         output += signature.format(name=t.name)
 
+        # make Array type appear before the others:
+        # some arrays have dynamic length, and we want to iterate over
+        # them before changing endiann for the length field
+        t.block.sort(key=lambda x: x.type)
+
         for o in t.block:
             output += endianfun_obj(o)
         output += "}\n\n"
@@ -1576,6 +1581,31 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
         except KeyError:
             pass
 
+        try:
+            if s.stream:
+                d = define_hash[s.stream_message]
+                write(
+                    "   c = (vl_msg_api_msg_config_t) "
+                    "{{.id = VL_API_{ID} + msg_id_base,\n"
+                    '  .name = "{n}",\n'
+                    "  .handler = 0,\n"
+                    "  .endian = vl_api_{n}_t_endian,\n"
+                    "  .format_fn = vl_api_{n}_t_format,\n"
+                    "  .traced = 1,\n"
+                    "  .replay = 1,\n"
+                    "  .tojson = vl_api_{n}_t_tojson,\n"
+                    "  .fromjson = vl_api_{n}_t_fromjson,\n"
+                    "  .calc_size = vl_api_{n}_t_calc_size,\n"
+                    "  .is_autoendian = {auto}}};\n".format(
+                        n=s.stream_message,
+                        ID=s.stream_message.upper(),
+                        auto=d.autoendian,
+                    )
+                )
+                write("   vl_msg_api_config (&c);\n")
+        except KeyError:
+            pass
+
     write("   return msg_id_base;\n")
     write("}\n")
 
index 5766f2c..288af78 100644 (file)
@@ -1228,24 +1228,20 @@ send_interface_tx_placement_details (vnet_hw_if_tx_queue_t **all_queues,
   n_bits = clib_bitmap_count_set_bits (bitmap);
   u32 n = n_bits * sizeof (u32);
 
-  /*
-   * FIXME: Use the REPLY_MACRO_DETAILS5_END once endian handler is registered
-   * and available.
-   */
-  REPLY_MACRO_DETAILS5 (
-    VL_API_SW_INTERFACE_TX_PLACEMENT_DETAILS, n, rp, context, ({
-      rmp->sw_if_index = clib_host_to_net_u32 (hw_if->sw_if_index);
-      rmp->queue_id = clib_host_to_net_u32 (q[0]->queue_id);
-      rmp->shared = q[0]->shared_queue;
-      rmp->array_size = clib_host_to_net_u32 (n_bits);
-
-      v = clib_bitmap_first_set (bitmap);
-      for (u32 i = 0; i < n_bits; i++)
-       {
-         rmp->threads[i] = clib_host_to_net_u32 (v);
-         v = clib_bitmap_next_set (bitmap, v + 1);
-       }
-    }));
+  REPLY_MACRO_DETAILS5_END (VL_API_SW_INTERFACE_TX_PLACEMENT_DETAILS, n, rp,
+                           context, ({
+                             rmp->sw_if_index = hw_if->sw_if_index;
+                             rmp->queue_id = q[0]->queue_id;
+                             rmp->shared = q[0]->shared_queue;
+                             rmp->array_size = n_bits;
+
+                             v = clib_bitmap_first_set (bitmap);
+                             for (u32 i = 0; i < n_bits; i++)
+                               {
+                                 rmp->threads[i] = v;
+                                 v = clib_bitmap_next_set (bitmap, v + 1);
+                               }
+                           }));
 }
 
 static void