From 1bc24ca8faf5df62f9be2100ad632df2e8f92274 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Thu, 2 Sep 2021 12:10:53 +0800 Subject: [PATCH] [portstat pfcstat] Unify the packet number format in the output of portstat and pfcstat in all cases (#1755) #### What I did Unify the packet number format in the output of "portstat" and "pfcstat" for all cases. In some cases, the packet numbers in the output of these two commands are formatted with a comma, in some cases not. This is because only when the numbers are treated by function `ns_diff`, it will format the numbers with commas: `return '{:,}'.format(max(0, new - old))` , but `ns_diff` is not called in all cases. **for example, packet numbers in the output are NOT formatted with commas:** ``` pfcstat root@r-qa-sw-eth-2133:/home/admin# pfcstat Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ----------- ------ ------ ------ ------ ------ ------ ------ ------ Ethernet120 0 0 0 0 0 0 0 0 Ethernet124 137407 0 45659 45660 0 45662 0 0 <-----FORMAT OF DATA BEFORE clear counters portstat portstat 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 X 0 N/A N/A 0 0 0 0 N/A N/A 0 0 0 Ethernet4 U 12804864 N/A N/A 0 0 0 9 N/A N/A 0 0 0 Ethernet8 X 0 N/A N/A 0 0 0 0 N/A N/A 0 0 0 Ethernet120 U 1 N/A N/A 0 0 0 11 N/A N/A 0 0 0 Ethernet124 U 1 N/A N/A 0 0 0 12363470 N/A N/A 0 429517 0 ``` **packet numbers in the output are formatted with commas:** ``` pfcstat Last cached time was 2021-08-02 10:35:32.725158 Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ----------- ------ ------ ------ ------ ------ ------ ------ ------ Ethernet120 0 0 0 0 0 0 0 0 Ethernet124 25,007 0 25,006 25,006 0 25,007 0 0 <-----DIFFERENT FORMAT AFTER COUNTER CLEAR COMMAND portstat Last cached time was 2021-08-02 10:35:47.829677 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 X 0 0.00 B/s 0.00% 0 0 0 0 0.00 B/s 0.00% 0 0 0 Ethernet4 U 1,570,775 862.60 MB/s 69.01% 0 0 0 0 28.29 KB/s 0.00% 0 0 0 Ethernet120 U 0 0.00 B/s 0.00% 0 0 0 0 0.00 B/s 0.00% 0 0 0 Ethernet124 U 0 1406.45 KB/s 0.11% 0 0 0 1,488,765 817.56 MB/s 65.40% 0 83,040 0 <----DIFFERENT PRESENTATION FORMAT OF NUMBERS ``` #### How I did it Add a new function `format_number_with_comma` to format the packet numbers with comma, this function will be called in case `ns_diff` is not applicable. Update the unitest to cover this new change. #### How to verify it execute portstat and pfcstat to check the output whether the number format is expected. #### Previous command output (if the output of a command-line utility has changed) ``` pfcstat root@r-qa-sw-eth-2133:/home/admin# pfcstat Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ----------- ------ ------ ------ ------ ------ ------ ------ ------ Ethernet116 0 0 0 0 0 0 0 0 Ethernet120 0 0 0 0 0 0 0 0 Ethernet124 137407 0 45659 45660 0 45662 0 0 portstat 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 X 0 N/A N/A 0 0 0 0 N/A N/A 0 0 0 Ethernet4 U 804864 N/A N/A 0 0 0 9 N/A N/A 0 0 0 Ethernet120 U 1 N/A N/A 0 0 0 11 N/A N/A 0 0 0 Ethernet124 U 1 N/A N/A 0 0 0 363470 N/A N/A 0 429517 0 ``` #### New command output (if the output of a command-line utility has changed) ``` pfcstat root@r-qa-sw-eth-2133:/home/admin# pfcstat Port Rx PFC0 PFC1 PFC2 PFC3 PFC4 PFC5 PFC6 PFC7 ----------- ------ ------ ------ ------ ------ ------ ------ ------ Ethernet116 0 0 0 0 0 0 0 0 Ethernet120 0 0 0 0 0 0 0 0 Ethernet124 137,407 0 45,659 45,660 0 45,662 0 0 portstat Last cached time was 2021-08-02 10:35:47.829677 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 X 0 N/A N/A 0 0 0 0 N/A N/A 0 0 0 Ethernet4 U 804,864 N/A N/A 0 0 0 9 N/A N/A 0 0 0 Ethernet120 U 1 N/A N/A 0 0 0 11 N/A N/A 0 0 0 Ethernet124 U 1 N/A N/A 0 0 0 363,470 N/A N/A 0 429,517 0 ``` --- scripts/pfcstat | 26 +++++--- scripts/portstat | 76 +++++++++++++++--------- 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, 157 insertions(+), 121 deletions(-) diff --git a/scripts/pfcstat b/scripts/pfcstat index f3256444bef9..6d1136152781 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 7fa37108cf8d..82d673fea1ff 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -38,7 +38,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) PORT_RATE = 40 @@ -238,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)) @@ -371,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), @@ -423,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 167805e3136a..97dc7739e00a 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 279963b81bd3..d346d427741c 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 3286a0a7528e..3c40e04bdbe0 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 1d4ce33a0276..3aed25f1c76a 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -539,7 +539,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", @@ -547,7 +547,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", @@ -596,7 +596,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", @@ -604,7 +604,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", @@ -653,7 +653,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", @@ -661,7 +661,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 5115ad11f1c9..955db3c23b44 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 b0f60b1e8a53..86714b523349 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 9bb203af67ea..3d856e576f99 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