}
}
-int vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
- __attribute__ ((weak));
-
-int
-vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
+u8 *
+vl_api_serialize_message_table (api_main_t * am, u8 * vector)
{
- return 0;
+ serialize_main_t _sm, *sm = &_sm;
+ hash_pair_t *hp;
+ u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
+
+ serialize_open_vector (sm, vector);
+
+ /* serialize the count */
+ serialize_integer (sm, nmsg, sizeof (u32));
+
+ hash_foreach_pair (hp, am->msg_index_by_name_and_crc, (
+ {
+ serialize_likely_small_unsigned_integer
+ (sm, hp->value[0]);
+ serialize_cstring
+ (sm,
+ (char *) hp->key);
+ }));
+
+ return serialize_close_vector (sm);
}
/*
vl_api_memclnt_create_reply_t *rp;
svm_region_t *svm;
unix_shared_memory_queue_t *q;
- int rv;
+ int rv = 0;
void *oldheap;
api_main_t *am = &api_main;
-
- /* Indicate API version mismatch if appropriate */
- rv = vl_msg_api_version_check (mp);
+ u8 *serialized_message_table = 0;
/*
* This is tortured. Maintain a vlib-address-space private
svm = am->vlib_rp;
+ if (am->serialized_message_table_in_shmem == 0)
+ serialized_message_table = vl_api_serialize_message_table (am, 0);
+
pthread_mutex_lock (&svm->mutex);
oldheap = svm_push_data_heap (svm);
*regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
regp->name = format (0, "%s", mp->name);
vec_add1 (regp->name, 0);
+ if (serialized_message_table)
+ am->serialized_message_table_in_shmem =
+ vec_dup (serialized_message_table);
pthread_mutex_unlock (&svm->mutex);
svm_pop_heap (oldheap);
+ vec_free (serialized_message_table);
+
rp = vl_msg_api_alloc (sizeof (*rp));
rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
rp->handle = (uword) regp;
am->shmem_hdr->application_restarts);
rp->context = mp->context;
rp->response = ntohl (rv);
+ rp->message_table = (u64) am->serialized_message_table_in_shmem;
vl_msg_api_send_shmem (q, (u8 *) & rp);
}
};
/* *INDENT-ON* */
-void
-vl_api_trace_print_file_cmd (vlib_main_t * vm, u32 first, u32 last,
- u8 * filename)
-{
- FILE *fp;
- static vl_api_trace_t *tp = 0;
- int endian_swap = 0;
- u32 i;
- u16 msg_id;
- static u8 *msg_buf = 0;
- void (*endian_fp) (void *);
- u8 *(*print_fp) (void *, void *);
- int size;
- api_main_t *am = &api_main;
-
- /*
- * On-demand: allocate enough space for the largest message
- */
- if (msg_buf == 0)
- {
- vec_validate (tp, 0);
- int max_size = 0;
- for (i = 0; i < vec_len (am->api_trace_cfg); i++)
- {
- if (am->api_trace_cfg[i].size > max_size)
- max_size = am->api_trace_cfg[i].size;
- }
- /* round size to a multiple of the cache-line size */
- max_size = (max_size + (CLIB_CACHE_LINE_BYTES - 1)) &
- (~(CLIB_CACHE_LINE_BYTES - 1));
- vec_validate (msg_buf, max_size - 1);
- }
-
- fp = fopen ((char *) filename, "r");
-
- if (fp == NULL)
- {
- vlib_cli_output (vm, "Couldn't open %s\n", filename);
- return;
- }
-
- /* first, fish the header record from the file */
-
- if (fread (tp, sizeof (*tp), 1, fp) != 1)
- {
- fclose (fp);
- vlib_cli_output (vm, "Header read error\n");
- return;
- }
-
- /* Endian swap required? */
- if (clib_arch_is_big_endian != tp->endian)
- {
- endian_swap = 1;
- }
-
- for (i = 0; i <= last; i++)
- {
- /* First 2 bytes are the message type */
- if (fread (&msg_id, sizeof (u16), 1, fp) != 1)
- {
- break;
- }
- msg_id = ntohs (msg_id);
-
- if (fseek (fp, -2, SEEK_CUR) < 0)
- {
- vlib_cli_output (vm, "fseek failed, %s", strerror (errno));
- fclose (fp);
- return;
- }
-
- /* Mild sanity check */
- if (msg_id >= vec_len (am->msg_handlers))
- {
- fclose (fp);
- vlib_cli_output (vm, "msg_id %d out of bounds\n", msg_id);
- return;
- }
-
- size = am->api_trace_cfg[msg_id].size;
-
- if (fread (msg_buf, size, 1, fp) != 1)
- {
- fclose (fp);
- vlib_cli_output (vm, "read error on %s\n", filename);
- return;
- }
-
- if (i < first)
- continue;
-
- if (endian_swap)
- {
- endian_fp = am->msg_endian_handlers[msg_id];
- (*endian_fp) (msg_buf);
- }
-
- vlib_cli_output (vm, "[%d]: %s\n", i, am->msg_names[msg_id]);
-
- print_fp = (void *) am->msg_print_handlers[msg_id];
- (*print_fp) (msg_buf, vm);
- vlib_cli_output (vm, "-------------\n");
- }
- fclose (fp);
-}
-
static clib_error_t *
vl_api_trace_command (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cli_cmd)
{
u32 nitems = 1024;
vl_api_trace_which_t which = VL_API_TRACE_RX;
- u8 *filename;
- u32 first = 0;
- u32 last = ~0;
api_main_t *am = &api_main;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
vl_msg_api_trace_free (am, VL_API_TRACE_RX);
vl_msg_api_trace_free (am, VL_API_TRACE_TX);
}
- else if (unformat (input, "print %s from %d to %d", &filename,
- &first, &last)
- || unformat (input, "print %s", &filename))
- {
- goto print;
- }
else if (unformat (input, "debug on"))
{
am->msg_print_flag = 1;
}
return 0;
-print:
- vl_api_trace_print_file_cmd (vm, first, last, filename);
- goto out;
-
configure:
if (vl_msg_api_trace_configure (am, which, nitems))
{
which, nitems);
}
-out:
return 0;
}