Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vcl/vcl_private.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vpp/api/vpe_msg_enum.h> |
| 19 | |
| 20 | #define vl_typedefs /* define message structures */ |
| 21 | #include <vpp/api/vpe_all_api_h.h> |
| 22 | #undef vl_typedefs |
| 23 | |
| 24 | /* declare message handlers for each api */ |
| 25 | |
| 26 | #define vl_endianfun /* define message structures */ |
| 27 | #include <vpp/api/vpe_all_api_h.h> |
| 28 | #undef vl_endianfun |
| 29 | |
| 30 | /* instantiate all the print functions we know about */ |
| 31 | #define vl_print(handle, ...) |
| 32 | #define vl_printfun |
| 33 | #include <vpp/api/vpe_all_api_h.h> |
| 34 | #undef vl_printfun |
| 35 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 36 | u8 * |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 37 | format_api_error (u8 * s, va_list * args) |
| 38 | { |
| 39 | i32 error = va_arg (*args, u32); |
| 40 | uword *p; |
| 41 | |
| 42 | p = hash_get (vcm->error_string_by_error_number, -error); |
| 43 | |
| 44 | if (p) |
| 45 | s = format (s, "%s (%d)", p[0], error); |
| 46 | else |
| 47 | s = format (s, "%d", error); |
| 48 | return s; |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | vl_api_session_enable_disable_reply_t_handler |
| 53 | (vl_api_session_enable_disable_reply_t * mp) |
| 54 | { |
| 55 | if (mp->retval) |
| 56 | { |
| 57 | clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (), |
| 58 | format_api_error, ntohl (mp->retval)); |
| 59 | } |
| 60 | else |
| 61 | vcm->app_state = STATE_APP_ENABLED; |
| 62 | } |
| 63 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 64 | static int |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 65 | vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type, |
| 66 | int fd) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 67 | { |
| 68 | svm_fifo_segment_create_args_t _a, *a = &_a; |
| 69 | int rv; |
| 70 | |
| 71 | memset (a, 0, sizeof (*a)); |
| 72 | a->segment_name = (char *) name; |
| 73 | a->segment_type = type; |
| 74 | |
| 75 | if (type == SSVM_SEGMENT_MEMFD) |
| 76 | a->memfd_fd = fd; |
| 77 | |
Florin Coras | adc74d7 | 2018-12-02 13:36:00 -0800 | [diff] [blame] | 78 | if ((rv = svm_fifo_segment_attach (&vcm->segment_main, a))) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 79 | { |
| 80 | clib_warning ("svm_fifo_segment_attach ('%s') failed", name); |
| 81 | return rv; |
| 82 | } |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 83 | vcl_segment_table_add (segment_handle, a->new_segment_indices[0]); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 84 | vec_reset_length (a->new_segment_indices); |
| 85 | return 0; |
| 86 | } |
| 87 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 88 | static void |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 89 | vcl_segment_detach (u64 segment_handle) |
| 90 | { |
Florin Coras | adc74d7 | 2018-12-02 13:36:00 -0800 | [diff] [blame] | 91 | svm_fifo_segment_main_t *sm = &vcm->segment_main; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 92 | svm_fifo_segment_private_t *segment; |
| 93 | u32 segment_index; |
| 94 | |
| 95 | segment_index = vcl_segment_table_lookup (segment_handle); |
| 96 | if (segment_index == (u32) ~ 0) |
| 97 | return; |
Florin Coras | adc74d7 | 2018-12-02 13:36:00 -0800 | [diff] [blame] | 98 | segment = svm_fifo_segment_get_segment (sm, segment_index); |
| 99 | svm_fifo_segment_delete (sm, segment); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 100 | vcl_segment_table_del (segment_handle); |
| 101 | } |
| 102 | |
| 103 | static u64 |
| 104 | vcl_vpp_worker_segment_handle (u32 wrk_index) |
| 105 | { |
| 106 | return (VCL_INVALID_SEGMENT_HANDLE - wrk_index - 1); |
| 107 | } |
| 108 | |
| 109 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 110 | vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t * |
| 111 | mp) |
| 112 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 113 | vcl_worker_t *wrk = vcl_worker_get (0); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 114 | u64 segment_handle; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 115 | u32 n_fds = 0; |
| 116 | int *fds = 0; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 117 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 118 | if (mp->retval) |
| 119 | { |
| 120 | clib_warning ("VCL<%d>: attach failed: %U", getpid (), |
| 121 | format_api_error, ntohl (mp->retval)); |
| 122 | return; |
| 123 | } |
| 124 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 125 | wrk->app_event_queue = uword_to_pointer (mp->app_event_queue_address, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 126 | svm_msg_q_t *); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 127 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 128 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 129 | { |
| 130 | clib_warning ("invalid segment handle"); |
| 131 | return; |
| 132 | } |
| 133 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 134 | if (mp->n_fds) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 135 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 136 | vec_validate (fds, mp->n_fds); |
| 137 | vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5); |
| 138 | |
| 139 | if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 140 | if (vcl_segment_attach (vcl_vpp_worker_segment_handle (0), |
| 141 | "vpp-mq-seg", SSVM_SEGMENT_MEMFD, |
| 142 | fds[n_fds++])) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 143 | return; |
| 144 | |
| 145 | if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 146 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 147 | SSVM_SEGMENT_MEMFD, fds[n_fds++])) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 148 | return; |
| 149 | |
| 150 | if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) |
| 151 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 152 | svm_msg_q_set_consumer_eventfd (wrk->app_event_queue, fds[n_fds]); |
| 153 | vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 154 | n_fds++; |
| 155 | } |
| 156 | |
| 157 | vec_free (fds); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 158 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 159 | else |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 160 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 161 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 162 | SSVM_SEGMENT_SHM, -1)) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 163 | return; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 166 | vcm->app_index = clib_net_to_host_u32 (mp->app_index); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 167 | vcm->app_state = STATE_APP_ATTACHED; |
| 168 | } |
| 169 | |
| 170 | static void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 171 | vl_api_app_worker_add_del_reply_t_handler (vl_api_app_worker_add_del_reply_t * |
| 172 | mp) |
| 173 | { |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 174 | int n_fds = 0, *fds = 0; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 175 | u64 segment_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 176 | vcl_worker_t *wrk; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 177 | u32 wrk_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 178 | |
| 179 | if (mp->retval) |
| 180 | { |
| 181 | clib_warning ("VCL<%d>: add/del worker failed: %U", getpid (), |
| 182 | format_api_error, ntohl (mp->retval)); |
| 183 | goto failed; |
| 184 | } |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 185 | |
Florin Coras | 3348a4c | 2018-09-07 17:09:35 -0700 | [diff] [blame] | 186 | if (!mp->is_add) |
| 187 | return; |
| 188 | |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 189 | wrk_index = mp->context; |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 190 | wrk = vcl_worker_get_if_valid (wrk_index); |
| 191 | if (!wrk) |
| 192 | return; |
| 193 | |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 194 | wrk->vpp_wrk_index = clib_net_to_host_u32 (mp->wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 195 | wrk->app_event_queue = uword_to_pointer (mp->app_event_queue_address, |
| 196 | svm_msg_q_t *); |
| 197 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 198 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 199 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 200 | { |
| 201 | clib_warning ("invalid segment handle"); |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 202 | goto failed; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 205 | if (mp->n_fds) |
| 206 | { |
| 207 | vec_validate (fds, mp->n_fds); |
| 208 | vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5); |
| 209 | |
| 210 | if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 211 | if (vcl_segment_attach (vcl_vpp_worker_segment_handle (wrk_index), |
| 212 | "vpp-worker-seg", SSVM_SEGMENT_MEMFD, |
| 213 | fds[n_fds++])) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 214 | goto failed; |
| 215 | |
| 216 | if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 217 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 218 | SSVM_SEGMENT_MEMFD, fds[n_fds++])) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 219 | goto failed; |
| 220 | |
| 221 | if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) |
| 222 | { |
| 223 | svm_msg_q_set_consumer_eventfd (wrk->app_event_queue, fds[n_fds]); |
| 224 | vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); |
| 225 | n_fds++; |
| 226 | } |
| 227 | |
| 228 | vec_free (fds); |
| 229 | } |
| 230 | else |
| 231 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 232 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 233 | SSVM_SEGMENT_SHM, -1)) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 234 | goto failed; |
| 235 | } |
| 236 | vcm->app_state = STATE_APP_READY; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 237 | VDBG (0, "worker %u vpp-worker %u added", wrk_index, wrk->vpp_wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 238 | return; |
| 239 | |
| 240 | failed: |
| 241 | vcm->app_state = STATE_APP_FAILED; |
| 242 | } |
| 243 | |
| 244 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 245 | vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t * |
| 246 | mp) |
| 247 | { |
| 248 | if (mp->retval) |
| 249 | clib_warning ("VCL<%d>: detach failed: %U", getpid (), format_api_error, |
| 250 | ntohl (mp->retval)); |
| 251 | |
| 252 | vcm->app_state = STATE_APP_ENABLED; |
| 253 | } |
| 254 | |
| 255 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 256 | vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp) |
| 257 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 258 | ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 259 | u64 segment_handle; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 260 | int fd = -1; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 261 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 262 | if (mp->fd_flags) |
| 263 | { |
| 264 | vl_socket_client_recv_fd_msg (&fd, 1, 5); |
| 265 | seg_type = SSVM_SEGMENT_MEMFD; |
| 266 | } |
| 267 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 268 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 269 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 270 | { |
| 271 | clib_warning ("invalid segment handle"); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 276 | seg_type, fd)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 277 | { |
| 278 | clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed", |
| 279 | getpid (), mp->segment_name); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (), |
| 284 | mp->segment_name, mp->segment_size); |
| 285 | } |
| 286 | |
| 287 | static void |
| 288 | vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp) |
| 289 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 290 | u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 291 | vcl_segment_detach (segment_handle); |
| 292 | VDBG (1, "Unmapped segment: %d", segment_handle); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 296 | vl_api_app_cut_through_registration_add_t_handler |
| 297 | (vl_api_app_cut_through_registration_add_t * mp) |
| 298 | { |
| 299 | vcl_cut_through_registration_t *ctr; |
| 300 | u32 mqc_index = ~0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 301 | vcl_worker_t *wrk; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 302 | int *fds = 0; |
| 303 | |
| 304 | if (mp->n_fds) |
| 305 | { |
| 306 | ASSERT (mp->n_fds == 2); |
| 307 | vec_validate (fds, mp->n_fds); |
| 308 | vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5); |
| 309 | } |
| 310 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 311 | wrk = vcl_worker_get (mp->wrk_index); |
| 312 | ctr = vcl_ct_registration_lock_and_alloc (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 313 | ctr->mq = uword_to_pointer (mp->evt_q_address, svm_msg_q_t *); |
| 314 | ctr->peer_mq = uword_to_pointer (mp->peer_evt_q_address, svm_msg_q_t *); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 315 | VDBG (0, "Adding ct registration %u", vcl_ct_registration_index (wrk, ctr)); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 316 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 317 | if (mp->n_fds && (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 318 | { |
| 319 | svm_msg_q_set_consumer_eventfd (ctr->mq, fds[0]); |
| 320 | svm_msg_q_set_producer_eventfd (ctr->peer_mq, fds[1]); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 321 | mqc_index = vcl_mq_epoll_add_evfd (wrk, ctr->mq); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 322 | ctr->epoll_evt_conn_index = mqc_index; |
| 323 | vec_free (fds); |
| 324 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 325 | vcl_ct_registration_lookup_add (wrk, mp->evt_q_address, |
| 326 | vcl_ct_registration_index (wrk, ctr)); |
| 327 | vcl_ct_registration_unlock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 331 | vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp) |
| 332 | { |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 333 | /* Expecting a similar message on mq. So ignore this */ |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 334 | VDBG (0, "bapi msg vpp handle 0x%llx, sid %u: bind retval: %u!", |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 335 | getpid (), mp->handle, mp->context, mp->retval); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void |
| 339 | vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp) |
| 340 | { |
| 341 | if (mp->retval) |
| 342 | clib_warning ("VCL<%d>: ERROR: sid %u: unbind failed: %U", |
| 343 | getpid (), mp->context, format_api_error, |
| 344 | ntohl (mp->retval)); |
| 345 | |
| 346 | else |
| 347 | VDBG (1, "VCL<%d>: sid %u: unbind succeeded!", getpid (), mp->context); |
| 348 | } |
| 349 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 350 | static void |
| 351 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 352 | mp) |
| 353 | { |
| 354 | if (mp->retval) |
| 355 | clib_warning ("VCL<%d>: ERROR: sid %u: disconnect failed: %U", |
| 356 | getpid (), mp->context, format_api_error, |
| 357 | ntohl (mp->retval)); |
| 358 | } |
| 359 | |
| 360 | static void |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 361 | vl_api_connect_session_reply_t_handler (vl_api_connect_sock_reply_t * mp) |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 362 | { |
| 363 | if (mp->retval) |
| 364 | clib_warning ("VCL<%d>: ERROR: sid %u: connect failed: %U", |
| 365 | getpid (), mp->context, format_api_error, |
| 366 | ntohl (mp->retval)); |
| 367 | } |
| 368 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 369 | #define foreach_sock_msg \ |
| 370 | _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \ |
| 371 | _(BIND_SOCK_REPLY, bind_sock_reply) \ |
| 372 | _(UNBIND_SOCK_REPLY, unbind_sock_reply) \ |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 373 | _(CONNECT_SESSION_REPLY, connect_session_reply) \ |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 374 | _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \ |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 375 | _(APPLICATION_ATTACH_REPLY, application_attach_reply) \ |
| 376 | _(APPLICATION_DETACH_REPLY, application_detach_reply) \ |
| 377 | _(MAP_ANOTHER_SEGMENT, map_another_segment) \ |
| 378 | _(UNMAP_SEGMENT, unmap_segment) \ |
| 379 | _(APP_CUT_THROUGH_REGISTRATION_ADD, app_cut_through_registration_add) \ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 380 | _(APP_WORKER_ADD_DEL_REPLY, app_worker_add_del_reply) \ |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 381 | |
| 382 | void |
| 383 | vppcom_api_hookup (void) |
| 384 | { |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 385 | #define _(N, n) \ |
| 386 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 387 | vl_api_##n##_t_handler, \ |
| 388 | vl_noop_handler, \ |
| 389 | vl_api_##n##_t_endian, \ |
| 390 | vl_api_##n##_t_print, \ |
| 391 | sizeof(vl_api_##n##_t), 1); |
| 392 | foreach_sock_msg; |
| 393 | #undef _ |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * VPP-API message functions |
| 398 | */ |
| 399 | void |
| 400 | vppcom_send_session_enable_disable (u8 is_enable) |
| 401 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 402 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 403 | vl_api_session_enable_disable_t *bmp; |
| 404 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 405 | memset (bmp, 0, sizeof (*bmp)); |
| 406 | |
| 407 | bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 408 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 409 | bmp->context = htonl (0xfeedface); |
| 410 | bmp->is_enable = is_enable; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 411 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void |
| 415 | vppcom_app_send_attach (void) |
| 416 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 417 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 418 | vl_api_application_attach_t *bmp; |
| 419 | u8 nsid_len = vec_len (vcm->cfg.namespace_id); |
| 420 | u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp || |
| 421 | vcm->cfg.app_proxy_transport_udp); |
| 422 | |
| 423 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 424 | memset (bmp, 0, sizeof (*bmp)); |
| 425 | |
| 426 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 427 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 428 | bmp->context = htonl (0xfeedface); |
| 429 | bmp->options[APP_OPTIONS_FLAGS] = |
| 430 | APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT | |
| 431 | (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) | |
| 432 | (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 433 | (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0) | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 434 | APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS | |
| 435 | (vcm->cfg.use_mq_eventfd ? APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD : 0); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 436 | bmp->options[APP_OPTIONS_PROXY_TRANSPORT] = |
| 437 | (u64) ((vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) | |
| 438 | (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0)); |
| 439 | bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size; |
| 440 | bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size; |
| 441 | bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size; |
| 442 | bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size; |
| 443 | bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = |
| 444 | vcm->cfg.preallocated_fifo_pairs; |
| 445 | bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size; |
| 446 | if (nsid_len) |
| 447 | { |
| 448 | bmp->namespace_id_len = nsid_len; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 449 | clib_memcpy_fast (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 450 | bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret; |
| 451 | } |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 452 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void |
| 456 | vppcom_app_send_detach (void) |
| 457 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 458 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 459 | vl_api_application_detach_t *bmp; |
| 460 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 461 | memset (bmp, 0, sizeof (*bmp)); |
| 462 | |
| 463 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 464 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 465 | bmp->context = htonl (0xfeedface); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 466 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 470 | vcl_send_app_worker_add_del (u8 is_add) |
| 471 | { |
| 472 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 473 | vl_api_app_worker_add_del_t *mp; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 474 | |
| 475 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 476 | memset (mp, 0, sizeof (*mp)); |
| 477 | |
| 478 | mp->_vl_msg_id = ntohs (VL_API_APP_WORKER_ADD_DEL); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 479 | mp->client_index = wrk->my_client_index; |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 480 | mp->app_index = clib_host_to_net_u32 (vcm->app_index); |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 481 | mp->context = wrk->wrk_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 482 | mp->is_add = is_add; |
| 483 | if (!is_add) |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 484 | mp->wrk_index = clib_host_to_net_u32 (wrk->vpp_wrk_index); |
| 485 | |
| 486 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & mp); |
| 487 | } |
| 488 | |
| 489 | void |
| 490 | vcl_send_child_worker_del (vcl_worker_t * child_wrk) |
| 491 | { |
| 492 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 493 | vl_api_app_worker_add_del_t *mp; |
| 494 | |
| 495 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 496 | memset (mp, 0, sizeof (*mp)); |
| 497 | |
| 498 | mp->_vl_msg_id = ntohs (VL_API_APP_WORKER_ADD_DEL); |
| 499 | mp->client_index = wrk->my_client_index; |
| 500 | mp->app_index = clib_host_to_net_u32 (vcm->app_index); |
| 501 | mp->context = wrk->wrk_index; |
| 502 | mp->is_add = 0; |
| 503 | mp->wrk_index = clib_host_to_net_u32 (child_wrk->vpp_wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 504 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 505 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & mp); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void |
| 509 | vppcom_send_connect_sock (vcl_session_t * session) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 510 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 511 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 512 | vl_api_connect_sock_t *cmp; |
| 513 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 514 | cmp = vl_msg_api_alloc (sizeof (*cmp)); |
| 515 | memset (cmp, 0, sizeof (*cmp)); |
| 516 | cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 517 | cmp->client_index = wrk->my_client_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 518 | cmp->context = session->session_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 519 | cmp->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 520 | cmp->is_ip4 = session->transport.is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 521 | clib_memcpy_fast (cmp->ip, &session->transport.rmt_ip, sizeof (cmp->ip)); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 522 | cmp->port = session->transport.rmt_port; |
| 523 | cmp->proto = session->session_type; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 524 | clib_memcpy_fast (cmp->options, session->options, sizeof (cmp->options)); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 525 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & cmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 529 | vppcom_send_disconnect_session (u64 vpp_handle) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 530 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 531 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 532 | vl_api_disconnect_session_t *dmp; |
| 533 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 534 | dmp = vl_msg_api_alloc (sizeof (*dmp)); |
| 535 | memset (dmp, 0, sizeof (*dmp)); |
| 536 | dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 537 | dmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 538 | dmp->handle = vpp_handle; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 539 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & dmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /* VPP combines bind and listen as one operation. VCL manages the separation |
| 543 | * of bind and listen locally via vppcom_session_bind() and |
| 544 | * vppcom_session_listen() */ |
| 545 | void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 546 | vppcom_send_bind_sock (vcl_session_t * session) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 547 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 548 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 549 | vl_api_bind_sock_t *bmp; |
| 550 | |
| 551 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
| 552 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 553 | memset (bmp, 0, sizeof (*bmp)); |
| 554 | |
| 555 | bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 556 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 557 | bmp->context = session->session_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 558 | bmp->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 559 | bmp->is_ip4 = session->transport.is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 560 | clib_memcpy_fast (bmp->ip, &session->transport.lcl_ip, sizeof (bmp->ip)); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 561 | bmp->port = session->transport.lcl_port; |
| 562 | bmp->proto = session->session_type; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 563 | clib_memcpy_fast (bmp->options, session->options, sizeof (bmp->options)); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 564 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | void |
| 568 | vppcom_send_unbind_sock (u64 vpp_handle) |
| 569 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 570 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 571 | vl_api_unbind_sock_t *ump; |
| 572 | |
| 573 | ump = vl_msg_api_alloc (sizeof (*ump)); |
| 574 | memset (ump, 0, sizeof (*ump)); |
| 575 | |
| 576 | ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 577 | ump->client_index = wrk->my_client_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 578 | ump->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 579 | ump->handle = vpp_handle; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 580 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & ump); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | void |
| 584 | vppcom_send_accept_session_reply (u64 handle, u32 context, int retval) |
| 585 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 586 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 587 | vl_api_accept_session_reply_t *rmp; |
| 588 | |
| 589 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 590 | memset (rmp, 0, sizeof (*rmp)); |
| 591 | rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY); |
| 592 | rmp->retval = htonl (retval); |
| 593 | rmp->context = context; |
| 594 | rmp->handle = handle; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 595 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & rmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | u32 |
| 599 | vcl_max_nsid_len (void) |
| 600 | { |
| 601 | vl_api_application_attach_t *mp; |
| 602 | return (sizeof (mp->namespace_id) - 1); |
| 603 | } |
| 604 | |
| 605 | void |
| 606 | vppcom_init_error_string_table (void) |
| 607 | { |
| 608 | vcm->error_string_by_error_number = hash_create (0, sizeof (uword)); |
| 609 | |
| 610 | #define _(n, v, s) hash_set (vcm->error_string_by_error_number, -v, s); |
| 611 | foreach_vnet_api_error; |
| 612 | #undef _ |
| 613 | |
| 614 | hash_set (vcm->error_string_by_error_number, 99, "Misc"); |
| 615 | } |
| 616 | |
| 617 | int |
| 618 | vppcom_connect_to_vpp (char *app_name) |
| 619 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 620 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 621 | api_main_t *am = &api_main; |
| 622 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 623 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 624 | if (vcl_cfg->vpp_api_socket_name) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 625 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 626 | if (vl_socket_client_connect ((char *) vcl_cfg->vpp_api_socket_name, |
| 627 | app_name, 0 /* default rx/tx buffer */ )) |
| 628 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 629 | VERR ("app (%s) socket connect failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 630 | return VPPCOM_ECONNREFUSED; |
| 631 | } |
| 632 | |
| 633 | if (vl_socket_client_init_shm (0)) |
| 634 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 635 | VERR ("app (%s) init shm failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 636 | return VPPCOM_ECONNREFUSED; |
| 637 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 638 | } |
| 639 | else |
| 640 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 641 | if (!vcl_cfg->vpp_api_filename) |
| 642 | vcl_cfg->vpp_api_filename = format (0, "/vpe-api%c", 0); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 643 | |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 644 | VDBG (0, "app (%s) connecting to VPP api (%s)...", |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 645 | app_name, vcl_cfg->vpp_api_filename); |
| 646 | |
| 647 | if (vl_client_connect_to_vlib ((char *) vcl_cfg->vpp_api_filename, |
| 648 | app_name, vcm->cfg.vpp_api_q_length) < 0) |
| 649 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 650 | VERR ("app (%s) connect failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 651 | return VPPCOM_ECONNREFUSED; |
| 652 | } |
| 653 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 656 | wrk->vl_input_queue = am->shmem_hdr->vl_input_queue; |
| 657 | wrk->my_client_index = (u32) am->my_client_index; |
| 658 | wrk->wrk_state = STATE_APP_CONN_VPP; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 659 | |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 660 | VDBG (0, "app (%s) is connected to VPP!", app_name); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 661 | vcl_evt (VCL_EVT_INIT, vcm); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 662 | return VPPCOM_OK; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /* |
| 666 | * fd.io coding-style-patch-verification: ON |
| 667 | * |
| 668 | * Local Variables: |
| 669 | * eval: (c-set-style "gnu") |
| 670 | * End: |
| 671 | */ |