26 #include <sys/types.h> 91 u16 msg_id = ntohs (*((
u16 *) msg));
119 this_trace = old_trace;
122 length = clib_net_to_host_u32 (header->
data_len);
126 *this_trace = msg_copy;
162 if (tp == 0 || tp->
nitems == 0)
193 if (!tp || tp->
nitems == 0)
212 vl_api_trace_file_header_t fh;
246 if (fwrite (&fh,
sizeof (fh), 1, fp) != 1)
272 msg_length = clib_host_to_net_u32 (vec_len (msg));
273 if (fwrite (&msg_length, 1,
sizeof (msg_length), fp)
274 !=
sizeof (msg_length))
278 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
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))
323 msg_length = clib_host_to_net_u32 (
vec_len (msg));
324 if (fwrite (&msg_length, 1,
sizeof (msg_length), fp)
325 !=
sizeof (msg_length))
381 memset (tp, 0,
sizeof (*tp));
402 void *the_msg,
int trace_it,
int do_it,
int free_it)
404 u16 id = ntohs (*((
u16 *) the_msg));
405 u8 *(*print_fp) (
void *,
void *);
418 fformat (stdout,
" [no registered print fn]\n");
422 (*print_fp) (the_msg, stdout);
445 #define ELOG_API_MESSAGE_HANDLERS 0 447 #if ELOG_API_MESSAGE_HANDLERS > 0 463 name_copy =
format (0,
"%s%c", msg_name, 0);
477 u16 id = ntohs (*((
u16 *) the_msg));
478 u8 *(*handler) (
void *,
void *,
void *);
480 #if ELOG_API_MESSAGE_HANDLERS > 0 485 .format =
"api-msg: %s",
510 (*handler) (the_msg, vm, node);
526 #if ELOG_API_MESSAGE_HANDLERS > 0 530 .format =
"api-msg-done: %s",
601 u16 id = ntohs (*((
u16 *) the_msg));
622 u16 id = ntohs (*((
u16 *) the_msg));
649 #define foreach_msg_api_vector \ 652 _(msg_cleanup_handlers) \ 653 _(msg_endian_handlers) \ 654 _(msg_print_handlers) \ 666 #define _(a) vec_validate (am->a, c->id); 689 void *endian,
void *print,
int size,
int traced)
694 memset (c, 0,
sizeof (*c));
772 __attribute__ ((weak));
782 u32 first_index,
u32 last_index,
785 vl_api_trace_file_header_t *hp;
790 u8 endian_swap_needed = 0;
794 void **saved_print_handlers = 0;
796 fd = open ((
char *) filename, O_RDONLY);
804 if (fstat (fd, &statb) < 0)
811 if (!(statb.st_mode & S_IFREG) || (statb.st_size < sizeof (*hp)))
818 file_size = statb.st_size;
819 file_size = (file_size + 4095) & ~(4096);
821 hp = mmap (0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
823 if (hp == (vl_api_trace_file_header_t *) MAP_FAILED)
833 endian_swap_needed = 1;
835 if (endian_swap_needed)
836 nitems = ntohl (hp->nitems);
840 if (last_index == (
u32) ~ 0)
842 last_index = nitems - 1;
845 if (first_index >= nitems || last_index >= nitems)
848 first_index, last_index, nitems - 1);
849 munmap (hp, file_size);
854 "Note: wrapped/incomplete trace, results may vary\n");
863 msg = (
u8 *) (hp + 1);
865 for (i = 0; i < first_index; i++)
871 size = clib_host_to_net_u32 (*(
u32 *) msg);
875 msg_id = ntohs (*((
u16 *) msg));
877 msg_id = *((
u16 *) msg);
883 munmap (hp, file_size);
889 for (; i <= last_index; i++)
899 size = clib_host_to_net_u32 (*(
u32 *) msg);
903 msg_id = ntohs (*((
u16 *) msg));
905 msg_id = *((
u16 *) msg);
911 munmap (hp, file_size);
919 memset (tmpbuf, 0xf,
sizeof (
uword));
929 void (*endian_fp) (
void *);
934 munmap (hp, file_size);
939 (*endian_fp) (tmpbuf +
sizeof (
uword));
945 msg_idp = (
u16 *) (tmpbuf +
sizeof (
uword));
956 u8 *(*print_fp) (
void *,
void *);
959 (*print_fp) (tmpbuf +
sizeof (
uword), vm);
975 u8 *(*print_fp) (
void *,
void *);
981 (*print_fp) (tmpbuf +
sizeof (
uword), vm);
984 s =
format (0,
"static u8 * vl_api_%s_%d[%d] = {",
992 s =
format (s,
"0x%02x,", tmpbuf[
sizeof (
uword) + j]);
994 s =
format (s,
"\n};\n%c", 0);
1004 void (*handler) (
void *);
1010 (*handler) (tmpbuf +
sizeof (
uword));
1024 _vec_len (tmpbuf) = 0;
1028 if (saved_print_handlers)
1035 munmap (hp, file_size);
1051 trace_name =
"TX trace";
1056 trace_name =
"RX trace";
1065 s =
format (s,
"%s: not yet configured.\n", trace_name);
1069 s =
format (s,
"%s: used %d of %d items, %s enabled, %s wrapped\n",
1081 u32 nitems = 256 << 10;
1094 if (
unformat (input,
"nitems %d", &nitems))
1103 else if (
unformat (input,
"save %s", &filename))
1105 u8 *chroot_filename;
1106 if (strstr ((
char *) filename,
"..")
1107 || index ((
char *) filename,
'/'))
1114 chroot_filename =
format (0,
"/tmp/%s%c", filename, 0);
1118 fp = fopen ((
char *) chroot_filename,
"w");
1136 "Error while writing end of buffer trace to file\n");
1139 "Error while writing start of buffer trace to file\n");
1146 else if (
unformat (input,
"dump %s", &filename))
1150 else if (
unformat (input,
"custom-dump %s", &filename))
1154 else if (
unformat (input,
"replay %s", &filename))
1158 else if (
unformat (input,
"initializers %s", &filename))
1166 else if (
unformat (input,
"first %d", &first))
1170 else if (
unformat (input,
"last %d", &last))
1174 else if (
unformat (input,
"status"))
1184 else if (
unformat (input,
"post-mortem-on"))
1186 else if (
unformat (input,
"post-mortem-off"))
1197 .path =
"api trace",
1199 "api trace [on|off][dump|save|replay <file>][status][free][post-mortem-on]",
1207 u32 nitems = 256 << 10;
1215 if (
unformat (input,
"nitems %d", &nitems))
1241 snprintf (filename,
sizeof (filename),
"/tmp/api_post_mortem.%d",
1244 fp = fopen (filename,
"w");
1247 rv = write (2,
"Couldn't create ", 16);
1248 rv = write (2, filename, strlen (filename));
1249 rv = write (2,
"\n", 1);
1256 rv = write (2,
"Failed to save post-mortem API trace to ", 40);
1257 rv = write (2, filename, strlen (filename));
1258 rv = write (2,
"\n", 1);
1271 if (msg_id_host_byte_order > 10000)
1272 clib_warning (
"msg_id_host_byte_order endian issue? %d arg vs %d",
1273 msg_id_host_byte_order,
1274 clib_net_to_host_u16 (msg_id_host_byte_order));
1283 int (*fp) (
void *, int);
1287 msg_id = clib_net_to_host_u16 (*((
u16 *) mp));
1289 msg_id = *((
u16 *) mp);
1296 rv = (*fp) (mp, rv);
1320 name_copy =
format (0,
"%s%c", name, 0);
1325 clib_warning (
"WARNING: duplicate message range registration for '%s'",
1331 if (n < 0 || n > 1024)
1334 (
"WARNING: bad number of message-IDs (%d) requested by '%s'",
1345 rp->
name = name_copy;
1363 clib_warning (
"attempt to redefine '%s' ignored...",
string);
#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)
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)
sll srl srl sll sra u16x4 i
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)
static void msg_handler_internal(api_main_t *am, void *the_msg, int trace_it, int do_it, int free_it)
static u8 post_mortem_dump_enabled
#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)
static void vl_msg_api_process_file(vlib_main_t *vm, u8 *filename, u32 first_index, u32 last_index, vl_api_replay_t which)
static heap_elt_t * last(heap_header_t *h)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static clib_error_t * api_config_fn(vlib_main_t *vm, unformat_input_t *input)
#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(** msg_cleanup_handlers)(void *)
void vl_noop_handler(void *mp)
trace_cfg_t * api_trace_cfg
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
void vl_msg_api_add_msg_name_crc(api_main_t *am, char *string, u32 id)
clib_error_t * vl_api_init(vlib_main_t *vm)
void vl_msg_api_cleanup_handler(void *the_msg)
vl_api_trace_t * rx_trace
#define VLIB_INIT_FUNCTION(x)
void vl_msg_api_config(vl_msg_api_msg_config_t *c)
void vl_msg_api_free(void *)
#define clib_arch_is_little_endian
static clib_error_t * api_trace_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define clib_warning(format, args...)
int vl_msg_api_tx_trace_enabled(api_main_t *am)
void vl_msg_api_trace_only(void *the_msg)
#define hash_create_string(elts, value_bytes)
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
void vl_msg_api_handler_with_vm_node(api_main_t *am, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node)
static heap_elt_t * first(heap_header_t *h)
int vl_msg_api_rx_trace_enabled(api_main_t *am)
void(** msg_print_handlers)(void *, void *)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define VLIB_CONFIG_FUNCTION(x, n,...)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u8 * format_vl_msg_api_trace_status(u8 *s, va_list *args)
#define clib_arch_is_big_endian
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
#define VL_API_LITTLE_ENDIAN
#define vec_free(V)
Free vector's memory (no header).
void vl_msg_api_barrier_release(void)
vl_api_msg_range_t * msg_ranges
void vl_msg_api_post_mortem_dump(void)
#define clib_memcpy(a, b, c)
#define ELOG_TYPE_DECLARE(f)
#define VLIB_CLI_COMMAND(x,...)
void vl_msg_api_socket_handler(void *the_msg)
vl_api_trace_t * tx_trace
static u32 elog_id_for_msg_name(mc_main_t *m, char *msg_name)
#define VL_API_BIG_ENDIAN
void vl_msg_api_replay_handler(void *the_msg)
void vl_msg_api_handler_no_free(void *the_msg)
void vl_msg_api_increment_missing_client_counter(void)
void vl_msg_api_register_pd_handler(void *fp, u16 msg_id_host_byte_order)
void(** msg_endian_handlers)(void *)
u32 elog_string(elog_main_t *em, char *fmt,...)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int(** pd_msg_handlers)(void *, int)
#define foreach_msg_api_vector
#define hash_get_mem(h, key)
u16 first_available_msg_id
void(** msg_handlers)(void *)
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
u16 vl_msg_api_get_msg_ids(char *name, int n)
#define clib_error_return(e, args...)
uword * msg_index_by_name_and_crc
uword * msg_range_by_name
struct _unix_shared_memory_queue unix_shared_memory_queue_t
void vl_msg_api_custom_dump_configure(api_main_t *am)
void vl_msg_api_barrier_sync(void)