Skip to content

Commit

Permalink
Add asic id for linecards so "show fabric counters queue/port" can wo…
Browse files Browse the repository at this point in the history
…rk 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.
  • Loading branch information
jfeng-arista authored Feb 9, 2023
1 parent 2591e8b commit 496a077
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 6 deletions.
20 changes: 14 additions & 6 deletions scripts/fabricstat
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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'))
Expand Down
30 changes: 30 additions & 0 deletions tests/fabricstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
140 changes: 140 additions & 0 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 496a077

Please sign in to comment.