sr: api cleanup 47/32847/2
authorFilip Tehlar <ftehlar@cisco.com>
Tue, 22 Jun 2021 13:00:40 +0000 (13:00 +0000)
committerOle Tr�an <otroan@employees.org>
Tue, 22 Jun 2021 13:54:23 +0000 (13:54 +0000)
Use autogenerated code.
Does not change API definitions.

Type: improvement

Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Change-Id: I0bdf870e2e9b0ebc11a3ce252fbd0667a83de4e6

src/vat/api_format.c
src/vnet/srv6/sr.h
src/vnet/srv6/sr_api.c
src/vnet/vnet_all_api_h.h

index 0457a3c..8df56ae 100644 (file)
@@ -2059,14 +2059,6 @@ _(sw_interface_set_unnumbered_reply)                    \
 _(set_ip_flow_hash_reply)                               \
 _(sw_interface_ip6_enable_disable_reply)                \
 _(l2_patch_add_del_reply)                               \
-_(sr_mpls_policy_add_reply)                             \
-_(sr_mpls_policy_mod_reply)                             \
-_(sr_mpls_policy_del_reply)                             \
-_(sr_policy_add_reply)                                  \
-_(sr_policy_mod_reply)                                  \
-_(sr_policy_del_reply)                                  \
-_(sr_localsid_add_del_reply)                            \
-_(sr_steering_add_del_reply)                            \
 _(l2_fib_clear_table_reply)                             \
 _(l2_interface_efp_filter_reply)                        \
 _(l2_interface_vlan_tag_rewrite_reply)                  \
@@ -2185,14 +2177,6 @@ _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply)                       \
 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY,                                \
   sw_interface_ip6_enable_disable_reply)                                \
 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply)                       \
-_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply)                   \
-_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply)                   \
-_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply)                   \
-_(SR_POLICY_ADD_REPLY, sr_policy_add_reply)                             \
-_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply)                             \
-_(SR_POLICY_DEL_REPLY, sr_policy_del_reply)                             \
-_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply)                 \
-_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply)                 \
 _(GET_NODE_INDEX_REPLY, get_node_index_reply)                           \
 _(ADD_NODE_NEXT_REPLY, add_node_next_reply)                             \
 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply)                   \
@@ -5040,109 +5024,6 @@ api_mpls_ip_bind_unbind (vat_main_t * vam)
   return (0);
 }
 
-static int
-api_sr_mpls_policy_add (vat_main_t * vam)
-{
-  unformat_input_t *i = vam->input;
-  vl_api_sr_mpls_policy_add_t *mp;
-  u32 bsid = 0;
-  u32 weight = 1;
-  u8 type = 0;
-  u8 n_segments = 0;
-  u32 sid;
-  u32 *segments = NULL;
-  int ret;
-
-  /* Parse args required to build the message */
-  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (i, "bsid %d", &bsid))
-       ;
-      else if (unformat (i, "weight %d", &weight))
-       ;
-      else if (unformat (i, "spray"))
-       type = 1;
-      else if (unformat (i, "next %d", &sid))
-       {
-         n_segments += 1;
-         vec_add1 (segments, htonl (sid));
-       }
-      else
-       {
-         clib_warning ("parse error '%U'", format_unformat_error, i);
-         return -99;
-       }
-    }
-
-  if (bsid == 0)
-    {
-      errmsg ("bsid not set");
-      return -99;
-    }
-
-  if (n_segments == 0)
-    {
-      errmsg ("no sid in segment stack");
-      return -99;
-    }
-
-  /* Construct the API message */
-  M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
-
-  mp->bsid = htonl (bsid);
-  mp->weight = htonl (weight);
-  mp->is_spray = type;
-  mp->n_segments = n_segments;
-  memcpy (mp->segments, segments, sizeof (u32) * n_segments);
-  vec_free (segments);
-
-  /* send it... */
-  S (mp);
-
-  /* Wait for a reply... */
-  W (ret);
-  return ret;
-}
-
-static int
-api_sr_mpls_policy_del (vat_main_t * vam)
-{
-  unformat_input_t *i = vam->input;
-  vl_api_sr_mpls_policy_del_t *mp;
-  u32 bsid = 0;
-  int ret;
-
-  /* Parse args required to build the message */
-  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (i, "bsid %d", &bsid))
-       ;
-      else
-       {
-         clib_warning ("parse error '%U'", format_unformat_error, i);
-         return -99;
-       }
-    }
-
-  if (bsid == 0)
-    {
-      errmsg ("bsid not set");
-      return -99;
-    }
-
-  /* Construct the API message */
-  M (SR_MPLS_POLICY_DEL, mp);
-
-  mp->bsid = htonl (bsid);
-
-  /* send it... */
-  S (mp);
-
-  /* Wait for a reply... */
-  W (ret);
-  return ret;
-}
-
 static int
 api_mpls_tunnel_add_del (vat_main_t * vam)
 {
@@ -5672,59 +5553,6 @@ u32 vlan_index;
 u32 fib_table;
 u8 nh_addr[16];
 
-static int
-api_sr_localsid_add_del (vat_main_t * vam)
-{
-  unformat_input_t *i = vam->input;
-  vl_api_sr_localsid_add_del_t *mp;
-
-  u8 is_del;
-  ip6_address_t localsid;
-  u8 end_psp = 0;
-  u8 behavior = ~0;
-  u32 sw_if_index;
-  u32 fib_table = ~(u32) 0;
-  ip46_address_t nh_addr;
-  clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
-
-  bool nexthop_set = 0;
-
-  int ret;
-
-  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
-    {
-      if (unformat (i, "del"))
-       is_del = 1;
-      else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
-      else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
-       nexthop_set = 1;
-      else if (unformat (i, "behavior %u", &behavior));
-      else if (unformat (i, "sw_if_index %u", &sw_if_index));
-      else if (unformat (i, "fib-table %u", &fib_table));
-      else if (unformat (i, "end.psp %u", &behavior));
-      else
-       break;
-    }
-
-  M (SR_LOCALSID_ADD_DEL, mp);
-
-  clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
-
-  if (nexthop_set)
-    {
-      clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
-    }
-  mp->behavior = behavior;
-  mp->sw_if_index = ntohl (sw_if_index);
-  mp->fib_table = ntohl (fib_table);
-  mp->end_psp = end_psp;
-  mp->is_del = is_del;
-
-  S (mp);
-  W (ret);
-  return ret;
-}
-
 static int
 api_ioam_enable (vat_main_t * vam)
 {
@@ -10530,10 +10358,6 @@ _(mpls_tunnel_add_del,                                                  \
   "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
   "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n"                \
   "[l2-only]  [out-label <n>]")                                         \
-_(sr_mpls_policy_add,                                                   \
-  "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]")             \
-_(sr_mpls_policy_del,                                                   \
-  "bsid <id>")                                                          \
 _(sw_interface_set_unnumbered,                                          \
   "<intfc> | sw_if_index <id> unnum_if_index <id> [del]")               \
 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>")             \
@@ -10551,9 +10375,6 @@ _(sw_interface_ip6_enable_disable,                                      \
 _(l2_patch_add_del,                                                     \
   "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
   "enable | disable")                                                   \
-_(sr_localsid_add_del,                                                  \
-  "(del) address <addr> next_hop <addr> behavior <beh>\n"               \
-  "fib-table <num> (end.psp) sw_if_index <num>")                        \
 _(get_node_index, "node <node-name")                                    \
 _(add_node_next, "node <node-name> next <next-node-name>")              \
 _(l2_fib_clear_table, "")                                               \
index 98304b8..d47c213 100644 (file)
@@ -309,6 +309,7 @@ typedef struct
   /* convenience */
   vlib_main_t *vlib_main;
   vnet_main_t *vnet_main;
+  u16 msg_id_base;
 } ip6_sr_main_t;
 
 extern ip6_sr_main_t sr_main;
index cb468b9..c68b355 100644 (file)
 #include <vnet/api_errno.h>
 #include <vnet/feature/feature.h>
 #include <vnet/fib/fib_table.h>
-
 #include <vnet/ip/ip_types_api.h>
 
-#include <vnet/vnet_msg_enum.h>
-
-#define vl_typedefs            /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun           /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vnet/vnet_all_api_h.h>
-#undef vl_printfun
+#include <vnet/format_fns.h>
+#include <vnet/srv6/sr.api_enum.h>
+#include <vnet/srv6/sr.api_types.h>
 
+#define REPLY_MSG_ID_BASE sr_main.msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-#define foreach_vpe_api_msg                             \
-_(SR_LOCALSID_ADD_DEL, sr_localsid_add_del)             \
-_(SR_POLICY_ADD, sr_policy_add)                         \
-_(SR_POLICY_MOD, sr_policy_mod)                         \
-_(SR_POLICY_DEL, sr_policy_del)                         \
-_(SR_STEERING_ADD_DEL, sr_steering_add_del)             \
-_(SR_SET_ENCAP_SOURCE, sr_set_encap_source)             \
-_(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit)       \
-_(SR_LOCALSIDS_DUMP, sr_localsids_dump)                 \
-_(SR_POLICIES_DUMP, sr_policies_dump)                   \
-_(SR_POLICIES_WITH_SL_INDEX_DUMP, sr_policies_with_sl_index_dump) \
-_(SR_STEERING_POL_DUMP, sr_steering_pol_dump)
-
 static void vl_api_sr_localsid_add_del_t_handler
   (vl_api_sr_localsid_add_del_t * mp)
 {
@@ -239,7 +214,7 @@ static void send_sr_localsid_details
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
   clib_memset (rmp, 0, sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS);
+  rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_LOCALSIDS_DETAILS);
   ip6_address_encode (&t->localsid, rmp->addr);
   rmp->end_psp = t->end_psp;
   rmp->behavior = htons (t->behavior);
@@ -299,7 +274,7 @@ static void send_sr_policies_details
                vec_len (t->segments_lists) *
                sizeof (vl_api_srv6_sid_list_t)));
 
-  rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS);
+  rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_POLICIES_DETAILS);
   ip6_address_encode (&t->bsid, rmp->bsid);
   rmp->is_encap = t->is_encap;
   rmp->is_spray = t->type;
@@ -366,7 +341,8 @@ static void send_sr_policies_details_with_sl_index
                vec_len (t->segments_lists) *
                sizeof (vl_api_srv6_sid_list_with_sl_index_t)));
 
-  rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_WITH_SL_INDEX_DETAILS);
+  rmp->_vl_msg_id =
+    ntohs (REPLY_MSG_ID_BASE + VL_API_SR_POLICIES_WITH_SL_INDEX_DETAILS);
   ip6_address_encode (&t->bsid, rmp->bsid);
   rmp->is_encap = t->is_encap;
   rmp->is_spray = t->type;
@@ -421,7 +397,7 @@ static void send_sr_steering_pol_details
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
   clib_memset (rmp, 0, sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_SR_STEERING_POL_DETAILS);
+  rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SR_STEERING_POL_DETAILS);
 
   //Get the SR policy BSID
   ip6_sr_policy_t *p;
@@ -460,44 +436,14 @@ static void vl_api_sr_steering_pol_dump_t_handler
   /* *INDENT-ON* */
 }
 
-/*
- * sr_api_hookup
- * Add vpe's API message handlers to the table.
- * vlib has already mapped shared memory and
- * added the client registration handlers.
- * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
- */
-#define vl_msg_name_crc_list
-#include <vnet/vnet_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (api_main_t * am)
-{
-#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
-  foreach_vl_msg_name_crc_sr;
-#undef _
-}
-
+#include <vnet/srv6/sr.api.c>
 static clib_error_t *
 sr_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = vlibapi_get_main ();
-
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers(VL_API_##N, #n,                     \
-                           vl_api_##n##_t_handler,              \
-                           vl_noop_handler,                     \
-                           vl_api_##n##_t_endian,               \
-                           vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1);
-  foreach_vpe_api_msg;
-#undef _
-
   /*
    * Set up the (msg_name, crc, message-id) table
    */
-  setup_message_id_table (am);
+  REPLY_MSG_ID_BASE = setup_message_id_table ();
 
   return 0;
 }
index 5730974..6f24ef4 100644 (file)
@@ -42,7 +42,6 @@
 #include <vnet/ip/ip.api.h>
 #include <vnet/session/session.api.h>
 #include <vnet/mpls/mpls.api.h>
-#include <vnet/srv6/sr.api.h>
 #include <vnet/srmpls/sr_mpls.api.h>
 #include <vnet/tcp/tcp.api.h>
 #include <vnet/ip/punt.api.h>