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);
225 call_reaper_functions (u32 client_index)
227 clib_error_t *error = 0;
228 _vl_msg_api_function_list_elt_t *i;
230 i = api_main.reaper_function_registrations;
233 error = i->f (client_index);
235 clib_error_report (error);
236 i = i->next_init_function;
242 * vl_api_memclnt_delete_t_handler
245 vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
247 vl_api_registration_t **regpp;
248 vl_api_registration_t *regp;
249 vl_api_memclnt_delete_reply_t *rp;
252 api_main_t *am = &api_main;
253 u32 handle, client_index, epoch;
257 if (call_reaper_functions (handle))
260 epoch = vl_msg_api_handle_get_epoch (handle);
261 client_index = vl_msg_api_handle_get_index (handle);
263 if (epoch != (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK))
266 ("Stale clnt delete index %d old epoch %d cur epoch %d",
268 (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK));
272 regpp = am->vl_clients + client_index;
274 if (!pool_is_free (am->vl_clients, regpp))
279 /* $$$ check the input queue for e.g. punted sf's */
281 rp = vl_msg_api_alloc (sizeof (*rp));
282 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
283 rp->handle = mp->handle;
286 vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
288 if (client_index != regp->vl_api_registration_pool_index)
290 clib_warning ("mismatch client_index %d pool_index %d",
291 client_index, regp->vl_api_registration_pool_index);
292 vl_msg_api_free (rp);
296 /* No dangling references, please */
299 pool_put_index (am->vl_clients, regp->vl_api_registration_pool_index);
301 pthread_mutex_lock (&svm->mutex);
302 oldheap = svm_push_data_heap (svm);
303 /* Poison the old registration */
304 memset (regp, 0xF1, sizeof (*regp));
305 clib_mem_free (regp);
306 pthread_mutex_unlock (&svm->mutex);
307 svm_pop_heap (oldheap);
311 clib_warning ("unknown client ID %d", mp->index);
316 vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
318 vl_api_get_first_msg_id_reply_t *rmp;
319 unix_shared_memory_queue_t *q;
321 api_main_t *am = &api_main;
322 vl_api_msg_range_t *rp;
324 u16 first_msg_id = ~0;
325 int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
327 q = vl_api_client_index_to_input_queue (mp->client_index);
331 if (am->msg_range_by_name == 0)
334 strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name) - 1);
336 p = hash_get_mem (am->msg_range_by_name, name);
340 rp = vec_elt_at_index (am->msg_ranges, p[0]);
342 first_msg_id = rp->first_msg_id;
347 rmp = vl_msg_api_alloc (sizeof (*rmp));
348 rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
349 rmp->context = mp->context;
350 rmp->retval = ntohl (rv);
351 rmp->first_msg_id = ntohs (first_msg_id);
352 vl_msg_api_send_shmem (q, (u8 *) & rmp);
355 #define foreach_vlib_api_msg \
356 _(MEMCLNT_CREATE, memclnt_create) \
357 _(MEMCLNT_DELETE, memclnt_delete) \
358 _(GET_FIRST_MSG_ID, get_first_msg_id)
364 memory_api_init (const char *region_name)
367 vl_msg_api_msg_config_t cfg;
368 vl_msg_api_msg_config_t *c = &cfg;
370 memset (c, 0, sizeof (*c));
372 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
375 #define _(N,n) do { \
376 c->id = VL_API_##N; \
378 c->handler = vl_api_##n##_t_handler; \
379 c->cleanup = vl_noop_handler; \
380 c->endian = vl_api_##n##_t_endian; \
381 c->print = vl_api_##n##_t_print; \
382 c->size = sizeof(vl_api_##n##_t); \
383 c->traced = 1; /* trace, so these msgs print */ \
384 c->replay = 0; /* don't replay client create/delete msgs */ \
385 c->message_bounce = 0; /* don't bounce this message */ \
386 vl_msg_api_config(c);} while (0);
388 foreach_vlib_api_msg;
394 #define foreach_histogram_bucket \
402 #define _(n) SLEEP_##n##_US,
403 foreach_histogram_bucket
408 static u64 vector_rate_histogram[SLEEP_N_BUCKETS];
410 static void memclnt_queue_callback (vlib_main_t * vm);
413 * Callback to send ourselves a plugin numbering-space trace msg
416 send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
418 vl_api_trace_plugin_msg_ids_t *mp;
419 api_main_t *am = &api_main;
420 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
421 unix_shared_memory_queue_t *q;
423 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
424 memset (mp, 0, sizeof (*mp));
426 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
427 strncpy ((char *) mp->plugin_name, (char *) name,
428 sizeof (mp->plugin_name) - 1);
429 mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
430 mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
432 q = shmem_hdr->vl_input_queue;
434 vl_msg_api_send_shmem (q, (u8 *) & mp);
438 memclnt_process (vlib_main_t * vm,
439 vlib_node_runtime_t * node, vlib_frame_t * f)
443 unix_shared_memory_queue_t *q;
446 api_main_t *am = &api_main;
447 f64 dead_client_scan_time;
448 f64 sleep_time, start_time;
452 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
454 if ((rv = memory_api_init (am->region_name)) < 0)
456 clib_warning ("memory_api_init returned %d, wait for godot...", rv);
457 vlib_process_suspend (vm, 1e70);
462 q = shm->vl_input_queue;
465 e = vlib_call_init_exit_functions
466 (vm, vm->api_init_function_registrations, 1 /* call_once */ );
468 clib_error_report (e);
471 dead_client_scan_time = vlib_time_now (vm) + 20.0;
474 * Send plugin message range messages for each plugin we loaded
476 for (i = 0; i < vec_len (am->msg_ranges); i++)
478 vl_api_msg_range_t *rp = am->msg_ranges + i;
479 send_one_plugin_msg_ids_msg (rp->name, rp->first_msg_id,
483 /* $$$ pay attention to frame size, control CPU usage */
486 uword event_type __attribute__ ((unused));
491 * There's a reason for checking the queue before
492 * sleeping. If the vlib application crashes, it's entirely
493 * possible for a client to enqueue a connect request
494 * during the process restart interval.
496 * Unless some force of physics causes the new incarnation
497 * of the application to process the request, the client will
498 * sit and wait for Godot...
500 vector_rate = vlib_last_vector_length_per_node (vm);
501 start_time = vlib_time_now (vm);
504 pthread_mutex_lock (&q->mutex);
507 vm->api_queue_nonempty = 0;
508 pthread_mutex_unlock (&q->mutex);
510 if (TRACE_VLIB_MEMORY_QUEUE)
513 ELOG_TYPE_DECLARE (e) =
515 .format = "q-underflow: len %d",
523 ed = ELOG_DATA (&vm->elog_main, e);
530 headp = (i8 *) (q->data + sizeof (uword) * q->head);
531 clib_memcpy (&mp, headp, sizeof (uword));
534 need_broadcast = (q->cursize == q->maxsize / 2);
537 if (PREDICT_FALSE (q->head == q->maxsize))
539 pthread_mutex_unlock (&q->mutex);
541 (void) pthread_cond_broadcast (&q->condvar);
543 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
545 /* Allow no more than 10us without a pause */
546 if (vlib_time_now (vm) > start_time + 10e-6)
548 int index = SLEEP_400_US;
549 if (vector_rate > 40.0)
551 else if (vector_rate > 20.0)
553 index = SLEEP_200_US;
556 else if (vector_rate >= 1.0)
558 index = SLEEP_100_US;
566 vector_rate_histogram[index] += 1;
571 event_type = vlib_process_wait_for_event_or_clock (vm, sleep_time);
572 vm->queue_signal_pending = 0;
573 vlib_process_get_events (vm, 0 /* event_data */ );
575 if (vlib_time_now (vm) > dead_client_scan_time)
577 vl_api_registration_t **regpp;
578 vl_api_registration_t *regp;
579 unix_shared_memory_queue_t *q;
580 static u32 *dead_indices;
581 static u32 *confused_indices;
583 vec_reset_length (dead_indices);
584 vec_reset_length (confused_indices);
587 pool_foreach (regpp, am->vl_clients,
592 q = regp->vl_input_queue;
593 if (kill (q->consumer_pid, 0) < 0)
595 vec_add1(dead_indices, regpp - am->vl_clients);
600 clib_warning ("NULL client registration index %d",
601 regpp - am->vl_clients);
602 vec_add1 (confused_indices, regpp - am->vl_clients);
606 /* This should "never happen," but if it does, fix it... */
607 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
610 for (i = 0; i < vec_len (confused_indices); i++)
612 pool_put_index (am->vl_clients, confused_indices[i]);
616 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
622 /* Allow the application to clean up its registrations */
623 for (i = 0; i < vec_len (dead_indices); i++)
625 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
630 handle = vl_msg_api_handle_from_index_and_epoch
631 (dead_indices[i], shm->application_restarts);
632 (void) call_reaper_functions (handle);
637 pthread_mutex_lock (&svm->mutex);
638 oldheap = svm_push_data_heap (svm);
640 for (i = 0; i < vec_len (dead_indices); i++)
642 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
645 /* Poison the old registration */
646 memset (*regpp, 0xF3, sizeof (**regpp));
647 clib_mem_free (*regpp);
648 /* no dangling references, please */
653 svm_pop_heap (oldheap);
654 clib_warning ("Duplicate free, client index %d",
655 regpp - am->vl_clients);
656 oldheap = svm_push_data_heap (svm);
660 svm_client_scan_this_region_nolock (am->vlib_rp);
662 pthread_mutex_unlock (&svm->mutex);
663 svm_pop_heap (oldheap);
664 for (i = 0; i < vec_len (dead_indices); i++)
665 pool_put_index (am->vl_clients, dead_indices[i]);
668 dead_client_scan_time = vlib_time_now (vm) + 20.0;
671 if (TRACE_VLIB_MEMORY_QUEUE)
674 ELOG_TYPE_DECLARE (e) = {
675 .format = "q-awake: len %d",
683 ed = ELOG_DATA (&vm->elog_main, e);
684 ed->len = q->cursize;
691 static clib_error_t *
692 vl_api_show_histogram_command (vlib_main_t * vm,
693 unformat_input_t * input,
694 vlib_cli_command_t * cli_cmd)
696 u64 total_counts = 0;
699 for (i = 0; i < SLEEP_N_BUCKETS; i++)
701 total_counts += vector_rate_histogram[i];
704 if (total_counts == 0)
706 vlib_cli_output (vm, "No control-plane activity.");
713 percent = ((f64) vector_rate_histogram[SLEEP_##n##_US]) \
714 / (f64) total_counts; \
716 vlib_cli_output (vm, "Sleep %3d us: %llu, %.2f%%",n, \
717 vector_rate_histogram[SLEEP_##n##_US], \
720 foreach_histogram_bucket;
727 VLIB_CLI_COMMAND (cli_show_api_histogram_command, static) = {
728 .path = "show api histogram",
729 .short_help = "show api histogram",
730 .function = vl_api_show_histogram_command,
734 static clib_error_t *
735 vl_api_clear_histogram_command (vlib_main_t * vm,
736 unformat_input_t * input,
737 vlib_cli_command_t * cli_cmd)
741 for (i = 0; i < SLEEP_N_BUCKETS; i++)
742 vector_rate_histogram[i] = 0;
747 VLIB_CLI_COMMAND (cli_clear_api_histogram_command, static) = {
748 .path = "clear api histogram",
749 .short_help = "clear api histogram",
750 .function = vl_api_clear_histogram_command,
756 VLIB_REGISTER_NODE (memclnt_node,static) = {
757 .function = memclnt_process,
758 .type = VLIB_NODE_TYPE_PROCESS,
759 .name = "api-rx-from-ring",
760 .state = VLIB_NODE_STATE_DISABLED,
765 memclnt_queue_callback (vlib_main_t * vm)
767 static volatile int *cursizep;
769 if (PREDICT_FALSE (cursizep == 0))
771 api_main_t *am = &api_main;
772 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
773 unix_shared_memory_queue_t *q;
778 q = shmem_hdr->vl_input_queue;
781 cursizep = &q->cursize;
786 vm->queue_signal_pending = 1;
787 vm->api_queue_nonempty = 1;
788 vlib_process_signal_event (vm, memclnt_node.index,
789 /* event_type */ 0, /* event_data */ 0);
794 vl_enable_disable_memory_api (vlib_main_t * vm, int enable)
796 vlib_node_set_state (vm, memclnt_node.index,
798 ? VLIB_NODE_STATE_POLLING
799 : VLIB_NODE_STATE_DISABLED));
803 api_rx_from_node (vlib_main_t * vm,
804 vlib_node_runtime_t * node, vlib_frame_t * frame)
806 uword n_packets = frame->n_vectors;
811 vec_validate (long_msg, 4095);
812 n_left_from = frame->n_vectors;
813 from = vlib_frame_args (frame);
815 while (n_left_from > 0)
823 b0 = vlib_get_buffer (vm, bi0);
827 msg = b0->data + b0->current_data;
828 msg_len = b0->current_length;
829 if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
831 ASSERT (long_msg != 0);
832 _vec_len (long_msg) = 0;
833 vec_add (long_msg, msg, msg_len);
834 while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
836 b0 = vlib_get_buffer (vm, b0->next_buffer);
837 msg = b0->data + b0->current_data;
838 msg_len = b0->current_length;
839 vec_add (long_msg, msg, msg_len);
843 vl_msg_api_handler_no_trace_no_free (msg);
846 /* Free what we've been given. */
847 vlib_buffer_free (vm, vlib_frame_args (frame), n_packets);
853 VLIB_REGISTER_NODE (api_rx_from_node_node,static) = {
854 .function = api_rx_from_node,
855 .type = VLIB_NODE_TYPE_INTERNAL,
857 .name = "api-rx-from-node",
861 static clib_error_t *
862 setup_memclnt_exit (vlib_main_t * vm)
864 atexit (vl_unmap_shmem);
868 VLIB_INIT_FUNCTION (setup_memclnt_exit);
871 static clib_error_t *
872 vl_api_ring_command (vlib_main_t * vm,
873 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
877 vl_shmem_hdr_t *shmem_hdr;
878 api_main_t *am = &api_main;
880 shmem_hdr = am->shmem_hdr;
884 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
888 vlib_cli_output (vm, "%8s %8s %8s %8s %8s\n",
889 "Owner", "Size", "Nitems", "Hits", "Misses");
891 ap = shmem_hdr->vl_rings;
893 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
895 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
896 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
900 ap = shmem_hdr->client_rings;
902 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
904 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
905 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
909 vlib_cli_output (vm, "%d ring miss fallback allocations\n",
913 (vm, "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
914 shmem_hdr->application_restarts,
915 shmem_hdr->restart_reclaims, shmem_hdr->garbage_collects);
919 void dump_socket_clients (vlib_main_t * vm, api_main_t * am)
920 __attribute__ ((weak));
923 dump_socket_clients (vlib_main_t * vm, api_main_t * am)
927 static clib_error_t *
928 vl_api_client_command (vlib_main_t * vm,
929 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
931 vl_api_registration_t **regpp, *regp;
932 unix_shared_memory_queue_t *q;
934 api_main_t *am = &api_main;
935 u32 *confused_indices = 0;
937 if (!pool_elts (am->vl_clients))
939 vlib_cli_output (vm, "Shared memory clients");
940 vlib_cli_output (vm, "%16s %8s %14s %18s %s",
941 "Name", "PID", "Queue Length", "Queue VA", "Health");
944 pool_foreach (regpp, am->vl_clients,
950 q = regp->vl_input_queue;
951 if (kill (q->consumer_pid, 0) < 0)
959 vlib_cli_output (vm, "%16s %8d %14d 0x%016llx %s\n",
960 regp->name, q->consumer_pid, q->cursize,
965 clib_warning ("NULL client registration index %d",
966 regpp - am->vl_clients);
967 vec_add1 (confused_indices, regpp - am->vl_clients);
972 /* This should "never happen," but if it does, fix it... */
973 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
976 for (i = 0; i < vec_len (confused_indices); i++)
978 pool_put_index (am->vl_clients, confused_indices[i]);
981 vec_free (confused_indices);
983 if (am->missing_clients)
984 vlib_cli_output (vm, "%u messages with missing clients",
985 am->missing_clients);
987 dump_socket_clients (vm, am);
992 static clib_error_t *
993 vl_api_status_command (vlib_main_t * vm,
994 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
996 api_main_t *am = &api_main;
998 // check if rx_trace and tx_trace are not null pointers
1000 if (am->rx_trace == 0)
1002 vlib_cli_output (vm, "RX Trace disabled\n");
1006 if (am->rx_trace->enabled == 0)
1007 vlib_cli_output (vm, "RX Trace disabled\n");
1009 vlib_cli_output (vm, "RX Trace enabled\n");
1012 if (am->tx_trace == 0)
1014 vlib_cli_output (vm, "TX Trace disabled\n");
1018 if (am->tx_trace->enabled == 0)
1019 vlib_cli_output (vm, "TX Trace disabled\n");
1021 vlib_cli_output (vm, "TX Trace enabled\n");
1028 VLIB_CLI_COMMAND (cli_show_api_command, static) = {
1030 .short_help = "Show API information",
1035 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) = {
1036 .path = "show api ring-stats",
1037 .short_help = "Message ring statistics",
1038 .function = vl_api_ring_command,
1043 VLIB_CLI_COMMAND (cli_show_api_clients_command, static) = {
1044 .path = "show api clients",
1045 .short_help = "Client information",
1046 .function = vl_api_client_command,
1051 VLIB_CLI_COMMAND (cli_show_api_status_command, static) = {
1052 .path = "show api status",
1053 .short_help = "Show API trace status",
1054 .function = vl_api_status_command,
1058 static clib_error_t *
1059 vl_api_message_table_command (vlib_main_t * vm,
1060 unformat_input_t * input,
1061 vlib_cli_command_t * cli_cmd)
1063 api_main_t *am = &api_main;
1067 if (unformat (input, "verbose"))
1072 vlib_cli_output (vm, "%-4s %s", "ID", "Name");
1074 vlib_cli_output (vm, "%-4s %-40s %6s %7s", "ID", "Name", "Bounce",
1077 for (i = 1; i < vec_len (am->msg_names); i++)
1081 vlib_cli_output (vm, "%-4d %s", i,
1082 am->msg_names[i] ? am->msg_names[i] :
1087 vlib_cli_output (vm, "%-4d %-40s %6d %7d", i,
1088 am->msg_names[i] ? am->msg_names[i] :
1089 " [no handler]", am->message_bounce[i],
1098 VLIB_CLI_COMMAND (cli_show_api_message_table_command, static) = {
1099 .path = "show api message-table",
1100 .short_help = "Message Table",
1101 .function = vl_api_message_table_command,
1105 static clib_error_t *
1106 vl_api_trace_command (vlib_main_t * vm,
1107 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
1110 vl_api_trace_which_t which = VL_API_TRACE_RX;
1111 api_main_t *am = &api_main;
1113 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1115 if (unformat (input, "rx nitems %u", &nitems) || unformat (input, "rx"))
1117 else if (unformat (input, "tx nitems %u", &nitems)
1118 || unformat (input, "tx"))
1120 which = VL_API_TRACE_RX;
1123 else if (unformat (input, "on rx"))
1125 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1127 else if (unformat (input, "on tx"))
1129 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 1);
1131 else if (unformat (input, "on"))
1133 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1135 else if (unformat (input, "off"))
1137 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1138 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1140 else if (unformat (input, "free"))
1142 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1143 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1144 vl_msg_api_trace_free (am, VL_API_TRACE_RX);
1145 vl_msg_api_trace_free (am, VL_API_TRACE_TX);
1147 else if (unformat (input, "debug on"))
1149 am->msg_print_flag = 1;
1151 else if (unformat (input, "debug off"))
1153 am->msg_print_flag = 0;
1156 return clib_error_return (0, "unknown input `%U'",
1157 format_unformat_error, input);
1162 if (vl_msg_api_trace_configure (am, which, nitems))
1164 vlib_cli_output (vm, "warning: trace configure error (%d, %d)",
1172 VLIB_CLI_COMMAND (trace, static) = {
1173 .path = "set api-trace",
1174 .short_help = "API trace",
1175 .function = vl_api_trace_command,
1180 vlibmemory_init (vlib_main_t * vm)
1182 api_main_t *am = &api_main;
1183 svm_map_region_args_t _a, *a = &_a;
1185 memset (a, 0, sizeof (*a));
1186 a->root_path = am->root_path;
1187 a->name = SVM_GLOBAL_REGION_NAME;
1188 a->baseva = (am->global_baseva != 0) ?
1189 am->global_baseva : SVM_GLOBAL_REGION_BASEVA;
1190 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
1191 a->flags = SVM_FLAGS_NODATA;
1192 a->uid = am->api_uid;
1193 a->gid = am->api_gid;
1195 (am->global_pvt_heap_size !=
1196 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
1198 svm_region_init_args (a);
1202 VLIB_INIT_FUNCTION (vlibmemory_init);
1205 vl_set_memory_region_name (const char *name)
1207 api_main_t *am = &api_main;
1209 am->region_name = name;
1213 range_compare (vl_api_msg_range_t * a0, vl_api_msg_range_t * a1)
1215 int len0, len1, clen;
1217 len0 = vec_len (a0->name);
1218 len1 = vec_len (a1->name);
1219 clen = len0 < len1 ? len0 : len1;
1220 return (strncmp ((char *) a0->name, (char *) a1->name, clen));
1224 format_api_msg_range (u8 * s, va_list * args)
1226 vl_api_msg_range_t *rp = va_arg (*args, vl_api_msg_range_t *);
1229 s = format (s, "%-20s%9s%9s", "Name", "First-ID", "Last-ID");
1231 s = format (s, "%-20s%9d%9d", rp->name, rp->first_msg_id,
1237 static clib_error_t *
1238 vl_api_show_plugin_command (vlib_main_t * vm,
1239 unformat_input_t * input,
1240 vlib_cli_command_t * cli_cmd)
1242 api_main_t *am = &api_main;
1243 vl_api_msg_range_t *rp = 0;
1246 if (vec_len (am->msg_ranges) == 0)
1248 vlib_cli_output (vm, "No plugin API message ranges configured...");
1252 rp = vec_dup (am->msg_ranges);
1254 vec_sort_with_function (rp, range_compare);
1256 vlib_cli_output (vm, "Plugin API message ID ranges...\n");
1257 vlib_cli_output (vm, "%U", format_api_msg_range, 0 /* header */ );
1259 for (i = 0; i < vec_len (rp); i++)
1260 vlib_cli_output (vm, "%U", format_api_msg_range, rp + i);
1268 VLIB_CLI_COMMAND (cli_show_api_plugin_command, static) = {
1269 .path = "show api plugin",
1270 .short_help = "show api plugin",
1271 .function = vl_api_show_plugin_command,
1276 vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
1278 vl_api_rpc_call_reply_t *rmp;
1281 vlib_main_t *vm = vlib_get_main ();
1283 if (mp->function == 0)
1286 clib_warning ("rpc NULL function pointer");
1291 if (mp->need_barrier_sync)
1292 vlib_worker_thread_barrier_sync (vm);
1294 fp = uword_to_pointer (mp->function, int (*)(void *));
1297 if (mp->need_barrier_sync)
1298 vlib_worker_thread_barrier_release (vm);
1303 unix_shared_memory_queue_t *q =
1304 vl_api_client_index_to_input_queue (mp->client_index);
1307 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
1308 rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
1309 rmp->context = mp->context;
1311 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1316 clib_warning ("multicast not yet implemented...");
1321 vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t * mp)
1323 clib_warning ("unimplemented");
1327 vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
1329 vl_api_rpc_call_t *mp;
1330 api_main_t *am = &api_main;
1331 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
1332 unix_shared_memory_queue_t *q;
1334 /* Main thread: call the function directly */
1335 if (os_get_cpu_number () == 0)
1337 vlib_main_t *vm = vlib_get_main ();
1338 void (*call_fp) (void *);
1340 vlib_worker_thread_barrier_sync (vm);
1345 vlib_worker_thread_barrier_release (vm);
1349 /* Any other thread, actually do an RPC call... */
1350 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
1352 memset (mp, 0, sizeof (*mp));
1353 clib_memcpy (mp->data, data, data_length);
1354 mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
1355 mp->function = pointer_to_uword (fp);
1356 mp->need_barrier_sync = 1;
1359 * Use the "normal" control-plane mechanism for the main thread.
1360 * Well, almost. if the main input queue is full, we cannot
1361 * block. Otherwise, we can expect a barrier sync timeout.
1363 q = shmem_hdr->vl_input_queue;
1365 while (pthread_mutex_trylock (&q->mutex))
1366 vlib_worker_thread_barrier_check ();
1368 while (PREDICT_FALSE (unix_shared_memory_queue_is_full (q)))
1370 pthread_mutex_unlock (&q->mutex);
1371 vlib_worker_thread_barrier_check ();
1372 while (pthread_mutex_trylock (&q->mutex))
1373 vlib_worker_thread_barrier_check ();
1376 vl_msg_api_send_shmem_nolock (q, (u8 *) & mp);
1378 pthread_mutex_unlock (&q->mutex);
1382 vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
1384 api_main_t *am = &api_main;
1385 vl_api_msg_range_t *rp;
1388 /* Noop (except for tracing) during normal operation */
1389 if (am->replay_in_progress == 0)
1392 p = hash_get_mem (am->msg_range_by_name, mp->plugin_name);
1395 clib_warning ("WARNING: traced plugin '%s' not in current image",
1400 rp = vec_elt_at_index (am->msg_ranges, p[0]);
1401 if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
1403 clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
1404 mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
1408 if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
1410 clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
1411 mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
1416 #define foreach_rpc_api_msg \
1417 _(RPC_CALL,rpc_call) \
1418 _(RPC_CALL_REPLY,rpc_call_reply)
1420 #define foreach_plugin_trace_msg \
1421 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
1423 static clib_error_t *
1424 rpc_api_hookup (vlib_main_t * vm)
1427 vl_msg_api_set_handlers(VL_API_##N, #n, \
1428 vl_api_##n##_t_handler, \
1431 vl_api_##n##_t_print, \
1432 sizeof(vl_api_##n##_t), 0 /* do not trace */);
1433 foreach_rpc_api_msg;
1437 vl_msg_api_set_handlers(VL_API_##N, #n, \
1438 vl_api_##n##_t_handler, \
1441 vl_api_##n##_t_print, \
1442 sizeof(vl_api_##n##_t), 1 /* do trace */);
1443 foreach_plugin_trace_msg;
1448 VLIB_API_INIT_FUNCTION (rpc_api_hookup);
1459 format_vl_msg_api_trace_status (u8 * s, va_list * args)
1461 api_main_t *am = va_arg (*args, api_main_t *);
1462 vl_api_trace_which_t which = va_arg (*args, vl_api_trace_which_t);
1468 case VL_API_TRACE_TX:
1470 trace_name = "TX trace";
1473 case VL_API_TRACE_RX:
1475 trace_name = "RX trace";
1484 s = format (s, "%s: not yet configured.\n", trace_name);
1488 s = format (s, "%s: used %d of %d items, %s enabled, %s wrapped\n",
1489 trace_name, vec_len (tp->traces), tp->nitems,
1490 tp->enabled ? "is" : "is not", tp->wrapped ? "has" : "has not");
1494 void vl_msg_api_custom_dump_configure (api_main_t * am)
1495 __attribute__ ((weak));
1497 vl_msg_api_custom_dump_configure (api_main_t * am)
1502 vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
1503 u32 first_index, u32 last_index,
1504 vl_api_replay_t which)
1506 vl_api_trace_file_header_t *hp;
1511 u8 endian_swap_needed = 0;
1512 api_main_t *am = &api_main;
1515 void **saved_print_handlers = 0;
1517 fd = open ((char *) filename, O_RDONLY);
1521 vlib_cli_output (vm, "Couldn't open %s\n", filename);
1525 if (fstat (fd, &statb) < 0)
1527 vlib_cli_output (vm, "Couldn't stat %s\n", filename);
1532 if (!(statb.st_mode & S_IFREG) || (statb.st_size < sizeof (*hp)))
1534 vlib_cli_output (vm, "File not plausible: %s\n", filename);
1539 file_size = statb.st_size;
1540 file_size = (file_size + 4095) & ~(4096);
1542 hp = mmap (0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
1544 if (hp == (vl_api_trace_file_header_t *) MAP_FAILED)
1546 vlib_cli_output (vm, "mmap failed: %s\n", filename);
1552 if ((clib_arch_is_little_endian && hp->endian == VL_API_BIG_ENDIAN)
1553 || (clib_arch_is_big_endian && hp->endian == VL_API_LITTLE_ENDIAN))
1554 endian_swap_needed = 1;
1556 if (endian_swap_needed)
1557 nitems = ntohl (hp->nitems);
1559 nitems = hp->nitems;
1561 if (last_index == (u32) ~ 0)
1563 last_index = nitems - 1;
1566 if (first_index >= nitems || last_index >= nitems)
1568 vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
1569 first_index, last_index, nitems - 1);
1570 munmap (hp, file_size);
1574 vlib_cli_output (vm,
1575 "Note: wrapped/incomplete trace, results may vary\n");
1577 if (which == CUSTOM_DUMP)
1579 saved_print_handlers = (void **) vec_dup (am->msg_print_handlers);
1580 vl_msg_api_custom_dump_configure (am);
1584 msg = (u8 *) (hp + 1);
1586 for (i = 0; i < first_index; i++)
1592 size = clib_host_to_net_u32 (*(u32 *) msg);
1593 msg += sizeof (u32);
1595 if (clib_arch_is_little_endian)
1596 msg_id = ntohs (*((u16 *) msg));
1598 msg_id = *((u16 *) msg);
1600 cfgp = am->api_trace_cfg + msg_id;
1603 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1604 munmap (hp, file_size);
1610 if (which == REPLAY)
1611 am->replay_in_progress = 1;
1613 for (; i <= last_index; i++)
1621 vlib_cli_output (vm, "---------- trace %d -----------\n", i);
1623 size = clib_host_to_net_u32 (*(u32 *) msg);
1624 msg += sizeof (u32);
1626 if (clib_arch_is_little_endian)
1627 msg_id = ntohs (*((u16 *) msg));
1629 msg_id = *((u16 *) msg);
1631 cfgp = am->api_trace_cfg + msg_id;
1634 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1635 munmap (hp, file_size);
1637 am->replay_in_progress = 0;
1641 /* Copy the buffer (from the read-only mmap'ed file) */
1642 vec_validate (tmpbuf, size - 1 + sizeof (uword));
1643 clib_memcpy (tmpbuf + sizeof (uword), msg, size);
1644 memset (tmpbuf, 0xf, sizeof (uword));
1647 * Endian swap if needed. All msg data is supposed to be
1648 * in network byte order. All msg handlers are supposed to
1649 * know that. The generic message dumpers don't know that.
1650 * One could fix apigen, I suppose.
1652 if ((which == DUMP && clib_arch_is_little_endian) || endian_swap_needed)
1654 void (*endian_fp) (void *);
1655 if (msg_id >= vec_len (am->msg_endian_handlers)
1656 || (am->msg_endian_handlers[msg_id] == 0))
1658 vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
1659 munmap (hp, file_size);
1661 am->replay_in_progress = 0;
1664 endian_fp = am->msg_endian_handlers[msg_id];
1665 (*endian_fp) (tmpbuf + sizeof (uword));
1668 /* msg_id always in network byte order */
1669 if (clib_arch_is_little_endian)
1671 msg_idp = (u16 *) (tmpbuf + sizeof (uword));
1679 if (msg_id < vec_len (am->msg_print_handlers) &&
1680 am->msg_print_handlers[msg_id])
1682 u8 *(*print_fp) (void *, void *);
1684 print_fp = (void *) am->msg_print_handlers[msg_id];
1685 (*print_fp) (tmpbuf + sizeof (uword), vm);
1689 vlib_cli_output (vm, "Skipping msg id %d: no print fcn\n",
1696 if (msg_id < vec_len (am->msg_print_handlers) &&
1697 am->msg_print_handlers[msg_id])
1701 u8 *(*print_fp) (void *, void *);
1703 print_fp = (void *) am->msg_print_handlers[msg_id];
1705 vlib_cli_output (vm, "/*");
1707 (*print_fp) (tmpbuf + sizeof (uword), vm);
1708 vlib_cli_output (vm, "*/\n");
1710 s = format (0, "static u8 * vl_api_%s_%d[%d] = {",
1711 am->msg_names[msg_id], i,
1712 am->api_trace_cfg[msg_id].size);
1714 for (j = 0; j < am->api_trace_cfg[msg_id].size; j++)
1717 s = format (s, "\n ");
1718 s = format (s, "0x%02x,", tmpbuf[sizeof (uword) + j]);
1720 s = format (s, "\n};\n%c", 0);
1721 vlib_cli_output (vm, (char *) s);
1727 if (msg_id < vec_len (am->msg_print_handlers) &&
1728 am->msg_print_handlers[msg_id] && cfgp->replay_enable)
1730 void (*handler) (void *);
1732 handler = (void *) am->msg_handlers[msg_id];
1734 if (!am->is_mp_safe[msg_id])
1735 vl_msg_api_barrier_sync ();
1736 (*handler) (tmpbuf + sizeof (uword));
1737 if (!am->is_mp_safe[msg_id])
1738 vl_msg_api_barrier_release ();
1742 if (cfgp->replay_enable)
1743 vlib_cli_output (vm, "Skipping msg id %d: no handler\n",
1750 _vec_len (tmpbuf) = 0;
1754 if (saved_print_handlers)
1756 clib_memcpy (am->msg_print_handlers, saved_print_handlers,
1757 vec_len (am->msg_print_handlers) * sizeof (void *));
1758 vec_free (saved_print_handlers);
1761 munmap (hp, file_size);
1763 am->replay_in_progress = 0;
1766 static clib_error_t *
1767 api_trace_command_fn (vlib_main_t * vm,
1768 unformat_input_t * input, vlib_cli_command_t * cmd)
1770 u32 nitems = 256 << 10;
1771 api_main_t *am = &api_main;
1772 vl_api_trace_which_t which = VL_API_TRACE_RX;
1775 u32 last = (u32) ~ 0;
1779 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1781 if (unformat (input, "on") || unformat (input, "enable"))
1783 if (unformat (input, "nitems %d", &nitems))
1785 vl_msg_api_trace_configure (am, which, nitems);
1786 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1788 else if (unformat (input, "off"))
1790 vl_msg_api_trace_onoff (am, which, 0);
1792 else if (unformat (input, "save %s", &filename))
1794 u8 *chroot_filename;
1795 if (strstr ((char *) filename, "..")
1796 || index ((char *) filename, '/'))
1798 vlib_cli_output (vm, "illegal characters in filename '%s'",
1803 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1805 vec_free (filename);
1807 fp = fopen ((char *) chroot_filename, "w");
1810 vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
1813 rv = vl_msg_api_trace_save (am, which, fp);
1816 vlib_cli_output (vm, "API Trace data not present\n");
1818 vlib_cli_output (vm, "File for writing is closed\n");
1820 vlib_cli_output (vm, "Error while writing header to file\n");
1822 vlib_cli_output (vm, "Error while writing trace to file\n");
1824 vlib_cli_output (vm,
1825 "Error while writing end of buffer trace to file\n");
1827 vlib_cli_output (vm,
1828 "Error while writing start of buffer trace to file\n");
1830 vlib_cli_output (vm, "Unkown error while saving: %d", rv);
1832 vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
1833 vec_free (chroot_filename);
1835 else if (unformat (input, "dump %s", &filename))
1837 vl_msg_api_process_file (vm, filename, first, last, DUMP);
1839 else if (unformat (input, "custom-dump %s", &filename))
1841 vl_msg_api_process_file (vm, filename, first, last, CUSTOM_DUMP);
1843 else if (unformat (input, "replay %s", &filename))
1845 vl_msg_api_process_file (vm, filename, first, last, REPLAY);
1847 else if (unformat (input, "initializers %s", &filename))
1849 vl_msg_api_process_file (vm, filename, first, last, INITIALIZERS);
1851 else if (unformat (input, "tx"))
1853 which = VL_API_TRACE_TX;
1855 else if (unformat (input, "first %d", &first))
1859 else if (unformat (input, "last %d", &last))
1863 else if (unformat (input, "status"))
1865 vlib_cli_output (vm, "%U", format_vl_msg_api_trace_status,
1868 else if (unformat (input, "free"))
1870 vl_msg_api_trace_onoff (am, which, 0);
1871 vl_msg_api_trace_free (am, which);
1873 else if (unformat (input, "post-mortem-on"))
1874 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1875 else if (unformat (input, "post-mortem-off"))
1876 vl_msg_api_post_mortem_dump_enable_disable (0 /* enable */ );
1878 return clib_error_return (0, "unknown input `%U'",
1879 format_unformat_error, input);
1885 VLIB_CLI_COMMAND (api_trace_command, static) = {
1886 .path = "api trace",
1888 "api trace [on|off][dump|save|replay <file>][status][free][post-mortem-on]",
1889 .function = api_trace_command_fn,
1893 static clib_error_t *
1894 api_config_fn (vlib_main_t * vm, unformat_input_t * input)
1896 u32 nitems = 256 << 10;
1897 vl_api_trace_which_t which = VL_API_TRACE_RX;
1898 api_main_t *am = &api_main;
1900 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1902 if (unformat (input, "on") || unformat (input, "enable"))
1904 if (unformat (input, "nitems %d", &nitems))
1906 vl_msg_api_trace_configure (am, which, nitems);
1907 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1908 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1911 return clib_error_return (0, "unknown input `%U'",
1912 format_unformat_error, input);
1917 VLIB_CONFIG_FUNCTION (api_config_fn, "api-trace");
1920 * fd.io coding-style-patch-verification: ON
1923 * eval: (c-set-style "gnu")