From 496a0774b066b545130ac032d227e1a6985f6c04 Mon Sep 17 00:00:00 2001 From: jfeng-arista <98421150+jfeng-arista@users.noreply.github.com> Date: Thu, 9 Feb 2023 14:11:31 -0800 Subject: [PATCH] Add asic id for linecards so "show fabric counters queue/port" can work for single chip systems (#2656) Add asic id for linecards so "show fabric counters queue/port" can work for single chip systems. This is from #2499. 2499 cannot be cherry-picked to 202205 branch cleanly. This PR is for merging up to 202205 branch. It looks like repeated work already in the branch when I tested locally. --- scripts/fabricstat | 20 +++-- tests/fabricstat_test.py | 30 +++++++ tests/mock_tables/counters_db.json | 140 +++++++++++++++++++++++++++++ tests/mock_tables/state_db.json | 34 +++++++ 4 files changed, 218 insertions(+), 6 deletions(-) diff --git a/scripts/fabricstat b/scripts/fabricstat index 18200785ff..fea92e6402 100755 --- a/scripts/fabricstat +++ b/scripts/fabricstat @@ -14,7 +14,7 @@ import utilities_common.multi_asic as multi_asic_util # mock the redis for unit test purposes # try: - if os.environ["UTILITIES_UNIT_TESTING"] == "2": + if os.environ["UTILITIES_UNIT_TESTING"] == "1" or os.environ["UTILITIES_UNIT_TESTING"] == "2": modules_path = os.path.join(os.path.dirname(__file__), "..") tests_path = os.path.join(modules_path, "tests") sys.path.insert(0, modules_path) @@ -122,17 +122,21 @@ class FabricPortStat(FabricStat): table = [] header = None - asic = multi_asic.get_asic_id_from_name(self.namespace) + # Default ASIC name is 0 for single-ASIC systems. For multi-ASIC systems, + # derive name from namespace. + asic_name = '0' + if self.namespace: + asic_name = multi_asic.get_asic_id_from_name(self.namespace) for key, data in cnstat_dict.items(): port_id = key[len(PORT_NAME_PREFIX):] if errors_only: header = portstat_header_errors_only - table.append((asic, port_id, self.get_port_state(key), + table.append((asic_name, port_id, self.get_port_state(key), data.crc, data.fec_correctable, data.fec_uncorrectable, data.symbol_err)) else: header = portstat_header_all - table.append((asic, port_id, self.get_port_state(key), + table.append((asic_name, port_id, self.get_port_state(key), data.in_cell, data.in_octet, data.out_cell, data.out_octet, data.crc, data.fec_correctable, data.fec_uncorrectable, data.symbol_err)) @@ -168,11 +172,15 @@ class FabricQueueStat(FabricStat): return table = [] - asic = multi_asic.get_asic_id_from_name(self.namespace) + # Default ASIC name is 0 for single-ASIC systems. For multi-ASIC systems, + # derive name from namespace. + asic_name = '0' + if self.namespace: + asic_name = multi_asic.get_asic_id_from_name(self.namespace) for key, data in cnstat_dict.items(): port_name, queue_id = key.split(':') port_id = port_name[len(PORT_NAME_PREFIX):] - table.append((asic, port_id, self.get_port_state(port_name), queue_id, + table.append((asic_name, port_id, self.get_port_state(port_name), queue_id, data.curbyte, data.curlevel, data.watermarklevel)) print(tabulate(table, queuestat_header, tablefmt='simple', stralign='right')) diff --git a/tests/fabricstat_test.py b/tests/fabricstat_test.py index 23bb37d2ed..d975951ff6 100644 --- a/tests/fabricstat_test.py +++ b/tests/fabricstat_test.py @@ -90,6 +90,36 @@ """ +class TestFabricStat(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["PATH"] += os.pathsep + scripts_path + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_single_show_fabric_counters(self): + from .mock_tables import mock_single_asic + import importlib + importlib.reload(mock_single_asic) + from .mock_tables import dbconnector + dbconnector.load_database_config + dbconnector.load_namespace_config() + + return_code, result = get_result_and_return_code('fabricstat') + print("return_code: {}".format(return_code)) + print("result = {}".format(result)) + assert return_code == 0 + assert result == multi_asic_fabric_counters_asic0 + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join( + os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" + + class TestMultiAsicFabricStat(object): @classmethod def setup_class(cls): diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index e12e3347fd..d82301dc63 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1617,6 +1617,146 @@ "oid:0x1500000000067d": "SAI_QUEUE_TYPE_UNICAST_VOQ", "oid:0x1500000000067e": "SAI_QUEUE_TYPE_UNICAST_VOQ" }, + "COUNTERS_FABRIC_PORT_NAME_MAP" : { + "PORT0": "oid:0x1000000000143", + "PORT1": "oid:0x1000000000144", + "PORT2": "oid:0x1000000000145", + "PORT3": "oid:0x1000000000146", + "PORT4": "oid:0x1000000000147", + "PORT5": "oid:0x1000000000148", + "PORT6": "oid:0x1000000000149", + "PORT7": "oid:0x100000000014a" + }, + "COUNTERS:oid:0x1000000000143": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "1113", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "6", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "5", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "1759692040", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "5" + }, + "COUNTERS:oid:0x1000000000144": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "0", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "58977677898", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "0" + }, + "COUNTERS:oid:0x1000000000145": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "371", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "2", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "0", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "1769448760", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "0" + }, + "COUNTERS:oid:0x1000000000146": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "0", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "58976477608", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "0" + }, + "COUNTERS:oid:0x1000000000147": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "1855", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "10", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "73", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "1763293100", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "73" + }, + "COUNTERS:oid:0x1000000000148": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "44196", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "58975150569", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "0" + }, + "COUNTERS:oid:0x1000000000149": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "742", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "4", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "10", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "1763174090", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "0" + }, + "COUNTERS:oid:0x100000000014a": { + "SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS": "0", + "SAI_PORT_STAT_IF_OUT_OCTETS": "0", + "SAI_PORT_STAT_IF_IN_OCTETS": "1855", + "SAI_PORT_STAT_IF_IN_ERRORS": "0", + "SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS": "10", + "SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES": "187", + "SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES": "1768439529", + "SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS": "1331" + }, + "COUNTERS_FABRIC_QUEUE_NAME_MAP" : { + "PORT0:0": "oid:0x15000000000186", + "PORT1:0": "oid:0x15000000000187", + "PORT2:0": "oid:0x15000000000188", + "PORT3:0": "oid:0x15000000000189", + "PORT4:0": "oid:0x1500000000018a", + "PORT5:0": "oid:0x1500000000018b", + "PORT6:0": "oid:0x1500000000018c", + "PORT7:0": "oid:0x1500000000018d" + }, + "COUNTERS:oid:0x15000000000186": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "20", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "763", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "12" + }, + "COUNTERS:oid:0x15000000000187": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "0" + }, + "COUNTERS:oid:0x15000000000188": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "8", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "104", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "8" + }, + "COUNTERS:oid:0x15000000000189": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "0" + }, + "COUNTERS:oid:0x1500000000018a": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "22", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "1147", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "14" + }, + "COUNTERS:oid:0x1500000000018b": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "0", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "0" + }, + "COUNTERS:oid:0x1500000000018c": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "10", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "527", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "8" + }, + "COUNTERS:oid:0x1500000000018d": { + "SAI_QUEUE_STAT_WATERMARK_LEVEL": "17", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "1147", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL": "14" + }, "COUNTERS_DEBUG_NAME_PORT_STAT_MAP": { "DEBUG_0": "SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE", "DEBUG_2": "SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS" diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 0a3ba0dca5..5d66b00cc5 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -946,5 +946,39 @@ }, "ADVERTISE_NETWORK_TABLE|fccc:a250:a251::a6:1/128": { "profile": "" + }, + "FABRIC_PORT_TABLE|PORT0" : { + "STATUS": "up", + "REMOTE_MOD": "0", + "REMOTE_PORT": "79" + }, + "FABRIC_PORT_TABLE|PORT1" : { + "STATUS": "down" + }, + "FABRIC_PORT_TABLE|PORT2" : { + "STATUS": "up", + "REMOTE_MOD": "0", + "REMOTE_PORT": "94" + }, + "FABRIC_PORT_TABLE|PORT3" : { + "STATUS": "down" + }, + "FABRIC_PORT_TABLE|PORT4" : { + "STATUS": "up", + "REMOTE_MOD": "0", + "REMOTE_PORT": "85" + }, + "FABRIC_PORT_TABLE|PORT5" : { + "STATUS": "down" + }, + "FABRIC_PORT_TABLE|PORT6" : { + "STATUS": "up", + "REMOTE_MOD": "0", + "REMOTE_PORT": "84" + }, + "FABRIC_PORT_TABLE|PORT7" : { + "STATUS": "up", + "REMOTE_MOD": "0", + "REMOTE_PORT": "93" } }