|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
58 am->missing_clients++;
64 return (
am->rx_trace &&
am->rx_trace->enabled);
70 return (
am->tx_trace &&
am->tx_trace->enabled);
84 u16 msg_id = clib_net_to_host_u16 (*((
u16 *) msg));
87 cfgp =
am->api_trace_cfg + msg_id;
112 msg_copy = *old_trace;
114 this_trace = old_trace;
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))
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",
457 if (
id <
vec_len (
am->msg_names) &&
am->msg_names[
id])
463 if (
id <
vec_len (
am->msg_handlers) &&
am->msg_handlers[
id])
468 if (
am->msg_print_flag)
470 fformat (stdout,
"[%d]: %s\n",
id,
am->msg_names[
id]);
471 print_fp = (
void *)
am->msg_print_handlers[
id];
474 fformat (stdout,
" [no registered print fn]\n");
478 (*print_fp) (the_msg, stdout);
484 if (!
am->is_mp_safe[
id])
490 if (
am->is_autoendian[
id])
492 void (*endian_fp) (
void *);
493 endian_fp =
am->msg_endian_handlers[
id];
494 (*endian_fp) (the_msg);
501 (*
am->msg_handlers[
id]) (the_msg);
506 if (!
am->is_mp_safe[
id])
523 .format =
"api-msg-done(%s): %s",
524 .format_args =
"t4T4",
540 if (
id <
vec_len (
am->msg_names) &&
am->msg_names[
id])
543 ed->barrier = !
am->is_mp_safe[
id];
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",
582 if (
id <
vec_len (
am->msg_names) &&
am->msg_names[
id])
588 if (
id <
vec_len (
am->msg_handlers) &&
am->msg_handlers[
id])
590 handler = (
void *)
am->msg_handlers[
id];
597 fformat (stdout,
"[%d]: %s\n",
id,
am->msg_names[
id]);
598 print_fp = (
void *)
am->msg_print_handlers[
id];
601 fformat (stdout,
" [no registered print fn for msg %d]\n",
id);
605 (*print_fp) (the_msg,
vm);
617 old_vlib_rp =
am->vlib_rp;
618 save_shmem_hdr =
am->shmem_hdr;
626 if (
am->is_autoendian[
id])
628 void (*endian_fp) (
void *);
629 endian_fp =
am->msg_endian_handlers[
id];
630 (*endian_fp) (the_msg);
635 (*handler) (the_msg,
vm,
node);
641 am->vlib_rp = old_vlib_rp;
642 am->shmem_hdr = save_shmem_hdr;
656 if (
id >=
vec_len (
am->message_bounce) || !(
am->message_bounce[
id]))
660 old_vlib_rp =
am->vlib_rp;
661 save_shmem_hdr =
am->shmem_hdr;
668 am->vlib_rp = old_vlib_rp;
669 am->shmem_hdr = save_shmem_hdr;
678 .format =
"api-msg-done(%s): %s",
679 .format_args =
"t4T4",
695 if (
id <
vec_len (
am->msg_names) &&
am->msg_names[
id])
710 &&
am->rx_trace->enabled) ,
720 &&
am->rx_trace->enabled) ,
748 &&
am->rx_trace->enabled) ,
756 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
763 if (
am->msg_cleanup_handlers[
id])
764 (*
am->msg_cleanup_handlers[
id]) (the_msg);
777 u16 id = clib_net_to_host_u16 (*((
u16 *) the_msg));
785 if (
am->msg_handlers[
id])
786 (*
am->msg_handlers[
id]) (the_msg);
806 &&
am->rx_trace->enabled) ,
810 #define foreach_msg_api_vector \
813 _(msg_cleanup_handlers) \
814 _(msg_endian_handlers) \
815 _(msg_print_handlers) \
836 clib_warning (
"Trying to register %s with a NULL msg id!",
c->name);
838 clib_warning (
"Trying to register a NULL msg with a NULL msg id!");
839 clib_warning (
"Did you forget to call setup_message_id_table?");
843 #define _(a) vec_validate (am->a, c->id);
847 if (
am->msg_handlers[
c->id] &&
am->msg_handlers[
c->id] !=
c->handler)
849 (
"BUG: re-registering 'vl_api_%s_t_handler'."
850 "Handler was %llx, replaced by %llx",
851 c->name,
am->msg_handlers[
c->id],
c->handler);
853 am->msg_names[
c->id] =
c->name;
854 am->msg_handlers[
c->id] =
c->handler;
855 am->msg_cleanup_handlers[
c->id] =
c->cleanup;
856 am->msg_endian_handlers[
c->id] =
c->endian;
857 am->msg_print_handlers[
c->id] =
c->print;
858 am->message_bounce[
c->id] =
c->message_bounce;
859 am->is_mp_safe[
c->id] =
c->is_mp_safe;
860 am->is_autoendian[
c->id] =
c->is_autoendian;
862 am->api_trace_cfg[
c->id].size =
c->size;
863 am->api_trace_cfg[
c->id].trace_enable =
c->traced;
864 am->api_trace_cfg[
c->id].replay_enable =
c->replay;
873 void *endian,
void *
print,
int size,
int traced)
882 c->handler = handler;
888 c->message_bounce = 0;
890 c->is_autoendian = 0;
913 am->msg_cleanup_handlers[msg_id] = fp;
979 snprintf (filename,
sizeof (filename),
"/tmp/api_post_mortem.%d",
982 fp = fopen (filename,
"w");
985 rv = write (2,
"Couldn't create ", 16);
986 rv = write (2, filename, strlen (filename));
987 rv = write (2,
"\n", 1);
994 rv = write (2,
"Failed to save post-mortem API trace to ", 40);
995 rv = write (2, filename, strlen (filename));
996 rv = write (2,
"\n", 1);
1009 if (msg_id_host_byte_order > 10000)
1010 clib_warning (
"msg_id_host_byte_order endian issue? %d arg vs %d",
1011 msg_id_host_byte_order,
1012 clib_net_to_host_u16 (msg_id_host_byte_order));
1014 am->pd_msg_handlers[msg_id_host_byte_order] = fp;
1021 int (*fp) (
void *, int);
1025 msg_id = clib_net_to_host_u16 (*((
u16 *) mp));
1027 msg_id = *((
u16 *) mp);
1029 if (msg_id >=
vec_len (
am->pd_msg_handlers)
1030 ||
am->pd_msg_handlers[msg_id] == 0)
1033 fp =
am->pd_msg_handlers[msg_id];
1034 rv = (*fp) (mp,
rv);
1043 am->first_available_msg_id = first_avail;
1055 if (
am->msg_range_by_name == 0)
1063 clib_warning (
"WARNING: duplicate message range registration for '%s'",
1069 if (n < 0 || n > 1024)
1072 (
"WARNING: bad number of message-IDs (%d) requested by '%s'",
1081 am->first_available_msg_id += n;
1083 rp->
name = name_copy;
1095 if (
am->msg_index_by_name_and_crc == 0)
1101 clib_warning (
"attempt to redefine '%s' ignored...",
string);
1113 ASSERT (strlen (
string) < 64);
1114 strncpy (
version.name,
string, 64 - 1);
1124 if (
am->msg_index_by_name_and_crc)
1170 return len +
sizeof (
u32);
1180 return len +
sizeof (
u32);
1186 return clib_net_to_host_u32 (astr->
length);
1193 vec_add (s,
a->buf, clib_net_to_host_u32 (
a->length));
1207 return format (0,
"insane astr->length %u%c",
1208 clib_net_to_host_u32 (astr->
length), 0);
1221 if (clib_net_to_host_u32 (astr->
length) > 0)
1242 rv =
am->elog_trace_api_messages;
1243 am->elog_trace_api_messages = enable;
1252 return am->elog_trace_api_messages;
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
void * vl_msg_push_heap_w_region(svm_region_t *vlib_rp)
void vl_msg_api_replay_handler(void *the_msg)
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static u32 vl_msg_api_get_msg_length_inline(void *msg_arg)
#define clib_memcpy(d, s, n)
u8 * name
name of the plugin
#define VL_API_LITTLE_ENDIAN
#define VL_API_BIG_ENDIAN
vlib_main_t vlib_node_runtime_t * node
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
struct _svm_queue svm_queue_t
#define clib_arch_is_big_endian
Message configuration definition.
void vl_msg_api_set_handlers(int id, char *name, void *handler, void *cleanup, void *endian, void *print, int size, int traced)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
u32 data_len
message length not including header
#define hash_create_string(elts, value_bytes)
vl_api_trace_which_t
Trace RX / TX enum.
__clib_export u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
void vl_msg_api_post_mortem_dump_enable_disable(int enable)
u16 last_msg_id
last assigned message ID
void vl_msg_api_set_global_main(void *am_arg)
__clib_export void serialize_open_vector(serialize_main_t *m, u8 *vector)
int vl_api_get_elog_trace_api_messages(void)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
void vl_msg_api_socket_handler(void *the_msg)
Callback multiplex scheme For a fully worked-out example, see .../src/vlib/main.[ch] and ....
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
void vl_api_set_elog_main(elog_main_t *m)
int vl_msg_api_rx_trace_enabled(api_main_t *am)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
u16 vl_msg_api_get_msg_ids(const char *name, int n)
u8 enabled
trace is enabled
static void msg_handler_internal(api_main_t *am, void *the_msg, int trace_it, int do_it, int free_it)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Trace configuration for a single message.
#define ELOG_TYPE_DECLARE(f)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
void vl_msg_api_add_version(api_main_t *am, const char *string, u32 major, u32 minor, u32 patch)
static u8 post_mortem_dump_enabled
const char * region_name
Shared VM binary API region name.
u8 endian
trace endianness
void vl_msg_api_barrier_sync(void)
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
void vl_msg_pop_heap_w_region(svm_region_t *vlib_rp, void *oldheap)
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
void vl_msg_api_clean_handlers(int msg_id)
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
static void svm_pop_heap(void *oldheap)
#define hash_set_mem(h, key, value)
static api_main_t * vlibapi_get_main(void)
sll srl srl sll sra u16x4 i
void vl_msg_api_register_pd_handler(void *fp, u16 msg_id_host_byte_order)
void vl_msg_api_trace_only(void *the_msg)
u8 * vl_api_serialize_message_table(api_main_t *am, u8 *vector)
void vl_msg_api_handler(void *the_msg)
void(* vl_msg_api_fuzz_hook)(u16, void *)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
u32 curindex
Current index in circular buffer
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
void vl_msg_api_post_mortem_dump(void)
void * vl_msg_push_heap(void)
#define foreach_msg_api_vector
void vl_msg_api_queue_handler(svm_queue_t *q)
u32 vl_api_string_len(vl_api_string_t *astr)
u8 * vl_api_format_string(u8 *s, va_list *args)
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
void vl_msg_api_add_msg_name_crc(api_main_t *am, const char *string, u32 id)
void vl_msg_api_barrier_release(void)
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
void vl_msg_api_handler_no_free(void *the_msg)
API main structure, used by both vpp and binary API clients.
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
static uword hash_elts(void *v)
int vl_api_set_elog_trace_api_messages(int enable)
int vl_api_c_string_to_api_string(const char *buf, vl_api_string_t *str)
#define vec_free(V)
Free vector's memory (no header).
svm_region_t * vlib_rp
Current binary api segment descriptor.
u32 nitems
Number of trace records.
void vl_noop_handler(void *mp)
void vl_msg_api_free(void *)
#define hash_get_mem(h, key)
int vl_api_vec_to_api_string(const u8 *vec, vl_api_string_t *str)
u8 wrapped
trace has wrapped
#define clib_call_callbacks(h,...)
call the specified callback set
description fragment has unexpected format
void vl_msg_pop_heap(void *oldheap)
__clib_export void * serialize_close_vector(serialize_main_t *m)
#define vl_msg_api_barrier_trace_context(X)
api_main_t api_global_main
int vl_msg_api_tx_trace_enabled(api_main_t *am)
Message range (belonging to a plugin)
int trace_enable
trace this message
void vl_msg_api_increment_missing_client_counter(void)
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)
u16 first_msg_id
first assigned message ID
Message header structure.
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
#define clib_arch_is_little_endian
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
int vl_msg_api_pd_handler(void *mp, int rv)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 vl_msg_api_get_msg_index(u8 *name_and_crc)
__thread api_main_t * my_api_main
#define clib_warning(format, args...)
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
static void cleanup(void)
@ SVM_Q_WAIT
blocking call - best used in combination with condvars, for eventfds we don't yield the cpu
void vl_msg_api_config(vl_msg_api_msg_config_t *c)
u32 vl_msg_api_max_length(void *mp)
static void * svm_push_data_heap(svm_region_t *rp)
char * vl_api_from_api_to_new_c_string(vl_api_string_t *astr)
u8 * is_mp_safe
Message is mp safe vector.
u32 vl_msg_api_get_msg_length(void *msg_arg)
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
void vl_msg_api_cleanup_handler(void *the_msg)