Skip to content

Commit

Permalink
[drop counters] Fix CLI script for unconfigured PGs (sonic-net#2518)
Browse files Browse the repository at this point in the history
- What I did
Since PG counters are created only if they are configured in the switch, it is not enough to relay only on the first entry in the DB when building the output table of watermarkstat script.
We need to go over all configured counters, check what is the max configured and build the table accordingly.

- How I did it
Iterate all configured PG buffers for all ports and find the max index.
Build the output table according to the max index.

- How to verify it
Run test "pgdropstat_test.py" including this PR and observe it passes.
  • Loading branch information
liorghub authored and preetham-singh committed Dec 6, 2022
1 parent b799c4a commit 66e1fd0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/pg-drop
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,23 @@ class PgDropStat(object):

self.header_list = ['Port']
header_map = pg_drop_type["obj_map"]
single_key = list(header_map.keys())[0]
header_len = len(header_map[single_key])
min_idx = sys.maxsize

for name, counter_oid in header_map[single_key].items():
curr_idx = int(pg_drop_type["idx_func"](counter_oid))
min_idx = min(min_idx, curr_idx)
max_idx = 0
min_idx = sys.maxsize
for port in header_map.keys():
for element in header_map[port].keys():
element_idx = int(element.split(':')[1])
if element_idx > max_idx:
max_idx = element_idx
if min_idx > element_idx:
min_idx = element_idx

if min_idx == sys.maxsize:
print("Header info is not available!")
sys.exit(1)

self.min_idx = min_idx
self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, self.min_idx + header_len)]
self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)]

def get_counters(self, table_prefix, port_obj, idx_func, counter_name):
"""
Expand Down

0 comments on commit 66e1fd0

Please sign in to comment.