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);
220 pointer_to_uword (am->serialized_message_table_in_shmem);
222 vl_msg_api_send_shmem (q, (u8 *) & rp);
226 call_reaper_functions (u32 client_index)
228 clib_error_t *error = 0;
229 _vl_msg_api_function_list_elt_t *i;
231 i = api_main.reaper_function_registrations;
234 error = i->f (client_index);
236 clib_error_report (error);
237 i = i->next_init_function;
243 * vl_api_memclnt_delete_t_handler
246 vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
248 vl_api_registration_t **regpp;
249 vl_api_registration_t *regp;
250 vl_api_memclnt_delete_reply_t *rp;
253 api_main_t *am = &api_main;
254 u32 handle, client_index, epoch;
258 if (call_reaper_functions (handle))
261 epoch = vl_msg_api_handle_get_epoch (handle);
262 client_index = vl_msg_api_handle_get_index (handle);
264 if (epoch != (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK))
267 ("Stale clnt delete index %d old epoch %d cur epoch %d",
269 (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK));
273 regpp = am->vl_clients + client_index;
275 if (!pool_is_free (am->vl_clients, regpp))
280 /* $$$ check the input queue for e.g. punted sf's */
282 rp = vl_msg_api_alloc (sizeof (*rp));
283 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
284 rp->handle = mp->handle;
287 vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
289 if (client_index != regp->vl_api_registration_pool_index)
291 clib_warning ("mismatch client_index %d pool_index %d",
292 client_index, regp->vl_api_registration_pool_index);
293 vl_msg_api_free (rp);
297 /* No dangling references, please */
300 pool_put_index (am->vl_clients, regp->vl_api_registration_pool_index);
302 pthread_mutex_lock (&svm->mutex);
303 oldheap = svm_push_data_heap (svm);
304 /* Poison the old registration */
305 memset (regp, 0xF1, sizeof (*regp));
306 clib_mem_free (regp);
307 pthread_mutex_unlock (&svm->mutex);
308 svm_pop_heap (oldheap);
312 clib_warning ("unknown client ID %d", mp->index);
317 vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
319 vl_api_get_first_msg_id_reply_t *rmp;
320 unix_shared_memory_queue_t *q;
322 api_main_t *am = &api_main;
323 vl_api_msg_range_t *rp;
325 u16 first_msg_id = ~0;
326 int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
328 q = vl_api_client_index_to_input_queue (mp->client_index);
332 if (am->msg_range_by_name == 0)
335 strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name) - 1);
337 p = hash_get_mem (am->msg_range_by_name, name);
341 rp = vec_elt_at_index (am->msg_ranges, p[0]);
343 first_msg_id = rp->first_msg_id;
348 rmp = vl_msg_api_alloc (sizeof (*rmp));
349 rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
350 rmp->context = mp->context;
351 rmp->retval = ntohl (rv);
352 rmp->first_msg_id = ntohs (first_msg_id);
353 vl_msg_api_send_shmem (q, (u8 *) & rmp);
356 #define foreach_vlib_api_msg \
357 _(MEMCLNT_CREATE, memclnt_create) \
358 _(MEMCLNT_DELETE, memclnt_delete) \
359 _(GET_FIRST_MSG_ID, get_first_msg_id)
365 memory_api_init (const char *region_name)
368 vl_msg_api_msg_config_t cfg;
369 vl_msg_api_msg_config_t *c = &cfg;
371 memset (c, 0, sizeof (*c));
373 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
376 #define _(N,n) do { \
377 c->id = VL_API_##N; \
379 c->handler = vl_api_##n##_t_handler; \
380 c->cleanup = vl_noop_handler; \
381 c->endian = vl_api_##n##_t_endian; \
382 c->print = vl_api_##n##_t_print; \
383 c->size = sizeof(vl_api_##n##_t); \
384 c->traced = 1; /* trace, so these msgs print */ \
385 c->replay = 0; /* don't replay client create/delete msgs */ \
386 c->message_bounce = 0; /* don't bounce this message */ \
387 vl_msg_api_config(c);} while (0);
389 foreach_vlib_api_msg;
395 #define foreach_histogram_bucket \
403 #define _(n) SLEEP_##n##_US,
404 foreach_histogram_bucket
409 static u64 vector_rate_histogram[SLEEP_N_BUCKETS];
411 static void memclnt_queue_callback (vlib_main_t * vm);
414 * Callback to send ourselves a plugin numbering-space trace msg
417 send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
419 vl_api_trace_plugin_msg_ids_t *mp;
420 api_main_t *am = &api_main;
421 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
422 unix_shared_memory_queue_t *q;
424 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
425 memset (mp, 0, sizeof (*mp));
427 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
428 strncpy ((char *) mp->plugin_name, (char *) name,
429 sizeof (mp->plugin_name) - 1);
430 mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
431 mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
433 q = shmem_hdr->vl_input_queue;
435 vl_msg_api_send_shmem (q, (u8 *) & mp);
439 memclnt_process (vlib_main_t * vm,
440 vlib_node_runtime_t * node, vlib_frame_t * f)
444 unix_shared_memory_queue_t *q;
447 api_main_t *am = &api_main;
448 f64 dead_client_scan_time;
449 f64 sleep_time, start_time;
453 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
455 if ((rv = memory_api_init (am->region_name)) < 0)
457 clib_warning ("memory_api_init returned %d, wait for godot...", rv);
458 vlib_process_suspend (vm, 1e70);
463 q = shm->vl_input_queue;
466 e = vlib_call_init_exit_functions
467 (vm, vm->api_init_function_registrations, 1 /* call_once */ );
469 clib_error_report (e);
472 dead_client_scan_time = vlib_time_now (vm) + 20.0;
475 * Send plugin message range messages for each plugin we loaded
477 for (i = 0; i < vec_len (am->msg_ranges); i++)
479 vl_api_msg_range_t *rp = am->msg_ranges + i;
480 send_one_plugin_msg_ids_msg (rp->name, rp->first_msg_id,
484 /* $$$ pay attention to frame size, control CPU usage */
487 uword event_type __attribute__ ((unused));
492 * There's a reason for checking the queue before
493 * sleeping. If the vlib application crashes, it's entirely
494 * possible for a client to enqueue a connect request
495 * during the process restart interval.
497 * Unless some force of physics causes the new incarnation
498 * of the application to process the request, the client will
499 * sit and wait for Godot...
501 vector_rate = vlib_last_vector_length_per_node (vm);
502 start_time = vlib_time_now (vm);
505 pthread_mutex_lock (&q->mutex);
508 vm->api_queue_nonempty = 0;
509 pthread_mutex_unlock (&q->mutex);
511 if (TRACE_VLIB_MEMORY_QUEUE)
514 ELOG_TYPE_DECLARE (e) =
516 .format = "q-underflow: len %d",
524 ed = ELOG_DATA (&vm->elog_main, e);
531 headp = (i8 *) (q->data + sizeof (uword) * q->head);
532 clib_memcpy (&mp, headp, sizeof (uword));
535 need_broadcast = (q->cursize == q->maxsize / 2);
538 if (PREDICT_FALSE (q->head == q->maxsize))
540 pthread_mutex_unlock (&q->mutex);
542 (void) pthread_cond_broadcast (&q->condvar);
544 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
546 /* Allow no more than 10us without a pause */
547 if (vlib_time_now (vm) > start_time + 10e-6)
549 int index = SLEEP_400_US;
550 if (vector_rate > 40.0)
552 else if (vector_rate > 20.0)
554 index = SLEEP_200_US;
557 else if (vector_rate >= 1.0)
559 index = SLEEP_100_US;
567 vector_rate_histogram[index] += 1;
572 event_type = vlib_process_wait_for_event_or_clock (vm, sleep_time);
573 vm->queue_signal_pending = 0;
574 vlib_process_get_events (vm, 0 /* event_data */ );
576 if (vlib_time_now (vm) > dead_client_scan_time)
578 vl_api_registration_t **regpp;
579 vl_api_registration_t *regp;
580 unix_shared_memory_queue_t *q;
581 static u32 *dead_indices;
582 static u32 *confused_indices;
584 vec_reset_length (dead_indices);
585 vec_reset_length (confused_indices);
588 pool_foreach (regpp, am->vl_clients,
593 q = regp->vl_input_queue;
594 if (kill (q->consumer_pid, 0) < 0)
596 vec_add1(dead_indices, regpp - am->vl_clients);
601 clib_warning ("NULL client registration index %d",
602 regpp - am->vl_clients);
603 vec_add1 (confused_indices, regpp - am->vl_clients);
607 /* This should "never happen," but if it does, fix it... */
608 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
611 for (i = 0; i < vec_len (confused_indices); i++)
613 pool_put_index (am->vl_clients, confused_indices[i]);
617 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
623 /* Allow the application to clean up its registrations */
624 for (i = 0; i < vec_len (dead_indices); i++)
626 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
631 handle = vl_msg_api_handle_from_index_and_epoch
632 (dead_indices[i], shm->application_restarts);
633 (void) call_reaper_functions (handle);
638 pthread_mutex_lock (&svm->mutex);
639 oldheap = svm_push_data_heap (svm);
641 for (i = 0; i < vec_len (dead_indices); i++)
643 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
646 /* Poison the old registration */
647 memset (*regpp, 0xF3, sizeof (**regpp));
648 clib_mem_free (*regpp);
649 /* no dangling references, please */
654 svm_pop_heap (oldheap);
655 clib_warning ("Duplicate free, client index %d",
656 regpp - am->vl_clients);
657 oldheap = svm_push_data_heap (svm);
661 svm_client_scan_this_region_nolock (am->vlib_rp);
663 pthread_mutex_unlock (&svm->mutex);
664 svm_pop_heap (oldheap);
665 for (i = 0; i < vec_len (dead_indices); i++)
666 pool_put_index (am->vl_clients, dead_indices[i]);
669 dead_client_scan_time = vlib_time_now (vm) + 20.0;
672 if (TRACE_VLIB_MEMORY_QUEUE)
675 ELOG_TYPE_DECLARE (e) = {
676 .format = "q-awake: len %d",
684 ed = ELOG_DATA (&vm->elog_main, e);
685 ed->len = q->cursize;
692 static clib_error_t *
693 vl_api_show_histogram_command (vlib_main_t * vm,
694 unformat_input_t * input,
695 vlib_cli_command_t * cli_cmd)
697 u64 total_counts = 0;
700 for (i = 0; i < SLEEP_N_BUCKETS; i++)
702 total_counts += vector_rate_histogram[i];
705 if (total_counts == 0)
707 vlib_cli_output (vm, "No control-plane activity.");
714 percent = ((f64) vector_rate_histogram[SLEEP_##n##_US]) \
715 / (f64) total_counts; \
717 vlib_cli_output (vm, "Sleep %3d us: %llu, %.2f%%",n, \
718 vector_rate_histogram[SLEEP_##n##_US], \
721 foreach_histogram_bucket;
728 VLIB_CLI_COMMAND (cli_show_api_histogram_command, static) = {
729 .path = "show api histogram",
730 .short_help = "show api histogram",
731 .function = vl_api_show_histogram_command,
735 static clib_error_t *
736 vl_api_clear_histogram_command (vlib_main_t * vm,
737 unformat_input_t * input,
738 vlib_cli_command_t * cli_cmd)
742 for (i = 0; i < SLEEP_N_BUCKETS; i++)
743 vector_rate_histogram[i] = 0;
748 VLIB_CLI_COMMAND (cli_clear_api_histogram_command, static) = {
749 .path = "clear api histogram",
750 .short_help = "clear api histogram",
751 .function = vl_api_clear_histogram_command,
757 VLIB_REGISTER_NODE (memclnt_node,static) = {
758 .function = memclnt_process,
759 .type = VLIB_NODE_TYPE_PROCESS,
760 .name = "api-rx-from-ring",
761 .state = VLIB_NODE_STATE_DISABLED,
766 memclnt_queue_callback (vlib_main_t * vm)
768 static volatile int *cursizep;
770 if (PREDICT_FALSE (cursizep == 0))
772 api_main_t *am = &api_main;
773 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
774 unix_shared_memory_queue_t *q;
779 q = shmem_hdr->vl_input_queue;
782 cursizep = &q->cursize;
787 vm->queue_signal_pending = 1;
788 vm->api_queue_nonempty = 1;
789 vlib_process_signal_event (vm, memclnt_node.index,
790 /* event_type */ 0, /* event_data */ 0);
795 vl_enable_disable_memory_api (vlib_main_t * vm, int enable)
797 vlib_node_set_state (vm, memclnt_node.index,
799 ? VLIB_NODE_STATE_POLLING
800 : VLIB_NODE_STATE_DISABLED));
804 api_rx_from_node (vlib_main_t * vm,
805 vlib_node_runtime_t * node, vlib_frame_t * frame)
807 uword n_packets = frame->n_vectors;
812 vec_validate (long_msg, 4095);
813 n_left_from = frame->n_vectors;
814 from = vlib_frame_args (frame);
816 while (n_left_from > 0)
824 b0 = vlib_get_buffer (vm, bi0);
828 msg = b0->data + b0->current_data;
829 msg_len = b0->current_length;
830 if (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
832 ASSERT (long_msg != 0);
833 _vec_len (long_msg) = 0;
834 vec_add (long_msg, msg, msg_len);
835 while (b0->flags & VLIB_BUFFER_NEXT_PRESENT)
837 b0 = vlib_get_buffer (vm, b0->next_buffer);
838 msg = b0->data + b0->current_data;
839 msg_len = b0->current_length;
840 vec_add (long_msg, msg, msg_len);
844 vl_msg_api_handler_no_trace_no_free (msg);
847 /* Free what we've been given. */
848 vlib_buffer_free (vm, vlib_frame_args (frame), n_packets);
854 VLIB_REGISTER_NODE (api_rx_from_node_node,static) = {
855 .function = api_rx_from_node,
856 .type = VLIB_NODE_TYPE_INTERNAL,
858 .name = "api-rx-from-node",
862 static clib_error_t *
863 setup_memclnt_exit (vlib_main_t * vm)
865 atexit (vl_unmap_shmem);
869 VLIB_INIT_FUNCTION (setup_memclnt_exit);
872 static clib_error_t *
873 vl_api_ring_command (vlib_main_t * vm,
874 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
878 vl_shmem_hdr_t *shmem_hdr;
879 api_main_t *am = &api_main;
881 shmem_hdr = am->shmem_hdr;
885 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
889 vlib_cli_output (vm, "%8s %8s %8s %8s %8s\n",
890 "Owner", "Size", "Nitems", "Hits", "Misses");
892 ap = shmem_hdr->vl_rings;
894 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
896 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
897 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
901 ap = shmem_hdr->client_rings;
903 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
905 vlib_cli_output (vm, "%8s %8d %8d %8d %8d\n",
906 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
910 vlib_cli_output (vm, "%d ring miss fallback allocations\n",
914 (vm, "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
915 shmem_hdr->application_restarts,
916 shmem_hdr->restart_reclaims, shmem_hdr->garbage_collects);
920 void dump_socket_clients (vlib_main_t * vm, api_main_t * am)
921 __attribute__ ((weak));
924 dump_socket_clients (vlib_main_t * vm, api_main_t * am)
928 static clib_error_t *
929 vl_api_client_command (vlib_main_t * vm,
930 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
932 vl_api_registration_t **regpp, *regp;
933 unix_shared_memory_queue_t *q;
935 api_main_t *am = &api_main;
936 u32 *confused_indices = 0;
938 if (!pool_elts (am->vl_clients))
940 vlib_cli_output (vm, "Shared memory clients");
941 vlib_cli_output (vm, "%16s %8s %14s %18s %s",
942 "Name", "PID", "Queue Length", "Queue VA", "Health");
945 pool_foreach (regpp, am->vl_clients,
951 q = regp->vl_input_queue;
952 if (kill (q->consumer_pid, 0) < 0)
960 vlib_cli_output (vm, "%16s %8d %14d 0x%016llx %s\n",
961 regp->name, q->consumer_pid, q->cursize,
966 clib_warning ("NULL client registration index %d",
967 regpp - am->vl_clients);
968 vec_add1 (confused_indices, regpp - am->vl_clients);
973 /* This should "never happen," but if it does, fix it... */
974 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
977 for (i = 0; i < vec_len (confused_indices); i++)
979 pool_put_index (am->vl_clients, confused_indices[i]);
982 vec_free (confused_indices);
984 if (am->missing_clients)
985 vlib_cli_output (vm, "%u messages with missing clients",
986 am->missing_clients);
988 dump_socket_clients (vm, am);
993 static clib_error_t *
994 vl_api_status_command (vlib_main_t * vm,
995 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
997 api_main_t *am = &api_main;
999 // check if rx_trace and tx_trace are not null pointers
1001 if (am->rx_trace == 0)
1003 vlib_cli_output (vm, "RX Trace disabled\n");
1007 if (am->rx_trace->enabled == 0)
1008 vlib_cli_output (vm, "RX Trace disabled\n");
1010 vlib_cli_output (vm, "RX Trace enabled\n");
1013 if (am->tx_trace == 0)
1015 vlib_cli_output (vm, "TX Trace disabled\n");
1019 if (am->tx_trace->enabled == 0)
1020 vlib_cli_output (vm, "TX Trace disabled\n");
1022 vlib_cli_output (vm, "TX Trace enabled\n");
1029 VLIB_CLI_COMMAND (cli_show_api_command, static) = {
1031 .short_help = "Show API information",
1036 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) = {
1037 .path = "show api ring-stats",
1038 .short_help = "Message ring statistics",
1039 .function = vl_api_ring_command,
1044 VLIB_CLI_COMMAND (cli_show_api_clients_command, static) = {
1045 .path = "show api clients",
1046 .short_help = "Client information",
1047 .function = vl_api_client_command,
1052 VLIB_CLI_COMMAND (cli_show_api_status_command, static) = {
1053 .path = "show api status",
1054 .short_help = "Show API trace status",
1055 .function = vl_api_status_command,
1059 static clib_error_t *
1060 vl_api_message_table_command (vlib_main_t * vm,
1061 unformat_input_t * input,
1062 vlib_cli_command_t * cli_cmd)
1064 api_main_t *am = &api_main;
1068 if (unformat (input, "verbose"))
1073 vlib_cli_output (vm, "%-4s %s", "ID", "Name");
1075 vlib_cli_output (vm, "%-4s %-40s %6s %7s", "ID", "Name", "Bounce",
1078 for (i = 1; i < vec_len (am->msg_names); i++)
1082 vlib_cli_output (vm, "%-4d %s", i,
1083 am->msg_names[i] ? am->msg_names[i] :
1088 vlib_cli_output (vm, "%-4d %-40s %6d %7d", i,
1089 am->msg_names[i] ? am->msg_names[i] :
1090 " [no handler]", am->message_bounce[i],
1099 VLIB_CLI_COMMAND (cli_show_api_message_table_command, static) = {
1100 .path = "show api message-table",
1101 .short_help = "Message Table",
1102 .function = vl_api_message_table_command,
1106 static clib_error_t *
1107 vl_api_trace_command (vlib_main_t * vm,
1108 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
1111 vl_api_trace_which_t which = VL_API_TRACE_RX;
1112 api_main_t *am = &api_main;
1114 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1116 if (unformat (input, "rx nitems %u", &nitems) || unformat (input, "rx"))
1118 else if (unformat (input, "tx nitems %u", &nitems)
1119 || unformat (input, "tx"))
1121 which = VL_API_TRACE_RX;
1124 else if (unformat (input, "on rx"))
1126 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1128 else if (unformat (input, "on tx"))
1130 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 1);
1132 else if (unformat (input, "on"))
1134 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 1);
1136 else if (unformat (input, "off"))
1138 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1139 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1141 else if (unformat (input, "free"))
1143 vl_msg_api_trace_onoff (am, VL_API_TRACE_RX, 0);
1144 vl_msg_api_trace_onoff (am, VL_API_TRACE_TX, 0);
1145 vl_msg_api_trace_free (am, VL_API_TRACE_RX);
1146 vl_msg_api_trace_free (am, VL_API_TRACE_TX);
1148 else if (unformat (input, "debug on"))
1150 am->msg_print_flag = 1;
1152 else if (unformat (input, "debug off"))
1154 am->msg_print_flag = 0;
1157 return clib_error_return (0, "unknown input `%U'",
1158 format_unformat_error, input);
1163 if (vl_msg_api_trace_configure (am, which, nitems))
1165 vlib_cli_output (vm, "warning: trace configure error (%d, %d)",
1173 VLIB_CLI_COMMAND (trace, static) = {
1174 .path = "set api-trace",
1175 .short_help = "API trace",
1176 .function = vl_api_trace_command,
1181 vlibmemory_init (vlib_main_t * vm)
1183 api_main_t *am = &api_main;
1184 svm_map_region_args_t _a, *a = &_a;
1186 memset (a, 0, sizeof (*a));
1187 a->root_path = am->root_path;
1188 a->name = SVM_GLOBAL_REGION_NAME;
1189 a->baseva = (am->global_baseva != 0) ?
1190 am->global_baseva : SVM_GLOBAL_REGION_BASEVA;
1191 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
1192 a->flags = SVM_FLAGS_NODATA;
1193 a->uid = am->api_uid;
1194 a->gid = am->api_gid;
1196 (am->global_pvt_heap_size !=
1197 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
1199 svm_region_init_args (a);
1203 VLIB_INIT_FUNCTION (vlibmemory_init);
1206 vl_set_memory_region_name (const char *name)
1208 api_main_t *am = &api_main;
1210 am->region_name = name;
1214 range_compare (vl_api_msg_range_t * a0, vl_api_msg_range_t * a1)
1216 int len0, len1, clen;
1218 len0 = vec_len (a0->name);
1219 len1 = vec_len (a1->name);
1220 clen = len0 < len1 ? len0 : len1;
1221 return (strncmp ((char *) a0->name, (char *) a1->name, clen));
1225 format_api_msg_range (u8 * s, va_list * args)
1227 vl_api_msg_range_t *rp = va_arg (*args, vl_api_msg_range_t *);
1230 s = format (s, "%-20s%9s%9s", "Name", "First-ID", "Last-ID");
1232 s = format (s, "%-20s%9d%9d", rp->name, rp->first_msg_id,
1238 static clib_error_t *
1239 vl_api_show_plugin_command (vlib_main_t * vm,
1240 unformat_input_t * input,
1241 vlib_cli_command_t * cli_cmd)
1243 api_main_t *am = &api_main;
1244 vl_api_msg_range_t *rp = 0;
1247 if (vec_len (am->msg_ranges) == 0)
1249 vlib_cli_output (vm, "No plugin API message ranges configured...");
1253 rp = vec_dup (am->msg_ranges);
1255 vec_sort_with_function (rp, range_compare);
1257 vlib_cli_output (vm, "Plugin API message ID ranges...\n");
1258 vlib_cli_output (vm, "%U", format_api_msg_range, 0 /* header */ );
1260 for (i = 0; i < vec_len (rp); i++)
1261 vlib_cli_output (vm, "%U", format_api_msg_range, rp + i);
1269 VLIB_CLI_COMMAND (cli_show_api_plugin_command, static) = {
1270 .path = "show api plugin",
1271 .short_help = "show api plugin",
1272 .function = vl_api_show_plugin_command,
1277 vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
1279 vl_api_rpc_call_reply_t *rmp;
1282 vlib_main_t *vm = vlib_get_main ();
1284 if (mp->function == 0)
1287 clib_warning ("rpc NULL function pointer");
1292 if (mp->need_barrier_sync)
1293 vlib_worker_thread_barrier_sync (vm);
1295 fp = uword_to_pointer (mp->function, int (*)(void *));
1298 if (mp->need_barrier_sync)
1299 vlib_worker_thread_barrier_release (vm);
1304 unix_shared_memory_queue_t *q =
1305 vl_api_client_index_to_input_queue (mp->client_index);
1308 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
1309 rmp->_vl_msg_id = ntohs (VL_API_RPC_CALL_REPLY);
1310 rmp->context = mp->context;
1312 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1317 clib_warning ("multicast not yet implemented...");
1322 vl_api_rpc_call_reply_t_handler (vl_api_rpc_call_reply_t * mp)
1324 clib_warning ("unimplemented");
1328 vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
1330 vl_api_rpc_call_t *mp;
1331 api_main_t *am = &api_main;
1332 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
1333 unix_shared_memory_queue_t *q;
1335 /* Main thread: call the function directly */
1336 if (vlib_get_thread_index () == 0)
1338 vlib_main_t *vm = vlib_get_main ();
1339 void (*call_fp) (void *);
1341 vlib_worker_thread_barrier_sync (vm);
1346 vlib_worker_thread_barrier_release (vm);
1350 /* Any other thread, actually do an RPC call... */
1351 mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
1353 memset (mp, 0, sizeof (*mp));
1354 clib_memcpy (mp->data, data, data_length);
1355 mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
1356 mp->function = pointer_to_uword (fp);
1357 mp->need_barrier_sync = 1;
1360 * Use the "normal" control-plane mechanism for the main thread.
1361 * Well, almost. if the main input queue is full, we cannot
1362 * block. Otherwise, we can expect a barrier sync timeout.
1364 q = shmem_hdr->vl_input_queue;
1366 while (pthread_mutex_trylock (&q->mutex))
1367 vlib_worker_thread_barrier_check ();
1369 while (PREDICT_FALSE (unix_shared_memory_queue_is_full (q)))
1371 pthread_mutex_unlock (&q->mutex);
1372 vlib_worker_thread_barrier_check ();
1373 while (pthread_mutex_trylock (&q->mutex))
1374 vlib_worker_thread_barrier_check ();
1377 vl_msg_api_send_shmem_nolock (q, (u8 *) & mp);
1379 pthread_mutex_unlock (&q->mutex);
1383 vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
1385 api_main_t *am = &api_main;
1386 vl_api_msg_range_t *rp;
1389 /* Noop (except for tracing) during normal operation */
1390 if (am->replay_in_progress == 0)
1393 p = hash_get_mem (am->msg_range_by_name, mp->plugin_name);
1396 clib_warning ("WARNING: traced plugin '%s' not in current image",
1401 rp = vec_elt_at_index (am->msg_ranges, p[0]);
1402 if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
1404 clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
1405 mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
1409 if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
1411 clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
1412 mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
1417 #define foreach_rpc_api_msg \
1418 _(RPC_CALL,rpc_call) \
1419 _(RPC_CALL_REPLY,rpc_call_reply)
1421 #define foreach_plugin_trace_msg \
1422 _(TRACE_PLUGIN_MSG_IDS,trace_plugin_msg_ids)
1424 static clib_error_t *
1425 rpc_api_hookup (vlib_main_t * vm)
1428 vl_msg_api_set_handlers(VL_API_##N, #n, \
1429 vl_api_##n##_t_handler, \
1432 vl_api_##n##_t_print, \
1433 sizeof(vl_api_##n##_t), 0 /* do not trace */);
1434 foreach_rpc_api_msg;
1438 vl_msg_api_set_handlers(VL_API_##N, #n, \
1439 vl_api_##n##_t_handler, \
1442 vl_api_##n##_t_print, \
1443 sizeof(vl_api_##n##_t), 1 /* do trace */);
1444 foreach_plugin_trace_msg;
1449 VLIB_API_INIT_FUNCTION (rpc_api_hookup);
1460 format_vl_msg_api_trace_status (u8 * s, va_list * args)
1462 api_main_t *am = va_arg (*args, api_main_t *);
1463 vl_api_trace_which_t which = va_arg (*args, vl_api_trace_which_t);
1469 case VL_API_TRACE_TX:
1471 trace_name = "TX trace";
1474 case VL_API_TRACE_RX:
1476 trace_name = "RX trace";
1485 s = format (s, "%s: not yet configured.\n", trace_name);
1489 s = format (s, "%s: used %d of %d items, %s enabled, %s wrapped\n",
1490 trace_name, vec_len (tp->traces), tp->nitems,
1491 tp->enabled ? "is" : "is not", tp->wrapped ? "has" : "has not");
1495 void vl_msg_api_custom_dump_configure (api_main_t * am)
1496 __attribute__ ((weak));
1498 vl_msg_api_custom_dump_configure (api_main_t * am)
1503 vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
1504 u32 first_index, u32 last_index,
1505 vl_api_replay_t which)
1507 vl_api_trace_file_header_t *hp;
1512 u8 endian_swap_needed = 0;
1513 api_main_t *am = &api_main;
1516 void **saved_print_handlers = 0;
1518 fd = open ((char *) filename, O_RDONLY);
1522 vlib_cli_output (vm, "Couldn't open %s\n", filename);
1526 if (fstat (fd, &statb) < 0)
1528 vlib_cli_output (vm, "Couldn't stat %s\n", filename);
1533 if (!(statb.st_mode & S_IFREG) || (statb.st_size < sizeof (*hp)))
1535 vlib_cli_output (vm, "File not plausible: %s\n", filename);
1540 file_size = statb.st_size;
1541 file_size = (file_size + 4095) & ~(4096);
1543 hp = mmap (0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
1545 if (hp == (vl_api_trace_file_header_t *) MAP_FAILED)
1547 vlib_cli_output (vm, "mmap failed: %s\n", filename);
1553 if ((clib_arch_is_little_endian && hp->endian == VL_API_BIG_ENDIAN)
1554 || (clib_arch_is_big_endian && hp->endian == VL_API_LITTLE_ENDIAN))
1555 endian_swap_needed = 1;
1557 if (endian_swap_needed)
1558 nitems = ntohl (hp->nitems);
1560 nitems = hp->nitems;
1562 if (last_index == (u32) ~ 0)
1564 last_index = nitems - 1;
1567 if (first_index >= nitems || last_index >= nitems)
1569 vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
1570 first_index, last_index, nitems - 1);
1571 munmap (hp, file_size);
1575 vlib_cli_output (vm,
1576 "Note: wrapped/incomplete trace, results may vary\n");
1578 if (which == CUSTOM_DUMP)
1580 saved_print_handlers = (void **) vec_dup (am->msg_print_handlers);
1581 vl_msg_api_custom_dump_configure (am);
1585 msg = (u8 *) (hp + 1);
1587 for (i = 0; i < first_index; i++)
1593 size = clib_host_to_net_u32 (*(u32 *) msg);
1594 msg += sizeof (u32);
1596 if (clib_arch_is_little_endian)
1597 msg_id = ntohs (*((u16 *) msg));
1599 msg_id = *((u16 *) msg);
1601 cfgp = am->api_trace_cfg + msg_id;
1604 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1605 munmap (hp, file_size);
1611 if (which == REPLAY)
1612 am->replay_in_progress = 1;
1614 for (; i <= last_index; i++)
1622 vlib_cli_output (vm, "---------- trace %d -----------\n", i);
1624 size = clib_host_to_net_u32 (*(u32 *) msg);
1625 msg += sizeof (u32);
1627 if (clib_arch_is_little_endian)
1628 msg_id = ntohs (*((u16 *) msg));
1630 msg_id = *((u16 *) msg);
1632 cfgp = am->api_trace_cfg + msg_id;
1635 vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
1636 munmap (hp, file_size);
1638 am->replay_in_progress = 0;
1642 /* Copy the buffer (from the read-only mmap'ed file) */
1643 vec_validate (tmpbuf, size - 1 + sizeof (uword));
1644 clib_memcpy (tmpbuf + sizeof (uword), msg, size);
1645 memset (tmpbuf, 0xf, sizeof (uword));
1648 * Endian swap if needed. All msg data is supposed to be
1649 * in network byte order. All msg handlers are supposed to
1650 * know that. The generic message dumpers don't know that.
1651 * One could fix apigen, I suppose.
1653 if ((which == DUMP && clib_arch_is_little_endian) || endian_swap_needed)
1655 void (*endian_fp) (void *);
1656 if (msg_id >= vec_len (am->msg_endian_handlers)
1657 || (am->msg_endian_handlers[msg_id] == 0))
1659 vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
1660 munmap (hp, file_size);
1662 am->replay_in_progress = 0;
1665 endian_fp = am->msg_endian_handlers[msg_id];
1666 (*endian_fp) (tmpbuf + sizeof (uword));
1669 /* msg_id always in network byte order */
1670 if (clib_arch_is_little_endian)
1672 msg_idp = (u16 *) (tmpbuf + sizeof (uword));
1680 if (msg_id < vec_len (am->msg_print_handlers) &&
1681 am->msg_print_handlers[msg_id])
1683 u8 *(*print_fp) (void *, void *);
1685 print_fp = (void *) am->msg_print_handlers[msg_id];
1686 (*print_fp) (tmpbuf + sizeof (uword), vm);
1690 vlib_cli_output (vm, "Skipping msg id %d: no print fcn\n",
1697 if (msg_id < vec_len (am->msg_print_handlers) &&
1698 am->msg_print_handlers[msg_id])
1702 u8 *(*print_fp) (void *, void *);
1704 print_fp = (void *) am->msg_print_handlers[msg_id];
1706 vlib_cli_output (vm, "/*");
1708 (*print_fp) (tmpbuf + sizeof (uword), vm);
1709 vlib_cli_output (vm, "*/\n");
1711 s = format (0, "static u8 * vl_api_%s_%d[%d] = {",
1712 am->msg_names[msg_id], i,
1713 am->api_trace_cfg[msg_id].size);
1715 for (j = 0; j < am->api_trace_cfg[msg_id].size; j++)
1718 s = format (s, "\n ");
1719 s = format (s, "0x%02x,", tmpbuf[sizeof (uword) + j]);
1721 s = format (s, "\n};\n%c", 0);
1722 vlib_cli_output (vm, (char *) s);
1728 if (msg_id < vec_len (am->msg_print_handlers) &&
1729 am->msg_print_handlers[msg_id] && cfgp->replay_enable)
1731 void (*handler) (void *);
1733 handler = (void *) am->msg_handlers[msg_id];
1735 if (!am->is_mp_safe[msg_id])
1736 vl_msg_api_barrier_sync ();
1737 (*handler) (tmpbuf + sizeof (uword));
1738 if (!am->is_mp_safe[msg_id])
1739 vl_msg_api_barrier_release ();
1743 if (cfgp->replay_enable)
1744 vlib_cli_output (vm, "Skipping msg id %d: no handler\n",
1751 _vec_len (tmpbuf) = 0;
1755 if (saved_print_handlers)
1757 clib_memcpy (am->msg_print_handlers, saved_print_handlers,
1758 vec_len (am->msg_print_handlers) * sizeof (void *));
1759 vec_free (saved_print_handlers);
1762 munmap (hp, file_size);
1764 am->replay_in_progress = 0;
1767 static clib_error_t *
1768 api_trace_command_fn (vlib_main_t * vm,
1769 unformat_input_t * input, vlib_cli_command_t * cmd)
1771 u32 nitems = 256 << 10;
1772 api_main_t *am = &api_main;
1773 vl_api_trace_which_t which = VL_API_TRACE_RX;
1776 u32 last = (u32) ~ 0;
1780 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1782 if (unformat (input, "on") || unformat (input, "enable"))
1784 if (unformat (input, "nitems %d", &nitems))
1786 vl_msg_api_trace_configure (am, which, nitems);
1787 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1789 else if (unformat (input, "off"))
1791 vl_msg_api_trace_onoff (am, which, 0);
1793 else if (unformat (input, "save %s", &filename))
1795 u8 *chroot_filename;
1796 if (strstr ((char *) filename, "..")
1797 || index ((char *) filename, '/'))
1799 vlib_cli_output (vm, "illegal characters in filename '%s'",
1804 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1806 vec_free (filename);
1808 fp = fopen ((char *) chroot_filename, "w");
1811 vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
1814 rv = vl_msg_api_trace_save (am, which, fp);
1817 vlib_cli_output (vm, "API Trace data not present\n");
1819 vlib_cli_output (vm, "File for writing is closed\n");
1821 vlib_cli_output (vm, "Error while writing header to file\n");
1823 vlib_cli_output (vm, "Error while writing trace to file\n");
1825 vlib_cli_output (vm,
1826 "Error while writing end of buffer trace to file\n");
1828 vlib_cli_output (vm,
1829 "Error while writing start of buffer trace to file\n");
1831 vlib_cli_output (vm, "Unkown error while saving: %d", rv);
1833 vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
1834 vec_free (chroot_filename);
1836 else if (unformat (input, "dump %s", &filename))
1838 vl_msg_api_process_file (vm, filename, first, last, DUMP);
1840 else if (unformat (input, "custom-dump %s", &filename))
1842 vl_msg_api_process_file (vm, filename, first, last, CUSTOM_DUMP);
1844 else if (unformat (input, "replay %s", &filename))
1846 vl_msg_api_process_file (vm, filename, first, last, REPLAY);
1848 else if (unformat (input, "initializers %s", &filename))
1850 vl_msg_api_process_file (vm, filename, first, last, INITIALIZERS);
1852 else if (unformat (input, "tx"))
1854 which = VL_API_TRACE_TX;
1856 else if (unformat (input, "first %d", &first))
1860 else if (unformat (input, "last %d", &last))
1864 else if (unformat (input, "status"))
1866 vlib_cli_output (vm, "%U", format_vl_msg_api_trace_status,
1869 else if (unformat (input, "free"))
1871 vl_msg_api_trace_onoff (am, which, 0);
1872 vl_msg_api_trace_free (am, which);
1874 else if (unformat (input, "post-mortem-on"))
1875 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1876 else if (unformat (input, "post-mortem-off"))
1877 vl_msg_api_post_mortem_dump_enable_disable (0 /* enable */ );
1879 return clib_error_return (0, "unknown input `%U'",
1880 format_unformat_error, input);
1886 VLIB_CLI_COMMAND (api_trace_command, static) = {
1887 .path = "api trace",
1889 "api trace [on|off][dump|save|replay <file>][status][free][post-mortem-on]",
1890 .function = api_trace_command_fn,
1894 static clib_error_t *
1895 api_config_fn (vlib_main_t * vm, unformat_input_t * input)
1897 u32 nitems = 256 << 10;
1898 vl_api_trace_which_t which = VL_API_TRACE_RX;
1899 api_main_t *am = &api_main;
1901 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1903 if (unformat (input, "on") || unformat (input, "enable"))
1905 if (unformat (input, "nitems %d", &nitems))
1907 vl_msg_api_trace_configure (am, which, nitems);
1908 vl_msg_api_trace_onoff (am, which, 1 /* on */ );
1909 vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
1912 return clib_error_return (0, "unknown input `%U'",
1913 format_unformat_error, input);
1918 VLIB_CONFIG_FUNCTION (api_config_fn, "api-trace");
1920 static clib_error_t *
1921 api_queue_config_fn (vlib_main_t * vm, unformat_input_t * input)
1923 api_main_t *am = &api_main;
1926 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1928 if (unformat (input, "length %d", &nitems) ||
1929 (unformat (input, "len %d", &nitems)))
1932 am->vlib_input_queue_length = nitems;
1934 clib_warning ("vlib input queue length %d too small, ignored",
1938 return clib_error_return (0, "unknown input `%U'",
1939 format_unformat_error, input);
1944 VLIB_CONFIG_FUNCTION (api_queue_config_fn, "api-queue");
1947 * fd.io coding-style-patch-verification: ON
1950 * eval: (c-set-style "gnu")