From e2fc003f46f70659045e563368db73eeca9a9647 Mon Sep 17 00:00:00 2001 From: Filip Tehlar Date: Tue, 22 Jun 2021 13:00:40 +0000 Subject: [PATCH] sr: api cleanup Use autogenerated code. Does not change API definitions. Type: improvement Signed-off-by: Filip Tehlar Change-Id: I0bdf870e2e9b0ebc11a3ce252fbd0667a83de4e6 --- src/vat/api_format.c | 179 ---------------------------------------------- src/vnet/srv6/sr.h | 1 + src/vnet/srv6/sr_api.c | 76 +++----------------- src/vnet/vnet_all_api_h.h | 1 - 4 files changed, 12 insertions(+), 245 deletions(-) diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 0457a3cac7a..8df56aee474 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -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 >] via >\n" \ "[ | sw_if_index | next-hop-table ]\n" \ "[l2-only] [out-label ]") \ -_(sr_mpls_policy_add, \ - "bsid [weight ] [spray] next [next ]") \ -_(sr_mpls_policy_del, \ - "bsid ") \ _(sw_interface_set_unnumbered, \ " | sw_if_index unnum_if_index [del]") \ _(create_vlan_subif, " | sw_if_index vlan ") \ @@ -10551,9 +10375,6 @@ _(sw_interface_ip6_enable_disable, \ _(l2_patch_add_del, \ "rx | rx_sw_if_index tx | tx_sw_if_index \n" \ "enable | disable") \ -_(sr_localsid_add_del, \ - "(del) address next_hop behavior \n" \ - "fib-table (end.psp) sw_if_index ") \ _(get_node_index, "node next ") \ _(l2_fib_clear_table, "") \ diff --git a/src/vnet/srv6/sr.h b/src/vnet/srv6/sr.h index 98304b8bafd..d47c2132ee4 100644 --- a/src/vnet/srv6/sr.h +++ b/src/vnet/srv6/sr.h @@ -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; diff --git a/src/vnet/srv6/sr_api.c b/src/vnet/srv6/sr_api.c index cb468b97ef5..c68b355922b 100644 --- a/src/vnet/srv6/sr_api.c +++ b/src/vnet/srv6/sr_api.c @@ -25,40 +25,15 @@ #include #include #include - #include -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#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 -#undef vl_printfun +#include +#include +#include +#define REPLY_MSG_ID_BASE sr_main.msg_id_base #include -#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 -#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 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; } diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index 5730974f151..6f24ef457ac 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include -- 2.16.6