From 3f0d4554f838db59f04df12cee435b44846cbc05 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Wed, 13 Sep 2023 16:51:19 +0000 Subject: [PATCH] Added support of queue non zero counter option Signed-off-by: Abhishek Dosi --- scripts/queuestat | 66 +- show/main.py | 6 +- tests/mock_tables/counters_db.json | 16 +- tests/queue_counter_test.py | 1136 +++++++++++++++++++++++++++- 4 files changed, 1163 insertions(+), 61 deletions(-) diff --git a/scripts/queuestat b/scripts/queuestat index 19fdca6ae..590fd8bf4 100755 --- a/scripts/queuestat +++ b/scripts/queuestat @@ -198,7 +198,7 @@ class Queuestat(object): cnstat_dict[queue] = get_counters(queue_map[queue]) return cnstat_dict - def cnstat_print(self, port, cnstat_dict, json_opt): + def cnstat_print(self, port, cnstat_dict, json_opt, non_zero): """ Print the cnstat. If JSON option is True, return data in JSON format. @@ -211,19 +211,22 @@ class Queuestat(object): if json_opt: json_output[port][key] = data continue - table.append((port, data.queuetype + str(data.queueindex), - data.totalpacket, data.totalbytes, - data.droppacket, data.dropbytes)) + + if not non_zero or data.totalpacket != '0' or data.totalbytes != '0' or data.droppacket !='0' or data.dropbytes != '0': + table.append((port, data.queuetype + str(data.queueindex), + data.totalpacket, data.totalbytes, + data.droppacket, data.dropbytes)) if json_opt: json_output[port].update(build_json(port, table)) return json_output else: hdr = voq_header if self.voq else header - print(tabulate(table, hdr, tablefmt='simple', stralign='right')) - print() + if table: + print(tabulate(table, hdr, tablefmt='simple', stralign='right')) + print() - def cnstat_diff_print(self, port, cnstat_new_dict, cnstat_old_dict, json_opt): + def cnstat_diff_print(self, port, cnstat_new_dict, cnstat_old_dict, json_opt, non_zero): """ Print the difference between two cnstat results. If JSON option is True, return data in JSON format. @@ -241,12 +244,16 @@ class Queuestat(object): old_cntr = cnstat_old_dict.get(key) if old_cntr is not None: - table.append((port, cntr.queuetype + str(cntr.queueindex), - ns_diff(cntr.totalpacket, old_cntr.totalpacket), - ns_diff(cntr.totalbytes, old_cntr.totalbytes), - ns_diff(cntr.droppacket, old_cntr.droppacket), - ns_diff(cntr.dropbytes, old_cntr.dropbytes))) - else: + if not non_zero or ns_diff(cntr.totalpacket, old_cntr.totalpacket) != '0' or \ + ns_diff(cntr.totalbytes, old_cntr.totalbytes) != '0' or \ + ns_diff(cntr.droppacket, old_cntr.droppacket) != '0' or \ + ns_diff(cntr.dropbytes, old_cntr.dropbytes) != '0': + table.append((port, cntr.queuetype + str(cntr.queueindex), + ns_diff(cntr.totalpacket, old_cntr.totalpacket), + ns_diff(cntr.totalbytes, old_cntr.totalbytes), + ns_diff(cntr.droppacket, old_cntr.droppacket), + ns_diff(cntr.dropbytes, old_cntr.dropbytes))) + elif not non_zero or cntr.totalpacket != '0' or cntr.totalbytes != '0' or cntr.droppacket !='0' or cntr.dropbytes != '0': table.append((port, cntr.queuetype + str(cntr.queueindex), cntr.totalpacket, cntr.totalbytes, cntr.droppacket, cntr.dropbytes)) @@ -256,10 +263,12 @@ class Queuestat(object): return json_output else: hdr = voq_header if self.voq else header - print(tabulate(table, hdr, tablefmt='simple', stralign='right')) - print() + if table: + print(port + " Last cached time was " + str(cnstat_old_dict.get('time'))) + print(tabulate(table, hdr, tablefmt='simple', stralign='right')) + print() - def get_print_all_stat(self, json_opt): + def get_print_all_stat(self, json_opt, non_zero): """ Get stat for each port If JSON option is True, collect data for each port and @@ -276,22 +285,21 @@ class Queuestat(object): cnstat_cached_dict = pickle.load(open(cnstat_fqn_file_name, 'rb')) if json_opt: json_output[port].update({"cached_time":cnstat_cached_dict.get('time')}) - json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt)) + json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero)) else: - print(port + " Last cached time was " + str(cnstat_cached_dict.get('time'))) - self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt) + self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero) except IOError as e: print(e.errno, e) else: if json_opt: - json_output.update(self.cnstat_print(port, cnstat_dict, json_opt)) + json_output.update(self.cnstat_print(port, cnstat_dict, json_opt, non_zero)) else: - self.cnstat_print(port, cnstat_dict, json_opt) + self.cnstat_print(port, cnstat_dict, json_opt, non_zero) if json_opt: print(json_dump(json_output)) - def get_print_port_stat(self, port, json_opt): + def get_print_port_stat(self, port, json_opt, non_zero): """ Get stat for the port If JSON option is True print data in JSON format @@ -310,17 +318,17 @@ class Queuestat(object): cnstat_cached_dict = pickle.load(open(cnstat_fqn_file_name, 'rb')) if json_opt: json_output[port].update({"cached_time":cnstat_cached_dict.get('time')}) - json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt)) + json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero)) else: print("Last cached time was " + str(cnstat_cached_dict.get('time'))) - self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt) + self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero) except IOError as e: print(e.errno, e) else: if json_opt: - json_output.update(self.cnstat_print(port, cnstat_dict, json_opt)) + json_output.update(self.cnstat_print(port, cnstat_dict, json_opt, non_zero)) else: - self.cnstat_print(port, cnstat_dict, json_opt) + self.cnstat_print(port, cnstat_dict, json_opt, non_zero) if json_opt: print(json_dump(json_output)) @@ -358,6 +366,7 @@ Examples: parser.add_argument('-j', '--json_opt', action='store_true', help='Print in JSON format') parser.add_argument('-V', '--voq', action='store_true', help='display voq stats') parser.add_argument('-n','--namespace', default=None, help='Display queue counters for specific namespace') + parser.add_argument('-nz','--non_zero', action='store_true', help='Display non-zero queue counters') args = parser.parse_args() save_fresh_stats = args.clear @@ -365,6 +374,7 @@ Examples: json_opt = args.json_opt voq = args.voq namespace = args.namespace + non_zero = args.non_zero port_to_show_stats = args.port @@ -383,9 +393,9 @@ Examples: sys.exit(0) if port_to_show_stats!=None: - queuestat.get_print_port_stat(port_to_show_stats, json_opt) + queuestat.get_print_port_stat(port_to_show_stats, json_opt, non_zero) else: - queuestat.get_print_all_stat(json_opt) + queuestat.get_print_all_stat(json_opt, non_zero) sys.exit(0) diff --git a/show/main.py b/show/main.py index 17306d5c3..8e14c641e 100755 --- a/show/main.py +++ b/show/main.py @@ -554,7 +554,8 @@ def queue(): @click.option('--verbose', is_flag=True, help="Enable verbose output") @click.option('--json', is_flag=True, help="JSON output") @click.option('--voq', is_flag=True, help="VOQ counters") -def counters(interfacename, namespace, display, verbose, json, voq): +@click.option('--nonzero', is_flag=True, help="Non Zero Counters") +def counters(interfacename, namespace, display, verbose, json, voq, nonzero): """Show queue counters""" cmd = "queuestat" @@ -575,6 +576,9 @@ def counters(interfacename, namespace, display, verbose, json, voq): if voq: cmd += " -V" + if nonzero: + cmd += " -nz" + run_command(cmd, display_cmd=verbose) # diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index c0c37880d..40248ed47 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1,9 +1,9 @@ { "COUNTERS:oid:0x15000000000357": { - "SAI_QUEUE_STAT_BYTES": "30", - "SAI_QUEUE_STAT_DROPPED_BYTES": "74", - "SAI_QUEUE_STAT_DROPPED_PACKETS": "56", - "SAI_QUEUE_STAT_PACKETS": "68", + "SAI_QUEUE_STAT_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "0", + "SAI_QUEUE_STAT_PACKETS": "0", "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "61" }, "COUNTERS:oid:0x15000000000358": { @@ -266,10 +266,10 @@ "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "49" }, "COUNTERS:oid:0x150000000003a7": { - "SAI_QUEUE_STAT_BYTES": "5", - "SAI_QUEUE_STAT_DROPPED_BYTES": "56", - "SAI_QUEUE_STAT_DROPPED_PACKETS": "36", - "SAI_QUEUE_STAT_PACKETS": "19", + "SAI_QUEUE_STAT_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "0", + "SAI_QUEUE_STAT_PACKETS": "0", "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "65" }, "COUNTERS:oid:0x150000000003a8": { diff --git a/tests/queue_counter_test.py b/tests/queue_counter_test.py index 404014cbb..26689bf72 100644 --- a/tests/queue_counter_test.py +++ b/tests/queue_counter_test.py @@ -20,11 +20,111 @@ sys.path.insert(0, test_path) sys.path.insert(0, modules_path) - show_queue_counters = """\ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet0 UC0 68 30 56 74 +Ethernet0 UC0 0 0 0 0 +Ethernet0 UC1 60 43 39 1 +Ethernet0 UC2 82 7 39 21 +Ethernet0 UC3 52 70 19 76 +Ethernet0 UC4 11 59 12 94 +Ethernet0 UC5 36 62 35 40 +Ethernet0 UC6 49 91 2 88 +Ethernet0 UC7 33 17 94 74 +Ethernet0 UC8 40 71 95 33 +Ethernet0 UC9 54 8 93 78 +Ethernet0 MC10 83 96 74 9 +Ethernet0 MC11 15 60 61 31 +Ethernet0 MC12 45 52 82 94 +Ethernet0 MC13 55 88 89 52 +Ethernet0 MC14 14 70 95 79 +Ethernet0 MC15 68 60 66 81 +Ethernet0 MC16 63 4 48 76 +Ethernet0 MC17 41 73 77 74 +Ethernet0 MC18 60 21 56 54 +Ethernet0 MC19 57 31 12 39 +Ethernet0 ALL20 N/A N/A N/A N/A +Ethernet0 ALL21 N/A N/A N/A N/A +Ethernet0 ALL22 N/A N/A N/A N/A +Ethernet0 ALL23 N/A N/A N/A N/A +Ethernet0 ALL24 N/A N/A N/A N/A +Ethernet0 ALL25 N/A N/A N/A N/A +Ethernet0 ALL26 N/A N/A N/A N/A +Ethernet0 ALL27 N/A N/A N/A N/A +Ethernet0 ALL28 N/A N/A N/A N/A +Ethernet0 ALL29 N/A N/A N/A N/A + + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet4 UC0 41 96 70 98 +Ethernet4 UC1 18 49 63 36 +Ethernet4 UC2 99 90 3 15 +Ethernet4 UC3 60 89 48 41 +Ethernet4 UC4 8 84 82 94 +Ethernet4 UC5 83 15 75 92 +Ethernet4 UC6 84 26 50 71 +Ethernet4 UC7 27 19 49 80 +Ethernet4 UC8 13 89 13 33 +Ethernet4 UC9 43 48 86 31 +Ethernet4 MC10 50 1 57 82 +Ethernet4 MC11 67 99 84 59 +Ethernet4 MC12 4 58 27 5 +Ethernet4 MC13 74 5 57 39 +Ethernet4 MC14 21 59 4 14 +Ethernet4 MC15 24 61 19 53 +Ethernet4 MC16 51 15 15 32 +Ethernet4 MC17 98 18 23 15 +Ethernet4 MC18 41 34 9 57 +Ethernet4 MC19 57 7 18 99 +Ethernet4 ALL20 N/A N/A N/A N/A +Ethernet4 ALL21 N/A N/A N/A N/A +Ethernet4 ALL22 N/A N/A N/A N/A +Ethernet4 ALL23 N/A N/A N/A N/A +Ethernet4 ALL24 N/A N/A N/A N/A +Ethernet4 ALL25 N/A N/A N/A N/A +Ethernet4 ALL26 N/A N/A N/A N/A +Ethernet4 ALL27 N/A N/A N/A N/A +Ethernet4 ALL28 N/A N/A N/A N/A +Ethernet4 ALL29 N/A N/A N/A N/A + + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet8 UC0 0 0 0 0 +Ethernet8 UC1 38 17 68 91 +Ethernet8 UC2 16 65 79 51 +Ethernet8 UC3 11 97 63 72 +Ethernet8 UC4 54 89 62 62 +Ethernet8 UC5 13 84 30 59 +Ethernet8 UC6 49 67 99 85 +Ethernet8 UC7 2 63 38 88 +Ethernet8 UC8 0 82 93 43 +Ethernet8 UC9 80 17 91 61 +Ethernet8 MC10 81 63 76 73 +Ethernet8 MC11 29 16 29 66 +Ethernet8 MC12 32 12 61 35 +Ethernet8 MC13 79 17 72 93 +Ethernet8 MC14 23 21 67 50 +Ethernet8 MC15 37 10 97 14 +Ethernet8 MC16 30 17 74 43 +Ethernet8 MC17 0 63 54 84 +Ethernet8 MC18 69 88 24 79 +Ethernet8 MC19 20 12 84 3 +Ethernet8 ALL20 N/A N/A N/A N/A +Ethernet8 ALL21 N/A N/A N/A N/A +Ethernet8 ALL22 N/A N/A N/A N/A +Ethernet8 ALL23 N/A N/A N/A N/A +Ethernet8 ALL24 N/A N/A N/A N/A +Ethernet8 ALL25 N/A N/A N/A N/A +Ethernet8 ALL26 N/A N/A N/A N/A +Ethernet8 ALL27 N/A N/A N/A N/A +Ethernet8 ALL28 N/A N/A N/A N/A +Ethernet8 ALL29 N/A N/A N/A N/A + +""" + +show_queue_counters_nonzero = """\ + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet0 UC1 60 43 39 1 Ethernet0 UC2 82 7 39 21 Ethernet0 UC3 52 70 19 76 @@ -90,7 +190,40 @@ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet8 UC0 19 5 36 56 +Ethernet8 UC1 38 17 68 91 +Ethernet8 UC2 16 65 79 51 +Ethernet8 UC3 11 97 63 72 +Ethernet8 UC4 54 89 62 62 +Ethernet8 UC5 13 84 30 59 +Ethernet8 UC6 49 67 99 85 +Ethernet8 UC7 2 63 38 88 +Ethernet8 UC8 0 82 93 43 +Ethernet8 UC9 80 17 91 61 +Ethernet8 MC10 81 63 76 73 +Ethernet8 MC11 29 16 29 66 +Ethernet8 MC12 32 12 61 35 +Ethernet8 MC13 79 17 72 93 +Ethernet8 MC14 23 21 67 50 +Ethernet8 MC15 37 10 97 14 +Ethernet8 MC16 30 17 74 43 +Ethernet8 MC17 0 63 54 84 +Ethernet8 MC18 69 88 24 79 +Ethernet8 MC19 20 12 84 3 +Ethernet8 ALL20 N/A N/A N/A N/A +Ethernet8 ALL21 N/A N/A N/A N/A +Ethernet8 ALL22 N/A N/A N/A N/A +Ethernet8 ALL23 N/A N/A N/A N/A +Ethernet8 ALL24 N/A N/A N/A N/A +Ethernet8 ALL25 N/A N/A N/A N/A +Ethernet8 ALL26 N/A N/A N/A N/A +Ethernet8 ALL27 N/A N/A N/A N/A +Ethernet8 ALL28 N/A N/A N/A N/A +Ethernet8 ALL29 N/A N/A N/A N/A + +""" +show_queue_counters_port_nonzero = """\ + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet8 UC1 38 17 68 91 Ethernet8 UC2 16 65 79 51 Ethernet8 UC3 11 97 63 72 @@ -127,7 +260,7 @@ show_queue_counters_port = """\ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet8 UC0 19 5 36 56 +Ethernet8 UC0 0 0 0 0 Ethernet8 UC1 38 17 68 91 Ethernet8 UC2 16 65 79 51 Ethernet8 UC3 11 97 63 72 @@ -158,9 +291,925 @@ Ethernet8 ALL28 N/A N/A N/A N/A Ethernet8 ALL29 N/A N/A N/A N/A -""" +""" +show_queue_counters_json = """\ +{ + "Ethernet0": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "9", + "droppacket": "74", + "totalbytes": "96", + "totalpacket": "83" + }, + "MC11": { + "dropbytes": "31", + "droppacket": "61", + "totalbytes": "60", + "totalpacket": "15" + }, + "MC12": { + "dropbytes": "94", + "droppacket": "82", + "totalbytes": "52", + "totalpacket": "45" + }, + "MC13": { + "dropbytes": "52", + "droppacket": "89", + "totalbytes": "88", + "totalpacket": "55" + }, + "MC14": { + "dropbytes": "79", + "droppacket": "95", + "totalbytes": "70", + "totalpacket": "14" + }, + "MC15": { + "dropbytes": "81", + "droppacket": "66", + "totalbytes": "60", + "totalpacket": "68" + }, + "MC16": { + "dropbytes": "76", + "droppacket": "48", + "totalbytes": "4", + "totalpacket": "63" + }, + "MC17": { + "dropbytes": "74", + "droppacket": "77", + "totalbytes": "73", + "totalpacket": "41" + }, + "MC18": { + "dropbytes": "54", + "droppacket": "56", + "totalbytes": "21", + "totalpacket": "60" + }, + "MC19": { + "dropbytes": "39", + "droppacket": "12", + "totalbytes": "31", + "totalpacket": "57" + }, + "UC0": { + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" + }, + "UC1": { + "dropbytes": "1", + "droppacket": "39", + "totalbytes": "43", + "totalpacket": "60" + }, + "UC2": { + "dropbytes": "21", + "droppacket": "39", + "totalbytes": "7", + "totalpacket": "82" + }, + "UC3": { + "dropbytes": "76", + "droppacket": "19", + "totalbytes": "70", + "totalpacket": "52" + }, + "UC4": { + "dropbytes": "94", + "droppacket": "12", + "totalbytes": "59", + "totalpacket": "11" + }, + "UC5": { + "dropbytes": "40", + "droppacket": "35", + "totalbytes": "62", + "totalpacket": "36" + }, + "UC6": { + "dropbytes": "88", + "droppacket": "2", + "totalbytes": "91", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "74", + "droppacket": "94", + "totalbytes": "17", + "totalpacket": "33" + }, + "UC8": { + "dropbytes": "33", + "droppacket": "95", + "totalbytes": "71", + "totalpacket": "40" + }, + "UC9": { + "dropbytes": "78", + "droppacket": "93", + "totalbytes": "8", + "totalpacket": "54" + } + }, + "Ethernet4": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "82", + "droppacket": "57", + "totalbytes": "1", + "totalpacket": "50" + }, + "MC11": { + "dropbytes": "59", + "droppacket": "84", + "totalbytes": "99", + "totalpacket": "67" + }, + "MC12": { + "dropbytes": "5", + "droppacket": "27", + "totalbytes": "58", + "totalpacket": "4" + }, + "MC13": { + "dropbytes": "39", + "droppacket": "57", + "totalbytes": "5", + "totalpacket": "74" + }, + "MC14": { + "dropbytes": "14", + "droppacket": "4", + "totalbytes": "59", + "totalpacket": "21" + }, + "MC15": { + "dropbytes": "53", + "droppacket": "19", + "totalbytes": "61", + "totalpacket": "24" + }, + "MC16": { + "dropbytes": "32", + "droppacket": "15", + "totalbytes": "15", + "totalpacket": "51" + }, + "MC17": { + "dropbytes": "15", + "droppacket": "23", + "totalbytes": "18", + "totalpacket": "98" + }, + "MC18": { + "dropbytes": "57", + "droppacket": "9", + "totalbytes": "34", + "totalpacket": "41" + }, + "MC19": { + "dropbytes": "99", + "droppacket": "18", + "totalbytes": "7", + "totalpacket": "57" + }, + "UC0": { + "dropbytes": "98", + "droppacket": "70", + "totalbytes": "96", + "totalpacket": "41" + }, + "UC1": { + "dropbytes": "36", + "droppacket": "63", + "totalbytes": "49", + "totalpacket": "18" + }, + "UC2": { + "dropbytes": "15", + "droppacket": "3", + "totalbytes": "90", + "totalpacket": "99" + }, + "UC3": { + "dropbytes": "41", + "droppacket": "48", + "totalbytes": "89", + "totalpacket": "60" + }, + "UC4": { + "dropbytes": "94", + "droppacket": "82", + "totalbytes": "84", + "totalpacket": "8" + }, + "UC5": { + "dropbytes": "92", + "droppacket": "75", + "totalbytes": "15", + "totalpacket": "83" + }, + "UC6": { + "dropbytes": "71", + "droppacket": "50", + "totalbytes": "26", + "totalpacket": "84" + }, + "UC7": { + "dropbytes": "80", + "droppacket": "49", + "totalbytes": "19", + "totalpacket": "27" + }, + "UC8": { + "dropbytes": "33", + "droppacket": "13", + "totalbytes": "89", + "totalpacket": "13" + }, + "UC9": { + "dropbytes": "31", + "droppacket": "86", + "totalbytes": "48", + "totalpacket": "43" + } + }, + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC0": { + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { + "dropbytes": "59", + "droppacket": "30", + "totalbytes": "84", + "totalpacket": "13" + }, + "UC6": { + "dropbytes": "85", + "droppacket": "99", + "totalbytes": "67", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "88", + "droppacket": "38", + "totalbytes": "63", + "totalpacket": "2" + }, + "UC8": { + "dropbytes": "43", + "droppacket": "93", + "totalbytes": "82", + "totalpacket": "0" + }, + "UC9": { + "dropbytes": "61", + "droppacket": "91", + "totalbytes": "17", + "totalpacket": "80" + } + } +}""" + +show_queue_counters_port_json_nonzero = """\ +{ + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { + "dropbytes": "59", + "droppacket": "30", + "totalbytes": "84", + "totalpacket": "13" + }, + "UC6": { + "dropbytes": "85", + "droppacket": "99", + "totalbytes": "67", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "88", + "droppacket": "38", + "totalbytes": "63", + "totalpacket": "2" + }, + "UC8": { + "dropbytes": "43", + "droppacket": "93", + "totalbytes": "82", + "totalpacket": "0" + }, + "UC9": { + "dropbytes": "61", + "droppacket": "91", + "totalbytes": "17", + "totalpacket": "80" + } + } +}""" + -show_queue_counters_json = """\ +show_queue_counters_port_json = """\ +{ + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC0": { + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { + "dropbytes": "59", + "droppacket": "30", + "totalbytes": "84", + "totalpacket": "13" + }, + "UC6": { + "dropbytes": "85", + "droppacket": "99", + "totalbytes": "67", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "88", + "droppacket": "38", + "totalbytes": "63", + "totalpacket": "2" + }, + "UC8": { + "dropbytes": "43", + "droppacket": "93", + "totalbytes": "82", + "totalpacket": "0" + }, + "UC9": { + "dropbytes": "61", + "droppacket": "91", + "totalbytes": "17", + "totalpacket": "80" + } + } +}""" + +show_queue_counters_json_nonzero = """\ { "Ethernet0": { "ALL20": { @@ -283,12 +1332,6 @@ "totalbytes": "31", "totalpacket": "57" }, - "UC0": { - "dropbytes": "74", - "droppacket": "56", - "totalbytes": "30", - "totalpacket": "68" - }, "UC1": { "dropbytes": "1", "droppacket": "39", @@ -647,12 +1690,6 @@ "totalbytes": "12", "totalpacket": "20" }, - "UC0": { - "dropbytes": "56", - "droppacket": "36", - "totalbytes": "5", - "totalpacket": "19" - }, "UC1": { "dropbytes": "91", "droppacket": "68", @@ -834,10 +1871,10 @@ "totalpacket": "20" }, "UC0": { - "dropbytes": "56", - "droppacket": "36", - "totalbytes": "5", - "totalpacket": "19" + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" }, "UC1": { "dropbytes": "91", @@ -1207,6 +2244,17 @@ def test_queue_counters(self): assert result.exit_code == 0 assert result.output == show_queue_counters + def test_queue_counters_nonzero(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_counters_nonzero + + def test_queue_counters_port(self): runner = CliRunner() result = runner.invoke( @@ -1217,6 +2265,16 @@ def test_queue_counters_port(self): assert result.exit_code == 0 assert result.output == show_queue_counters_port + def test_queue_counters_port_nonzero(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["Ethernet8", "--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_counters_port_nonzero + def test_queue_counters_json(self): runner = CliRunner() result = runner.invoke( @@ -1230,7 +2288,22 @@ def test_queue_counters_json(self): # remove "time" from the output for _, v in json_output.items(): del v["time"] - assert json_dump(json_output) == show_queue_counters_json + assert json_dump(json_output) == show_queue_counters_json + + def test_queue_counters_json_nonzero(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["--json", "--nonzero"] + ) + assert result.exit_code == 0 + print(result.output) + json_output = json.loads(result.output) + + # remove "time" from the output + for _, v in json_output.items(): + del v["time"] + assert json_dump(json_output) == show_queue_counters_json_nonzero def test_queue_counters_port_json(self): runner = CliRunner() @@ -1245,7 +2318,22 @@ def test_queue_counters_port_json(self): # remove "time" from the output for _, v in json_output.items(): del v["time"] - assert json_dump(json_output) == show_queue_counters_port_json + assert json_dump(json_output) == show_queue_counters_port_json + + def test_queue_counters_port_json_nonzero(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["Ethernet8", "--json", "--nonzero"] + ) + assert result.exit_code == 0 + print(result.output) + json_output = json.loads(result.output) + + # remove "time" from the output + for _, v in json_output.items(): + del v["time"] + assert json_dump(json_output) == show_queue_counters_port_json_nonzero def test_queue_voq_counters(self): runner = CliRunner()