X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fmpls%2Fmpls_api.c;h=58998a6576cb4095abba6e205af4fa7837a822d2;hb=e8ea6be8dfb626b5bb4ff3355ce8037724ce1d83;hp=530ceec31c422bb49b1f47fab1db021be1e89507;hpb=c2ac2357fb0ff598ca1cb650a5766a552e017833;p=vpp.git diff --git a/src/vnet/mpls/mpls_api.c b/src/vnet/mpls/mpls_api.c index 530ceec31c4..58998a6576c 100644 --- a/src/vnet/mpls/mpls_api.c +++ b/src/vnet/mpls/mpls_api.c @@ -30,34 +30,13 @@ #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 mpls_main.msg_id_base #include -#define foreach_vpe_api_msg \ -_(MPLS_IP_BIND_UNBIND, mpls_ip_bind_unbind) \ -_(MPLS_ROUTE_ADD_DEL, mpls_route_add_del) \ -_(MPLS_TABLE_ADD_DEL, mpls_table_add_del) \ -_(MPLS_TUNNEL_ADD_DEL, mpls_tunnel_add_del) \ -_(MPLS_TUNNEL_DUMP, mpls_tunnel_dump) \ -_(SW_INTERFACE_SET_MPLS_ENABLE, sw_interface_set_mpls_enable) \ -_(MPLS_TABLE_DUMP, mpls_table_dump) \ -_(MPLS_ROUTE_DUMP, mpls_route_dump) - void mpls_table_delete (u32 table_id, u8 is_api) { @@ -192,13 +171,11 @@ mpls_route_add_del_t_handler (vnet_main_t * vnm, goto out; } - rv = fib_api_route_add_del (mp->mr_is_add, - mp->mr_is_multipath, - fib_index, - &pfx, - (mp->mr_route.mr_is_multicast ? - FIB_ENTRY_FLAG_MULTICAST : - FIB_ENTRY_FLAG_NONE), rpaths); + rv = fib_api_route_add_del ( + mp->mr_is_add, mp->mr_is_multipath, fib_index, &pfx, FIB_SOURCE_API, + (mp->mr_route.mr_is_multicast ? FIB_ENTRY_FLAG_MULTICAST : + FIB_ENTRY_FLAG_NONE), + rpaths); if (mp->mr_is_add && 0 == rv) *stats_index = fib_table_entry_get_stats_index (fib_index, &pfx); @@ -222,19 +199,15 @@ vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp) rv = mpls_route_add_del_t_handler (vnm, mp, &stats_index); - /* *INDENT-OFF* */ REPLY_MACRO2 (VL_API_MPLS_ROUTE_ADD_DEL_REPLY, ({ rmp->stats_index = htonl (stats_index); })); - /* *INDENT-ON* */ } void mpls_table_create (u32 table_id, u8 is_api, const u8 * name) { - u32 fib_index; - /* * The MPLS defult table must also be explicitly created via the API. * So in contrast to IP, it gets no special treatment here. @@ -245,16 +218,11 @@ mpls_table_create (u32 table_id, u8 is_api, const u8 * name) * i.e. it can be added many times via the API but needs to be * deleted only once. */ - fib_index = fib_table_find (FIB_PROTOCOL_MPLS, table_id); - - if (~0 == fib_index) - { fib_table_find_or_create_and_lock_w_name (FIB_PROTOCOL_MPLS, table_id, (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI), name); - } } static void @@ -283,7 +251,8 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp) if (~0 == tunnel_sw_if_index) tunnel_sw_if_index = vnet_mpls_tunnel_create (mp->mt_tunnel.mt_l2_only, - mp->mt_tunnel.mt_is_multicast); + mp->mt_tunnel.mt_is_multicast, + mp->mt_tunnel.mt_tag); vnet_mpls_tunnel_path_add (tunnel_sw_if_index, rpaths); tunnel_index = vnet_mpls_tunnel_get_index (tunnel_sw_if_index); @@ -299,13 +268,11 @@ vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp) vec_free (rpaths); out: - /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_MPLS_TUNNEL_ADD_DEL_REPLY, ({ rmp->sw_if_index = ntohl(tunnel_sw_if_index); rmp->tunnel_index = ntohl(tunnel_index); })); - /* *INDENT-ON* */ } static void @@ -317,9 +284,8 @@ static void VALIDATE_SW_IF_INDEX (mp); - rv = mpls_sw_interface_enable_disable (&mpls_main, - ntohl (mp->sw_if_index), - mp->enable, 1); + rv = mpls_sw_interface_enable_disable (&mpls_main, ntohl (mp->sw_if_index), + mp->enable); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_MPLS_ENABLE_REPLY); @@ -357,14 +323,15 @@ send_mpls_tunnel_entry (u32 mti, void *arg) mp = vl_msg_api_alloc (sizeof (*mp) + n * sizeof (vl_api_fib_path_t)); clib_memset (mp, 0, sizeof (*mp) + n * sizeof (vl_api_fib_path_t)); - mp->_vl_msg_id = ntohs (VL_API_MPLS_TUNNEL_DETAILS); + mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MPLS_TUNNEL_DETAILS); mp->context = ctx->context; - mp->mt_tunnel.mt_n_paths = ntohl (n); + mp->mt_tunnel.mt_n_paths = n; mp->mt_tunnel.mt_sw_if_index = ntohl (mt->mt_sw_if_index); mp->mt_tunnel.mt_tunnel_index = ntohl (mti); mp->mt_tunnel.mt_l2_only = ! !(MPLS_TUNNEL_FLAG_L2 & mt->mt_flags); mp->mt_tunnel.mt_is_multicast = ! !(MPLS_TUNNEL_FLAG_MCAST & mt->mt_flags); + memcpy (mp->mt_tunnel.mt_tag, mt->mt_tag, sizeof (mp->mt_tunnel.mt_tag)); fib_path_list_walk_w_ext (mt->mt_path_list, &mt->mt_path_exts, fib_path_encode, &path_ctx); @@ -407,7 +374,7 @@ send_mpls_table_details (vpe_api_main_t * am, mp = vl_msg_api_alloc (sizeof (*mp)); memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = ntohs (VL_API_MPLS_TABLE_DETAILS); + mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MPLS_TABLE_DETAILS); mp->context = context; mp->mt_table.mt_table_id = htonl (table->ft_table_id); @@ -430,12 +397,58 @@ vl_api_mpls_table_dump_t_handler (vl_api_mpls_table_dump_t * mp) if (!reg) return; - /* *INDENT-OFF* */ - pool_foreach (fib_table, mm->fibs, - ({ + pool_foreach (fib_table, mm->fibs) + { send_mpls_table_details(am, reg, mp->context, fib_table); - })); - /* *INDENT-ON* */ + } +} + +static void +send_mpls_interface_details (vpe_api_main_t *am, vl_api_registration_t *reg, + u32 context, const u32 sw_if_index) +{ + vl_api_mpls_interface_details_t *mp; + + mp = vl_msg_api_alloc_zero (sizeof (*mp)); + mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MPLS_INTERFACE_DETAILS); + mp->context = context; + + mp->sw_if_index = htonl (sw_if_index); + vl_api_send_msg (reg, (u8 *) mp); +} + +static void +vl_api_mpls_interface_dump_t_handler (vl_api_mpls_interface_dump_t *mp) +{ + vpe_api_main_t *am = &vpe_api_main; + vl_api_registration_t *reg; + vnet_interface_main_t *im = &vnet_main.interface_main; + vnet_sw_interface_t *si; + u32 sw_if_index = ~0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + sw_if_index = ntohl (mp->sw_if_index); + + if (sw_if_index == ~0) + { + pool_foreach (si, im->sw_interfaces) + { + if (mpls_sw_interface_is_enabled (si->sw_if_index)) + { + send_mpls_interface_details (am, reg, mp->context, + si->sw_if_index); + } + } + } + else + { + if (mpls_sw_interface_is_enabled (sw_if_index)) + { + send_mpls_interface_details (am, reg, mp->context, sw_if_index); + } + } } static void @@ -457,7 +470,7 @@ send_mpls_route_details (vpe_api_main_t * am, if (!mp) return; clib_memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = ntohs (VL_API_MPLS_ROUTE_DETAILS); + mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_MPLS_ROUTE_DETAILS); mp->context = context; mp->mr_route.mr_table_id = @@ -528,49 +541,22 @@ vl_api_mpls_route_dump_t_handler (vl_api_mpls_route_dump_t * mp) } } -/* - * mpls_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_mpls; -#undef _ -} - +#include static clib_error_t * mpls_api_hookup (vlib_main_t * vm) { - api_main_t *am = &api_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 _ + api_main_t *am = vlibapi_get_main (); /* * Trace space for 8 MPLS encap labels */ - am->api_trace_cfg[VL_API_MPLS_TUNNEL_ADD_DEL].size += 8 * sizeof (u32); + vl_api_increase_msg_trace_size (am, VL_API_MPLS_TUNNEL_ADD_DEL, + 8 * sizeof (u32)); /* * Set up the (msg_name, crc, message-id) table */ - setup_message_id_table (am); + REPLY_MSG_ID_BASE = setup_message_id_table (); return 0; }