2 *------------------------------------------------------------------
5 * Copyright (c) 2009 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 *------------------------------------------------------------------
24 #include <sys/types.h>
29 #include <vppinfra/vec.h>
30 #include <vppinfra/hash.h>
31 #include <vppinfra/pool.h>
32 #include <vppinfra/format.h>
33 #include <vppinfra/byte_order.h>
34 #include <vppinfra/elog.h>
36 #include <vlib/vlib.h>
37 #include <vlib/unix/unix.h>
38 #include <vlibapi/api.h>
39 #include <vlibmemory/api.h>
41 #define TRACE_VLIB_MEMORY_QUEUE 0
43 #include <vlibmemory/vl_memory_msg_enum.h> /* enumerate all vlib messages */
45 #define vl_typedefs /* define message structures */
46 #include <vlibmemory/vl_memory_api_h.h>
49 /* instantiate all the print functions we know about */
50 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
52 #include <vlibmemory/vl_memory_api_h.h>
56 vl_api_memclnt_create_t_print (vl_api_memclnt_create_t * a, void *handle)
58 vl_print (handle, "vl_api_memclnt_create_t:\n");
59 vl_print (handle, "name: %s\n", a->name);
60 vl_print (handle, "input_queue: 0x%wx\n", a->input_queue);
61 vl_print (handle, "context: %u\n", (unsigned) a->context);
62 vl_print (handle, "ctx_quota: %ld\n", (long) a->ctx_quota);
67 vl_api_memclnt_delete_t_print (vl_api_memclnt_delete_t * a, void *handle)
69 vl_print (handle, "vl_api_memclnt_delete_t:\n");
70 vl_print (handle, "index: %u\n", (unsigned) a->index);
71 vl_print (handle, "handle: 0x%wx\n", a->handle);
76 vl_api_trace_plugin_msg_ids_t_print (vl_api_trace_plugin_msg_ids_t * a,
79 vl_print (handle, "vl_api_trace_plugin_msg_ids: %s first %u last %u\n",
81 clib_host_to_net_u16 (a->first_msg_id),
82 clib_host_to_net_u16 (a->last_msg_id));
86 /* instantiate all the endian swap functions we know about */
88 #include <vlibmemory/vl_memory_api_h.h>
91 void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem)
92 __attribute__ ((weak));
95 vl_socket_api_send (vl_api_registration_t * rp, u8 * elem)
100 clib_warning ("need to link against -lvlibsocket, msg not sent!");
104 vl_msg_api_send (vl_api_registration_t * rp, u8 * elem)
106 if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM))
108 vl_socket_api_send (rp, elem);
112 vl_msg_api_send_shmem (rp->vl_input_queue, elem);
117 vl_api_serialize_message_table (api_main_t * am, u8 * vector)
119 serialize_main_t _sm, *sm = &_sm;
121 u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
123 serialize_open_vector (sm, vector);
125 /* serialize the count */
126 serialize_integer (sm, nmsg, sizeof (u32));
129 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
131 serialize_likely_small_unsigned_integer (sm, hp->value[0]);
132 serialize_cstring (sm, (char *) hp->key);
136 return serialize_close_vector (sm);
140 * vl_api_memclnt_create_t_handler
143 vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
145 vl_api_registration_t **regpp;
146 vl_api_registration_t *regp;
147 vl_api_memclnt_create_reply_t *rp;
149 unix_shared_memory_queue_t *q;
152 api_main_t *am = &api_main;
153 u8 *serialized_message_table = 0;
156 * This is tortured. Maintain a vlib-address-space private
157 * pool of client registrations. We use the shared-memory virtual
158 * address of client structure as a handle, to allow direct
159 * manipulation of context quota vbls from the client library.
161 * This scheme causes trouble w/ API message trace replay, since
162 * some random VA from clib_mem_alloc() certainly won't
163 * occur in the Linux sim. The (very) few places
164 * that care need to use the pool index.
166 * Putting the registration object(s) into a pool in shared memory and
167 * using the pool index as a handle seems like a great idea.
168 * Unfortunately, each and every reference to that pool would need
169 * to be protected by a mutex:
173 * convert pool index to
181 pool_get (am->vl_clients, regpp);
185 if (am->serialized_message_table_in_shmem == 0)
186 serialized_message_table = vl_api_serialize_message_table (am, 0);
188 pthread_mutex_lock (&svm->mutex);
189 oldheap = svm_push_data_heap (svm);
190 *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
193 memset (regp, 0, sizeof (*regp));
194 regp->registration_type = REGISTRATION_TYPE_SHMEM;
195 regp->vl_api_registration_pool_index = regpp - am->vl_clients;
197 q = regp->vl_input_queue = (unix_shared_memory_queue_t *) (uword)
200 regp->name = format (0, "%s", mp->name);
201 vec_add1 (regp->name, 0);
202 if (serialized_message_table)
203 am->serialized_message_table_in_shmem =
204 vec_dup (serialized_message_table);
206 pthread_mutex_unlock (&svm->mutex);
207 svm_pop_heap (oldheap);
209 vec_free (serialized_message_table);
211 rp = vl_msg_api_alloc (sizeof (*rp));
212 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
213 rp->handle = (uword) regp;
214 rp->index = vl_msg_api_handle_from_index_and_epoch
215 (regp->vl_api_registration_pool_index,
216 am->shmem_hdr->application_restarts);
217 rp->context = mp->context;
218 rp->response = ntohl (rv);
219 rp->message_table = (u64) am->serialized_message_table_in_shmem;
221 vl_msg_api_send_shmem (q, (u8 *) & rp);
224 /* Application callback to clean up leftover registrations from this client */
225 int vl_api_memclnt_delete_callback (u32 client_index) __attribute__ ((weak));
228 vl_api_memclnt_delete_callback (u32 client_index)
234 * vl_api_memclnt_delete_t_handler
237 vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
239 vl_api_registration_t **regpp;
240 vl_api_registration_t *regp;
241 vl_api_memclnt_delete_reply_t *rp;
244 api_main_t *am = &api_main;
245 u32 handle, client_index, epoch;
249 if (vl_api_memclnt_delete_callback (handle))
252 epoch = vl_msg_api_handle_get_epoch (handle);
253 client_index = vl_msg_api_handle_get_index (handle);
255 if (epoch != (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK))
258 ("Stale clnt delete index %d old epoch %d cur epoch %d",
260 (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK));
264 regpp = am->vl_clients + client_index;
266 if (!pool_is_free (am->vl_clients, regpp))
271 /* $$$ check the input queue for e.g. punted sf's */
273 rp = vl_msg_api_alloc (sizeof (*rp));
274 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
275 rp->handle = mp->handle;
278 vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
280 if (client_index != regp->vl_api_registration_pool_index)
282 clib_warning ("mismatch client_index %d pool_index %d",
283 client_index, regp->vl_api_registration_pool_index);
284 vl_msg_api_free (rp);
288 /* No dangling references, please */
291 pool_put_index (am->vl_clients, regp->vl_api_registration_pool_index);
293 pthread_mutex_lock (&svm->mutex);
294 oldheap = svm_push_data_heap (svm);
295 /* Poison the old registration */
296 memset (regp, 0xF1, sizeof (*regp));
297 clib_mem_free (regp);
298 pthread_mutex_unlock (&svm->mutex);
299 svm_pop_heap (oldheap);
303 clib_warning ("unknown client ID %d", mp->index);
308 vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
310 vl_api_get_first_msg_id_reply_t *rmp;
311 unix_shared_memory_queue_t *q;
313 api_main_t *am = &api_main;
314 vl_api_msg_range_t *rp;
316 u16 first_msg_id = ~0;
317 int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
319 q = vl_api_client_index_to_input_queue (mp->client_index);
323 if (am->msg_range_by_name == 0)
326 strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name) - 1);
328 p = hash_get_mem (am->msg_range_by_name, name);
332 rp = vec_elt_at_index (am->msg_ranges, p[0]);
334 first_msg_id = rp->first_msg_id;
339 rmp = vl_msg_api_alloc (sizeof (*rmp));
340 rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
341 rmp->context = mp->context;
342 rmp->retval = ntohl (rv);
343 rmp->first_msg_id = ntohs (first_msg_id);
344 vl_msg_api_send_shmem (q, (u8 *) & rmp);
347 #define foreach_vlib_api_msg \
348 _(MEMCLNT_CREATE, memclnt_create) \
349 _(MEMCLNT_DELETE, memclnt_delete) \
350 _(GET_FIRST_MSG_ID, get_first_msg_id)
356 memory_api_init (char *region_name)
359 vl_msg_api_msg_config_t cfg;
360 vl_msg_api_msg_config_t *c = &cfg;
362 memset (c, 0, sizeof (*c));
364 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
367 #define _(N,n) do { \
368 c->id = VL_API_##N; \
370 c->handler = vl_api_##n##_t_handler; \
371 c->cleanup = vl_noop_handler; \
372 c->endian = vl_api_##n##_t_endian; \
373 c->print = vl_api_##n##_t_print; \
374 c->size = sizeof(vl_api_##n##_t); \
375 c->traced = 1; /* trace, so these msgs print */ \
376 c->replay = 0; /* don't replay client create/delete msgs */ \
377 c->message_bounce = 0; /* don't bounce this message */ \
378 vl_msg_api_config(c);} while (0);
380 foreach_vlib_api_msg;
386 #define foreach_histogram_bucket \
394 #define _(n) SLEEP_##n##_US,
395 foreach_histogram_bucket
400 static u64 vector_rate_histogram[SLEEP_N_BUCKETS];
402 static void memclnt_queue_callback (vlib_main_t * vm);
405 * Callback to send ourselves a plugin numbering-space trace msg
408 send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
410 vl_api_trace_plugin_msg_ids_t *mp;
411 api_main_t *am = &api_main;
412 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
413 unix_shared_memory_queue_t *q;
415 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
416 memset (mp, 0, sizeof (*mp));
418 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
419 strncpy ((char *) mp->plugin_name, (char *) name,
420 sizeof (mp->plugin_name) - 1);
421 mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
422 mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
424 q = shmem_hdr->vl_input_queue;
426 vl_msg_api_send_shmem (q, (u8 *) & mp);
430 memclnt_process (vlib_main_t * vm,
431 vlib_node_runtime_t * node, vlib_frame_t * f)
435 unix_shared_memory_queue_t *q;
438 api_main_t *am = &api_main;
439 f64 dead_client_scan_time;
440 f64 sleep_time, start_time;
444 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
446 if ((rv = memory_api_init (am->region_name)) < 0)
448 clib_warning ("memory_api_init returned %d, wait for godot...", rv);
449 vlib_process_suspend (vm, 1e70);
454 q = shm->vl_input_queue;
457 e = vlib_call_init_exit_functions
458 (vm, vm->api_init_function_registrations, 1 /* call_once */ );
460 clib_error_report (e);
463 dead_client_scan_time = vlib_time_now (vm) + 20.0;
466 * Send plugin message range messages for each plugin we loaded
468 for (i = 0; i < vec_len (am->msg_ranges); i++)
470 vl_api_msg_range_t *rp = am->msg_ranges + i;
471 send_one_plugin_msg_ids_msg (rp->name, rp->first_msg_id,
475 /* $$$ pay attention to frame size, control CPU usage */
478 uword event_type __attribute__ ((unused));
483 * There's a reason for checking the queue before
484 * sleeping. If the vlib application crashes, it's entirely
485 * possible for a client to enqueue a connect request
486 * during the process restart interval.
488 * Unless some force of physics causes the new incarnation
489 * of the application to process the request, the client will
490 * sit and wait for Godot...
492 vector_rate = vlib_last_vector_length_per_node (vm);
493 start_time = vlib_time_now (vm);
496 pthread_mutex_lock (&q->mutex);
499 vm->api_queue_nonempty = 0;
500 pthread_mutex_unlock (&q->mutex);
502 if (TRACE_VLIB_MEMORY_QUEUE)
505 ELOG_TYPE_DECLARE (e) =
507 .format = "q-underflow: len %d",
515 ed = ELOG_DATA (&vm->elog_main, e);
522 headp = (i8 *) (q->data + sizeof (uword) * q->head);
523 clib_memcpy (&mp, headp, sizeof (uword));
526 need_broadcast = (q->cursize == q->maxsize / 2);
529 if (PREDICT_FALSE (q->head == q->maxsize))
531 pthread_mutex_unlock (&q->mutex);
533 (void) pthread_cond_broadcast (&q->condvar);
535 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
537 /* Allow no more than 10us without a pause */
538 if (vlib_time_now (vm) > start_time + 10e-6)
540 int index = SLEEP_400_US;
541 if (vector_rate > 40.0)
543 else if (vector_rate > 20.0)
545 index = SLEEP_200_US;
548 else if (vector_rate >= 1.0)
550 index = SLEEP_100_US;
558 vector_rate_histogram[index] += 1;
563 event_type = vlib_process_wait_for_event_or_clock (vm, sleep_time);
564 vm->queue_signal_pending = 0;
565 vlib_process_get_events (vm, 0 /* event_data */ );
567 if (vlib_time_now (vm) > dead_client_scan_time)
569 vl_api_registration_t **regpp;
570 vl_api_registration_t *regp;
571 unix_shared_memory_queue_t *q;
572 static u32 *dead_indices;
573 static u32 *confused_indices;
575 vec_reset_length (dead_indices);
576 vec_reset_length (confused_indices);
579 pool_foreach (regpp, am->vl_clients,
584 q = regp->vl_input_queue;
585 if (kill (q->consumer_pid, 0) < 0)
587 vec_add1(dead_indices, regpp - am->vl_clients);
592 clib_warning ("NULL client registration index %d",
593 regpp - am->vl_clients);
594 vec_add1 (confused_indices, regpp - am->vl_clients);
598 /* This should "never happen," but if it does, fix it... */
599 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
602 for (i = 0; i < vec_len (confused_indices); i++)
604 pool_put_index (am->vl_clients, confused_indices[i]);
608 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
614 /* Allow the application to clean up its registrations */
615 for (i = 0; i < vec_len (dead_indices); i++)
617 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
622 handle = vl_msg_api_handle_from_index_and_epoch
623 (dead_indices[i], shm->application_restarts);
624 (void) vl_api_memclnt_delete_callback (handle);
629 pthread_mutex_lock (&svm->mutex);
630 oldheap = svm_push_data_heap (svm);
632 for (i = 0; i < vec_len (dead_indices); i++)
634 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
637 /* Poison the old registration */
638 memset (*regpp, 0xF3, sizeof (**regpp));
639 clib_mem_free (*regpp);
640 /* no dangling references, please */
645 svm_pop_heap (oldheap);
646 clib_warning ("Duplicate free, client index %d",
647 regpp - am->vl_clients);
648 oldheap = svm_push_data_heap (svm);
652 svm_client_scan_this_region_nolock (am->vlib_rp);
654 pthread_mutex_unlock (&svm->mutex);
655 svm_pop_heap (oldheap);
656 for (i = 0; i < vec_len (dead_indices); i++)
657 pool_put_index (am->vl_clients, dead_indices[i]);
660 dead_client_scan_time = vlib_time_now (vm) + 20.0;
663 if (TRACE_VLIB_MEMORY_QUEUE)
666 ELOG_TYPE_DECLARE (e) = {
667 .format = "q-awake: len %d",
675 ed = ELOG_DATA (&vm->elog_main, e);
676 ed->len = q->cursize;
683 static clib_error_t *
684 vl_api_show_histogram_command (vlib_main_t * vm,
685 unformat_input_t * input,
686 vlib_cli_command_t * cli_cmd)
688 u64 total_counts = 0;
691 for (i = 0; i < SLEEP_N_BUCKETS; i++)
693 total_counts += vector_rate_histogram[i];
696 if (total_counts == 0)
698 vlib_cli_output (vm, "No control-plane activity.");
705 percent = ((f64) vector_rate_histogram[SLEEP_##n##_US]) \
706 / (f64) total_counts; \
708 vlib_cli_output (vm, "Sleep %3d us: %llu, %.2f%%",n, \
709 vector_rate_histogram[SLEEP_##n##_US], \
712 foreach_histogram_bucket;
719 VLIB_CLI_COMMAND (cli_show_api_histogram_command, static) = {
720 .path = "show api histogram",
721 .short_help = "show api histogram",
722 .function = vl_api_show_histogram_command,
726 static clib_error_t *
727 vl_api_clear_histogram_command (vlib_main_t * vm,
728 unformat_input_t * input,
729 vlib_cli_command_t * cli_cmd)
733 for (i = 0; i < SLEEP_N_BUCKETS; i++)
734 vector_rate_histogram[i] = 0;
739 VLIB_CLI_COMMAND (cli_clear_api_histogram_command, static) = {
740 .path = "clear api histogram",
741 .short_help = "clear api histogram",
742 .function = vl_api_clear_histogram_command,
748 VLIB_REGISTER_NODE (memclnt_node,static) = {
749 .function = memclnt_process,
750 .type = VLIB_NODE_TYPE_PROCESS,
751 .name = "api-rx-from-ring",
752 .state = VLIB_NODE_STATE_DISABLED,
757 memclnt_queue_callback (vlib_main_t * vm)
759 static volatile int *cursizep;
761 if (PREDICT_FALSE (cursizep == 0))
763 api_main_t *am = &api_main;
764 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
765 unix_shared_memory_queue_t *q;
770 q = shmem_hdr->vl_input_queue;
773 cursizep = &q->cursize;
778 vm->queue_signal_pending = 1;
779 vm->api_queue_nonempty = 1;
780 vlib_process_signal_event (vm, memclnt_node.index,
781 /* event_type */ 0, /* event_data */ 0);
786 vl_enable_disable_memory_api (vlib_main_t * vm, int enable)
788 vlib_node_set_state (vm, memclnt_node.index,
790 ? VLIB_NODE_STATE_POLLING
791 : VLIB_NODE_STATE_DISABLED));
795 api_rx_from_node (vlib_main_t * vm,
796 vlib_node_runtime_t * node, vlib_frame_t * frame)
798 uword n_packets = frame->n_vectors;
803 vec_validate (long_msg, 4095);
804 n_left_from = frame->n_vectors;
805 from = vlib_frame_args (frame);
807 while (n_left_from > 0)
815 b0 = vlib_get_buffer (vm, bi0);
819 msg = b0->data + b0->current_data;
820 msg_len = b0->current_length;
821 if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
823 ASSERT (long_msg != 0);
824 _vec_len (long_msg) = 0;
825 vec_add (long_msg, msg, msg_len);
826 while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
828 b0 = vlib_get_buffer (vm, b0->next_buffer);
829 msg = b0->data + b0->current_data;
830 msg_len = b0->current_length;
831 vec_add (long_msg, msg, msg_len);
835 vl_msg_api_handler_no_trace_no_free (msg);
838 /* Free what we've been given. */
839 vlib_buffer_free (vm, vlib_frame_args (frame), n_packets);
845 VLIB_REGISTER_NODE (api_rx_from_node_node,static) = {
846 .function = api_rx_from_node,
847 .type = VLIB_NODE_TYPE_INTERNAL,
849 .name = "api-rx-from-node",
853 static clib_error_t *
854 setup_memclnt_exit (vlib_main_t * vm)
856 atexit (vl_unmap_shmem);
860 VLIB_INIT_FUNCTION (setup_memclnt_exit);
863 static clib_error_t *
864 vl_api_ring_command (vlib_main_t * vm,
865 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
869 vl_shmem_hdr_t *shmem_hdr;
870 api_main_t *am = &api_main;
872 shmem_hdr = am->shmem_hdr;
876 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
880 vlib_cli_output (vm, "%8s %8s %8s %8s %8s\n",
881 "Owner", "Size", "Nitems", "Hits", "Misses");
883 ap = shmem_hdr->vl_rings;
885 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
887 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
888 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
892 ap = shmem_hdr->client_rings;
894 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
896 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
897 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
901 vlib_cli_output (vm, "%d ring miss fallback allocations\n",
905 (vm, "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
906 shmem_hdr->application_restarts,
907 shmem_hdr->restart_reclaims, shmem_hdr->garbage_collects);
911 void dump_socket_clients (vlib_main_t * vm, api_main_t * am)
912 __attribute__ ((weak));
915 dump_socket_clients (vlib_main_t * vm, api_main_t * am)
919 static clib_error_t *
920 vl_api_client_command (vlib_main_t * vm,
921 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
923 vl_api_registration_t **regpp, *regp;
924 unix_shared_memory_queue_t *q;
926 api_main_t *am = &api_main;
927 u32 *confused_indices = 0;
929 if (!pool_elts (am->vl_clients))
931 vlib_cli_output (vm, "Shared memory clients");
932 vlib_cli_output (vm, "%16s %8s %14s %18s %s",
933 "Name", "PID", "Queue Length", "Queue VA", "Health");
936 pool_foreach (regpp, am->vl_clients,
942 q = regp->vl_input_queue;
943 if (kill (q->consumer_pid, 0) < 0)
951 vlib_cli_output (vm, "%16s %8d %14d 0x%016llx %s\n",
952 regp->name, q->consumer_pid, q->cursize,
957 clib_warning ("NULL client registration index %d",
958 regpp - am->vl_clients);
959 vec_add1 (confused_indices, regpp - am->vl_clients);
964 /* This should "never happen," but if it does, fix it... */
965 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
968 for (i = 0; i < vec_len (confused_indices); i++)
970 pool_put_index (am->vl_clients, confused_indices[i]);
973 vec_free (confused_indices);
975 if (am->missing_clients)
976 vlib_cli_output (vm, "%u messages with missing clients",
977 am->missing_clients);
979 dump_socket_clients (vm, am);
984 static clib_error_t *
985 vl_api_status_command (vlib_main_t * vm,
986 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
988 api_main_t *am = &api_main;
990 // check if rx_trace and tx_trace are not null pointers
992 if (am->rx_trace == 0)
994 vlib_cli_output (vm, "RX Trace disabled\n");
998 if (am->rx_trace->enabled == 0)
999 vlib_cli_output (vm, "RX Trace disabled\n");
1001 vlib_cli_output (vm, "RX Trace enabled\n");
1004 if (am->tx_trace == 0)
1006 vlib_cli_output (vm, "TX Trace disabled\n");
1010 if (am->tx_trace->enabled == 0)
1011 vlib_cli_output (vm, "TX Trace disabled\n");
1013 vlib_cli_output (vm, "TX Trace enabled\n");
1020 VLIB_CLI_COMMAND (cli_show_api_command, static) = {
1022 .short_help = "Show API information",
1027 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) = {
1028 .path = "show api ring-stats",
1029 .short_help = "Message ring statistics",
1030 .function = vl_api_ring_command,
1035 VLIB_CLI_COMMAND (cli_show_api_clients_command, static) = {
1036 .path = "show api clients",
1037 .short_help = "Client information",
1038 .function = vl_api_client_command,
1043 VLIB_CLI_COMMAND (cli_show_api_status_command, static) = {
1044 .path = "show api status",
1045 .short_help = "Show API trace status",
1046 .function = vl_api_status_command,
1050 static clib_error_t *
1051 vl_api_message_table_command (vlib_main_t * vm,
1052 unformat_input_t * input,
1053 vlib_cli_command_t * cli_cmd)
1055 api_main_t *am = &api_main;
1059 if (unformat (input, "verbose"))
1064 vlib_cli_output (vm, "%-4s %s", "ID", "Name");
1066 vlib_cli_output (vm, "%-4s %-40s %6s %7s", "ID", "Name", "Bounce",
1069 for (i = 1; i < vec_len (am->msg_names); i++)
1073 vlib_cli_output (vm, "%-4d %s", i,
1074 am->msg_names[i] ? am->msg_names[i] :
1079 vlib_cli_output (vm, "%-4d %-40s %6d %7d", i,
1080 am->msg_names[i] ? am->msg_names[i] :
1081 " [no handler]", am->message_bounce[i],
1090 VLIB_CLI_COMMAND (cli_show_api_message_table_command, static) = {
1091 .path = "show api message-table",
1092 .short_help = "Message Table",
1093 .function = vl_api_message_table_command,
1097 static clib_error_t *
1098 vl_api_trace_command (vlib_main_t * vm,
1099 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
1102 vl_api_trace_which_t which = VL_API_TRACE_RX;
1103 api_main_t *am = &api_main;
1105 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1107 if (unformat (input, "rx nitems %u", &nitems) || unformat (input, "rx"))
1109 else if (unformat (input, "tx nitems %u", &nitems)
1110 || unformat (input, "tx"))
1112 which = VL_API_TRACE_RX;
1115 else if (unformat (input, "on rx"))
1117 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1119 else if (unformat (input, "on tx"))
1121 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 1);
1123 else if (unformat (input, "on"))
1125 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1127 else if (unformat (input, "off"))
1129 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1130 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1132 else if (unformat (input, "free"))
1134 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1135 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1136 vl_msg_api_trace_free (am, VL_API_TRACE_RX);
1137 vl_msg_api_trace_free (am, VL_API_TRACE_TX);
1139 else if (unformat (input, "debug on"))
1141 am->msg_print_flag = 1;
1143 else if (unformat (input, "debug off"))
1145 am->msg_print_flag = 0;
1148 return clib_error_return (0, "unknown input `%U'",
1149 format_unformat_error, input);
1154 if (vl_msg_api_trace_configure (am, which, nitems))
1156 vlib_cli_output (vm, "warning: trace configure error (%d, %d)",
1164 VLIB_CLI_COMMAND (trace, static) = {
1165 .path = "set api-trace",
1166 .short_help = "API trace",
1167 .function = vl_api_trace_command,
1172 vlibmemory_init (vlib_main_t * vm)
1174 api_main_t *am = &api_main;
1175 svm_map_region_args_t _a, *a = &_a;
1177 memset (a, 0, sizeof (*a));
1178 a->root_path = am->root_path;
1179 a->name = SVM_GLOBAL_REGION_NAME;
1180 a->baseva = (am->global_baseva != 0) ?
1181 am->global_baseva : SVM_GLOBAL_REGION_BASEVA;
1182 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
1183 a->flags = SVM_FLAGS_NODATA;
1184 a->uid = am->api_uid;
1185 a->gid = am->api_gid;
1187 (am->global_pvt_heap_size !=
1188 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
1190 svm_region_init_args (a);
1194 VLIB_INIT_FUNCTION (vlibmemory_init);
1197 vl_set_memory_region_name (char *name)
1199 api_main_t *am = &api_main;
1201 am->region_name = name;
1205 range_compare (vl_api_msg_range_t * a0, vl_api_msg_range_t * a1)
1207 int len0, len1, clen;
1209 len0 = vec_len (a0->name);
1210 len1 = vec_len (a1->name);
1211 clen = len0 < len1 ? len0 : len1;
1212 return (strncmp ((char *) a0->name, (char *) a1->name, clen));
1216 format_api_msg_range (u8 * s, va_list * args)
1218 vl_api_msg_range_t *rp = va_arg (*args, vl_api_msg_range_t *);
1221 s = format (s, "%-20s%9s%9s", "Name", "First-ID", "Last-ID");
1223 s = format (s, "%-20s%9d%9d", rp->name, rp->first_msg_id,
1229 static clib_error_t *
1230 vl_api_show_plugin_command (vlib_main_t * vm,
1231 unformat_input_t * input,
1232 vlib_cli_command_t * cli_cmd)
1234 api_main_t *am = &api_main;
1235 vl_api_msg_range_t *rp = 0;
1238 if (vec_len (am->msg_ranges) == 0)
1240 vlib_cli_output (vm, "No plugin API message ranges configured...");
1244 rp = vec_dup (am->msg_ranges);
1246 vec_sort_with_function (rp, range_compare);
1248 vlib_cli_output (vm, "Plugin API message ID ranges...\n");
1249 vlib_cli_output (vm, "%U", format_api_msg_range, 0 /* header */ );
1251 for (i = 0; i < vec_len (rp); i++)
1252 vlib_cli_output (vm, "%U", format_api_msg_range, rp + i);
1260 VLIB_CLI_COMMAND (cli_show_api_plugin_command, static) = {
1261 .path = "show api plugin",
1262 .short_help = "show api plugin",
1263 .function = vl_api_show_plugin_command,
1268 vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
1270 vl_api_rpc_reply_t *rmp;
1273 vlib_main_t *vm = vlib_get_main ();
1275 if (mp->function == 0)
1278 clib_warning ("rpc NULL function pointer");
1283 if (mp->need_barrier_sync)
1284 vlib_worker_thread_barrier_sync (vm);
1286 fp = uword_to_pointer (mp->function, int (*)(void *));
1289 if (mp->need_barrier_sync)
1290 vlib_worker_thread_barrier_release (vm);
1295 unix_shared_memory_queue_t *q =
1296 vl_api_client_index_to_input_queue (mp->client_index);
1299 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
1300 rmp->_vl_msg_id = ntohs (VL_API_RPC_REPLY);
1301 rmp->context = mp->context;
1303 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1308 clib_warning ("multicast not yet implemented...");
1313 vl_api_rpc_reply_t_handler (vl_api_rpc_reply_t * mp)
1315 clib_warning ("unimplemented");
1319 vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
1321 vl_api_rpc_call_t *mp;
1322 api_main_t *am = &api_main;
1323 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
1324 unix_shared_memory_queue_t *q;
1326 /* Main thread: call the function directly */
1327 if (os_get_cpu_number () == 0)
1329 vlib_main_t *vm = vlib_get_main ();
1330 void (*call_fp) (void *);
1332 vlib_worker_thread_barrier_sync (vm);
1337 vlib_worker_thread_barrier_release (vm);
1341 /* Any other thread, actually do an RPC call... */
1342 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
1344 memset (mp, 0, sizeof (*mp));
1345 clib_memcpy (mp->data, data, data_length);
1346 mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
1347 mp->function = pointer_to_uword (fp);
1348 mp->need_barrier_sync = 1;
1351 * Use the "normal" control-plane mechanism for the main thread.
1352 * Well, almost. if the main input queue is full, we cannot
1353 * block. Otherwise, we can expect a barrier sync timeout.
1355 q = shmem_hdr->vl_input_queue;
1357 while (pthread_mutex_trylock (&q->mutex))
1358 vlib_worker_thread_barrier_check ();
1360 while (PREDICT_FALSE (unix_shared_memory_queue_is_full (q)))
1362 pthread_mutex_unlock (&q->mutex);
1363 vlib_worker_thread_barrier_check ();
1364 while (pthread_mutex_trylock (&q->mutex))
1365 vlib_worker_thread_barrier_check ();
1368 vl_msg_api_send_shmem_nolock (q, (u8 *) & mp);
1370 pthread_mutex_unlock (&q->mutex);
1374 vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
1376 api_main_t *am = &api_main;
1377 vl_api_msg_range_t *rp;
1380 /* Noop (except for tracing) during normal operation */
1381 if (am->replay_in_progress == 0)
1384 p = hash_get_mem (am->msg_range_by_name, mp->plugin_name);
1387 clib_warning ("WARNING: traced plugin '%s' not in current image",
1392 rp = vec_elt_at_index (am->msg_ranges, p[0]);
1393 if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
1395 clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
1396 mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
1400 if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
1402 clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
1403 mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
1408 #define foreach_rpc_api_msg \
1409 _(RPC_CALL,rpc_call) \
1410 _(RPC_REPLY,rpc_reply)
1412 #define foreach_plugin_trace_msg \
1413 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
1415 static clib_error_t *
1416 rpc_api_hookup (vlib_main_t * vm)
1419 vl_msg_api_set_handlers(VL_API_##N, #n, \
1420 vl_api_##n##_t_handler, \
1423 vl_api_##n##_t_print, \
1424 sizeof(vl_api_##n##_t), 0 /* do not trace */);
1425 foreach_rpc_api_msg;
1429 vl_msg_api_set_handlers(VL_API_##N, #n, \
1430 vl_api_##n##_t_handler, \
1433 vl_api_##n##_t_print, \
1434 sizeof(vl_api_##n##_t), 1 /* do trace */);
1435 foreach_plugin_trace_msg;
1440 VLIB_API_INIT_FUNCTION (rpc_api_hookup);
1451 format_vl_msg_api_trace_status (u8 * s, va_list * args)
1453 api_main_t *am = va_arg (*args, api_main_t *);
1454 vl_api_trace_which_t which = va_arg (*args, vl_api_trace_which_t);
1460 case VL_API_TRACE_TX:
1462 trace_name = "TX trace";
1465 case VL_API_TRACE_RX:
1467 trace_name = "RX trace";
1476 s = format (s, "%s: not yet configured.\n", trace_name);
1480 s = format (s, "%s: used %d of %d items, %s enabled, %s wrapped\n",
1481 trace_name, vec_len (tp->traces), tp->nitems,
1482 tp->enabled ? "is" : "is not", tp->wrapped ? "has" : "has not");
1486 void vl_msg_api_custom_dump_configure (api_main_t * am)
1487 __attribute__ ((weak));
1489 vl_msg_api_custom_dump_configure (api_main_t * am)
1494 vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
1495 u32 first_index, u32 last_index,
1496 vl_api_replay_t which)
1498 vl_api_trace_file_header_t *hp;
1503 u8 endian_swap_needed = 0;
1504 api_main_t *am = &api_main;
1507 void **saved_print_handlers = 0;
1509 fd = open ((char *) filename, O_RDONLY);
1513 vlib_cli_output (vm, "Couldn't open %s\n", filename);
1517 if (fstat (fd, &statb) < 0)
1519 vlib_cli_output (vm, "Couldn't stat %s\n", filename);
1524 if (!(statb.st_mode & S_IFREG) || (statb.st_size < sizeof (*hp)))
1526 vlib_cli_output (vm, "File not plausible: %s\n", filename);
1531 file_size = statb.st_size;
1532 file_size = (file_size + 4095) & ~(4096);
1534 hp = mmap (0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
1536 if (hp == (vl_api_trace_file_header_t *) MAP_FAILED)
1538 vlib_cli_output (vm, "mmap failed: %s\n", filename);
1544 if ((clib_arch_is_little_endian && hp->endian == VL_API_BIG_ENDIAN)
1545 || (clib_arch_is_big_endian && hp->endian == VL_API_LITTLE_ENDIAN))
1546 endian_swap_needed = 1;
1548 if (endian_swap_needed)
1549 nitems = ntohl (hp->nitems);
1551 nitems = hp->nitems;
1553 if (last_index == (u32) ~ 0)
1555 last_index = nitems - 1;
1558 if (first_index >= nitems || last_index >= nitems)
1560 vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
1561 first_index, last_index, nitems - 1);
1562 munmap (hp, file_size);
1566 vlib_cli_output (vm,
1567 "Note: wrapped/incomplete trace, results may vary\n");
1569 if (which == CUSTOM_DUMP)
1571 saved_print_handlers = (void **) vec_dup (am->msg_print_handlers);
1572 vl_msg_api_custom_dump_configure (am);
1576 msg = (u8 *) (hp + 1);
1578 for (i = 0; i < first_index; i++)
1584 size = clib_host_to_net_u32 (*(u32 *) msg);
1585 msg += sizeof (u32);
1587 if (clib_arch_is_little_endian)
1588 msg_id = ntohs (*((u16 *) msg));
1590 msg_id = *((u16 *) msg);
1592 cfgp = am->api_trace_cfg + msg_id;
1595 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1596 munmap (hp, file_size);
1602 if (which == REPLAY)
1603 am->replay_in_progress = 1;
1605 for (; i <= last_index; i++)
1613 vlib_cli_output (vm, "---------- trace %d -----------\n", i);
1615 size = clib_host_to_net_u32 (*(u32 *) msg);
1616 msg += sizeof (u32);
1618 if (clib_arch_is_little_endian)
1619 msg_id = ntohs (*((u16 *) msg));
1621 msg_id = *((u16 *) msg);
1623 cfgp = am->api_trace_cfg + msg_id;
1626 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1627 munmap (hp, file_size);
1629 am->replay_in_progress = 0;
1633 /* Copy the buffer (from the read-only mmap'ed file) */
1634 vec_validate (tmpbuf, size - 1 + sizeof (uword));
1635 clib_memcpy (tmpbuf + sizeof (uword), msg, size);
1636 memset (tmpbuf, 0xf, sizeof (uword));
1639 * Endian swap if needed. All msg data is supposed to be
1640 * in network byte order. All msg handlers are supposed to
1641 * know that. The generic message dumpers don't know that.
1642 * One could fix apigen, I suppose.
1644 if ((which == DUMP && clib_arch_is_little_endian) || endian_swap_needed)
1646 void (*endian_fp) (void *);
1647 if (msg_id >= vec_len (am->msg_endian_handlers)
1648 || (am->msg_endian_handlers[msg_id] == 0))
1650 vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
1651 munmap (hp, file_size);
1653 am->replay_in_progress = 0;
1656 endian_fp = am->msg_endian_handlers[msg_id];
1657 (*endian_fp) (tmpbuf + sizeof (uword));
1660 /* msg_id always in network byte order */
1661 if (clib_arch_is_little_endian)
1663 msg_idp = (u16 *) (tmpbuf + sizeof (uword));
1671 if (msg_id < vec_len (am->msg_print_handlers) &&
1672 am->msg_print_handlers[msg_id])
1674 u8 *(*print_fp) (void *, void *);
1676 print_fp = (void *) am->msg_print_handlers[msg_id];
1677 (*print_fp) (tmpbuf + sizeof (uword), vm);
1681 vlib_cli_output (vm, "Skipping msg id %d: no print fcn\n",
1688 if (msg_id < vec_len (am->msg_print_handlers) &&
1689 am->msg_print_handlers[msg_id])
1693 u8 *(*print_fp) (void *, void *);
1695 print_fp = (void *) am->msg_print_handlers[msg_id];
1697 vlib_cli_output (vm, "/*");
1699 (*print_fp) (tmpbuf + sizeof (uword), vm);
1700 vlib_cli_output (vm, "*/\n");
1702 s = format (0, "static u8 * vl_api_%s_%d[%d] = {",
1703 am->msg_names[msg_id], i,
1704 am->api_trace_cfg[msg_id].size);
1706 for (j = 0; j < am->api_trace_cfg[msg_id].size; j++)
1709 s = format (s, "\n ");
1710 s = format (s, "0x%02x,", tmpbuf[sizeof (uword) + j]);
1712 s = format (s, "\n};\n%c", 0);
1713 vlib_cli_output (vm, (char *) s);
1719 if (msg_id < vec_len (am->msg_print_handlers) &&
1720 am->msg_print_handlers[msg_id] && cfgp->replay_enable)
1722 void (*handler) (void *);
1724 handler = (void *) am->msg_handlers[msg_id];
1726 if (!am->is_mp_safe[msg_id])
1727 vl_msg_api_barrier_sync ();
1728 (*handler) (tmpbuf + sizeof (uword));
1729 if (!am->is_mp_safe[msg_id])
1730 vl_msg_api_barrier_release ();
1734 if (cfgp->replay_enable)
1735 vlib_cli_output (vm, "Skipping msg id %d: no handler\n",
1742 _vec_len (tmpbuf) = 0;
1746 if (saved_print_handlers)
1748 clib_memcpy (am->msg_print_handlers, saved_print_handlers,
1749 vec_len (am->msg_print_handlers) * sizeof (void *));
1750 vec_free (saved_print_handlers);
1753 munmap (hp, file_size);
1755 am->replay_in_progress = 0;
1758 static clib_error_t *
1759 api_trace_command_fn (vlib_main_t * vm,
1760 unformat_input_t * input, vlib_cli_command_t * cmd)
1762 u32 nitems = 256 << 10;
1763 api_main_t *am = &api_main;
1764 vl_api_trace_which_t which = VL_API_TRACE_RX;
1767 u32 last = (u32) ~ 0;
1771 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1773 if (unformat (input, "on") || unformat (input, "enable"))
1775 if (unformat (input, "nitems %d", &nitems))
1777 vl_msg_api_trace_configure (am, which, nitems);
1778 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1780 else if (unformat (input, "off"))
1782 vl_msg_api_trace_onoff (am, which, 0);
1784 else if (unformat (input, "save %s", &filename))
1786 u8 *chroot_filename;
1787 if (strstr ((char *) filename, "..")
1788 || index ((char *) filename, '/'))
1790 vlib_cli_output (vm, "illegal characters in filename '%s'",
1795 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1797 vec_free (filename);
1799 fp = fopen ((char *) chroot_filename, "w");
1802 vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
1805 rv = vl_msg_api_trace_save (am, which, fp);
1808 vlib_cli_output (vm, "API Trace data not present\n");
1810 vlib_cli_output (vm, "File for writing is closed\n");
1812 vlib_cli_output (vm, "Error while writing header to file\n");
1814 vlib_cli_output (vm, "Error while writing trace to file\n");
1816 vlib_cli_output (vm,
1817 "Error while writing end of buffer trace to file\n");
1819 vlib_cli_output (vm,
1820 "Error while writing start of buffer trace to file\n");
1822 vlib_cli_output (vm, "Unkown error while saving: %d", rv);
1824 vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
1825 vec_free (chroot_filename);
1827 else if (unformat (input, "dump %s", &filename))
1829 vl_msg_api_process_file (vm, filename, first, last, DUMP);
1831 else if (unformat (input, "custom-dump %s", &filename))
1833 vl_msg_api_process_file (vm, filename, first, last, CUSTOM_DUMP);
1835 else if (unformat (input, "replay %s", &filename))
1837 vl_msg_api_process_file (vm, filename, first, last, REPLAY);
1839 else if (unformat (input, "initializers %s", &filename))
1841 vl_msg_api_process_file (vm, filename, first, last, INITIALIZERS);
1843 else if (unformat (input, "tx"))
1845 which = VL_API_TRACE_TX;
1847 else if (unformat (input, "first %d", &first))
1851 else if (unformat (input, "last %d", &last))
1855 else if (unformat (input, "status"))
1857 vlib_cli_output (vm, "%U", format_vl_msg_api_trace_status,
1860 else if (unformat (input, "free"))
1862 vl_msg_api_trace_onoff (am, which, 0);
1863 vl_msg_api_trace_free (am, which);
1865 else if (unformat (input, "post-mortem-on"))
1866 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1867 else if (unformat (input, "post-mortem-off"))
1868 vl_msg_api_post_mortem_dump_enable_disable (0 /* enable */ );
1870 return clib_error_return (0, "unknown input `%U'",
1871 format_unformat_error, input);
1877 VLIB_CLI_COMMAND (api_trace_command, static) = {
1878 .path = "api trace",
1880 "api trace [on|off][dump|save|replay <file>][status][free][post-mortem-on]",
1881 .function = api_trace_command_fn,
1885 static clib_error_t *
1886 api_config_fn (vlib_main_t * vm, unformat_input_t * input)
1888 u32 nitems = 256 << 10;
1889 vl_api_trace_which_t which = VL_API_TRACE_RX;
1890 api_main_t *am = &api_main;
1892 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1894 if (unformat (input, "on") || unformat (input, "enable"))
1896 if (unformat (input, "nitems %d", &nitems))
1898 vl_msg_api_trace_configure (am, which, nitems);
1899 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1900 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1903 return clib_error_return (0, "unknown input `%U'",
1904 format_unformat_error, input);
1909 VLIB_CONFIG_FUNCTION (api_config_fn, "api-trace");
1912 * fd.io coding-style-patch-verification: ON
1915 * eval: (c-set-style "gnu")