+static clib_error_t *
+api_queue_config_fn (vlib_main_t * vm, unformat_input_t * input)
+{
+ api_main_t *am = &api_main;
+ u32 nitems;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "length %d", &nitems) ||
+ (unformat (input, "len %d", &nitems)))
+ {
+ if (nitems >= 1024)
+ am->vlib_input_queue_length = nitems;
+ else
+ clib_warning ("vlib input queue length %d too small, ignored",
+ nitems);
+ }
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
+ return 0;
+}
+
+VLIB_CONFIG_FUNCTION (api_queue_config_fn, "api-queue");
+
+static u8 *
+extract_name (u8 * s)
+{
+ u8 *rv;
+
+ rv = vec_dup (s);
+
+ while (vec_len (rv) && rv[vec_len (rv)] != '_')
+ _vec_len (rv)--;
+
+ rv[vec_len (rv)] = 0;
+
+ return rv;
+}
+
+static u8 *
+extract_crc (u8 * s)
+{
+ int i;
+ u8 *rv;
+
+ rv = vec_dup (s);
+
+ for (i = vec_len (rv) - 1; i >= 0; i--)
+ {
+ if (rv[i] == '_')
+ {
+ vec_delete (rv, i + 1, 0);
+ break;
+ }
+ }
+ return rv;
+}
+
+typedef struct
+{
+ u8 *name_and_crc;
+ u8 *name;
+ u8 *crc;
+ u32 msg_index;
+ int which;
+} msg_table_unserialize_t;
+
+static int
+table_id_cmp (void *a1, void *a2)
+{
+ msg_table_unserialize_t *n1 = a1;
+ msg_table_unserialize_t *n2 = a2;
+
+ return (n1->msg_index - n2->msg_index);
+}
+
+static int
+table_name_and_crc_cmp (void *a1, void *a2)
+{
+ msg_table_unserialize_t *n1 = a1;
+ msg_table_unserialize_t *n2 = a2;
+
+ return strcmp ((char *) n1->name_and_crc, (char *) n2->name_and_crc);
+}
+
+static clib_error_t *
+dump_api_table_file_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ u8 *filename = 0;
+ api_main_t *am = &api_main;
+ serialize_main_t _sm, *sm = &_sm;
+ clib_error_t *error;
+ u32 nmsgs;
+ u32 msg_index;
+ u8 *name_and_crc;
+ int compare_current = 0;
+ int numeric_sort = 0;
+ msg_table_unserialize_t *table = 0, *item;
+ u32 i;
+ u32 ndifferences = 0;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "file %s", &filename))
+ ;
+ else if (unformat (input, "compare-current")
+ || unformat (input, "compare"))
+ compare_current = 1;
+ else if (unformat (input, "numeric"))
+ numeric_sort = 1;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
+
+ if (numeric_sort && compare_current)
+ return clib_error_return
+ (0, "Comparison and numeric sorting are incompatible");
+
+ if (filename == 0)
+ return clib_error_return (0, "File not specified");
+
+ /* Load the serialized message table from the table dump */
+
+ error = unserialize_open_clib_file (sm, (char *) filename);
+
+ if (error)
+ return error;
+
+ unserialize_integer (sm, &nmsgs, sizeof (u32));
+
+ for (i = 0; i < nmsgs; i++)
+ {
+ msg_index = unserialize_likely_small_unsigned_integer (sm);
+ unserialize_cstring (sm, (char **) &name_and_crc);
+ vec_add2 (table, item, 1);
+ item->msg_index = msg_index;
+ item->name_and_crc = name_and_crc;
+ item->name = extract_name (name_and_crc);
+ item->crc = extract_crc (name_and_crc);
+ item->which = 0; /* file */
+ }
+ serialize_close (sm);
+
+ /* Compare with the current image? */
+ if (compare_current)
+ {
+ /* Append the current message table */
+ u8 *tblv = vl_api_serialize_message_table (am, 0);
+
+ serialize_open_vector (sm, tblv);
+ unserialize_integer (sm, &nmsgs, sizeof (u32));
+
+ for (i = 0; i < nmsgs; i++)
+ {
+ msg_index = unserialize_likely_small_unsigned_integer (sm);
+ unserialize_cstring (sm, (char **) &name_and_crc);
+
+ vec_add2 (table, item, 1);
+ item->msg_index = msg_index;
+ item->name_and_crc = name_and_crc;
+ item->name = extract_name (name_and_crc);
+ item->crc = extract_crc (name_and_crc);
+ item->which = 1; /* current_image */
+ }
+ vec_free (tblv);
+ }
+
+ /* Sort the table. */
+ if (numeric_sort)
+ vec_sort_with_function (table, table_id_cmp);
+ else
+ vec_sort_with_function (table, table_name_and_crc_cmp);
+
+ if (compare_current)
+ {
+ ndifferences = 0;
+
+ /*
+ * In this case, the recovered table will have two entries per
+ * API message. So, if entries i and i+1 match, the message definitions
+ * are identical. Otherwise, the crc is different, or a message is
+ * present in only one of the tables.
+ */
+ vlib_cli_output (vm, "%=60s %s", "Message Name", "Result");
+
+ for (i = 0; i < vec_len (table);)
+ {
+ /* Last message lonely? */
+ if (i == vec_len (table) - 1)
+ {
+ ndifferences++;
+ goto last_unique;
+ }
+
+ /* Identical pair? */
+ if (!strncmp
+ ((char *) table[i].name_and_crc,
+ (char *) table[i + 1].name_and_crc,
+ vec_len (table[i].name_and_crc)))
+ {
+ i += 2;
+ continue;
+ }
+
+ ndifferences++;
+
+ /* Only in one of two tables? */
+ if (strncmp ((char *) table[i].name, (char *) table[i + 1].name,
+ vec_len (table[i].name)))
+ {
+ last_unique:
+ vlib_cli_output (vm, "%-60s only in %s",
+ table[i].name, table[i].which ?
+ "image" : "file");
+ i++;
+ continue;
+ }
+ /* In both tables, but with different signatures */
+ vlib_cli_output (vm, "%-60s definition changed", table[i].name);
+ i += 2;
+ }
+ if (ndifferences == 0)
+ vlib_cli_output (vm, "No api message signature differences found.");
+ else
+ vlib_cli_output (vm, "Found %u api message signature differences",
+ ndifferences);
+ goto cleanup;
+ }
+
+ /* Dump the table, sorted as shown above */
+ vlib_cli_output (vm, "%=60s %=8s %=10s", "Message name", "MsgID", "CRC");
+
+ for (i = 0; i < vec_len (table); i++)
+ {
+ item = table + i;
+ vlib_cli_output (vm, "%-60s %8u %10s", item->name,
+ item->msg_index, item->crc);
+ }
+
+cleanup:
+ for (i = 0; i < vec_len (table); i++)
+ {
+ vec_free (table[i].name_and_crc);
+ vec_free (table[i].name);
+ vec_free (table[i].crc);
+ }
+
+ vec_free (table);
+
+ return 0;
+}
+
+/*?
+ * Displays a serialized API message decode table, sorted by message name
+ *
+ * @cliexpar
+ * @cliexstart{show api dump file <filename>}
+ * Message name MsgID CRC
+ * accept_session 407 8e2a127e
+ * accept_session_reply 408 67d8c22a
+ * add_node_next 549 e4202993
+ * add_node_next_reply 550 e89d6eed
+ * etc.
+ * @cliexend
+?*/
+
+/*?
+ * Compares a serialized API message decode table with the current image
+ *
+ * @cliexpar
+ * @cliexstart{show api dump file <filename> compare}
+ * ip_add_del_route definition changed
+ * ip_table_add_del definition changed
+ * l2_macs_event only in image
+ * vnet_ip4_fib_counters only in file
+ * vnet_ip4_nbr_counters only in file
+ * @cliexend
+?*/
+
+/*?
+ * Display a serialized API message decode table, compare a saved
+ * decode table with the current image, to establish API differences.
+ *
+?*/
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (dump_api_table_file, static) =
+{
+ .path = "show api dump",
+ .short_help = "show api dump file <filename> [numeric | compare-current]",
+ .function = dump_api_table_file_command_fn,
+};
+/* *INDENT-ON* */
+