6 vat_suspend (vlib_main_t * vm, f64 interval)
8 vlib_process_suspend (vm, interval);
12 format_api_error (u8 * s, va_list * args)
14 vat_main_t *vam = va_arg (*args, vat_main_t *);
15 i32 error = va_arg (*args, u32);
18 p = hash_get (vam->error_string_by_error_number, -error);
21 s = format (s, "%s", p[0]);
23 s = format (s, "%d", error);
29 init_error_string_table (vat_main_t * vam)
32 vam->error_string_by_error_number = hash_create (0, sizeof (uword));
34 #define _(n,v,s) hash_set (vam->error_string_by_error_number, -v, s);
35 foreach_vnet_api_error;
38 hash_set (vam->error_string_by_error_number, 99, "Misc");
42 api_main_init (vlib_main_t * vm)
44 vat_main_t *vam = &vat_main;
46 int vat_plugin_init (vat_main_t * vam);
49 vam->my_client_index = (u32) ~ 0;
50 /* Ensure that vam->inbuf is never NULL */
51 vec_validate (vam->inbuf, 0);
52 init_error_string_table (vam);
53 rv = vat_plugin_init (vam);
55 clib_warning ("vat_plugin_init returned %d", rv);
59 VLIB_INIT_FUNCTION (api_main_init);
62 vat_plugin_hash_create (void)
64 vat_main_t *vam = &vat_main;
66 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
67 vam->function_by_name = hash_create_string (0, sizeof (uword));
68 vam->help_by_name = hash_create_string (0, sizeof (uword));
72 api_command_fn (vlib_main_t * vm,
73 unformat_input_t * input, vlib_cli_command_t * cmd)
75 vat_main_t *vam = &vat_main;
76 unformat_input_t _input;
78 u8 *cmdp, *argsp, *this_cmd;
82 int (*fp) (vat_main_t *);
83 api_main_t *am = &api_main;
85 vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
87 /* vec_validated in the init routine */
88 _vec_len (vam->inbuf) = 0;
92 while (((c = unformat_get_input (input)) != '\n') &&
93 (c != UNFORMAT_END_OF_INPUT))
94 vec_add1 (vam->inbuf, c);
96 /* Null-terminate the command */
97 vec_add1 (vam->inbuf, 0);
99 /* In case no args given */
100 vec_add1 (vam->inbuf, 0);
102 /* Split input into cmd + args */
103 this_cmd = cmdp = vam->inbuf;
105 /* Skip leading whitespace */
106 while (cmdp < (this_cmd + vec_len (this_cmd)))
108 if (*cmdp == ' ' || *cmdp == '\t' || *cmdp == '\n')
118 /* Advance past the command */
119 while (argsp < (this_cmd + vec_len (this_cmd)))
121 if (*argsp != ' ' && *argsp != '\t' && *argsp != '\n' && *argsp != 0)
128 /* NULL terminate the command */
131 /* No arguments? Ensure that argsp points to a proper (empty) string */
132 if (argsp == (this_cmd + vec_len (this_cmd) - 1))
135 while (argsp < (this_cmd + vec_len (this_cmd)))
137 if (*argsp == ' ' || *argsp == '\t' || *argsp == '\n')
145 /* Blank input line? */
149 p = hash_get_mem (vam->function_by_name, cmdp);
152 return clib_error_return (0, "'%s': function not found\n", cmdp);
155 arg_len = strlen ((char *) argsp);
157 unformat_init_string (vam->input, (char *) argsp, arg_len);
164 unformat_free (vam->input);
165 return clib_error_return (0,
166 "%s error: %U\n", cmdp,
167 format_api_error, vam, rv);
170 if (vam->regenerate_interface_table)
172 vam->regenerate_interface_table = 0;
173 api_sw_interface_dump (vam);
175 unformat_free (vam->input);
180 VLIB_CLI_COMMAND (api_command, static) =
182 .path = "binary-api",
183 .short_help = "binary-api [help] <name> [<args>]",
184 .function = api_command_fn,
189 api_cli_output (void *notused, const char *fmt, ...)
192 vat_main_t *vam = &vat_main;
193 vlib_main_t *vm = vam->vlib_main;
194 vlib_process_t *cp = vlib_get_current_process (vm);
198 s = va_format (0, fmt, &va);
201 /* Terminate with \n if not present. */
202 if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n')
205 if ((!cp) || (!cp->output_function))
206 fformat (stdout, "%v", s);
208 cp->output_function (cp->output_function_arg, s, vec_len (s));
214 vl_client_get_first_plugin_msg_id (const char *plugin_name)
216 api_main_t *am = &api_main;
217 vl_api_msg_range_t *rp;
220 p = hash_get_mem (am->msg_range_by_name, plugin_name);
224 rp = vec_elt_at_index (am->msg_ranges, p[0]);
226 return (rp->first_msg_id);
230 unformat_sw_if_index (unformat_input_t * input, va_list * args)
232 u32 *result = va_arg (*args, u32 *);
233 vnet_main_t *vnm = vnet_get_main ();
234 u32 sw_if_index = ~0;
238 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
240 *result = sw_if_index;
247 * fd.io coding-style-patch-verification: ON
250 * eval: (c-set-style "gnu")