From 1b563527c143903b6e7e79b5978af5310372f605 Mon Sep 17 00:00:00 2001 From: AkshayaNadahalli Date: Mon, 23 Jan 2017 22:05:35 +0530 Subject: In-band OAM active probe (VPP-471) Change-Id: Icf0ddf76ba1c8b588c79387284cd0349ebc6e45f Signed-off-by: AkshayaNadahalli --- src/plugins/ioam/udp-ping/udp_ping_api.c | 190 +++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 src/plugins/ioam/udp-ping/udp_ping_api.c (limited to 'src/plugins/ioam/udp-ping/udp_ping_api.c') diff --git a/src/plugins/ioam/udp-ping/udp_ping_api.c b/src/plugins/ioam/udp-ping/udp_ping_api.c new file mode 100644 index 00000000..8cb8cc96 --- /dev/null +++ b/src/plugins/ioam/udp-ping/udp_ping_api.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + *------------------------------------------------------------------ + * udp_ping_api.c - UDP Ping related APIs to create + * and maintain ping flows + *------------------------------------------------------------------ + */ + +#include +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include + +/* define message structures */ +#define vl_typedefs +#include +#undef vl_typedefs + +/* define generated endian-swappers */ +#define vl_endianfun +#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 + +/* Get the API version number */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include +#undef vl_api_version + +/* + * A handy macro to set up a message reply. + * Assumes that the following variables are available: + * mp - pointer to request message + * rmp - pointer to reply message type + * rv - return value + */ + +#define REPLY_MACRO(t) \ + do { \ + unix_shared_memory_queue_t * q = \ + vl_api_client_index_to_input_queue (mp->client_index); \ + if (!q) \ + return; \ + \ + rmp = vl_msg_api_alloc (sizeof (*rmp)); \ + rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ + rmp->context = mp->context; \ + rmp->retval = ntohl(rv); \ + \ + vl_msg_api_send_shmem (q, (u8 *)&rmp); \ + } while(0); + +#define REPLY_MACRO2(t, body) \ + do { \ + unix_shared_memory_queue_t * q; \ + rv = vl_msg_api_pd_handler (mp, rv); \ + q = vl_api_client_index_to_input_queue (mp->client_index); \ + if (!q) \ + return; \ + \ + rmp = vl_msg_api_alloc (sizeof (*rmp)); \ + rmp->_vl_msg_id = ntohs((t)); \ + rmp->context = mp->context; \ + rmp->retval = ntohl(rv); \ + do {body;} while (0); \ + vl_msg_api_send_shmem (q, (u8 *)&rmp); \ + } while(0); + +/* List of message types that this module understands */ + +#define foreach_udp_ping_api_msg \ + _(UDP_PING_ADD_DEL_REQ, udp_ping_add_del_req) \ + _(UDP_PING_EXPORT_REQ, udp_ping_export_req) \ + +static void vl_api_udp_ping_add_del_req_t_handler + (vl_api_udp_ping_add_del_req_t * mp) +{ + ip46_address_t dst, src; + int rv = 0; + udp_ping_main_t *sm = &udp_ping_main; + vl_api_udp_ping_add_del_reply_t *rmp; + + if (mp->is_ipv4) + { + rv = -1; //Not supported + goto ERROROUT; + } + + clib_memcpy ((void *) &src.ip6, (void *) mp->src_ip_address, + sizeof (ip6_address_t)); + clib_memcpy ((void *) &dst.ip6, (void *) mp->dst_ip_address, + sizeof (ip6_address_t)); + + ip46_udp_ping_set_flow (src, dst, + ntohs (mp->start_src_port), + ntohs (mp->end_src_port), + ntohs (mp->start_dst_port), + ntohs (mp->end_dst_port), + ntohs (mp->interval), mp->fault_det, mp->dis); + rv = 0; //FIXME + +ERROROUT: + REPLY_MACRO (VL_API_UDP_PING_ADD_DEL_REPLY); +} + +static void vl_api_udp_ping_export_req_t_handler + (vl_api_udp_ping_export_req_t * mp) +{ + udp_ping_main_t *sm = &udp_ping_main; + int rv = 0; + vl_api_udp_ping_export_reply_t *rmp; + + (void) udp_ping_flow_create (!mp->enable); + rv = 0; //FIXME + + REPLY_MACRO (VL_API_UDP_PING_EXPORT_REPLY); +} + +/* Set up the API message handling tables */ +static clib_error_t * +udp_ping_api_hookup (vlib_main_t * vm) +{ + udp_ping_main_t *sm = &udp_ping_main; +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ + #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_udp_ping_api_msg; +#undef _ + + return 0; +} + +static clib_error_t * +udp_ping_api_init (vlib_main_t * vm) +{ + udp_ping_main_t *sm = &udp_ping_main; + clib_error_t *error = 0; + u8 *name; + + name = format (0, "udp_ping_%08x%c", api_version, 0); + + /* Ask for a correctly-sized block of API message decode slots */ + sm->msg_id_base = vl_msg_api_get_msg_ids + ((char *) name, VL_MSG_FIRST_AVAILABLE); + + error = udp_ping_api_hookup (vm); + + vec_free (name); + + return error; +} + +VLIB_INIT_FUNCTION (udp_ping_api_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From b614d08368cc0b04e01c5222d4c11a88845394e5 Mon Sep 17 00:00:00 2001 From: Eyal Bari Date: Thu, 16 Mar 2017 10:02:57 +0200 Subject: API:replaced all REPLY_MACRO's with api_helper_macros.h Change-Id: I08ab1fd0abdd1db4aff11a38c9c0134b01368e11 Signed-off-by: Eyal Bari --- src/examples/sample-plugin/sample/sample.c | 25 +------ src/plugins/acl/acl.c | 83 ++++------------------ src/plugins/flowperpkt/flowperpkt.c | 41 +---------- .../ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c | 27 +------ src/plugins/ioam/export/ioam_export.c | 26 +------ src/plugins/ioam/ip6/ioam_cache.c | 26 +------ src/plugins/ioam/lib-pot/pot_api.c | 41 +---------- src/plugins/ioam/udp-ping/udp_ping_api.c | 41 +---------- src/plugins/lb/api.c | 27 ++----- src/plugins/snat/snat.c | 2 +- src/vlibapi/api_helper_macros.h | 8 +-- 11 files changed, 39 insertions(+), 308 deletions(-) (limited to 'src/plugins/ioam/udp-ping/udp_ping_api.c') diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c index 7588dbc0..01852746 100644 --- a/src/examples/sample-plugin/sample/sample.c +++ b/src/examples/sample-plugin/sample/sample.c @@ -50,29 +50,8 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ diff --git a/src/plugins/acl/acl.c b/src/plugins/acl/acl.c index b6af7380..0d06531d 100644 --- a/src/plugins/acl/acl.c +++ b/src/plugins/acl/acl.c @@ -57,61 +57,8 @@ acl_main_t acl_main; -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO2(t, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+am->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO3(t, n, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \ - rmp->_vl_msg_id = ntohs((t)+am->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE am->msg_id_base +#include /* List of message types that this plugin understands */ @@ -1409,7 +1356,7 @@ vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp) static void vl_api_acl_del_t_handler (vl_api_acl_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_acl_del_reply_t *rmp; int rv; @@ -1421,8 +1368,8 @@ vl_api_acl_del_t_handler (vl_api_acl_del_t * mp) static void vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp) { - acl_main_t *sm = &acl_main; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + acl_main_t *am = &acl_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); vl_api_acl_interface_add_del_reply_t *rmp; int rv = -1; @@ -1441,11 +1388,11 @@ static void vl_api_acl_interface_set_acl_list_t_handler (vl_api_acl_interface_set_acl_list_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_acl_interface_set_acl_list_reply_t *rmp; int rv = 0; int i; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); if (pool_is_free_index(im->sw_interfaces, sw_if_index)) @@ -1667,7 +1614,7 @@ vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp) static void vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_macip_acl_del_reply_t *rmp; int rv; @@ -1680,10 +1627,10 @@ static void vl_api_macip_acl_interface_add_del_t_handler (vl_api_macip_acl_interface_add_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_macip_acl_interface_add_del_reply_t *rmp; int rv = -1; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); if (pool_is_free_index(im->sw_interfaces, sw_if_index)) @@ -1819,9 +1766,9 @@ vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t * static clib_error_t * acl_plugin_api_hookup (vlib_main_t * vm) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; #define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ + vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base), \ #n, \ vl_api_##n##_t_handler, \ vl_noop_handler, \ @@ -1839,10 +1786,10 @@ acl_plugin_api_hookup (vlib_main_t * vm) #undef vl_msg_name_crc_list static void -setup_message_id_table (acl_main_t * sm, api_main_t * am) +setup_message_id_table (acl_main_t * am, api_main_t * apim) { #define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base); foreach_vl_msg_name_crc_acl; #undef _ } @@ -1852,11 +1799,11 @@ register_match_action_nexts (u32 next_in_ip4, u32 next_in_ip6, u32 next_out_ip4, u32 next_out_ip6) { acl_main_t *am = &acl_main; - u32 act = am->n_match_actions; if (am->n_match_actions == 255) { return ~0; } + u32 act = am->n_match_actions; am->n_match_actions++; am->acl_in_ip4_match_next[act] = next_in_ip4; am->acl_in_ip6_match_next[act] = next_in_ip6; diff --git a/src/plugins/flowperpkt/flowperpkt.c b/src/plugins/flowperpkt/flowperpkt.c index 6b292eef..587972f7 100644 --- a/src/plugins/flowperpkt/flowperpkt.c +++ b/src/plugins/flowperpkt/flowperpkt.c @@ -58,6 +58,9 @@ flowperpkt_main_t flowperpkt_main; #include #undef vl_api_version +#define REPLY_MSG_ID_BASE fm->msg_id_base +#include + /* Define the per-interface configurable features */ /* *INDENT-OFF* */ VNET_FEATURE_INIT (flow_perpacket_ipv4, static) = @@ -75,28 +78,6 @@ VNET_FEATURE_INIT (flow_perpacket_l2, static) = }; /* *INDENT-ON* */ -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+fm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - /* Macro to finish up custom dump fns */ #define FINISH \ vec_add1 (s, 0); \ @@ -104,22 +85,6 @@ do { \ vec_free (s); \ return handle; -#define VALIDATE_SW_IF_INDEX(mp) \ - do { u32 __sw_if_index = ntohl(mp->sw_if_index); \ - vnet_main_t *__vnm = vnet_get_main(); \ - if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \ - __sw_if_index)) { \ - rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \ - goto bad_sw_if_index; \ - } \ -} while(0); - -#define BAD_SW_IF_INDEX_LABEL \ -do { \ -bad_sw_if_index: \ - ; \ -} while (0); - /** * @brief Create an IPFIX template packet rewrite string * @param frm flow_report_main_t * diff --git a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c index f05b5303..b703b8d0 100644 --- a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c +++ b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c @@ -53,33 +53,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - - #define foreach_vxlan_gpe_ioam_export_plugin_api_msg \ _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable) diff --git a/src/plugins/ioam/export/ioam_export.c b/src/plugins/ioam/export/ioam_export.c index eeeb9738..46ac3d4a 100644 --- a/src/plugins/ioam/export/ioam_export.c +++ b/src/plugins/ioam/export/ioam_export.c @@ -52,32 +52,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_ioam_export_plugin_api_msg \ _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable) diff --git a/src/plugins/ioam/ip6/ioam_cache.c b/src/plugins/ioam/ip6/ioam_cache.c index 9e90ff9a..a4079e84 100644 --- a/src/plugins/ioam/ip6/ioam_cache.c +++ b/src/plugins/ioam/ip6/ioam_cache.c @@ -53,32 +53,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+cm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE cm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_ioam_cache_plugin_api_msg \ _(IOAM_CACHE_IP6_ENABLE_DISABLE, ioam_cache_ip6_enable_disable) diff --git a/src/plugins/ioam/lib-pot/pot_api.c b/src/plugins/ioam/lib-pot/pot_api.c index 04c2aaa5..cc1b7b76 100644 --- a/src/plugins/ioam/lib-pot/pot_api.c +++ b/src/plugins/ioam/lib-pot/pot_api.c @@ -51,47 +51,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO2(t, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_pot_plugin_api_msg \ _(POT_PROFILE_ADD, pot_profile_add) \ _(POT_PROFILE_ACTIVATE, pot_profile_activate) \ diff --git a/src/plugins/ioam/udp-ping/udp_ping_api.c b/src/plugins/ioam/udp-ping/udp_ping_api.c index 8cb8cc96..6e5ef61e 100644 --- a/src/plugins/ioam/udp-ping/udp_ping_api.c +++ b/src/plugins/ioam/udp-ping/udp_ping_api.c @@ -51,47 +51,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ - do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ - } while(0); - -#define REPLY_MACRO2(t, body) \ - do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ - } while(0); +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this module understands */ - #define foreach_udp_ping_api_msg \ _(UDP_PING_ADD_DEL_REQ, udp_ping_add_del_req) \ _(UDP_PING_EXPORT_REQ, udp_ping_export_req) \ diff --git a/src/plugins/lb/api.c b/src/plugins/lb/api.c index 06c53fa1..9e3bcd65 100644 --- a/src/plugins/lb/api.c +++ b/src/plugins/lb/api.c @@ -51,6 +51,10 @@ typedef enum { #include #undef vl_msg_name_crc_list + +#define REPLY_MSG_ID_BASE lbm->msg_id_base +#include + static void setup_message_id_table (lb_main_t * lbm, api_main_t * am) { @@ -67,29 +71,6 @@ setup_message_id_table (lb_main_t * lbm, api_main_t * am) vec_free (s); \ return handle; -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+lbm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - static void vl_api_lb_conf_t_handler (vl_api_lb_conf_t * mp) diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c index 57274bbe..d42303f6 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/snat/snat.c @@ -47,7 +47,7 @@ snat_main_t snat_main; #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define REPLY_MSG_ID_BASE (sm->msg_id_base) +#define REPLY_MSG_ID_BASE sm->msg_id_base #include /* Get the API version number */ diff --git a/src/vlibapi/api_helper_macros.h b/src/vlibapi/api_helper_macros.h index aacea7c1..a492c3f4 100644 --- a/src/vlibapi/api_helper_macros.h +++ b/src/vlibapi/api_helper_macros.h @@ -36,7 +36,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ \ @@ -52,7 +52,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -68,7 +68,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -97,7 +97,7 @@ do { \ rv = VNET_API_ERROR_TABLE_TOO_BIG; \ is_error = 1; \ } \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ if (!is_error) \ -- cgit 1.2.3-korg From 851a37a78f80427a910a9cb571e5a7d70c120e38 Mon Sep 17 00:00:00 2001 From: Shwetha Bhandari Date: Thu, 27 Apr 2017 14:13:10 +0530 Subject: ioam: adding missing setup api msg crc table Change-Id: Ic95fe6179de1151796188813cc595187d4c842a0 Signed-off-by: Shwetha Bhandari --- .../ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c | 17 +++++++++++++++++ src/plugins/ioam/ip6/ioam_cache.c | 17 +++++++++++++++++ src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c | 16 ++++++++++++++++ src/plugins/ioam/udp-ping/udp_ping_api.c | 16 ++++++++++++++++ 4 files changed, 66 insertions(+) (limited to 'src/plugins/ioam/udp-ping/udp_ping_api.c') diff --git a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c index cef60903..ec43e484 100644 --- a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c +++ b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c @@ -155,6 +155,19 @@ vxlan_gpe_ioam_export_plugin_api_hookup (vlib_main_t * vm) return 0; } +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (ioam_export_main_t * sm, api_main_t * am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + foreach_vl_msg_name_crc_vxlan_gpe_ioam_export; +#undef _ +} + static clib_error_t * set_vxlan_gpe_ioam_export_ipfix_command_fn (vlib_main_t * vm, @@ -233,6 +246,10 @@ vxlan_gpe_ioam_export_init (vlib_main_t * vm) em->vlib_time_0 = vlib_time_now (vm); error = vxlan_gpe_ioam_export_plugin_api_hookup (vm); + + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (em, &api_main); + em->my_hbh_slot = ~0; em->vlib_main = vm; em->vnet_main = vnet_get_main (); diff --git a/src/plugins/ioam/ip6/ioam_cache.c b/src/plugins/ioam/ip6/ioam_cache.c index a4079e84..92e7075d 100644 --- a/src/plugins/ioam/ip6/ioam_cache.c +++ b/src/plugins/ioam/ip6/ioam_cache.c @@ -186,6 +186,19 @@ ioam_cache_plugin_api_hookup (vlib_main_t * vm) return 0; } +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (ioam_cache_main_t * sm, api_main_t * am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + foreach_vl_msg_name_crc_ioam_cache; +#undef _ +} + static clib_error_t * set_ioam_cache_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -334,6 +347,10 @@ ioam_cache_init (vlib_main_t * vm) ((char *) name, VL_MSG_FIRST_AVAILABLE); error = ioam_cache_plugin_api_hookup (vm); + + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (em, &api_main); + /* Hook this node to ip6-hop-by-hop */ ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop"); em->cache_hbh_slot = diff --git a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c index 247bcf59..634133a4 100644 --- a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c +++ b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c @@ -303,6 +303,19 @@ vxlan_gpe_plugin_api_hookup (vlib_main_t * vm) return 0; } +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (vxlan_gpe_ioam_main_t * sm, api_main_t * am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + foreach_vl_msg_name_crc_ioam_vxlan_gpe; +#undef _ +} + static clib_error_t * vxlan_gpe_init (vlib_main_t * vm) { @@ -328,6 +341,9 @@ vxlan_gpe_init (vlib_main_t * vm) error = vxlan_gpe_plugin_api_hookup (vm); + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (sm, &api_main); + /* Hook the ioam-encap node to vxlan-gpe-encap */ vxlan_gpe_encap_node = vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-encap"); sm->encap_v4_next_node = diff --git a/src/plugins/ioam/udp-ping/udp_ping_api.c b/src/plugins/ioam/udp-ping/udp_ping_api.c index 6e5ef61e..75938731 100644 --- a/src/plugins/ioam/udp-ping/udp_ping_api.c +++ b/src/plugins/ioam/udp-ping/udp_ping_api.c @@ -122,6 +122,19 @@ udp_ping_api_hookup (vlib_main_t * vm) return 0; } +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (udp_ping_main_t * sm, api_main_t * am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + foreach_vl_msg_name_crc_udp_ping; +#undef _ +} + static clib_error_t * udp_ping_api_init (vlib_main_t * vm) { @@ -137,6 +150,9 @@ udp_ping_api_init (vlib_main_t * vm) error = udp_ping_api_hookup (vm); + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (sm, &api_main); + vec_free (name); return error; -- cgit 1.2.3-korg