summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/vlib_api_cli.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-05-18 22:16:11 +0200
committerDamjan Marion <damarion@cisco.com>2022-05-19 18:32:23 +0200
commitcada9eb7894117db898f7c4def92cba5511baa4f (patch)
tree4cf552e2ad9e67b8bbc144eb5c6cb9aad0a8424b /src/vlibmemory/vlib_api_cli.c
parentbf95e3efde3402cf2f7beaf6d70433646cc68280 (diff)
api: refactor api data storage
single struct to hold all api handler, flags, etc. Provide functions to toggle flags instead of writing directly to internal data. Type: refactor Change-Id: I4730d7290e57489de8eda34a72211527e015b721 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlibmemory/vlib_api_cli.c')
-rw-r--r--src/vlibmemory/vlib_api_cli.c137
1 files changed, 48 insertions, 89 deletions
diff --git a/src/vlibmemory/vlib_api_cli.c b/src/vlibmemory/vlib_api_cli.c
index 39e22507c1b..084080f1e6d 100644
--- a/src/vlibmemory/vlib_api_cli.c
+++ b/src/vlibmemory/vlib_api_cli.c
@@ -242,20 +242,19 @@ vl_api_message_table_command (vlib_main_t * vm,
vlib_cli_output (vm, "%-4s %-40s %6s %7s", "ID", "Name", "Bounce",
"MP-safe");
- for (i = 1; i < vec_len (am->msg_names); i++)
+ for (i = 1; i < vec_len (am->msg_data); i++)
{
+ vl_api_msg_data_t *m = vl_api_get_msg_data (am, i);
if (verbose == 0)
{
vlib_cli_output (vm, "%-4d %s", i,
- am->msg_names[i] ? am->msg_names[i] :
- " [no handler]");
+ m->name ? m->name : " [no handler]");
}
else
{
vlib_cli_output (vm, "%-4d %-40s %6d %7d", i,
- am->msg_names[i] ? am->msg_names[i] :
- " [no handler]", am->message_bounce[i],
- am->is_mp_safe[i]);
+ m->name ? m->name : " [no handler]", m->bounce,
+ m->is_mp_safe);
}
}
@@ -510,7 +509,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
assert_size (file_size_left, clib_max (size, sizeof (u16)));
msg_id = ntohs (*((u16 *) msg));
if (msg_id >= vec_len (msgid_vec) ||
- msgid_vec[msg_id] >= vec_len (am->api_trace_cfg))
+ msgid_vec[msg_id] >= vec_len (am->msg_data))
vlib_cli_output (vm, "warning: unknown msg id %d for msg number %d\n",
msg_id, i);
@@ -522,7 +521,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
for (; i <= last_index; i++)
{
- trace_cfg_t *cfgp;
+ vl_api_msg_data_t *m;
u16 msg_id;
int size;
@@ -537,7 +536,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
msg_id = ntohs (*((u16 *) msg));
if (msg_id >= vec_len (msgid_vec) ||
- msgid_vec[msg_id] >= vec_len (am->api_trace_cfg))
+ msgid_vec[msg_id] >= vec_len (am->msg_data))
{
vlib_cli_output (
vm, "warning: unknown msg id %d for msg number %d, skipping\n",
@@ -547,7 +546,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
}
msg_id = msgid_vec[msg_id];
- cfgp = am->api_trace_cfg + msg_id;
+ m = vl_api_get_msg_data (am, msg_id);
/* Copy the buffer (from the read-only mmap'ed file) */
vec_validate (tmpbuf, size - 1 + sizeof (uword));
@@ -561,9 +560,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
if (((which == DUMP || which == DUMP_JSON) &&
clib_arch_is_little_endian))
{
- void (*endian_fp) (void *);
- if (msg_id >= vec_len (am->msg_endian_handlers)
- || (am->msg_endian_handlers[msg_id] == 0))
+ if (m && m->endian_handler == 0)
{
vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
munmap (hp, file_size);
@@ -571,8 +568,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
am->replay_in_progress = 0;
return;
}
- endian_fp = am->msg_endian_handlers[msg_id];
- (*endian_fp) (tmpbuf + sizeof (uword));
+ m->endian_handler (tmpbuf + sizeof (uword));
}
/* msg_id always in network byte order */
@@ -585,13 +581,9 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
switch (which)
{
case DUMP_JSON:
- if (msg_id < vec_len (am->msg_print_json_handlers) &&
- am->msg_print_json_handlers[msg_id])
+ if (m && m->print_json_handler)
{
- u8 *(*print_fp) (void *, void *);
-
- print_fp = (void *) am->msg_print_json_handlers[msg_id];
- (*print_fp) (tmpbuf + sizeof (uword), vm);
+ m->print_json_handler (tmpbuf + sizeof (uword), vm);
}
else
{
@@ -602,13 +594,9 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
break;
case DUMP:
- if (msg_id < vec_len (am->msg_print_handlers) &&
- am->msg_print_handlers[msg_id])
+ if (m && m->print_handler)
{
- u8 *(*print_fp) (void *, void *);
-
- print_fp = (void *) am->msg_print_handlers[msg_id];
- (*print_fp) (tmpbuf + sizeof (uword), vm);
+ m->print_handler (tmpbuf + sizeof (uword), vm);
}
else
{
@@ -619,25 +607,20 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
break;
case INITIALIZERS:
- if (msg_id < vec_len (am->msg_print_handlers) &&
- am->msg_print_handlers[msg_id])
+ if (m && m->print_handler)
{
u8 *s;
int j;
- u8 *(*print_fp) (void *, void *);
-
- print_fp = (void *) am->msg_print_handlers[msg_id];
vlib_cli_output (vm, "/*");
- (*print_fp) (tmpbuf + sizeof (uword), vm);
+ m->print_handler (tmpbuf + sizeof (uword), vm);
vlib_cli_output (vm, "*/\n");
- s = format (0, "static u8 * vl_api_%s_%d[%d] = {",
- am->msg_names[msg_id], i,
- am->api_trace_cfg[msg_id].size);
+ s = format (0, "static u8 * vl_api_%s_%d[%d] = {", m->name, i,
+ m->trace_size);
- for (j = 0; j < am->api_trace_cfg[msg_id].size; j++)
+ for (j = 0; j < m->trace_size; j++)
{
if ((j & 7) == 0)
s = format (s, "\n ");
@@ -650,22 +633,17 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
break;
case REPLAY:
- if (msg_id < vec_len (am->msg_print_handlers) &&
- am->msg_print_handlers[msg_id] && cfgp->replay_enable)
+ if (m && m->print_handler && m->replay_allowed)
{
- void (*handler) (void *, vlib_main_t *);
-
- handler = (void *) am->msg_handlers[msg_id];
-
- if (!am->is_mp_safe[msg_id])
+ if (!m->is_mp_safe)
vl_msg_api_barrier_sync ();
- (*handler) (tmpbuf + sizeof (uword), vm);
- if (!am->is_mp_safe[msg_id])
+ m->handler (tmpbuf + sizeof (uword));
+ if (!m->is_mp_safe)
vl_msg_api_barrier_release ();
}
else
{
- if (cfgp->replay_enable)
+ if (m->replay_allowed)
vlib_cli_output (vm, "Skipping msg id %d: no handler\n",
msg_id);
break;
@@ -708,11 +686,17 @@ vl_msg_print_trace (u8 *msg, void *ctx)
vl_msg_print_args *a = ctx;
api_main_t *am = vlibapi_get_main ();
u16 msg_id = ntohs (*((u16 *) msg));
- void (*print_fp) (void *, void *);
- void (**handlers) (void *, void *);
+ vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id);
+ void (*handler) (void *, void *) = 0;
u8 is_json = a->is_json;
u8 *tmpbuf = 0;
+ if (!m)
+ {
+ vlib_cli_output (a->vm, "Unknown msg id %d\n", msg_id);
+ return 0;
+ }
+
if (clib_arch_is_little_endian)
{
u32 msg_length = vec_len (msg);
@@ -720,25 +704,15 @@ vl_msg_print_trace (u8 *msg, void *ctx)
clib_memcpy_fast (tmpbuf, msg, msg_length);
msg = tmpbuf;
- void (*endian_fp) (void *);
- endian_fp = am->msg_endian_handlers[msg_id];
- (*endian_fp) (tmpbuf);
+ m->endian_handler (tmpbuf);
}
- if (is_json)
- handlers = am->msg_print_json_handlers;
- else
- handlers = am->msg_print_handlers;
+ handler = is_json ? m->print_json_handler : m->print_handler;
- if (msg_id < vec_len (handlers) && handlers[msg_id])
- {
- print_fp = (void *) handlers[msg_id];
- (*print_fp) (msg, a->vm);
- }
+ if (handler)
+ handler (msg, a->vm);
else
- {
- vlib_cli_output (a->vm, "Skipping msg id %d: no print fcn\n", msg_id);
- }
+ vlib_cli_output (a->vm, "Skipping msg id %d: no print fcn\n", msg_id);
vec_free (tmpbuf);
return 0;
@@ -825,9 +799,8 @@ vl_msg_exec_json_command (vlib_main_t *vm, cJSON *o)
{
api_main_t *am = vlibapi_get_main ();
u16 msg_id;
- void *(*fromjson) (cJSON *, int *);
int len = 0, rv = -1;
- trace_cfg_t *cfgp;
+ vl_api_msg_data_t *m;
u8 *msg = 0;
cJSON *msg_id_obj = cJSON_GetObjectItem (o, "_msgname");
@@ -849,6 +822,7 @@ vl_msg_exec_json_command (vlib_main_t *vm, cJSON *o)
u8 *name_crc = format (0, "%s_%s%c", name, crc, 0);
msg_id = vl_msg_find_id_by_name_and_crc (vm, am, (char *) name_crc);
+ m = vl_api_get_msg_data (am, msg_id);
if (msg_id == (u16) ~0)
{
msg_id = vl_msg_find_id_by_name (vm, am, name);
@@ -862,28 +836,19 @@ vl_msg_exec_json_command (vlib_main_t *vm, cJSON *o)
}
vec_free (name_crc);
- cfgp = am->api_trace_cfg + msg_id;
- if (!am->api_trace_cfg)
- {
- vlib_cli_output (vm, "msg id %d no trace config\n", msg_id);
- return rv;
- }
-
- if (cfgp->replay_enable)
+ if (m->replay_allowed)
{
-
if (proc_warning)
vlib_cli_output (vm, "warning: msg %d has different signature\n");
- fromjson = am->msg_fromjson_handlers[msg_id];
- if (!fromjson)
+ if (!m->fromjson_handler)
{
vlib_cli_output (vm, "missing fromjson convert function! id %d\n",
msg_id);
return rv;
}
- msg = (u8 *) fromjson (o, &len);
+ msg = (u8 *) m->fromjson_handler (o, &len);
if (!msg)
{
vlib_cli_output (vm, "failed to convert JSON (msg id %d)!\n",
@@ -892,24 +857,18 @@ vl_msg_exec_json_command (vlib_main_t *vm, cJSON *o)
}
if (clib_arch_is_little_endian)
- {
- void (*endian_fp) (void *);
- endian_fp = am->msg_endian_handlers[msg_id];
- (*endian_fp) (msg);
- }
+ m->endian_handler (msg);
- void (*handler) (void *, vlib_main_t *);
- handler = (void *) am->msg_handlers[msg_id];
- if (!handler)
+ if (!m->handler)
{
vlib_cli_output (vm, "no handler for msg id %d!\n", msg_id);
goto end;
}
- if (!am->is_mp_safe[msg_id])
+ if (!m->is_mp_safe)
vl_msg_api_barrier_sync ();
- (*handler) (msg, vm);
- if (!am->is_mp_safe[msg_id])
+ m->handler (msg);
+ if (!m->is_mp_safe)
vl_msg_api_barrier_release ();
}