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_msg_q_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 vcm->mounting_segment = 1;
136 memset (a, 0, sizeof (*a));
137 a->segment_name = (char *) mp->segment_name;
138 a->segment_size = mp->segment_size;
139 /* Attach to the segment vpp created */
140 rv = svm_fifo_segment_attach (a);
141 vec_reset_length (a->new_segment_indices);
142 if (PREDICT_FALSE (rv))
144 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
145 getpid (), mp->segment_name);
149 VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (),
150 mp->segment_name, mp->segment_size);
151 vcm->mounting_segment = 0;
155 vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
159 * XXX Need segment_name to session_id hash,
160 * XXX - have sessionID by handle hash currently
163 VDBG (1, "Unmapped segment '%s'", mp->segment_name);
167 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
171 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
175 vcl_session_t *session = 0;
176 u32 session_index = p[0];
178 VCL_SESSION_LOCK_AND_GET (session_index, &session);
179 session->session_state = STATE_CLOSE_ON_EMPTY;
181 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: setting state to 0x%x "
182 "(%s)", getpid (), mp->handle, session_index,
183 session->session_state,
184 vppcom_session_state_str (session->session_state));
185 VCL_SESSION_UNLOCK ();
189 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session lookup failed!",
190 getpid (), mp->handle, session_index);
193 clib_warning ("VCL<%d>: vpp handle 0x%llx: session lookup by "
194 "handle failed!", getpid (), mp->handle);
198 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
200 vcl_session_t *session = 0;
201 vl_api_reset_session_reply_t *rmp;
205 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
210 rval = vppcom_session_at_index (p[0], &session);
211 if (PREDICT_FALSE (rval))
213 rv = VNET_API_ERROR_INVALID_VALUE_2;
214 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
215 "session lookup failed! returning %d %U",
216 getpid (), mp->handle, p[0],
217 rv, format_api_error, rv);
221 /* TBD: should this disconnect immediately and
224 session->session_state = STATE_CLOSE_ON_EMPTY;
226 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: state set to %d "
227 "(%s)!", getpid (), mp->handle, p[0], session->session_state,
228 vppcom_session_state_str (session->session_state));
230 VCL_SESSION_UNLOCK ();
234 rv = VNET_API_ERROR_INVALID_VALUE;
235 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx: session lookup "
236 "failed! returning %d %U",
237 getpid (), mp->handle, rv, format_api_error, rv);
240 rmp = vl_msg_api_alloc (sizeof (*rmp));
241 memset (rmp, 0, sizeof (*rmp));
242 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
243 rmp->retval = htonl (rv);
244 rmp->handle = mp->handle;
245 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
249 vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
251 vcl_session_t *session = 0;
253 svm_fifo_t *rx_fifo, *tx_fifo;
256 session_index = mp->context;
257 VCL_SESSION_LOCK_AND_GET (session_index, &session);
261 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
262 "connect failed! %U",
263 getpid (), mp->handle, session_index,
264 format_api_error, ntohl (mp->retval));
267 session->session_state = STATE_FAILED;
268 session->vpp_handle = mp->handle;
272 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
273 "Invalid session index (%u)!",
274 getpid (), mp->handle, session_index);
285 if (vcm->session_io_thread.io_sessions_lockp)
287 // Add this connection to the active io sessions list
288 VCL_IO_SESSIONS_LOCK ();
289 u32 *active_session_index;
290 pool_get (vcm->session_io_thread.active_session_indexes,
291 active_session_index);
292 *active_session_index = session_index;
293 VCL_IO_SESSIONS_UNLOCK ();
295 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
298 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
299 rx_fifo->client_session_index = session_index;
300 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
301 tx_fifo->client_session_index = session_index;
303 session->rx_fifo = rx_fifo;
304 session->tx_fifo = tx_fifo;
305 session->vpp_handle = mp->handle;
306 session->transport.is_ip4 = mp->is_ip4;
307 clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip,
308 sizeof (session->transport.rmt_ip));
309 session->transport.lcl_port = mp->lcl_port;
310 session->session_state = STATE_CONNECT;
312 /* Add it to lookup table */
313 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
315 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded! "
316 "session_rx_fifo %p, refcnt %d, session_tx_fifo %p, refcnt %d",
317 getpid (), mp->handle, session_index, session->rx_fifo,
318 session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt);
320 VCL_SESSION_UNLOCK ();
324 vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp)
326 vcl_session_t *session = 0;
327 u32 session_index = mp->context;
330 VCL_SESSION_LOCK_AND_GET (session_index, &session);
334 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, "
335 "sid %u: bind failed: %U",
336 getpid (), mp->handle, session_index,
337 format_api_error, ntohl (mp->retval));
338 rv = vppcom_session_at_index (session_index, &session);
341 session->session_state = STATE_FAILED;
342 session->vpp_handle = mp->handle;
346 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
347 "Invalid session index (%u)!",
348 getpid (), mp->handle, session_index);
353 session->vpp_handle = mp->handle;
354 session->transport.is_ip4 = mp->lcl_is_ip4;
355 clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip,
356 sizeof (ip46_address_t));
357 session->transport.lcl_port = mp->lcl_port;
358 vppcom_session_table_add_listener (mp->handle, session_index);
359 session->session_state = STATE_LISTEN;
361 if (session->is_dgram)
363 svm_fifo_t *rx_fifo, *tx_fifo;
364 session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
365 rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *);
366 rx_fifo->client_session_index = session_index;
367 tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *);
368 tx_fifo->client_session_index = session_index;
369 session->rx_fifo = rx_fifo;
370 session->tx_fifo = tx_fifo;
373 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!",
374 getpid (), mp->handle, mp->context);
376 VCL_SESSION_UNLOCK ();
380 vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp)
383 clib_warning ("VCL<%d>: ERROR: sid %u: unbind failed: %U",
384 getpid (), mp->context, format_api_error,
388 VDBG (1, "VCL<%d>: sid %u: unbind succeeded!", getpid (), mp->context);
392 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
394 svm_fifo_t *rx_fifo, *tx_fifo;
395 vcl_session_t *session, *listen_session;
397 vce_event_connect_request_t *ecr;
405 VCL_ACCEPT_FIFO_LOCK ();
406 elts = clib_fifo_free_elts (vcm->client_session_index_fifo);
407 VCL_ACCEPT_FIFO_UNLOCK ();
411 clib_warning ("VCL<%d>: client session queue is full!", getpid ());
412 vppcom_send_accept_session_reply (mp->handle, mp->context,
413 VNET_API_ERROR_QUEUE_FULL);
414 VCL_SESSION_UNLOCK ();
418 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
421 clib_warning ("VCL<%d>: ERROR: couldn't find listen session: "
422 "unknown vpp listener handle %llx",
423 getpid (), mp->listener_handle);
424 vppcom_send_accept_session_reply (mp->handle, mp->context,
425 VNET_API_ERROR_INVALID_ARGUMENT);
426 VCL_SESSION_UNLOCK ();
430 /* TODO check listener depth and update */
431 /* TODO on "child" fd close, update listener depth */
433 /* Allocate local session and set it up */
434 pool_get (vcm->sessions, session);
435 memset (session, 0, sizeof (*session));
436 session_index = (u32) (session - vcm->sessions);
438 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
439 rx_fifo->client_session_index = session_index;
440 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
441 tx_fifo->client_session_index = session_index;
443 session->vpp_handle = mp->handle;
444 session->client_context = mp->context;
445 session->rx_fifo = rx_fifo;
446 session->tx_fifo = tx_fifo;
447 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
449 session->session_state = STATE_ACCEPT;
450 session->transport.rmt_port = mp->port;
451 session->transport.is_ip4 = mp->is_ip4;
452 clib_memcpy (&session->transport.rmt_ip, mp->ip, sizeof (ip46_address_t));
454 /* Add it to lookup table */
455 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
456 session->transport.lcl_port = listen_session->transport.lcl_port;
457 session->transport.lcl_ip = listen_session->transport.lcl_ip;
459 /* Create an event for handlers */
463 pool_get (vcm->event_thread.vce_events, ev);
464 ev_idx = (u32) (ev - vcm->event_thread.vce_events);
465 ecr = vce_get_event_data (ev, sizeof (*ecr));
466 ev->evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED;
467 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
468 ev->evk.session_index = (u32) (listen_session - vcm->sessions);
469 ecr->accepted_session_index = session_index;
471 VCL_EVENTS_UNLOCK ();
473 rv = vce_generate_event (&vcm->event_thread, ev_idx);
476 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: client accept request from %s"
477 " address %U port %d queue %p!", getpid (), mp->handle, session_index,
478 mp->is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &mp->ip,
479 mp->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6,
480 clib_net_to_host_u16 (mp->port), session->vpp_evt_q);
482 vcl_evt (VCL_EVT_ACCEPT, session, listen_session, session_index);
483 VCL_SESSION_UNLOCK ();
486 #define foreach_sock_msg \
487 _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
488 _(BIND_SOCK_REPLY, bind_sock_reply) \
489 _(UNBIND_SOCK_REPLY, unbind_sock_reply) \
490 _(ACCEPT_SESSION, accept_session) \
491 _(CONNECT_SESSION_REPLY, connect_session_reply) \
492 _(DISCONNECT_SESSION, disconnect_session) \
493 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
494 _(RESET_SESSION, reset_session) \
495 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
496 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
497 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
498 _(UNMAP_SEGMENT, unmap_segment)
501 vppcom_api_hookup (void)
504 vl_msg_api_set_handlers(VL_API_##N, #n, \
505 vl_api_##n##_t_handler, \
507 vl_api_##n##_t_endian, \
508 vl_api_##n##_t_print, \
509 sizeof(vl_api_##n##_t), 1);
515 * VPP-API message functions
518 vppcom_send_session_enable_disable (u8 is_enable)
520 vl_api_session_enable_disable_t *bmp;
521 bmp = vl_msg_api_alloc (sizeof (*bmp));
522 memset (bmp, 0, sizeof (*bmp));
524 bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE);
525 bmp->client_index = vcm->my_client_index;
526 bmp->context = htonl (0xfeedface);
527 bmp->is_enable = is_enable;
528 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
532 vppcom_app_send_attach (void)
534 vl_api_application_attach_t *bmp;
535 u8 nsid_len = vec_len (vcm->cfg.namespace_id);
536 u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp ||
537 vcm->cfg.app_proxy_transport_udp);
539 bmp = vl_msg_api_alloc (sizeof (*bmp));
540 memset (bmp, 0, sizeof (*bmp));
542 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
543 bmp->client_index = vcm->my_client_index;
544 bmp->context = htonl (0xfeedface);
545 bmp->options[APP_OPTIONS_FLAGS] =
546 APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
547 (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
548 (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) |
549 (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0) |
550 APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS;
551 bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
552 (u64) ((vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
553 (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0));
554 bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
555 bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
556 bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
557 bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
558 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
559 vcm->cfg.preallocated_fifo_pairs;
560 bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size;
563 bmp->namespace_id_len = nsid_len;
564 clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
565 bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
567 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
571 vppcom_app_send_detach (void)
573 vl_api_application_detach_t *bmp;
574 bmp = vl_msg_api_alloc (sizeof (*bmp));
575 memset (bmp, 0, sizeof (*bmp));
577 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
578 bmp->client_index = vcm->my_client_index;
579 bmp->context = htonl (0xfeedface);
580 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
584 vppcom_send_connect_sock (vcl_session_t * session, u32 session_index)
586 vl_api_connect_sock_t *cmp;
588 /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
589 cmp = vl_msg_api_alloc (sizeof (*cmp));
590 memset (cmp, 0, sizeof (*cmp));
591 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK);
592 cmp->client_index = vcm->my_client_index;
593 cmp->context = session_index;
595 cmp->is_ip4 = session->transport.is_ip4;
596 clib_memcpy (cmp->ip, &session->transport.rmt_ip, sizeof (cmp->ip));
597 cmp->port = session->transport.rmt_port;
598 cmp->proto = session->session_type;
599 clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
600 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
604 vppcom_send_disconnect_session_reply (u64 vpp_handle, u32 session_index,
607 vl_api_disconnect_session_reply_t *rmp;
609 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
610 getpid (), vpp_handle, session_index);
612 rmp = vl_msg_api_alloc (sizeof (*rmp));
613 memset (rmp, 0, sizeof (*rmp));
615 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
616 rmp->retval = htonl (rv);
617 rmp->handle = vpp_handle;
618 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
622 vppcom_send_disconnect_session (u64 vpp_handle, u32 session_index)
624 vl_api_disconnect_session_t *dmp;
626 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
627 getpid (), vpp_handle, session_index);
629 dmp = vl_msg_api_alloc (sizeof (*dmp));
630 memset (dmp, 0, sizeof (*dmp));
631 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
632 dmp->client_index = vcm->my_client_index;
633 dmp->handle = vpp_handle;
634 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
637 /* VPP combines bind and listen as one operation. VCL manages the separation
638 * of bind and listen locally via vppcom_session_bind() and
639 * vppcom_session_listen() */
641 vppcom_send_bind_sock (vcl_session_t * session, u32 session_index)
643 vl_api_bind_sock_t *bmp;
645 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
646 bmp = vl_msg_api_alloc (sizeof (*bmp));
647 memset (bmp, 0, sizeof (*bmp));
649 bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK);
650 bmp->client_index = vcm->my_client_index;
651 bmp->context = session_index;
652 bmp->is_ip4 = session->transport.is_ip4;
653 clib_memcpy (bmp->ip, &session->transport.lcl_ip, sizeof (bmp->ip));
654 bmp->port = session->transport.lcl_port;
655 bmp->proto = session->session_type;
656 clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
657 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
661 vppcom_send_unbind_sock (u64 vpp_handle)
663 vl_api_unbind_sock_t *ump;
665 ump = vl_msg_api_alloc (sizeof (*ump));
666 memset (ump, 0, sizeof (*ump));
668 ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK);
669 ump->client_index = vcm->my_client_index;
670 ump->handle = vpp_handle;
671 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & ump);
675 vppcom_send_accept_session_reply (u64 handle, u32 context, int retval)
677 vl_api_accept_session_reply_t *rmp;
679 rmp = vl_msg_api_alloc (sizeof (*rmp));
680 memset (rmp, 0, sizeof (*rmp));
681 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
682 rmp->retval = htonl (retval);
683 rmp->context = context;
684 rmp->handle = handle;
685 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
689 vcl_max_nsid_len (void)
691 vl_api_application_attach_t *mp;
692 return (sizeof (mp->namespace_id) - 1);
696 vppcom_init_error_string_table (void)
698 vcm->error_string_by_error_number = hash_create (0, sizeof (uword));
700 #define _(n, v, s) hash_set (vcm->error_string_by_error_number, -v, s);
701 foreach_vnet_api_error;
704 hash_set (vcm->error_string_by_error_number, 99, "Misc");
708 vppcom_connect_to_vpp (char *app_name)
710 api_main_t *am = &api_main;
711 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
714 if (!vcl_cfg->vpp_api_filename)
715 vcl_cfg->vpp_api_filename = format (0, "/vpe-api%c", 0);
717 VDBG (0, "VCL<%d>: app (%s) connecting to VPP api (%s)...",
718 getpid (), app_name, vcl_cfg->vpp_api_filename);
720 if (vl_client_connect_to_vlib ((char *) vcl_cfg->vpp_api_filename, app_name,
721 vcm->cfg.vpp_api_q_length) < 0)
723 clib_warning ("VCL<%d>: app (%s) connect failed!", getpid (), app_name);
724 rv = VPPCOM_ECONNREFUSED;
728 vcm->vl_input_queue = am->shmem_hdr->vl_input_queue;
729 vcm->my_client_index = (u32) am->my_client_index;
730 vcm->app_state = STATE_APP_CONN_VPP;
732 VDBG (0, "VCL<%d>: app (%s) is connected to VPP!", getpid (), app_name);
735 vcl_evt (VCL_EVT_INIT, vcm);
740 * fd.io coding-style-patch-verification: ON
743 * eval: (c-set-style "gnu")