- u32 nitems = 256 << 10;
- api_main_t *am = &api_main;
- vl_api_trace_which_t which = VL_API_TRACE_RX;
- u8 *filename;
- u32 first = 0;
- u32 last = (u32) ~ 0;
- FILE *fp;
- int rv;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "on") || unformat (input, "enable"))
- {
- if (unformat (input, "nitems %d", &nitems))
- ;
- vl_msg_api_trace_configure (am, which, nitems);
- vl_msg_api_trace_onoff (am, which, 1 /* on */ );
- }
- else if (unformat (input, "off"))
- {
- vl_msg_api_trace_onoff (am, which, 0);
- }
- else if (unformat (input, "save %s", &filename))
- {
- u8 *chroot_filename;
- if (strstr ((char *) filename, "..")
- || index ((char *) filename, '/'))
- {
- vlib_cli_output (vm, "illegal characters in filename '%s'",
- filename);
- return 0;
- }
-
- chroot_filename = format (0, "/tmp/%s%c", filename, 0);
-
- vec_free (filename);
-
- fp = fopen ((char *) chroot_filename, "w");
- if (fp == NULL)
- {
- vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
- return 0;
- }
- rv = vl_msg_api_trace_save (am, which, fp);
- fclose (fp);
- if (rv == -1)
- vlib_cli_output (vm, "API Trace data not present\n");
- else if (rv == -2)
- vlib_cli_output (vm, "File for writing is closed\n");
- else if (rv == -10)
- vlib_cli_output (vm, "Error while writing header to file\n");
- else if (rv == -11)
- vlib_cli_output (vm, "Error while writing trace to file\n");
- else if (rv == -12)
- vlib_cli_output (vm,
- "Error while writing end of buffer trace to file\n");
- else if (rv == -13)
- vlib_cli_output (vm,
- "Error while writing start of buffer trace to file\n");
- else if (rv < 0)
- vlib_cli_output (vm, "Unkown error while saving: %d", rv);
- else
- vlib_cli_output (vm, "API trace saved to %s\n", chroot_filename);
- vec_free (chroot_filename);
- }
- else if (unformat (input, "dump %s", &filename))
- {
- vl_msg_api_process_file (vm, filename, first, last, DUMP);
- }
- else if (unformat (input, "custom-dump %s", &filename))
- {
- vl_msg_api_process_file (vm, filename, first, last, CUSTOM_DUMP);
- }
- else if (unformat (input, "replay %s", &filename))
- {
- vl_msg_api_process_file (vm, filename, first, last, REPLAY);
- }
- else if (unformat (input, "initializers %s", &filename))
- {
- vl_msg_api_process_file (vm, filename, first, last, INITIALIZERS);
- }
- else if (unformat (input, "tx"))
- {
- which = VL_API_TRACE_TX;
- }
- else if (unformat (input, "first %d", &first))
- {
- ;
- }
- else if (unformat (input, "last %d", &last))
- {
- ;
- }
- else if (unformat (input, "status"))
- {
- vlib_cli_output (vm, "%U", format_vl_msg_api_trace_status,
- am, which);
- }
- else if (unformat (input, "free"))
- {
- vl_msg_api_trace_onoff (am, which, 0);
- vl_msg_api_trace_free (am, which);
- }
- else if (unformat (input, "post-mortem-on"))
- post_mortem_dump_enabled = 1;
- else if (unformat (input, "post-mortem-off"))
- post_mortem_dump_enabled = 0;
- else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- }
- return 0;