2 *------------------------------------------------------------------
3 * vat_helper_macros.h - collect api client helper macros in one place
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
19 #ifndef __vat_helper_macros_h__
20 #define __vat_helper_macros_h__
22 /* M: construct, but don't yet send a message */
25 socket_client_main_t *scm = vam->socket_client_main; \
26 vam->result_ready = 0; \
27 if (scm && scm->socket_enable) \
28 mp = vl_socket_client_msg_alloc (sizeof(*mp)); \
30 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
31 clib_memset (mp, 0, sizeof (*mp)); \
32 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
33 mp->client_index = vam->my_client_index; \
36 /* MPING: construct a control-ping message, don't send it yet */
37 #define MPING(T, mp) \
39 socket_client_main_t *scm = vam->socket_client_main; \
40 vam->result_ready = 0; \
41 if (scm && scm->socket_enable) \
42 mp = vl_socket_client_msg_alloc (sizeof(*mp)); \
44 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
45 clib_memset (mp, 0, sizeof (*mp)); \
46 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
47 mp->client_index = vam->my_client_index; \
49 scm->control_pings_outstanding++; \
52 #define M2(T, mp, n) \
54 socket_client_main_t *scm = vam->socket_client_main; \
55 vam->result_ready = 0; \
56 if (scm && scm->socket_enable) \
57 mp = vl_socket_client_msg_alloc (sizeof(*mp) + n); \
59 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp) + n); \
60 clib_memset (mp, 0, sizeof (*mp)); \
61 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
62 mp->client_index = vam->my_client_index; \
65 #define PING(_tm, mp_ping) \
68 socket_client_main_t *scm = vam->socket_client_main; \
69 if (scm && scm->socket_enable) \
70 mp_ping = vl_socket_client_msg_alloc (sizeof (*mp_ping)); \
72 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \
73 mp_ping->_vl_msg_id = htons (VL_API_CONTROL_PING + 1); \
74 mp_ping->client_index = vam->my_client_index; \
75 vam->result_ready = 0; \
77 scm->control_pings_outstanding++; \
81 /* S: send a message */
84 socket_client_main_t *scm = vam->socket_client_main; \
85 if (scm && scm->socket_enable) \
86 vl_socket_client_write (); \
88 vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp); \
91 /* W: wait for results, with timeout */
94 f64 timeout = vat_time_now (vam) + 1.0; \
95 socket_client_main_t *scm = vam->socket_client_main; \
98 if (scm && scm->socket_enable) \
99 vl_socket_client_read (5); \
100 while (vat_time_now (vam) < timeout) { \
101 if (vam->result_ready == 1) { \
105 vat_suspend (vam->vlib_main, 1e-5); \
109 /* W2: wait for results, with timeout */ \
110 #define W2(ret, body) \
112 f64 timeout = vat_time_now (vam) + 1.0; \
113 socket_client_main_t *scm = vam->socket_client_main; \
116 if (scm && scm->socket_enable) \
117 vl_socket_client_read (5); \
118 while (vat_time_now (vam) < timeout) { \
119 if (vam->result_ready == 1) { \
124 vat_suspend (vam->vlib_main, 1e-5); \
128 #define VAT_PLUGIN_REGISTER(plug) \
129 clib_error_t * vat_plugin_register (vat_main_t *vam) \
131 plug##_test_main_t * mp = &plug##_test_main; \
134 mp->vat_main = vam; \
136 /* Ask the vpp engine for the first assigned message-id */ \
137 name = format (0, #plug "_%08x%c", api_version, 0); \
139 vl_client_get_first_plugin_msg_id ((char *) name); \
142 if (mp->msg_id_base != (u16) ~0) \
143 plug##_api_hookup (vam); \
145 return clib_error_return (0, #plug " plugin not loaded...");\
150 #endif /* __vat_helper_macros_h__ */