2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vcl/vcl_private.h>
17 #include <vlibmemory/api.h>
18 #include <vpp/api/vpe_msg_enum.h>
20 #define vl_typedefs /* define message structures */
21 #include <vpp/api/vpe_all_api_h.h>
24 /* declare message handlers for each api */
26 #define vl_endianfun /* define message structures */
27 #include <vpp/api/vpe_all_api_h.h>
30 /* instantiate all the print functions we know about */
31 #define vl_print(handle, ...)
33 #include <vpp/api/vpe_all_api_h.h>
37 format_api_error (u8 * s, va_list * args)
39 i32 error = va_arg (*args, u32);
42 p = hash_get (vcm->error_string_by_error_number, -error);
45 s = format (s, "%s (%d)", p[0], error);
47 s = format (s, "%d", error);
52 vl_api_session_enable_disable_reply_t_handler
53 (vl_api_session_enable_disable_reply_t * mp)
57 clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (),
58 format_api_error, ntohl (mp->retval));
61 vcm->app_state = STATE_APP_ENABLED;
65 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
68 static svm_fifo_segment_create_args_t _a;
69 svm_fifo_segment_create_args_t *a = &_a;
72 memset (a, 0, sizeof (*a));
75 clib_warning ("VCL<%d>: attach failed: %U", getpid (),
76 format_api_error, ntohl (mp->retval));
80 if (mp->segment_name_length == 0)
82 clib_warning ("VCL<%d>: segment_name_length zero", getpid ());
86 a->segment_name = (char *) mp->segment_name;
87 a->segment_size = mp->segment_size;
89 ASSERT (mp->app_event_queue_address);
91 /* Attach to the segment vpp created */
92 rv = svm_fifo_segment_attach (a);
93 vec_reset_length (a->new_segment_indices);
94 if (PREDICT_FALSE (rv))
96 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
97 getpid (), mp->segment_name);
101 vcm->app_event_queue =
102 uword_to_pointer (mp->app_event_queue_address, svm_queue_t *);
104 vcm->app_state = STATE_APP_ATTACHED;
108 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
112 clib_warning ("VCL<%d>: detach failed: %U", getpid (), format_api_error,
115 vcm->app_state = STATE_APP_ENABLED;
119 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
123 clib_warning ("VCL<%d>: vpp handle 0x%llx: disconnect session failed: %U",
124 getpid (), mp->handle, format_api_error,
129 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
131 static svm_fifo_segment_create_args_t _a;
132 svm_fifo_segment_create_args_t *a = &_a;
135 memset (a, 0, sizeof (*a));
136 a->segment_name = (char *) mp->segment_name;
137 a->segment_size = mp->segment_size;
138 /* Attach to the segment vpp created */
139 rv = svm_fifo_segment_attach (a);
140 vec_reset_length (a->new_segment_indices);
141 if (PREDICT_FALSE (rv))
143 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
144 getpid (), mp->segment_name);
148 VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (),
149 mp->segment_name, mp->segment_size);
153 vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
157 * XXX Need segment_name to session_id hash,
158 * XXX - have sessionID by handle hash currently
161 VDBG (1, "Unmapped segment '%s'", mp->segment_name);
165 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
169 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
173 vcl_session_t *session = 0;
174 u32 session_index = p[0];
176 VCL_SESSION_LOCK_AND_GET (session_index, &session);
177 session->session_state = STATE_CLOSE_ON_EMPTY;
179 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: setting state to 0x%x "
180 "(%s)", getpid (), mp->handle, session_index,
181 session->session_state,
182 vppcom_session_state_str (session->session_state));
183 VCL_SESSION_UNLOCK ();
187 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session lookup failed!",
188 getpid (), mp->handle, session_index);
191 clib_warning ("VCL<%d>: vpp handle 0x%llx: session lookup by "
192 "handle failed!", getpid (), mp->handle);
196 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
198 vcl_session_t *session = 0;
199 vl_api_reset_session_reply_t *rmp;
203 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
208 rval = vppcom_session_at_index (p[0], &session);
209 if (PREDICT_FALSE (rval))
211 rv = VNET_API_ERROR_INVALID_VALUE_2;
212 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
213 "session lookup failed! returning %d %U",
214 getpid (), mp->handle, p[0],
215 rv, format_api_error, rv);
219 /* TBD: should this disconnect immediately and
222 session->session_state = STATE_CLOSE_ON_EMPTY;
224 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: state set to %d "
225 "(%s)!", getpid (), mp->handle, p[0], session->session_state,
226 vppcom_session_state_str (session->session_state));
228 VCL_SESSION_UNLOCK ();
232 rv = VNET_API_ERROR_INVALID_VALUE;
233 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx: session lookup "
234 "failed! returning %d %U",
235 getpid (), mp->handle, rv, format_api_error, rv);
238 rmp = vl_msg_api_alloc (sizeof (*rmp));
239 memset (rmp, 0, sizeof (*rmp));
240 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
241 rmp->retval = htonl (rv);
242 rmp->handle = mp->handle;
243 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
247 vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
249 vcl_session_t *session = 0;
251 svm_fifo_t *rx_fifo, *tx_fifo;
254 session_index = mp->context;
255 VCL_SESSION_LOCK_AND_GET (session_index, &session);
259 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
260 "connect failed! %U",
261 getpid (), mp->handle, session_index,
262 format_api_error, ntohl (mp->retval));
265 session->session_state = STATE_FAILED;
266 session->vpp_handle = mp->handle;
270 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
271 "Invalid session index (%u)!",
272 getpid (), mp->handle, session_index);
283 if (vcm->session_io_thread.io_sessions_lockp)
285 // Add this connection to the active io sessions list
286 VCL_IO_SESSIONS_LOCK ();
287 u32 *active_session_index;
288 pool_get (vcm->session_io_thread.active_session_indexes,
289 active_session_index);
290 *active_session_index = session_index;
291 VCL_IO_SESSIONS_UNLOCK ();
293 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
296 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
297 rx_fifo->client_session_index = session_index;
298 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
299 tx_fifo->client_session_index = session_index;
301 session->rx_fifo = rx_fifo;
302 session->tx_fifo = tx_fifo;
303 session->vpp_handle = mp->handle;
304 session->transport.is_ip4 = mp->is_ip4;
305 clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip,
306 sizeof (session->transport.rmt_ip));
307 session->transport.lcl_port = mp->lcl_port;
308 session->session_state = STATE_CONNECT;
310 /* Add it to lookup table */
311 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
313 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded! "
314 "session_rx_fifo %p, refcnt %d, session_tx_fifo %p, refcnt %d",
315 getpid (), mp->handle, session_index, session->rx_fifo,
316 session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt);
318 VCL_SESSION_UNLOCK ();
322 vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp)
324 vcl_session_t *session = 0;
325 u32 session_index = mp->context;
328 VCL_SESSION_LOCK_AND_GET (session_index, &session);
332 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, "
333 "sid %u: bind failed: %U",
334 getpid (), mp->handle, session_index,
335 format_api_error, ntohl (mp->retval));
336 rv = vppcom_session_at_index (session_index, &session);
339 session->session_state = STATE_FAILED;
340 session->vpp_handle = mp->handle;
344 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
345 "Invalid session index (%u)!",
346 getpid (), mp->handle, session_index);
351 session->vpp_handle = mp->handle;
352 session->transport.is_ip4 = mp->lcl_is_ip4;
353 session->transport.lcl_ip = to_ip46 (mp->lcl_is_ip4 ? IP46_TYPE_IP4 :
354 IP46_TYPE_IP6, mp->lcl_ip);
355 session->transport.lcl_port = mp->lcl_port;
356 vppcom_session_table_add_listener (mp->handle, session_index);
357 session->session_state = STATE_LISTEN;
359 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!",
360 getpid (), mp->handle, mp->context);
362 VCL_SESSION_UNLOCK ();
366 vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp)
369 clib_warning ("VCL<%d>: ERROR: sid %u: unbind failed: %U",
370 getpid (), mp->context, format_api_error,
374 VDBG (1, "VCL<%d>: sid %u: unbind succeeded!", getpid (), mp->context);
378 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
380 svm_fifo_t *rx_fifo, *tx_fifo;
381 vcl_session_t *session, *listen_session;
383 vce_event_connect_request_t *ecr;
391 VCL_ACCEPT_FIFO_LOCK ();
392 elts = clib_fifo_free_elts (vcm->client_session_index_fifo);
393 VCL_ACCEPT_FIFO_UNLOCK ();
397 clib_warning ("VCL<%d>: client session queue is full!", getpid ());
398 vppcom_send_accept_session_reply (mp->handle, mp->context,
399 VNET_API_ERROR_QUEUE_FULL);
400 VCL_SESSION_UNLOCK ();
404 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
407 clib_warning ("VCL<%d>: ERROR: couldn't find listen session: "
408 "unknown vpp listener handle %llx",
409 getpid (), mp->listener_handle);
410 vppcom_send_accept_session_reply (mp->handle, mp->context,
411 VNET_API_ERROR_INVALID_ARGUMENT);
412 VCL_SESSION_UNLOCK ();
416 /* TODO check listener depth and update */
417 /* TODO on "child" fd close, update listener depth */
419 /* Allocate local session and set it up */
420 pool_get (vcm->sessions, session);
421 memset (session, 0, sizeof (*session));
422 session_index = (u32) (session - vcm->sessions);
424 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
425 rx_fifo->client_session_index = session_index;
426 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
427 tx_fifo->client_session_index = session_index;
429 session->vpp_handle = mp->handle;
430 session->client_context = mp->context;
431 session->rx_fifo = rx_fifo;
432 session->tx_fifo = tx_fifo;
433 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
435 session->session_state = STATE_ACCEPT;
436 session->transport.rmt_port = mp->port;
437 session->transport.is_ip4 = mp->is_ip4;
438 session->transport.rmt_ip = to_ip46 (mp->is_ip4 ? IP46_TYPE_IP4 :
439 IP46_TYPE_IP6, mp->ip);
441 /* Add it to lookup table */
442 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
443 session->transport.lcl_port = listen_session->transport.lcl_port;
444 session->transport.lcl_ip = listen_session->transport.lcl_ip;
446 /* Create an event for handlers */
450 pool_get (vcm->event_thread.vce_events, ev);
451 ev_idx = (u32) (ev - vcm->event_thread.vce_events);
452 ecr = vce_get_event_data (ev, sizeof (*ecr));
453 ev->evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED;
454 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
455 ev->evk.session_index = (u32) (listen_session - vcm->sessions);
456 ecr->accepted_session_index = session_index;
458 VCL_EVENTS_UNLOCK ();
460 rv = vce_generate_event (&vcm->event_thread, ev_idx);
463 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: client accept request from %s"
464 " address %U port %d queue %p!", getpid (), mp->handle, session_index,
465 mp->is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &mp->ip,
466 mp->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6,
467 clib_net_to_host_u16 (mp->port), session->vpp_evt_q);
469 vcl_evt (VCL_EVT_ACCEPT, session, listen_session, session_index);
470 VCL_SESSION_UNLOCK ();
473 #define foreach_sock_msg \
474 _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
475 _(BIND_SOCK_REPLY, bind_sock_reply) \
476 _(UNBIND_SOCK_REPLY, unbind_sock_reply) \
477 _(ACCEPT_SESSION, accept_session) \
478 _(CONNECT_SESSION_REPLY, connect_session_reply) \
479 _(DISCONNECT_SESSION, disconnect_session) \
480 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
481 _(RESET_SESSION, reset_session) \
482 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
483 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
484 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
485 _(UNMAP_SEGMENT, unmap_segment)
488 vppcom_api_hookup (void)
491 vl_msg_api_set_handlers(VL_API_##N, #n, \
492 vl_api_##n##_t_handler, \
494 vl_api_##n##_t_endian, \
495 vl_api_##n##_t_print, \
496 sizeof(vl_api_##n##_t), 1);
502 * VPP-API message functions
505 vppcom_send_session_enable_disable (u8 is_enable)
507 vl_api_session_enable_disable_t *bmp;
508 bmp = vl_msg_api_alloc (sizeof (*bmp));
509 memset (bmp, 0, sizeof (*bmp));
511 bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE);
512 bmp->client_index = vcm->my_client_index;
513 bmp->context = htonl (0xfeedface);
514 bmp->is_enable = is_enable;
515 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
519 vppcom_app_send_attach (void)
521 vl_api_application_attach_t *bmp;
522 u8 nsid_len = vec_len (vcm->cfg.namespace_id);
523 u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp ||
524 vcm->cfg.app_proxy_transport_udp);
526 bmp = vl_msg_api_alloc (sizeof (*bmp));
527 memset (bmp, 0, sizeof (*bmp));
529 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
530 bmp->client_index = vcm->my_client_index;
531 bmp->context = htonl (0xfeedface);
532 bmp->options[APP_OPTIONS_FLAGS] =
533 APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
534 (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
535 (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) |
536 (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0);
537 bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
538 (u64) ((vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
539 (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0));
540 bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
541 bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
542 bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
543 bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
544 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
545 vcm->cfg.preallocated_fifo_pairs;
546 bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size;
549 bmp->namespace_id_len = nsid_len;
550 clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
551 bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
553 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
557 vppcom_app_send_detach (void)
559 vl_api_application_detach_t *bmp;
560 bmp = vl_msg_api_alloc (sizeof (*bmp));
561 memset (bmp, 0, sizeof (*bmp));
563 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
564 bmp->client_index = vcm->my_client_index;
565 bmp->context = htonl (0xfeedface);
566 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
570 vppcom_send_connect_sock (vcl_session_t * session, u32 session_index)
572 vl_api_connect_sock_t *cmp;
574 /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
575 cmp = vl_msg_api_alloc (sizeof (*cmp));
576 memset (cmp, 0, sizeof (*cmp));
577 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK);
578 cmp->client_index = vcm->my_client_index;
579 cmp->context = session_index;
581 cmp->is_ip4 = session->transport.is_ip4;
582 clib_memcpy (cmp->ip, &session->transport.rmt_ip, sizeof (cmp->ip));
583 cmp->port = session->transport.rmt_port;
584 cmp->proto = session->session_type;
585 clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
586 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
590 vppcom_send_disconnect_session_reply (u64 vpp_handle, u32 session_index,
593 vl_api_disconnect_session_reply_t *rmp;
595 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
596 getpid (), vpp_handle, session_index);
598 rmp = vl_msg_api_alloc (sizeof (*rmp));
599 memset (rmp, 0, sizeof (*rmp));
601 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
602 rmp->retval = htonl (rv);
603 rmp->handle = vpp_handle;
604 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
608 vppcom_send_disconnect_session (u64 vpp_handle, u32 session_index)
610 vl_api_disconnect_session_t *dmp;
612 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
613 getpid (), vpp_handle, session_index);
615 dmp = vl_msg_api_alloc (sizeof (*dmp));
616 memset (dmp, 0, sizeof (*dmp));
617 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
618 dmp->client_index = vcm->my_client_index;
619 dmp->handle = vpp_handle;
620 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
623 /* VPP combines bind and listen as one operation. VCL manages the separation
624 * of bind and listen locally via vppcom_session_bind() and
625 * vppcom_session_listen() */
627 vppcom_send_bind_sock (vcl_session_t * session, u32 session_index)
629 vl_api_bind_sock_t *bmp;
631 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
632 bmp = vl_msg_api_alloc (sizeof (*bmp));
633 memset (bmp, 0, sizeof (*bmp));
635 bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK);
636 bmp->client_index = vcm->my_client_index;
637 bmp->context = session_index;
638 bmp->is_ip4 = session->transport.is_ip4;
639 clib_memcpy (bmp->ip, &session->transport.lcl_ip, sizeof (bmp->ip));
640 bmp->port = session->transport.lcl_port;
641 bmp->proto = session->session_type;
642 clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
643 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
647 vppcom_send_unbind_sock (u64 vpp_handle)
649 vl_api_unbind_sock_t *ump;
651 ump = vl_msg_api_alloc (sizeof (*ump));
652 memset (ump, 0, sizeof (*ump));
654 ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK);
655 ump->client_index = vcm->my_client_index;
656 ump->handle = vpp_handle;
657 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & ump);
661 vppcom_send_accept_session_reply (u64 handle, u32 context, int retval)
663 vl_api_accept_session_reply_t *rmp;
665 rmp = vl_msg_api_alloc (sizeof (*rmp));
666 memset (rmp, 0, sizeof (*rmp));
667 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
668 rmp->retval = htonl (retval);
669 rmp->context = context;
670 rmp->handle = handle;
671 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
675 vcl_max_nsid_len (void)
677 vl_api_application_attach_t *mp;
678 return (sizeof (mp->namespace_id) - 1);
682 vppcom_init_error_string_table (void)
684 vcm->error_string_by_error_number = hash_create (0, sizeof (uword));
686 #define _(n, v, s) hash_set (vcm->error_string_by_error_number, -v, s);
687 foreach_vnet_api_error;
690 hash_set (vcm->error_string_by_error_number, 99, "Misc");
694 vppcom_connect_to_vpp (char *app_name)
696 api_main_t *am = &api_main;
697 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
700 if (!vcl_cfg->vpp_api_filename)
701 vcl_cfg->vpp_api_filename = format (0, "/vpe-api%c", 0);
703 VDBG (0, "VCL<%d>: app (%s) connecting to VPP api (%s)...",
704 getpid (), app_name, vcl_cfg->vpp_api_filename);
706 if (vl_client_connect_to_vlib ((char *) vcl_cfg->vpp_api_filename, app_name,
707 vcm->cfg.vpp_api_q_length) < 0)
709 clib_warning ("VCL<%d>: app (%s) connect failed!", getpid (), app_name);
710 rv = VPPCOM_ECONNREFUSED;
714 vcm->vl_input_queue = am->shmem_hdr->vl_input_queue;
715 vcm->my_client_index = (u32) am->my_client_index;
716 vcm->app_state = STATE_APP_CONN_VPP;
718 VDBG (0, "VCL<%d>: app (%s) is connected to VPP!", getpid (), app_name);
721 vcl_evt (VCL_EVT_INIT, vcm);
726 * fd.io coding-style-patch-verification: ON
729 * eval: (c-set-style "gnu")