Skip to content

Commit 13bd06b

Browse files
authored
Fixes the issue with show interface counters and for pfc and queue counters. (sonic-net#1180)
* Fix for Issue: sonic-net/sonic-buildimage#5655 Signed-off-by: Abhishek Dosi <[email protected]> * Updated the the fix for pfc/queue counters also. Signed-off-by: Abhishek Dosi <[email protected]>
1 parent 59a511d commit 13bd06b

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

scripts/pfcstat

+1-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from natsort import natsorted
1818
from tabulate import tabulate
1919

2020
from sonic_py_common.multi_asic import get_external_ports
21+
from utilities_common.netstat import ns_diff, STATUS_NA
2122
from utilities_common import multi_asic as multi_asic_util
2223
from utilities_common import constants
2324

@@ -63,7 +64,6 @@ counter_bucket_tx_dict = {
6364
'SAI_PORT_STAT_PFC_7_TX_PKTS': 7
6465
}
6566

66-
STATUS_NA = 'N/A'
6767

6868
COUNTER_TABLE_PREFIX = "COUNTERS:"
6969
COUNTERS_PORT_NAME_MAP = "COUNTERS_PORT_NAME_MAP"
@@ -155,16 +155,6 @@ class Pfcstat(object):
155155
"""
156156
Print the difference between two cnstat results.
157157
"""
158-
def ns_diff(newstr, oldstr):
159-
"""
160-
Calculate the diff.
161-
"""
162-
if newstr == STATUS_NA or oldstr == STATUS_NA:
163-
return STATUS_NA
164-
else:
165-
new, old = int(newstr), int(oldstr)
166-
return '{:,}'.format(new - old)
167-
168158
table = []
169159

170160
for key, cntr in cnstat_new_dict.iteritems():

scripts/portstat

+3-4
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ class Portstat(object):
140140
"""
141141
# Get speed from APPL_DB
142142
full_table_id = PORT_STATUS_TABLE_PREFIX + port_name
143-
speed = PORT_RATE
144143
for ns in self.multi_asic.get_ns_list_based_on_options():
145144
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)
146145
speed = self.db.get(self.db.APPL_DB, full_table_id, PORT_SPEED_FIELD)
147146
if speed is not None:
148147
return int(speed)//1000
149-
return speed
148+
return PORT_RATE
150149

151150
def get_port_state(self, port_name):
152151
"""
@@ -294,13 +293,13 @@ class Portstat(object):
294293
table.append((key, self.get_port_state(key),
295294
ns_diff(cntr.rx_ok, old_cntr.rx_ok),
296295
ns_brate(cntr.rx_byt, old_cntr.rx_byt, time_gap),
297-
ns_util(cntr.rx_byt, old_cntr.rx_byt, time_gap),
296+
ns_util(cntr.rx_byt, old_cntr.rx_byt, time_gap, port_speed),
298297
ns_diff(cntr.rx_err, old_cntr.rx_err),
299298
ns_diff(cntr.rx_drop, old_cntr.rx_drop),
300299
ns_diff(cntr.rx_ovr, old_cntr.rx_ovr),
301300
ns_diff(cntr.tx_ok, old_cntr.tx_ok),
302301
ns_brate(cntr.tx_byt, old_cntr.tx_byt, time_gap),
303-
ns_util(cntr.tx_byt, old_cntr.tx_byt, time_gap),
302+
ns_util(cntr.tx_byt, old_cntr.tx_byt, time_gap, port_speed),
304303
ns_diff(cntr.tx_err, old_cntr.tx_err),
305304
ns_diff(cntr.tx_drop, old_cntr.tx_drop),
306305
ns_diff(cntr.tx_ovr, old_cntr.tx_ovr)))

scripts/queuestat

+1-12
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ counter_bucket_dict = {
2828
'SAI_QUEUE_STAT_DROPPED_BYTES': 5,
2929
}
3030

31-
STATUS_NA = 'N/A'
32-
STATUS_INVALID = 'INVALID'
31+
from utilities_common.netstat import ns_diff, STATUS_NA
3332

3433
QUEUE_TYPE_MC = 'MC'
3534
QUEUE_TYPE_UC = 'UC'
@@ -158,16 +157,6 @@ class Queuestat(object):
158157
"""
159158
Print the difference between two cnstat results.
160159
"""
161-
def ns_diff(newstr, oldstr):
162-
"""
163-
Calculate the diff.
164-
"""
165-
if newstr == STATUS_NA or oldstr == STATUS_NA:
166-
return STATUS_NA
167-
else:
168-
new, old = int(newstr), int(oldstr)
169-
return '{:,}'.format(new - old)
170-
171160
table = []
172161

173162
for key, cntr in cnstat_new_dict.iteritems():

utilities_common/netstat.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ def ns_diff(newstr, oldstr):
99
"""
1010
Calculate the diff.
1111
"""
12-
if newstr == STATUS_NA or oldstr == STATUS_NA:
12+
if newstr == STATUS_NA:
1313
return STATUS_NA
14-
else:
15-
new, old = int(newstr), int(oldstr)
16-
return '{:,}'.format(max(0, new - old))
14+
15+
# if new is valid but old is not we should return new
16+
if oldstr == STATUS_NA:
17+
oldstr = '0'
18+
19+
new, old = int(newstr), int(oldstr)
20+
return '{:,}'.format(max(0, new - old))
1721

1822
def ns_brate(newstr, oldstr, delta):
1923
"""

0 commit comments

Comments
 (0)