diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index 612d580f9..e849bfbc6 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -13,6 +13,8 @@ COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP' COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP' +BUFFER_MAX_PARAM_TABLE = 'BUFFER_MAX_PARAM_TABLE' + LAG_TABLE = 'LAG_TABLE' LAG_MEMBER_TABLE = 'LAG_MEMBER_TABLE' LOC_CHASSIS_TABLE = 'LLDP_LOC_CHASSIS' @@ -60,6 +62,16 @@ def chassis_info_table(chassis_name): return "CHASSIS_INFO" + TABLE_NAME_SEPARATOR_VBAR + chassis_name + +def buffer_max_parm_table(port_name): + """ + :param: port_name: port name + :return: max buffer parametes info for this port + """ + + return "BUFFER_MAX_PARAM_TABLE" + TABLE_NAME_SEPARATOR_VBAR + port_name + + def fan_info_table(fan_name): """ :param: fan_name: fan name diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py index 2ee47e35c..a3d50379f 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py @@ -67,6 +67,10 @@ def __init__(self): self.port_index_namespace = {} self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn) + self.statedb = mibs.init_db() + self.statedb.connect(self.statedb.STATE_DB) + + def reinit_connection(self): Namespace.connect_namespace_dbs(self.db_conn) @@ -132,8 +136,10 @@ def update_stats(self): namespace = self.port_index_namespace[if_index] # The first half of queue id is for ucast, and second half is for mcast - # To simulate vendor OID, we wrap queues by half distance - pq_count = math.ceil((max(if_queues) + 1) / 2) + # To simulate vendor OID, we wrap queues by max priority groups + port_max_queues = self.statedb.get_all(self.statedb.STATE_DB, + mibs.buffer_max_parm_table(self.oid_name_map[if_index]))['max_queues'] + pq_count = math.ceil(int(port_max_queues) / 2) for queue in if_queues: # Get queue type and statistics diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index a120b8a61..7ba3c53a6 100755 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -3555,7 +3555,13 @@ "Ethernet8:12": "oid:0x15000000010254", "Ethernet8:13": "oid:0x15000000010255", "Ethernet8:14": "oid:0x15000000010256", - "Ethernet8:15": "oid:0x15000000010257" + "Ethernet8:15": "oid:0x15000000010257", + "Ethernet16:0": "oid:0x15000000000260", + "Ethernet16:1": "oid:0x15000000000261", + "Ethernet16:2": "oid:0x15000000000262", + "Ethernet16:3": "oid:0x15000000000263", + "Ethernet16:4": "oid:0x15000000000264", + "Ethernet16:6": "oid:0x15000000000266" }, "COUNTERS_QUEUE_TYPE_MAP": { "oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST", @@ -3605,7 +3611,13 @@ "oid:0x15000000010254": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010255": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010256": "SAI_QUEUE_TYPE_MULTICAST", - "oid:0x15000000010257": "SAI_QUEUE_TYPE_MULTICAST" + "oid:0x15000000010257": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000000260": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000261": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000262": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000263": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000264": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000266": "SAI_QUEUE_TYPE_UNICAST" }, "COUNTERS:oid:0x15000000000230": { "SAI_QUEUE_STAT_PACKETS": "1", @@ -3990,4 +4002,41 @@ "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" - }} + }, + "COUNTERS:oid:0x15000000000260": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "23492723984237432", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + }, + "COUNTERS:oid:0x15000000000261": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + }, + "COUNTERS:oid:0x15000000000262": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + }, + "COUNTERS:oid:0x15000000000263": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + }, + "COUNTERS:oid:0x15000000000264": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + }, + "COUNTERS:oid:0x15000000000266": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + } +} diff --git a/tests/mock_tables/global_db/state_db.json b/tests/mock_tables/global_db/state_db.json index 0674d83ab..ed5387890 100644 --- a/tests/mock_tables/global_db/state_db.json +++ b/tests/mock_tables/global_db/state_db.json @@ -123,5 +123,23 @@ "TEMPERATURE_INFO|thermal1": { "temperature": "20.5", "is_replaceable": "False" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet0": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet4": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet8": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet12": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet-BP16": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet-BP20": { + "max_queues": "16" } } diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index abccdb386..681e5747d 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -195,5 +195,17 @@ }, "NEIGH_STATE_TABLE|fc00::12": { "state" : "Deleted" - } + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet0": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet4": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet8": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet16": { + "max_queues": "16" + } } diff --git a/tests/test_queues_stat.py b/tests/test_queues_stat.py index 31f82e60b..71d629782 100644 --- a/tests/test_queues_stat.py +++ b/tests/test_queues_stat.py @@ -44,6 +44,32 @@ def test_getQueueCounters(self): self.assertEqual(str(value0.name), str(oid)) self.assertEqual(value0.data, 1) + # Test issue https://github.com/sonic-net/sonic-buildimage/issues/17448 + # In this Scenario not all counters are created. + # Ethernet16 is created on mock_tables\counters_db.json with only counters for UC 0,1,2,3,4,6 + def test_getQueueCountersForPortWithAllCounters(self): + configured_queues = [1,2,3,4,5,7] + for queue_id in range(1, 8): + oid = ObjectIdentifier(8, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 580, 1, 5, 5, 1, 4, 17, 2, queue_id, 1)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + value0 = response.values[0] + if queue_id in configured_queues: + self.assertEqual(value0.type_, ValueType.COUNTER_64) + self.assertEqual(str(value0.name), str(oid)) + self.assertEqual(value0.data, 1) + else: + self.assertEqual(value0.type_, ValueType.NO_SUCH_INSTANCE) + self.assertEqual(str(value0.name), str(oid)) + self.assertEqual(value0.data, None) + + def test_getNextPduForQueueCounter(self): oid = ObjectIdentifier(8, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 580, 1, 5, 5, 1, 4, 1, 2, 1, 1)) expected_oid = ObjectIdentifier(8, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 580, 1, 5, 5, 1, 4, 1, 2, 1, 2))