Skip to content

Commit

Permalink
[watermarkstat] Fix CLI script for unconfigured PG counters (#2239)
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn nazariig@nvidia.com

Propagating #2220 with resolved review comments

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 "iface_namingmode/test_iface_namingmode.py" including this PR: sonic-net/sonic-swss#2143 and observe it passes.
  • Loading branch information
malletvapid23 committed Jul 28, 2022
1 parent 84b23d2 commit 3a7193b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/watermarkstat
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,23 @@ class Watermarkstat(object):

self.header_list = ['Port']
header_map = wm_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(wm_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("Object map is empty!", file=sys.stderr)
sys.exit(1)

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

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

0 comments on commit 3a7193b

Please sign in to comment.