From 0d2cf43ca9b34598e022b96f50b9d39833193584 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Tue, 10 Aug 2021 18:45:42 +0800 Subject: [PATCH] Unify the number format in the ourput of portstat and pfcstat in all cases --- scripts/pfcstat | 26 +++++--- scripts/portstat | 77 +++++++++++++++--------- tests/mock_tables/asic0/counters_db.json | 16 ++--- tests/mock_tables/asic1/counters_db.json | 8 +-- tests/mock_tables/asic2/counters_db.json | 16 ++--- tests/mock_tables/counters_db.json | 12 ++-- tests/pfcstat_test.py | 76 +++++++++++------------ tests/portstat_test.py | 38 ++++++------ utilities_common/netstat.py | 10 +++ 9 files changed, 158 insertions(+), 121 deletions(-) diff --git a/scripts/pfcstat b/scripts/pfcstat index f3256444be..6d11361527 100755 --- a/scripts/pfcstat +++ b/scripts/pfcstat @@ -18,7 +18,7 @@ from natsort import natsorted from tabulate import tabulate from sonic_py_common.multi_asic import get_external_ports -from utilities_common.netstat import ns_diff, STATUS_NA +from utilities_common.netstat import ns_diff, STATUS_NA, format_number_with_comma from utilities_common import multi_asic as multi_asic_util from utilities_common import constants @@ -141,10 +141,14 @@ class Pfcstat(object): if key == 'time': continue table.append((key, - data.pfc0, data.pfc1, - data.pfc2, data.pfc3, - data.pfc4, data.pfc5, - data.pfc6, data.pfc7)) + format_number_with_comma(data.pfc0), + format_number_with_comma(data.pfc1), + format_number_with_comma(data.pfc2), + format_number_with_comma(data.pfc3), + format_number_with_comma(data.pfc4), + format_number_with_comma(data.pfc5), + format_number_with_comma(data.pfc6), + format_number_with_comma(data.pfc7))) if rx: print(tabulate(table, header_Rx, tablefmt='simple', stralign='right')) @@ -176,10 +180,14 @@ class Pfcstat(object): ns_diff(cntr.pfc7, old_cntr.pfc7))) else: table.append((key, - cntr.pfc0, cntr.pfc1, - cntr.pfc2, cntr.pfc3, - cntr.pfc4, cntr.pfc5, - cntr.pfc6, cntr.pfc7)) + format_number_with_comma(cntr.pfc0), + format_number_with_comma(cntr.pfc1), + format_number_with_comma(cntr.pfc2), + format_number_with_comma(cntr.pfc3), + format_number_with_comma(cntr.pfc4), + format_number_with_comma(cntr.pfc5), + format_number_with_comma(cntr.pfc6), + format_number_with_comma(cntr.pfc7))) if rx: print(tabulate(table, header_Rx, tablefmt='simple', stralign='right')) diff --git a/scripts/portstat b/scripts/portstat index 674d0c5aea..7d10f2695b 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -23,7 +23,7 @@ from utilities_common import constants from utilities_common.intf_filter import parse_interface_in_filter import utilities_common.multi_asic as multi_asic_util from utilities_common.netstat import (ns_brate, ns_diff, ns_prate, ns_util, - table_as_json) + table_as_json, format_number_with_comma) # mock the redis for unit test purposes # try: @@ -40,6 +40,7 @@ try: except KeyError: pass + PORT_RATE = 40 """ @@ -237,27 +238,45 @@ class Portstat(object): if print_all: header = header_all table.append((key, self.get_port_state(key), - data.rx_ok, STATUS_NA, STATUS_NA, STATUS_NA, data.rx_err, - data.rx_drop, data.rx_ovr, - data.tx_ok, STATUS_NA, STATUS_NA, STATUS_NA, data.tx_err, - data.tx_drop, data.tx_ovr)) + format_number_with_comma(data.rx_ok), + STATUS_NA, STATUS_NA, STATUS_NA, + format_number_with_comma(data.rx_err), + format_number_with_comma(data.rx_drop), + format_number_with_comma(data.rx_ovr), + format_number_with_comma(data.tx_ok), + STATUS_NA, STATUS_NA, STATUS_NA, + format_number_with_comma(data.tx_err), + format_number_with_comma(data.tx_drop), + format_number_with_comma(data.tx_ovr))) elif errors_only: header = header_errors_only table.append((key, self.get_port_state(key), - data.rx_err, data.rx_drop, data.rx_ovr, - data.tx_err, data.tx_drop, data.tx_ovr)) + format_number_with_comma(data.rx_err), + format_number_with_comma(data.rx_drop), + format_number_with_comma(data.rx_ovr), + format_number_with_comma(data.tx_err), + format_number_with_comma(data.tx_drop), + format_number_with_comma(data.tx_ovr))) elif rates_only: header = header_rates_only table.append((key, self.get_port_state(key), - data.rx_ok, STATUS_NA, STATUS_NA, STATUS_NA, - data.tx_ok, STATUS_NA, STATUS_NA, STATUS_NA)) + format_number_with_comma(data.rx_ok), + STATUS_NA, STATUS_NA, STATUS_NA, + format_number_with_comma(data.tx_ok), + STATUS_NA, STATUS_NA, STATUS_NA)) else: header = header_std table.append((key, self.get_port_state(key), - data.rx_ok, STATUS_NA, STATUS_NA, data.rx_err, - data.rx_drop, data.rx_ovr, - data.tx_ok, STATUS_NA, STATUS_NA, data.tx_err, - data.tx_drop, data.tx_ovr)) + format_number_with_comma(data.rx_ok), + STATUS_NA, STATUS_NA, + format_number_with_comma(data.rx_err), + format_number_with_comma(data.rx_drop), + format_number_with_comma(data.rx_ovr), + format_number_with_comma(data.tx_ok), + STATUS_NA, STATUS_NA, + format_number_with_comma(data.tx_err), + format_number_with_comma(data.tx_drop), + format_number_with_comma(data.tx_ovr))) if use_json: print(table_as_json(table, header)) @@ -370,20 +389,20 @@ class Portstat(object): ns_diff(cntr.tx_ovr, old_cntr.tx_ovr))) else: table.append((key, self.get_port_state(key), - cntr.rx_ok, + format_number_with_comma(cntr.rx_ok), STATUS_NA, STATUS_NA, STATUS_NA, - cntr.rx_err, - cntr.rx_drop, - cntr.rx_ovr, - cntr.tx_ok, + format_number_with_comma(cntr.rx_err), + format_number_with_comma(cntr.rx_drop), + format_number_with_comma(cntr.rx_ovr), + format_number_with_comma(cntr.tx_ok), STATUS_NA, STATUS_NA, STATUS_NA, - cntr.tx_err, - cntr.tx_drop, - cntr.tx_ovr)) + format_number_with_comma(cntr.tx_err), + format_number_with_comma(cntr.tx_drop), + format_number_with_comma(cntr.tx_ovr))) elif errors_only: header = header_errors_only table.append((key, self.get_port_state(key), @@ -422,18 +441,18 @@ class Portstat(object): ns_diff(cntr.tx_ovr, old_cntr.tx_ovr))) else: table.append((key, self.get_port_state(key), - cntr.rx_ok, + format_number_with_comma(cntr.rx_ok), STATUS_NA, STATUS_NA, - cntr.rx_err, - cntr.rx_drop, - cntr.rx_ovr, - cntr.tx_ok, + format_number_with_comma(cntr.rx_err), + format_number_with_comma(cntr.rx_drop), + format_number_with_comma(cntr.rx_ovr), + format_number_with_comma(cntr.tx_ok), STATUS_NA, STATUS_NA, - cntr.tx_err, - cntr.tx_drop, - cntr.tx_ovr)) + format_number_with_comma(cntr.tx_err), + format_number_with_comma(cntr.tx_drop), + format_number_with_comma(cntr.tx_ovr))) if use_json: print(table_as_json(table, header)) diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 9976978c64..3772f9cca0 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -1474,7 +1474,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "100", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "200", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1200", "SAI_PORT_STAT_PFC_1_RX_PKTS": "201", "SAI_PORT_STAT_PFC_2_RX_PKTS": "202", "SAI_PORT_STAT_PFC_3_RX_PKTS": "203", @@ -1482,7 +1482,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "205", "SAI_PORT_STAT_PFC_6_RX_PKTS": "206", "SAI_PORT_STAT_PFC_7_RX_PKTS": "207", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "210", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1210", "SAI_PORT_STAT_PFC_1_TX_PKTS": "211", "SAI_PORT_STAT_PFC_2_TX_PKTS": "212", "SAI_PORT_STAT_PFC_3_TX_PKTS": "213", @@ -1502,7 +1502,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "400", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1400", "SAI_PORT_STAT_PFC_1_RX_PKTS": "401", "SAI_PORT_STAT_PFC_2_RX_PKTS": "402", "SAI_PORT_STAT_PFC_3_RX_PKTS": "403", @@ -1510,7 +1510,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "405", "SAI_PORT_STAT_PFC_6_RX_PKTS": "406", "SAI_PORT_STAT_PFC_7_RX_PKTS": "407", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "410", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1410", "SAI_PORT_STAT_PFC_1_TX_PKTS": "411", "SAI_PORT_STAT_PFC_2_TX_PKTS": "412", "SAI_PORT_STAT_PFC_3_TX_PKTS": "413", @@ -1530,7 +1530,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "600", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1600", "SAI_PORT_STAT_PFC_1_RX_PKTS": "601", "SAI_PORT_STAT_PFC_2_RX_PKTS": "602", "SAI_PORT_STAT_PFC_3_RX_PKTS": "603", @@ -1538,7 +1538,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "605", "SAI_PORT_STAT_PFC_6_RX_PKTS": "606", "SAI_PORT_STAT_PFC_7_RX_PKTS": "607", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "610", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1610", "SAI_PORT_STAT_PFC_1_TX_PKTS": "611", "SAI_PORT_STAT_PFC_2_TX_PKTS": "612", "SAI_PORT_STAT_PFC_3_TX_PKTS": "613", @@ -1558,7 +1558,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "800", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1800", "SAI_PORT_STAT_PFC_1_RX_PKTS": "801", "SAI_PORT_STAT_PFC_2_RX_PKTS": "802", "SAI_PORT_STAT_PFC_3_RX_PKTS": "803", @@ -1566,7 +1566,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "805", "SAI_PORT_STAT_PFC_6_RX_PKTS": "806", "SAI_PORT_STAT_PFC_7_RX_PKTS": "807", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "810", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1810", "SAI_PORT_STAT_PFC_1_TX_PKTS": "811", "SAI_PORT_STAT_PFC_2_TX_PKTS": "812", "SAI_PORT_STAT_PFC_3_TX_PKTS": "813", diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 798bb80b4f..79d62e5ae7 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -130,7 +130,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "100", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "900", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1900", "SAI_PORT_STAT_PFC_1_RX_PKTS": "901", "SAI_PORT_STAT_PFC_2_RX_PKTS": "902", "SAI_PORT_STAT_PFC_3_RX_PKTS": "903", @@ -138,7 +138,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "905", "SAI_PORT_STAT_PFC_6_RX_PKTS": "906", "SAI_PORT_STAT_PFC_7_RX_PKTS": "907", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "910", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1910", "SAI_PORT_STAT_PFC_1_TX_PKTS": "911", "SAI_PORT_STAT_PFC_2_TX_PKTS": "912", "SAI_PORT_STAT_PFC_3_TX_PKTS": "913", @@ -158,7 +158,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "100", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1100", "SAI_PORT_STAT_PFC_1_RX_PKTS": "101", "SAI_PORT_STAT_PFC_2_RX_PKTS": "102", "SAI_PORT_STAT_PFC_3_RX_PKTS": "103", @@ -166,7 +166,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "105", "SAI_PORT_STAT_PFC_6_RX_PKTS": "106", "SAI_PORT_STAT_PFC_7_RX_PKTS": "107", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "110", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1110", "SAI_PORT_STAT_PFC_1_TX_PKTS": "111", "SAI_PORT_STAT_PFC_2_TX_PKTS": "112", "SAI_PORT_STAT_PFC_3_TX_PKTS": "113", diff --git a/tests/mock_tables/asic2/counters_db.json b/tests/mock_tables/asic2/counters_db.json index 3286a0a752..3c40e04bdb 100644 --- a/tests/mock_tables/asic2/counters_db.json +++ b/tests/mock_tables/asic2/counters_db.json @@ -1474,7 +1474,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "100", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "200", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1200", "SAI_PORT_STAT_PFC_1_RX_PKTS": "201", "SAI_PORT_STAT_PFC_2_RX_PKTS": "202", "SAI_PORT_STAT_PFC_3_RX_PKTS": "203", @@ -1482,7 +1482,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "205", "SAI_PORT_STAT_PFC_6_RX_PKTS": "206", "SAI_PORT_STAT_PFC_7_RX_PKTS": "207", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "210", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1210", "SAI_PORT_STAT_PFC_1_TX_PKTS": "211", "SAI_PORT_STAT_PFC_2_TX_PKTS": "212", "SAI_PORT_STAT_PFC_3_TX_PKTS": "213", @@ -1502,7 +1502,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "400", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1400", "SAI_PORT_STAT_PFC_1_RX_PKTS": "401", "SAI_PORT_STAT_PFC_2_RX_PKTS": "402", "SAI_PORT_STAT_PFC_3_RX_PKTS": "403", @@ -1510,7 +1510,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "405", "SAI_PORT_STAT_PFC_6_RX_PKTS": "406", "SAI_PORT_STAT_PFC_7_RX_PKTS": "407", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "410", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1410", "SAI_PORT_STAT_PFC_1_TX_PKTS": "411", "SAI_PORT_STAT_PFC_2_TX_PKTS": "412", "SAI_PORT_STAT_PFC_3_TX_PKTS": "413", @@ -1530,7 +1530,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "600", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1600", "SAI_PORT_STAT_PFC_1_RX_PKTS": "601", "SAI_PORT_STAT_PFC_2_RX_PKTS": "602", "SAI_PORT_STAT_PFC_3_RX_PKTS": "603", @@ -1538,7 +1538,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "605", "SAI_PORT_STAT_PFC_6_RX_PKTS": "606", "SAI_PORT_STAT_PFC_7_RX_PKTS": "607", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "610", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1610", "SAI_PORT_STAT_PFC_1_TX_PKTS": "611", "SAI_PORT_STAT_PFC_2_TX_PKTS": "612", "SAI_PORT_STAT_PFC_3_TX_PKTS": "613", @@ -1558,7 +1558,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "800", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1800", "SAI_PORT_STAT_PFC_1_RX_PKTS": "801", "SAI_PORT_STAT_PFC_2_RX_PKTS": "802", "SAI_PORT_STAT_PFC_3_RX_PKTS": "803", @@ -1566,7 +1566,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "805", "SAI_PORT_STAT_PFC_6_RX_PKTS": "806", "SAI_PORT_STAT_PFC_7_RX_PKTS": "807", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "810", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1810", "SAI_PORT_STAT_PFC_1_TX_PKTS": "811", "SAI_PORT_STAT_PFC_2_TX_PKTS": "812", "SAI_PORT_STAT_PFC_3_TX_PKTS": "813", diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 41396c4fa4..71edbc895b 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -130,7 +130,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "100", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "80", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "20", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "200", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1200", "SAI_PORT_STAT_PFC_1_RX_PKTS": "201", "SAI_PORT_STAT_PFC_2_RX_PKTS": "202", "SAI_PORT_STAT_PFC_3_RX_PKTS": "203", @@ -138,7 +138,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "205", "SAI_PORT_STAT_PFC_6_RX_PKTS": "206", "SAI_PORT_STAT_PFC_7_RX_PKTS": "207", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "210", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1210", "SAI_PORT_STAT_PFC_1_TX_PKTS": "211", "SAI_PORT_STAT_PFC_2_TX_PKTS": "212", "SAI_PORT_STAT_PFC_3_TX_PKTS": "213", @@ -187,7 +187,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "1000", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "800", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "100", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "400", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1400", "SAI_PORT_STAT_PFC_1_RX_PKTS": "401", "SAI_PORT_STAT_PFC_2_RX_PKTS": "402", "SAI_PORT_STAT_PFC_3_RX_PKTS": "403", @@ -195,7 +195,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "405", "SAI_PORT_STAT_PFC_6_RX_PKTS": "406", "SAI_PORT_STAT_PFC_7_RX_PKTS": "407", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "410", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1410", "SAI_PORT_STAT_PFC_1_TX_PKTS": "411", "SAI_PORT_STAT_PFC_2_TX_PKTS": "412", "SAI_PORT_STAT_PFC_3_TX_PKTS": "413", @@ -244,7 +244,7 @@ "SAI_PORT_STAT_IF_IN_DISCARDS": "10", "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE": "10", "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS": "0", - "SAI_PORT_STAT_PFC_0_RX_PKTS": "800", + "SAI_PORT_STAT_PFC_0_RX_PKTS": "1800", "SAI_PORT_STAT_PFC_1_RX_PKTS": "801", "SAI_PORT_STAT_PFC_2_RX_PKTS": "802", "SAI_PORT_STAT_PFC_3_RX_PKTS": "803", @@ -252,7 +252,7 @@ "SAI_PORT_STAT_PFC_5_RX_PKTS": "805", "SAI_PORT_STAT_PFC_6_RX_PKTS": "806", "SAI_PORT_STAT_PFC_7_RX_PKTS": "807", - "SAI_PORT_STAT_PFC_0_TX_PKTS": "810", + "SAI_PORT_STAT_PFC_0_TX_PKTS": "1810", "SAI_PORT_STAT_PFC_1_TX_PKTS": "811", "SAI_PORT_STAT_PFC_2_TX_PKTS": "812", "SAI_PORT_STAT_PFC_3_TX_PKTS": "813", diff --git a/tests/pfcstat_test.py b/tests/pfcstat_test.py index 8a63539efb..0c1479e1b7 100644 --- a/tests/pfcstat_test.py +++ b/tests/pfcstat_test.py @@ -16,15 +16,15 @@ show_pfc_counters_output = """\ Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 --------- ------ ------ ------ ------ ------ ------ ------ ------ -Ethernet0 200 201 202 203 204 205 206 207 -Ethernet4 400 401 402 403 404 405 406 407 -Ethernet8 800 801 802 803 804 805 806 807 +Ethernet0 1,200 201 202 203 204 205 206 207 +Ethernet4 1,400 401 402 403 404 405 406 407 +Ethernet8 1,800 801 802 803 804 805 806 807 Port Tx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 --------- ------ ------ ------ ------ ------ ------ ------ ------ -Ethernet0 210 211 212 213 214 215 216 217 -Ethernet4 410 411 412 413 414 415 416 417 -Ethernet8 810 811 812 813 814 815 816 817 +Ethernet0 1,210 211 212 213 214 215 216 217 +Ethernet4 1,410 411 412 413 414 415 416 417 +Ethernet8 1,810 811 812 813 814 815 816 817 """ show_pfc_counters_output_diff = """\ @@ -44,19 +44,19 @@ show_pfc_counters_all = """\ Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 -------------- ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 200 201 202 203 204 205 206 207 - Ethernet4 400 401 402 403 404 405 406 407 - Ethernet-BP0 600 601 602 603 604 605 606 607 - Ethernet-BP4 800 801 802 803 804 805 806 807 + Ethernet0 1,200 201 202 203 204 205 206 207 + Ethernet4 1,400 401 402 403 404 405 406 407 + Ethernet-BP0 1,600 601 602 603 604 605 606 607 + Ethernet-BP4 1,800 801 802 803 804 805 806 807 Ethernet-BP256 N/A N/A N/A N/A N/A N/A N/A N/A Ethernet-BP260 N/A N/A N/A N/A N/A N/A N/A N/A Port Tx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 -------------- ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 210 211 212 213 214 215 216 217 - Ethernet4 410 411 412 413 414 415 416 417 - Ethernet-BP0 610 611 612 613 614 615 616 617 - Ethernet-BP4 810 811 812 813 814 815 816 817 + Ethernet0 1,210 211 212 213 214 215 216 217 + Ethernet4 1,410 411 412 413 414 415 416 417 + Ethernet-BP0 1,610 611 612 613 614 615 616 617 + Ethernet-BP4 1,810 811 812 813 814 815 816 817 Ethernet-BP256 N/A N/A N/A N/A N/A N/A N/A N/A Ethernet-BP260 N/A N/A N/A N/A N/A N/A N/A N/A """ @@ -64,48 +64,48 @@ show_pfc_counters_all_asic = """\ Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ------------ ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 200 201 202 203 204 205 206 207 - Ethernet4 400 401 402 403 404 405 406 407 -Ethernet-BP0 600 601 602 603 604 605 606 607 -Ethernet-BP4 800 801 802 803 804 805 806 807 + Ethernet0 1,200 201 202 203 204 205 206 207 + Ethernet4 1,400 401 402 403 404 405 406 407 +Ethernet-BP0 1,600 601 602 603 604 605 606 607 +Ethernet-BP4 1,800 801 802 803 804 805 806 807 Port Tx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ------------ ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 210 211 212 213 214 215 216 217 - Ethernet4 410 411 412 413 414 415 416 417 -Ethernet-BP0 610 611 612 613 614 615 616 617 -Ethernet-BP4 810 811 812 813 814 815 816 817 + Ethernet0 1,210 211 212 213 214 215 216 217 + Ethernet4 1,410 411 412 413 414 415 416 417 +Ethernet-BP0 1,610 611 612 613 614 615 616 617 +Ethernet-BP4 1,810 811 812 813 814 815 816 817 """ show_pfc_counters_all = """\ Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 -------------- ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 200 201 202 203 204 205 206 207 - Ethernet4 400 401 402 403 404 405 406 407 - Ethernet-BP0 600 601 602 603 604 605 606 607 - Ethernet-BP4 800 801 802 803 804 805 806 807 -Ethernet-BP256 900 901 902 903 904 905 906 907 -Ethernet-BP260 100 101 102 103 104 105 106 107 + Ethernet0 1,200 201 202 203 204 205 206 207 + Ethernet4 1,400 401 402 403 404 405 406 407 + Ethernet-BP0 1,600 601 602 603 604 605 606 607 + Ethernet-BP4 1,800 801 802 803 804 805 806 807 +Ethernet-BP256 1,900 901 902 903 904 905 906 907 +Ethernet-BP260 1,100 101 102 103 104 105 106 107 Port Tx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 -------------- ------ ------ ------ ------ ------ ------ ------ ------ - Ethernet0 210 211 212 213 214 215 216 217 - Ethernet4 410 411 412 413 414 415 416 417 - Ethernet-BP0 610 611 612 613 614 615 616 617 - Ethernet-BP4 810 811 812 813 814 815 816 817 -Ethernet-BP256 910 911 912 913 914 915 916 917 -Ethernet-BP260 110 111 112 113 114 115 116 117 + Ethernet0 1,210 211 212 213 214 215 216 217 + Ethernet4 1,410 411 412 413 414 415 416 417 + Ethernet-BP0 1,610 611 612 613 614 615 616 617 + Ethernet-BP4 1,810 811 812 813 814 815 816 817 +Ethernet-BP256 1,910 911 912 913 914 915 916 917 +Ethernet-BP260 1,110 111 112 113 114 115 116 117 """ show_pfc_counters_asic0_frontend = """\ Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 --------- ------ ------ ------ ------ ------ ------ ------ ------ -Ethernet0 200 201 202 203 204 205 206 207 -Ethernet4 400 401 402 403 404 405 406 407 +Ethernet0 1,200 201 202 203 204 205 206 207 +Ethernet4 1,400 401 402 403 404 405 406 407 Port Tx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 --------- ------ ------ ------ ------ ------ ------ ------ ------ -Ethernet0 210 211 212 213 214 215 216 217 -Ethernet4 410 411 412 413 414 415 416 417 +Ethernet0 1,210 211 212 213 214 215 216 217 +Ethernet4 1,410 411 412 413 414 415 416 417 """ show_pfc_counters_msaic_output_diff = """\ diff --git a/tests/portstat_test.py b/tests/portstat_test.py index b0f60b1e8a..86714b5233 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -15,21 +15,21 @@ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 D 8 N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A -Ethernet4 N/A 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A +Ethernet4 N/A 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A Ethernet8 N/A 6 N/A N/A 100 10 N/A 60 N/A N/A N/A N/A N/A """ intf_counters_ethernet4 = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- -Ethernet4 N/A 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A +Ethernet4 N/A 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A """ intf_counters_all = """\ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS Tx_PPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- -------- -------- --------- -------- -------- -------- ------- -------- -------- --------- -------- -------- -------- Ethernet0 D 8 N/A N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A N/A -Ethernet4 N/A 4 N/A N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A N/A +Ethernet4 N/A 4 N/A N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A N/A Ethernet8 N/A 6 N/A N/A N/A 100 10 N/A 60 N/A N/A N/A N/A N/A N/A """ @@ -56,53 +56,53 @@ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A -Ethernet4 U 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A +Ethernet4 U 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A """ multi_asic_all_intf_counters = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR -------------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A - Ethernet4 U 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A - Ethernet-BP0 U 6 N/A N/A 0 1000 N/A 60 N/A N/A N/A N/A N/A - Ethernet-BP4 U 8 N/A N/A 0 1000 N/A 80 N/A N/A N/A N/A N/A + Ethernet4 U 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A + Ethernet-BP0 U 6 N/A N/A 0 1,000 N/A 60 N/A N/A N/A N/A N/A + Ethernet-BP4 U 8 N/A N/A 0 1,000 N/A 80 N/A N/A N/A N/A N/A Ethernet-BP256 U 8 N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A -Ethernet-BP260 U 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A +Ethernet-BP260 U 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A """ multi_asic_intf_counters_asic0 = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR ------------ ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A - Ethernet4 U 4 N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A -Ethernet-BP0 U 6 N/A N/A 0 1000 N/A 60 N/A N/A N/A N/A N/A -Ethernet-BP4 U 8 N/A N/A 0 1000 N/A 80 N/A N/A N/A N/A N/A + Ethernet4 U 4 N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A +Ethernet-BP0 U 6 N/A N/A 0 1,000 N/A 60 N/A N/A N/A N/A N/A +Ethernet-BP4 U 8 N/A N/A 0 1,000 N/A 80 N/A N/A N/A N/A N/A """ multi_asic_external_intf_counters_printall = """\ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS Tx_PPS TX_UTIL TX_ERR TX_DRP TX_OVR --------- ------- ------- -------- -------- --------- -------- -------- -------- ------- -------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A N/A -Ethernet4 U 4 N/A N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A N/A +Ethernet4 U 4 N/A N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A N/A """ multi_asic_intf_counters_printall = """\ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS Tx_PPS TX_UTIL TX_ERR TX_DRP TX_OVR -------------- ------- ------- -------- -------- --------- -------- -------- -------- ------- -------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A N/A - Ethernet4 U 4 N/A N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A N/A - Ethernet-BP0 U 6 N/A N/A N/A 0 1000 N/A 60 N/A N/A N/A N/A N/A N/A - Ethernet-BP4 U 8 N/A N/A N/A 0 1000 N/A 80 N/A N/A N/A N/A N/A N/A + Ethernet4 U 4 N/A N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A N/A + Ethernet-BP0 U 6 N/A N/A N/A 0 1,000 N/A 60 N/A N/A N/A N/A N/A N/A + Ethernet-BP4 U 8 N/A N/A N/A 0 1,000 N/A 80 N/A N/A N/A N/A N/A N/A Ethernet-BP256 U 8 N/A N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A N/A -Ethernet-BP260 U 4 N/A N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A N/A +Ethernet-BP260 U 4 N/A N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A N/A """ multi_asic_intf_counters_asic0_printall = """\ IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS Tx_PPS TX_UTIL TX_ERR TX_DRP TX_OVR ------------ ------- ------- -------- -------- --------- -------- -------- -------- ------- -------- -------- --------- -------- -------- -------- Ethernet0 U 8 N/A N/A N/A 10 100 N/A 10 N/A N/A N/A N/A N/A N/A - Ethernet4 U 4 N/A N/A N/A 0 1000 N/A 40 N/A N/A N/A N/A N/A N/A -Ethernet-BP0 U 6 N/A N/A N/A 0 1000 N/A 60 N/A N/A N/A N/A N/A N/A -Ethernet-BP4 U 8 N/A N/A N/A 0 1000 N/A 80 N/A N/A N/A N/A N/A N/A + Ethernet4 U 4 N/A N/A N/A 0 1,000 N/A 40 N/A N/A N/A N/A N/A N/A +Ethernet-BP0 U 6 N/A N/A N/A 0 1,000 N/A 60 N/A N/A N/A N/A N/A N/A +Ethernet-BP4 U 8 N/A N/A N/A 0 1,000 N/A 80 N/A N/A N/A N/A N/A N/A """ multi_asic_intf_counters_period = """\ The rates are calculated within 3 seconds period diff --git a/utilities_common/netstat.py b/utilities_common/netstat.py index 9bb203af67..3d856e576f 100755 --- a/utilities_common/netstat.py +++ b/utilities_common/netstat.py @@ -69,3 +69,13 @@ def table_as_json(table, header): output[if_name] = {header[i]: line[i] for i in range(1, len(header))} return json.dumps(output, indent=4, sort_keys=True) + + +def format_number_with_comma(number_in_str): + """ + Format the number with comma. + """ + if number_in_str.isdecimal(): + return '{:,}'.format(int(number_in_str)) + else: + return number_in_str