84 u16 msg_id = clib_net_to_host_u16 (*((
u16 *) msg));
112 msg_copy = *old_trace;
114 this_trace = old_trace;
117 length = clib_net_to_host_u32 (header->
data_len);
121 *this_trace = msg_copy;
157 if (tp == 0 || tp->
nitems == 0)
188 if (!tp || tp->
nitems == 0)
218 serialize_likely_small_unsigned_integer (sm, hp->value[0]);
219 serialize_cstring (sm, (char *) hp->key);
230 vl_api_trace_file_header_t fh;
263 fh.msgtbl_size = clib_host_to_net_u32 (
vec_len (m));
265 if (fwrite (&fh,
sizeof (fh), 1, fp) != 1)
271 if (fwrite (m,
vec_len (m), 1, fp) != 1)
298 msg_length = clib_host_to_net_u32 (vec_len (msg));
299 if (fwrite (&msg_length, 1,
sizeof (msg_length), fp)
300 !=
sizeof (msg_length))
304 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
324 msg_length = clib_host_to_net_u32 (
vec_len (msg));
325 if (fwrite (&msg_length, 1,
sizeof (msg_length), fp)
326 !=
sizeof (msg_length))
349 msg_length = clib_host_to_net_u32 (
vec_len (msg));
350 if (fwrite (&msg_length, 1,
sizeof (msg_length), fp)
351 !=
sizeof (msg_length))
438 void *the_msg,
int trace_it,
int do_it,
int free_it)
440 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
441 u8 *(*print_fp) (
void *,
void *);
448 .format =
"api-msg: %s",
474 fformat (stdout,
" [no registered print fn]\n");
478 (*print_fp) (the_msg, stdout);
492 void (*endian_fp) (
void *);
494 (*endian_fp) (the_msg);
523 .format =
"api-msg-done(%s): %s",
524 .format_args =
"t4T4",
561 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
562 u8 *(*handler) (
void *,
void *,
void *);
563 u8 *(*print_fp) (
void *,
void *);
565 void *save_shmem_hdr;
573 .format =
"api-msg: %s",
601 fformat (stdout,
" [no registered print fn for msg %d]\n",
id);
605 (*print_fp) (the_msg,
vm);
628 void (*endian_fp) (
void *);
630 (*endian_fp) (the_msg);
635 (*handler) (the_msg,
vm,
node);
664 .format =
"api-msg-done(%s): %s",
665 .format_args =
"t4T4",
742 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
763 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
796 #define foreach_msg_api_vector \ 799 _(msg_cleanup_handlers) \ 800 _(msg_endian_handlers) \ 801 _(msg_print_handlers) \ 824 clib_warning (
"Trying to register a NULL msg with a NULL msg id!");
825 clib_warning (
"Did you forget to call setup_message_id_table?");
829 #define _(a) vec_validate (am->a, c->id); 835 (
"BUG: re-registering 'vl_api_%s_t_handler'." 836 "Handler was %llx, replaced by %llx",
859 void *endian,
void *print,
int size,
int traced)
921 data_len = clib_net_to_host_u32 (mb->
data_len);
965 snprintf (filename,
sizeof (filename),
"/tmp/api_post_mortem.%d",
968 fp = fopen (filename,
"w");
971 rv = write (2,
"Couldn't create ", 16);
972 rv = write (2, filename, strlen (filename));
973 rv = write (2,
"\n", 1);
980 rv = write (2,
"Failed to save post-mortem API trace to ", 40);
981 rv = write (2, filename, strlen (filename));
982 rv = write (2,
"\n", 1);
995 if (msg_id_host_byte_order > 10000)
996 clib_warning (
"msg_id_host_byte_order endian issue? %d arg vs %d",
997 msg_id_host_byte_order,
998 clib_net_to_host_u16 (msg_id_host_byte_order));
1007 int (*fp) (
void *, int);
1011 msg_id = clib_net_to_host_u16 (*((
u16 *) mp));
1013 msg_id = *((
u16 *) mp);
1020 rv = (*fp) (mp, rv);
1044 name_copy =
format (0,
"%s%c", name, 0);
1049 clib_warning (
"WARNING: duplicate message range registration for '%s'",
1055 if (n < 0 || n > 1024)
1058 (
"WARNING: bad number of message-IDs (%d) requested by '%s'",
1069 rp->
name = name_copy;
1087 clib_warning (
"attempt to redefine '%s' ignored...",
string);
1099 ASSERT (strlen (
string) < 64);
1100 strncpy (version.
name,
string, 64 - 1);
1122 pthread_mutex_lock (&vlib_rp->
mutex);
1137 pthread_mutex_unlock (&vlib_rp->
mutex);
1155 str->
length = htonl (len);
1156 return len +
sizeof (
u32);
1165 str->
length = htonl (len);
1166 return len +
sizeof (
u32);
1172 return clib_net_to_host_u32 (astr->
length);
1193 return format (0,
"insane astr->length %u%c",
1194 clib_net_to_host_u32 (astr->
length), 0);
1207 if (clib_net_to_host_u32 (astr->
length) > 0)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
Message range (belonging to a plugin)
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
void vl_msg_api_set_handlers(int id, char *name, void *handler, void *cleanup, void *endian, void *print, int size, int traced)
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
u8 * name
name of the plugin
static void svm_pop_heap(void *oldheap)
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
int vl_msg_api_pd_handler(void *mp, int rv)
void vl_msg_api_handler(void *the_msg)
void * print
message print function
u8 wrapped
trace has wrapped
Optimized string handling code, including c11-compliant "safe C library" variants.
int size
for sanity checking
#define clib_memcpy_fast(a, b, c)
static void msg_handler_internal(api_main_t *am, void *the_msg, int trace_it, int do_it, int free_it)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u8 * message_bounce
Don't automatically free message buffer vetor.
static u8 post_mortem_dump_enabled
Message configuration definition.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
u32 vl_msg_api_get_msg_length(void *msg_arg)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
api_version_t * api_version_list
api version list
#define hash_set_mem(h, key, value)
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
void vl_msg_api_set_global_main(void *am_arg)
#define vl_msg_api_barrier_trace_context(X)
void(** msg_cleanup_handlers)(void *)
non-default message cleanup handler vector
void vl_noop_handler(void *mp)
void * cleanup
non-default message cleanup handler
trace_cfg_t * api_trace_cfg
Current trace configuration.
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define clib_memcpy(d, s, n)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
void vl_msg_api_cleanup_handler(void *the_msg)
void * endian
message endian function
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
vl_api_trace_t * rx_trace
Received message trace configuration.
static void * svm_push_data_heap(svm_region_t *rp)
Callback multiplex scheme For a fully worked-out example, see .../src/vlib/main.
void vl_msg_api_config(vl_msg_api_msg_config_t *c)
void(* vl_msg_api_fuzz_hook)(u16, void *)
void vl_msg_api_post_mortem_dump_enable_disable(int enable)
#define clib_arch_is_little_endian
svm_region_t * vlib_rp
Current binary api segment descriptor.
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
#define VL_API_BIG_ENDIAN
int vl_msg_api_tx_trace_enabled(api_main_t *am)
void vl_msg_api_trace_only(void *the_msg)
void vl_msg_api_clean_handlers(int msg_id)
#define hash_create_string(elts, value_bytes)
u16 last_msg_id
last assigned message ID
int vl_api_get_elog_trace_api_messages(void)
int elog_trace_api_messages
void vl_msg_pop_heap_w_region(svm_region_t *vlib_rp, void *oldheap)
void(** perf_counter_cbs)(struct api_main_t *, u32 id, int before_or_after)
performance counter callback
void vl_msg_api_add_msg_name_crc(api_main_t *am, const char *string, u32 id)
int vl_msg_api_rx_trace_enabled(api_main_t *am)
void(** msg_print_handlers)(void *, void *)
Message print function vector.
int replay_enable
This message can be replayed.
int message_bounce
do not free message after processing
u32 curindex
Current index in circular buffer.
static void cleanup(void)
u32 vl_api_string_len(vl_api_string_t *astr)
u32 vl_msg_api_max_length(void *mp)
elog_main_t * elog_main
event log
API main structure, used by both vpp and binary API clients.
u8 enabled
trace is enabled
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define clib_arch_is_big_endian
void vl_msg_api_handler_with_vm_node(api_main_t *am, svm_region_t *vlib_rp, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node, u8 is_private)
void serialize_open_vector(serialize_main_t *m, u8 *vector)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
void vl_msg_api_barrier_release(void)
vl_api_msg_range_t * msg_ranges
vector of message ranges
void vl_msg_api_post_mortem_dump(void)
#define clib_warning(format, args...)
int vl_api_set_elog_trace_api_messages(int enable)
char * vl_api_from_api_to_new_c_string(vl_api_string_t *astr)
u8 * is_autoendian
Message requires us to do endian conversion.
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
blocking call - best used in combination with condvars, for eventfds we don't yield the cpu ...
#define ELOG_TYPE_DECLARE(f)
const char ** msg_names
Message name vector.
vlib_main_t vlib_node_runtime_t * node
int replay
is this message to be replayed?
void vl_msg_api_socket_handler(void *the_msg)
vl_api_trace_t * tx_trace
Sent message trace configuration.
static uword hash_elts(void *v)
int vl_api_c_string_to_api_string(const char *buf, vl_api_string_t *str)
__thread api_main_t * my_api_main
int is_autoendian
endian conversion required?
api_main_t api_global_main
u32 data_len
message length not including header
Message header structure.
vl_api_trace_which_t
Trace RX / TX enum.
u8 * vl_api_serialize_message_table(api_main_t *am, u8 *vector)
void vl_msg_api_replay_handler(void *the_msg)
void vl_msg_api_add_version(api_main_t *am, const char *string, u32 major, u32 minor, u32 patch)
void vl_msg_api_handler_no_free(void *the_msg)
void vl_msg_api_free(void *)
void vl_api_set_elog_main(elog_main_t *m)
u32 missing_clients
Number of missing clients / failed message sends.
void * vl_msg_push_heap(void)
u32 vl_msg_api_get_msg_index(u8 *name_and_crc)
void vl_msg_api_increment_missing_client_counter(void)
u16 first_msg_id
first assigned message ID
void vl_msg_api_register_pd_handler(void *fp, u16 msg_id_host_byte_order)
void(** msg_endian_handlers)(void *)
Message endian handler vector.
u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
static u32 vl_msg_api_get_msg_length_inline(void *msg_arg)
int(** pd_msg_handlers)(void *, int)
Plaform-dependent (aka hardware) message handler vector.
#define foreach_msg_api_vector
struct _svm_queue svm_queue_t
#define hash_get_mem(h, key)
u16 vl_msg_api_get_msg_ids(const char *name, int n)
u16 first_available_msg_id
First available message ID, for theplugin msg allocator.
static api_main_t * vlibapi_get_main(void)
void vl_msg_pop_heap(void *oldheap)
u8 * vl_api_format_string(u8 *s, va_list *args)
u8 endian
trace endianness
void(** msg_handlers)(void *)
Message handler vector.
#define clib_call_callbacks(h,...)
call the specified callback set
u8 * is_mp_safe
Message is mp safe vector.
void vl_msg_api_queue_handler(svm_queue_t *q)
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
int trace_enable
trace this message
int msg_print_flag
Print every received message.
void * serialize_close_vector(serialize_main_t *m)
int is_mp_safe
worker thread barrier required?
int traced
is this message to be traced?
const char * region_name
Shared VM binary API region name.
void * vl_msg_push_heap_w_region(svm_region_t *vlib_rp)
Trace configuration for a single message.
#define VL_API_LITTLE_ENDIAN
uword * msg_index_by_name_and_crc
client message index hash table
uword * msg_range_by_name
Message range by name hash.
char * name
the message name
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
u32 nitems
Number of trace records.
int vl_api_vec_to_api_string(const u8 *vec, vl_api_string_t *str)
void * handler
the message handler
void vl_msg_api_barrier_sync(void)