From 150470da7976248658609dc9ca411ddaaa523afe Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 11 Dec 2019 13:35:16 +0100 Subject: [PATCH] bgpd/bmp: print active outbound connections ... including timer & details about current state and last failure. Fixes: #5401 Signed-off-by: David Lamparter --- bgpd/bgp_bmp.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index b184c9f567..24a9cab5d1 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -2079,9 +2079,12 @@ DEFPY(show_bmp, struct bmp_bgp *bmpbgp; struct bmp_targets *bt; struct bmp_listener *bl; + struct bmp_active *ba; struct bmp *bmp; struct ttable *tt; char buf[SU_ADDRSTRLEN]; + char uptime[BGP_UPTIME_LEN]; + char *out; frr_each(bmp_bgph, &bmp_bgph, bmpbgp) { vty_out(vty, "BMP state for BGP %s:\n\n", @@ -2130,6 +2133,51 @@ DEFPY(show_bmp, sockunion2str(&bl->addr, buf, SU_ADDRSTRLEN), bl->port); + vty_out(vty, "\n Outbound connections:\n"); + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row(tt, "remote|state||timer"); + ttable_rowseps(tt, 0, BOTTOM, true, '-'); + frr_each (bmp_actives, &bt->actives, ba) { + const char *state_str = "?"; + + if (ba->bmp) { + peer_uptime(ba->bmp->t_up.tv_sec, + uptime, sizeof(uptime), + false, NULL); + ttable_add_row(tt, "%s:%d|Up|%s|%s", + ba->hostname, ba->port, + ba->bmp->remote, uptime); + continue; + } + + uptime[0] = '\0'; + + if (ba->t_timer) { + long trem = thread_timer_remain_second( + ba->t_timer); + + peer_uptime(monotime(NULL) - trem, + uptime, sizeof(uptime), + false, NULL); + state_str = "RetryWait"; + } else if (ba->t_read) { + state_str = "Connecting"; + } else if (ba->resq.callback) { + state_str = "Resolving"; + } + + ttable_add_row(tt, "%s:%d|%s|%s|%s", + ba->hostname, ba->port, + state_str, + ba->last_err ? ba->last_err : "", + uptime); + continue; + } + out = ttable_dump(tt, "\n"); + vty_out(vty, "%s", out); + XFREE(MTYPE_TMP, out); + ttable_del(tt); + vty_out(vty, "\n %zu connected clients:\n", bmp_session_count(&bt->sessions)); tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); @@ -2138,7 +2186,6 @@ DEFPY(show_bmp, frr_each (bmp_session, &bt->sessions, bmp) { uint64_t total; - char uptime[BGP_UPTIME_LEN]; size_t q, kq; pullwr_stats(bmp->pullwr, &total, &q, &kq); @@ -2153,7 +2200,7 @@ DEFPY(show_bmp, bmp->cnt_mirror_overruns, total, q, kq); } - char *out = ttable_dump(tt, "\n"); + out = ttable_dump(tt, "\n"); vty_out(vty, "%s", out); XFREE(MTYPE_TMP, out); ttable_del(tt);