iplink: add support for STP xstats

Add support for the BRIDGE_XSTATS_STP xstats, as follow:

    # ip link xstats type bridge_slave dev lan4 stp
    lan4
                        STP BPDU:  RX: 0 TX: 61
                        STP TCN:   RX: 0 TX: 0
                        STP Transitions: Blocked: 2 Forwarding: 1

Or below as JSON:

    # ip -j -p link xstats type bridge_slave dev lan0 stp
    [ {
            "ifname": "lan0",
            "stp": {
                "rx_bpdu": 0,
                "tx_bpdu": 500,
                "rx_tcn": 0,
                "tx_tcn": 0,
                "transition_blk": 0,
                "transition_fwd": 0
            }
        } ]

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Vivien Didelot 2019-12-11 20:07:11 -05:00 committed by David Ahern
parent 2b8e6995fe
commit 0dcf36db1a
1 changed files with 26 additions and 0 deletions

View File

@ -688,6 +688,7 @@ static void bridge_print_xstats_help(struct link_util *lu, FILE *f)
static void bridge_print_stats_attr(struct rtattr *attr, int ifindex) static void bridge_print_stats_attr(struct rtattr *attr, int ifindex)
{ {
struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1]; struct rtattr *brtb[LINK_XSTATS_TYPE_MAX+1];
struct bridge_stp_xstats *sstats;
struct br_mcast_stats *mstats; struct br_mcast_stats *mstats;
struct rtattr *i, *list; struct rtattr *i, *list;
const char *ifname = ""; const char *ifname = "";
@ -807,6 +808,29 @@ static void bridge_print_stats_attr(struct rtattr *attr, int ifindex)
mstats->mld_parse_errors); mstats->mld_parse_errors);
close_json_object(); close_json_object();
break; break;
case BRIDGE_XSTATS_STP:
sstats = RTA_DATA(i);
open_json_object("stp");
print_string(PRINT_FP, NULL,
"%-16s STP BPDU: ", "");
print_u64(PRINT_ANY, "rx_bpdu", "RX: %llu ",
sstats->rx_bpdu);
print_u64(PRINT_ANY, "tx_bpdu", "TX: %llu\n",
sstats->tx_bpdu);
print_string(PRINT_FP, NULL,
"%-16s STP TCN: ", "");
print_u64(PRINT_ANY, "rx_tcn", "RX: %llu ",
sstats->rx_tcn);
print_u64(PRINT_ANY, "tx_tcn", "TX: %llu\n",
sstats->tx_tcn);
print_string(PRINT_FP, NULL,
"%-16s STP Transitions: ", "");
print_u64(PRINT_ANY, "transition_blk", "Blocked: %llu ",
sstats->transition_blk);
print_u64(PRINT_ANY, "transition_fwd", "Forwarding: %llu\n",
sstats->transition_fwd);
close_json_object();
break;
} }
} }
close_json_object(); close_json_object();
@ -843,6 +867,8 @@ int bridge_parse_xstats(struct link_util *lu, int argc, char **argv)
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "igmp") == 0 || strcmp(*argv, "mcast") == 0) { if (strcmp(*argv, "igmp") == 0 || strcmp(*argv, "mcast") == 0) {
xstats_print_attr = BRIDGE_XSTATS_MCAST; xstats_print_attr = BRIDGE_XSTATS_MCAST;
} else if (strcmp(*argv, "stp") == 0) {
xstats_print_attr = BRIDGE_XSTATS_STP;
} else if (strcmp(*argv, "dev") == 0) { } else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG(); NEXT_ARG();
filter_index = ll_name_to_index(*argv); filter_index = ll_name_to_index(*argv);