From e82eb635b1377c2b14d28127a121eabd10b3b83d Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Tue, 13 Nov 2018 13:27:18 +0000 Subject: IGMP: improve CLI debug output Change-Id: If88fc3acdba1f73b3e8be94d8014556c5239596c Signed-off-by: Neale Ranns --- src/plugins/igmp/igmp_cli.c | 16 +------------- src/plugins/igmp/igmp_config.c | 48 ++++++++++++++++++++++++++++++++++++++++++ src/plugins/igmp/igmp_config.h | 24 +++++++++++++-------- src/plugins/igmp/igmp_group.c | 40 +++++++++++++++++++++++++++++++++++ src/plugins/igmp/igmp_group.h | 39 ++++++++++++++++++---------------- src/plugins/igmp/igmp_src.c | 13 ++++++++++++ src/plugins/igmp/igmp_src.h | 1 + src/plugins/igmp/igmp_timer.c | 22 +++++++++++++++++++ src/plugins/igmp/igmp_timer.h | 2 ++ 9 files changed, 163 insertions(+), 42 deletions(-) diff --git a/src/plugins/igmp/igmp_cli.c b/src/plugins/igmp/igmp_cli.c index 6247f9a9388..5eceb685dbe 100644 --- a/src/plugins/igmp/igmp_cli.c +++ b/src/plugins/igmp/igmp_cli.c @@ -353,26 +353,12 @@ igmp_show_command_fn (vlib_main_t * vm, unformat_input_t * input, { clib_error_t *error = NULL; igmp_main_t *im = &igmp_main; - vnet_main_t *vnm = vnet_get_main (); igmp_config_t *config; - igmp_group_t *group; - igmp_src_t *src; /* *INDENT-OFF* */ pool_foreach (config, im->configs, ({ - vlib_cli_output (vm, "interface: %U mode: %U %U", - format_vnet_sw_if_index_name, vnm, config->sw_if_index, - format_igmp_mode, config->mode, format_igmp_proxy_device_id, config->proxy_device_id); - - FOR_EACH_GROUP (group, config, - ({ - vlib_cli_output (vm, "\t%U", format_igmp_key, group->key); - FOR_EACH_SRC (src, group, IGMP_FILTER_MODE_INCLUDE, - ({ - vlib_cli_output (vm, "\t\t%U", format_igmp_key, src->key); - })); - })); + vlib_cli_output (vm, "%U", format_igmp_config, config); })); /* *INDENT-ON* */ diff --git a/src/plugins/igmp/igmp_config.c b/src/plugins/igmp/igmp_config.c index 76e8ace14d9..f9acc299ff1 100644 --- a/src/plugins/igmp/igmp_config.c +++ b/src/plugins/igmp/igmp_config.c @@ -87,6 +87,54 @@ igmp_group_lookup (igmp_config_t * config, const igmp_key_t * key) return group; } +u8 * +format_igmp_config_timer_type (u8 * s, va_list * args) +{ + igmp_config_timer_type_t type = va_arg (*args, igmp_config_timer_type_t); + + switch (type) + { +#define _(v,t) case IGMP_CONFIG_TIMER_##v: return (format (s, "%s", t)); + foreach_igmp_config_timer_type +#undef _ + } + return (s); +} + + +u8 * +format_igmp_config (u8 * s, va_list * args) +{ + igmp_config_t *config; + igmp_group_t *group; + vnet_main_t *vnm; + u32 ii; + + config = va_arg (*args, igmp_config_t *); + vnm = vnet_get_main (); + + s = format (s, "interface: %U mode: %U %U", + format_vnet_sw_if_index_name, vnm, config->sw_if_index, + format_igmp_mode, config->mode, + format_igmp_proxy_device_id, config->proxy_device_id); + + for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++) + { + s = format (s, "\n %U:%U", + format_igmp_config_timer_type, ii, + format_igmp_timer_id, config->timers[ii]); + } + + /* *INDENT-OFF* */ + FOR_EACH_GROUP (group, config, + ({ + s = format (s, "\n%U", format_igmp_group, group, 4); + })); + /* *INDENT-ON* */ + + return (s); +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/plugins/igmp/igmp_config.h b/src/plugins/igmp/igmp_config.h index 0da2525a851..e3cd5d844c8 100644 --- a/src/plugins/igmp/igmp_config.h +++ b/src/plugins/igmp/igmp_config.h @@ -22,21 +22,25 @@ #include #include +/** + * GENERAL_REPORT = On expiry send a general report + * GENERAL_QUERY = On expiry send a general query + */ +#define foreach_igmp_config_timer_type \ + _(GENERAL_REPORT, "general-report") \ + _(GENERAL_QUERY, "general-query") + typedef enum igmp_config_timer_type_t_ { - /** - * On expiry send a general report - */ - IGMP_CONFIG_TIMER_GENERAL_REPORT, - - /** - * On expiry send a general query - */ - IGMP_CONFIG_TIMER_GENERAL_QUERY, +#define _(v,s) IGMP_CONFIG_TIMER_##v, + foreach_igmp_config_timer_type +#undef _ } igmp_config_timer_type_t; #define IGMP_CONFIG_N_TIMERS (IGMP_CONFIG_TIMER_GENERAL_QUERY + 1) +extern u8 *format_igmp_config_timer_type (u8 * s, va_list * args); + /** * @brief IGMP interface configuration */ @@ -122,6 +126,8 @@ extern igmp_config_t *igmp_config_get (u32 index); extern igmp_group_t *igmp_group_lookup (igmp_config_t * config, const igmp_key_t * key); +extern u8 *format_igmp_config (u8 * s, va_list * args); + #endif /* diff --git a/src/plugins/igmp/igmp_group.c b/src/plugins/igmp/igmp_group.c index 38499e4778f..51a44d2dfd5 100644 --- a/src/plugins/igmp/igmp_group.c +++ b/src/plugins/igmp/igmp_group.c @@ -280,6 +280,46 @@ igmp_group_get (u32 index) return (pool_elt_at_index (igmp_main.groups, index)); } +u8 * +format_igmp_group_timer_type (u8 * s, va_list * args) +{ + igmp_group_timer_type_t type = va_arg (*args, igmp_group_timer_type_t); + + switch (type) + { +#define _(v,t) case IGMP_GROUP_TIMER_##v: return (format (s, "%s", t)); + foreach_igmp_group_timer +#undef _ + } + return (s); +} + +u8 * +format_igmp_group (u8 * s, va_list * args) +{ + igmp_group_t *group = va_arg (*args, igmp_group_t *); + u32 indent = va_arg (*args, u32); + igmp_src_t *src; + u32 ii; + + s = format (s, "%U%U", + format_white_space, indent, format_igmp_key, group->key); + + for (ii = 0; ii < IGMP_GROUP_N_TIMERS; ii++) + s = format (s, "\n%U %U:%U", format_white_space, indent, + format_igmp_group_timer_type, ii, + format_igmp_timer_id, group->timers[ii]); + + /* *INDENT-OFF* */ + FOR_EACH_SRC (src, group, IGMP_FILTER_MODE_INCLUDE, + ({ + s = format (s, "\n%U", format_igmp_src, src, indent+4); + })); + /* *INDENT-ON* */ + + return (s); +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/plugins/igmp/igmp_group.h b/src/plugins/igmp/igmp_group.h index 6c363de6515..7d4dfb6d243 100644 --- a/src/plugins/igmp/igmp_group.h +++ b/src/plugins/igmp/igmp_group.h @@ -21,33 +21,34 @@ #include #include +/** + * QUERY_REPLY = Timer running to reply to a G/SG specific query + * QUERY_SENT = wait for response from a sent G/SG specific query. + * Sent when a host leaves a group + * RESEND_REPORT = Timer running to resend report + * FILTER_MODE_CHANGE = to check if the group can swap to + * INCLUDE mode (section 6.2.2) + */ +#define foreach_igmp_group_timer \ + _(QUERY_REPLY, "query-reply") \ + _(QUERY_SENT, "query-sent") \ + _(RESEND_REPORT, "resend-report") \ + _(FILTER_MODE_CHANGE, "filter-mode-change") + /** * Types of timers maintained for each group */ typedef enum igmp_group_timer_type_t_ { - /** - * Timer running to reply to a G/SG specific query - */ - IGMP_GROUP_TIMER_QUERY_REPLY, - /** - * wait for response from a sent G/SG specific query. - * Sent when a host leaves a group - */ - IGMP_GROUP_TIMER_QUERY_SENT, - /** - * Timer running to resend report - */ - IGMP_GROUP_TIMER_RESEND_REPORT, - /** - * filter-mode change timer, to check if the group can swap to - * INCLUDE mode (section 6.2.2) - */ - IGMP_GROUP_TIMER_FILTER_MODE_CHANGE, +#define _(v,s) IGMP_GROUP_TIMER_##v, + foreach_igmp_group_timer +#undef _ } igmp_group_timer_type_t; #define IGMP_GROUP_N_TIMERS (IGMP_GROUP_TIMER_FILTER_MODE_CHANGE + 1) +extern u8 *format_igmp_group_timer_type (u8 * s, va_list * args); + /** * @brief IGMP group * A multicast group address for which reception has been requested. @@ -114,6 +115,8 @@ extern igmp_src_t *igmp_group_src_update (igmp_group_t * group, igmp_mode_t mode); extern void igmp_group_src_remove (igmp_group_t * group, igmp_src_t * src); +extern u8 *format_igmp_group (u8 * s, va_list * args); + extern ip46_address_t *igmp_group_present_minus_new (igmp_group_t * group, igmp_filter_mode_t mode, diff --git a/src/plugins/igmp/igmp_src.c b/src/plugins/igmp/igmp_src.c index cc7de6c1921..64768ab59bd 100644 --- a/src/plugins/igmp/igmp_src.c +++ b/src/plugins/igmp/igmp_src.c @@ -143,6 +143,19 @@ igmp_src_index (igmp_src_t * src) return (src - igmp_main.srcs); } +u8 * +format_igmp_src (u8 * s, va_list * args) +{ + igmp_src_t *src = va_arg (*args, igmp_src_t *); + u32 indent = va_arg (*args, u32); + + s = format (s, "%U%U %U", + format_white_space, indent, + format_igmp_key, src->key, + format_igmp_timer_id, src->timers[IGMP_SRC_TIMER_EXP]); + + return (s); +} /* * fd.io coding-style-patch-verification: ON diff --git a/src/plugins/igmp/igmp_src.h b/src/plugins/igmp/igmp_src.h index 86a043fa5c8..e366494cf42 100644 --- a/src/plugins/igmp/igmp_src.h +++ b/src/plugins/igmp/igmp_src.h @@ -82,6 +82,7 @@ extern u32 igmp_src_index (igmp_src_t * src); extern void igmp_src_refresh (igmp_src_t * src); extern void igmp_src_blocked (igmp_src_t * src); +extern u8 *format_igmp_src (u8 * s, va_list * args); #endif diff --git a/src/plugins/igmp/igmp_timer.c b/src/plugins/igmp/igmp_timer.c index 278b7db917e..afa0c3693c9 100644 --- a/src/plugins/igmp/igmp_timer.c +++ b/src/plugins/igmp/igmp_timer.c @@ -232,6 +232,28 @@ igmp_timer_retire (igmp_timer_id_t * tid) IGMP_PROCESS_EVENT_UPDATE_TIMER, 0); } +u8 * +format_igmp_timer_id (u8 * s, va_list * args) +{ + igmp_timer_id_t tid = va_arg (*args, igmp_timer_id_t); + igmp_timer_t *timer; + + if (IGMP_TIMER_ID_INVALID == tid) + { + s = format (s, "not-running"); + } + else + { + timer = pool_elt_at_index (timer_pool, tid); + + s = + format (s, "[expires-in:%f]", + timer->exp_time - vlib_time_now (vlib_get_main ())); + } + + return (s); +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/plugins/igmp/igmp_timer.h b/src/plugins/igmp/igmp_timer.h index 21eb0425fb9..160c4cd6afe 100644 --- a/src/plugins/igmp/igmp_timer.h +++ b/src/plugins/igmp/igmp_timer.h @@ -51,6 +51,8 @@ extern f64 igmp_timer_get_expiry_time (igmp_timer_id_t t); extern void *igmp_timer_get_data (igmp_timer_id_t t); extern void igmp_timer_set_data (igmp_timer_id_t t, void *data); +extern u8 *format_igmp_timer_id (u8 * s, va_list * args); + /** * IGMP timer types and their values * QUERY - the general query timer -- cgit 1.2.3-korg