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->socket_enable) \
29 mp = (void *)scm->socket_tx_buffer; \
30 scm->socket_tx_nbytes = sizeof (*mp); \
33 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
34 memset (mp, 0, sizeof (*mp)); \
35 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
36 mp->client_index = vam->my_client_index; \
39 /* MPING: construct a control-ping message, don't send it yet */
40 #define MPING(T, mp) \
42 socket_client_main_t *scm = &vam->socket_client_main; \
43 vam->result_ready = 0; \
44 if (scm->socket_enable) \
46 mp = (void *)scm->socket_tx_buffer; \
47 scm->socket_tx_nbytes = sizeof (*mp); \
50 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
51 memset (mp, 0, sizeof (*mp)); \
52 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
53 mp->client_index = vam->my_client_index; \
54 scm->control_pings_outstanding++; \
57 #define M2(T, mp, n) \
59 socket_client_main_t *scm = &vam->socket_client_main; \
60 vam->result_ready = 0; \
61 if (scm->socket_enable) \
63 mp = (void *)scm->socket_tx_buffer; \
64 scm->socket_tx_nbytes = sizeof (*mp) + n; \
67 mp = vl_msg_api_alloc_as_if_client(sizeof(*mp) + n); \
68 memset (mp, 0, sizeof (*mp)); \
69 mp->_vl_msg_id = ntohs (VL_API_##T+__plugin_msg_base); \
70 mp->client_index = vam->my_client_index; \
73 /* S: send a message */
77 socket_client_main_t *scm = &vam->socket_client_main; \
78 if (scm->socket_enable) \
83 msgbuf.gc_mark_timestamp = 0; \
84 msgbuf.data_len = ntohl(scm->socket_tx_nbytes); \
86 n = write (scm->socket_fd, &msgbuf, sizeof (msgbuf)); \
87 if (n < sizeof (msgbuf)) \
88 clib_unix_warning ("socket write (msgbuf)"); \
90 n = write (scm->socket_fd, scm->socket_tx_buffer, \
91 scm->socket_tx_nbytes); \
92 if (n < scm->socket_tx_nbytes) \
93 clib_unix_warning ("socket write (msg)"); \
96 vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp); \
99 /* W: wait for results, with timeout */
102 f64 timeout = vat_time_now (vam) + 1.0; \
103 socket_client_main_t *scm = &vam->socket_client_main; \
106 vl_socket_client_read_reply (scm); \
107 while (vat_time_now (vam) < timeout) { \
108 if (vam->result_ready == 1) { \
112 vat_suspend (vam->vlib_main, 1e-5); \
116 /* W2: wait for results, with timeout */
117 #define W2(ret, body) \
119 f64 timeout = vat_time_now (vam) + 1.0; \
120 socket_client_main_t *scm = &vam->socket_client_main; \
123 vl_socket_client_read_reply (scm); \
124 while (vat_time_now (vam) < timeout) { \
125 if (vam->result_ready == 1) { \
130 vat_suspend (vam->vlib_main, 1e-5); \
135 #endif /* __vat_helper_macros_h__ */