From 7e53d9d34309197910aca9903345b7c113d60d46 Mon Sep 17 00:00:00 2001 From: davidza Date: Thu, 14 Dec 2023 18:54:18 +0200 Subject: [PATCH 1/9] Fix SNMP dropping some of the queue counter when create_only_config_db_buffers is set to true This happened because the MIB assumed that half the queues configured are for mcast. To remove this assumpetion we will check the max number of queues from STATE_DB.BUFFER_MAX_PARAM_TABLE|.max_queues --- src/sonic_ax_impl/mibs/__init__.py | 13 ++++++++++++- .../mibs/vendor/cisco/ciscoSwitchQosMIB.py | 10 +++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index 612d580f9..35e093ac3 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 @@ -439,7 +451,6 @@ def init_sync_d_queue_tables(db_conn): port_index = get_index_from_str(port_name) key = queue_key(port_index, queue_index) port_queues_map[key] = sai_id - queue_stat_name = queue_table(sai_id) queue_stat = db_conn.get_all(COUNTERS_DB, queue_stat_name, blocking=False) if queue_stat is not None: diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py index 2ee47e35c..3bd726e39 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,8 @@ 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_priority_groups = self.statedb.get_all(self.statedb.STATE_DB, mibs.buffer_max_parm_table(self.oid_name_map[if_index]))['max_priority_groups'] for queue in if_queues: # Get queue type and statistics @@ -146,7 +150,7 @@ def update_stats(self): # Add supported counters to MIBs list and store counters values for (counter, counter_type), counter_mib_id in CounterMap.items(): # Only egress queues are supported - mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % pq_count) + 1, counter_mib_id) + mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % int(port_max_priority_groups)) + 1, counter_mib_id) counter_value = 0 if queue_type == counter_type: From 71f9e819f88a2f61e32fdb35499dd7510956fccc Mon Sep 17 00:00:00 2001 From: davidza Date: Mon, 18 Dec 2023 10:13:05 +0200 Subject: [PATCH 2/9] Use max queues --- src/sonic_ax_impl/mibs/__init__.py | 1 + src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index 35e093ac3..e849bfbc6 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -451,6 +451,7 @@ def init_sync_d_queue_tables(db_conn): port_index = get_index_from_str(port_name) key = queue_key(port_index, queue_index) port_queues_map[key] = sai_id + queue_stat_name = queue_table(sai_id) queue_stat = db_conn.get_all(COUNTERS_DB, queue_stat_name, blocking=False) if queue_stat is not None: diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py index 3bd726e39..7e5988ad3 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py @@ -137,7 +137,9 @@ def update_stats(self): # The first half of queue id is for ucast, and second half is for mcast # To simulate vendor OID, we wrap queues by max priority groups - port_max_priority_groups = self.statedb.get_all(self.statedb.STATE_DB, mibs.buffer_max_parm_table(self.oid_name_map[if_index]))['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((port_max_queues + 1) / 2) for queue in if_queues: # Get queue type and statistics @@ -150,7 +152,7 @@ def update_stats(self): # Add supported counters to MIBs list and store counters values for (counter, counter_type), counter_mib_id in CounterMap.items(): # Only egress queues are supported - mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % int(port_max_priority_groups)) + 1, counter_mib_id) + mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % pq_count) + 1, counter_mib_id) counter_value = 0 if queue_type == counter_type: From 04c1e368f50618c98d3c8008de3a8a703cf39eb4 Mon Sep 17 00:00:00 2001 From: davidza Date: Mon, 18 Dec 2023 12:44:37 +0200 Subject: [PATCH 3/9] Add max_queues value to unit test state db --- tests/mock_tables/state_db.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index abccdb386..49519a64c 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -195,5 +195,8 @@ }, "NEIGH_STATE_TABLE|fc00::12": { "state" : "Deleted" - } + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet0": { + "max_queues": "16" + } } From d62f7399c5826dc4fb21d23a1b2b0531b5c0eeda Mon Sep 17 00:00:00 2001 From: davidza Date: Mon, 18 Dec 2023 21:05:24 +0200 Subject: [PATCH 4/9] Fix UT - add missing DB values and fix pq_count - should be 16 % 2 = 8 and not (16 + 1 ) % 2 = 9 --- .../mibs/vendor/cisco/ciscoSwitchQosMIB.py | 2 +- tests/mock_tables/global_db/state_db.json | 18 ++++++++++++++++++ tests/mock_tables/state_db.json | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py index 7e5988ad3..a3d50379f 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py @@ -139,7 +139,7 @@ def update_stats(self): # 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((port_max_queues + 1) / 2) + 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/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 49519a64c..1235c9815 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -198,5 +198,11 @@ }, "BUFFER_MAX_PARAM_TABLE|Ethernet0": { "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet4": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet8": { + "max_queues": "16" } } From 3d13de4fec13be532aa8f3edc1ef1acd8f8836c0 Mon Sep 17 00:00:00 2001 From: davidza Date: Tue, 19 Dec 2023 19:40:10 +0200 Subject: [PATCH 5/9] Add UT for port that doe --- tests/mock_tables/counters_db.json | 55 ++++++++++++++++++++++++++++-- tests/mock_tables/state_db.json | 3 ++ tests/test_queues_stat.py | 26 ++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) 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/state_db.json b/tests/mock_tables/state_db.json index 1235c9815..681e5747d 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -204,5 +204,8 @@ }, "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)) From f45e746d8503018c5cc545a784a09fe46ba95f4f Mon Sep 17 00:00:00 2001 From: davidza Date: Wed, 27 Dec 2023 13:21:33 +0200 Subject: [PATCH 6/9] Add UT for port that with an with incomplete MC and a port with incomplete UC and incomplete MC. --- tests/mock_tables/counters_db.json | 188 +++++++++++++++++++++++++++-- tests/mock_tables/state_db.json | 6 + tests/test_queues_stat.py | 59 ++++++--- 3 files changed, 225 insertions(+), 28 deletions(-) diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 7ba3c53a6..fdd76e764 100755 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -3561,7 +3561,23 @@ "Ethernet16:2": "oid:0x15000000000262", "Ethernet16:3": "oid:0x15000000000263", "Ethernet16:4": "oid:0x15000000000264", - "Ethernet16:6": "oid:0x15000000000266" + "Ethernet16:6": "oid:0x15000000000266", + "Ethernet24:8": "oid:0x15000000010270", + "Ethernet24:10": "oid:0x15000000010272", + "Ethernet24:11": "oid:0x15000000010273", + "Ethernet24:13": "oid:0x15000000010275", + "Ethernet24:14": "oid:0x15000000010276", + "Ethernet24:15": "oid:0x15000000010277", + "Ethernet32:1": "oid:0x15000000000281", + "Ethernet32:2": "oid:0x15000000000282", + "Ethernet32:4": "oid:0x15000000000284", + "Ethernet32:6": "oid:0x15000000000286", + "Ethernet32:7": "oid:0x15000000000287", + "Ethernet32:8": "oid:0x15000000010280", + "Ethernet32:9": "oid:0x15000000010281", + "Ethernet32:11": "oid:0x15000000010283", + "Ethernet32:13": "oid:0x15000000010285", + "Ethernet32:14": "oid:0x15000000010286" }, "COUNTERS_QUEUE_TYPE_MAP": { "oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST", @@ -3617,7 +3633,23 @@ "oid:0x15000000000262": "SAI_QUEUE_TYPE_UNICAST", "oid:0x15000000000263": "SAI_QUEUE_TYPE_UNICAST", "oid:0x15000000000264": "SAI_QUEUE_TYPE_UNICAST", - "oid:0x15000000000266": "SAI_QUEUE_TYPE_UNICAST" + "oid:0x15000000000266": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000010270": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010272": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010273": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010275": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010276": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010277": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000000281": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000282": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000284": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000286": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000287": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000010280": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010281": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010283": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010285": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010286": "SAI_QUEUE_TYPE_MULTICAST" }, "COUNTERS:oid:0x15000000000230": { "SAI_QUEUE_STAT_PACKETS": "1", @@ -4006,37 +4038,177 @@ "COUNTERS:oid:0x15000000000260": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "23492723984237432", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" }, "COUNTERS:oid:0x15000000000261": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" }, "COUNTERS:oid:0x15000000000262": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" }, "COUNTERS:oid:0x15000000000263": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" }, "COUNTERS:oid:0x15000000000264": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" }, "COUNTERS:oid:0x15000000000266": { "SAI_QUEUE_STAT_PACKETS": "1", "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010270": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010272": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010273": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010275": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010276": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010277": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000281": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000282": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", - "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "0" + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000284": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000286": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000287": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010280": { + "SAI_QUEUE_STAT_PACKETS": "123459", + "SAI_QUEUE_STAT_BYTES": "23492723984237432", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010281": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010283": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010285": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010286": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" } } diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 681e5747d..ad4cd5eca 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -207,5 +207,11 @@ }, "BUFFER_MAX_PARAM_TABLE|Ethernet16": { "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet24": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet32": { + "max_queues": "16" } } diff --git a/tests/test_queues_stat.py b/tests/test_queues_stat.py index 71d629782..3ae9695c9 100644 --- a/tests/test_queues_stat.py +++ b/tests/test_queues_stat.py @@ -47,27 +47,46 @@ def test_getQueueCounters(self): # 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 + # Ethernet24 is created on mock_tables\counters_db.json with only counters for MC 0,2,3,5,6,7 + # Ethernet32 is created on mock_tables\counters_db.json with only counters for UC 1,2,4,6,7 and MC 0,1,3,5,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) + tested_ports_counters_data = { + 17: { 1: {1:1, 2:23492723984237432, 5:3,6:0}, 2: {1:1, 2:2, 5:3, 6:0}, + 3: {1:1, 2:2, 5:3, 6:0}, 4: {1:1, 2:2, 5:3, 6:0}, + 5: {1:1, 2:2, 5:3, 6:0}, 7: {1:1, 2:2, 5:3, 6:0} + }, + 25: { 1: {3:1, 4:2, 7:3, 8:0}, 3: {3:1, 4:2, 7:3, 8:0}, + 4: {3:1, 4:2, 7:3, 8:0}, 6: {3:1, 4:2, 7:3, 8:0}, + 7: {3:1, 4:2, 7:3, 8:0}, 8: {3:1, 4:2, 7:3, 8:0} + }, + 33: { 1: {3:123459, 4:23492723984237432, 7:3, 8:0}, 2: {1:1, 2:2, 3:1, 4:2, 5:3, 6:0, 7:3,8:0}, + 3: {1:1, 2:2, 5:3, 6:0}, 4: {3:1, 4:2, 7:3, 8:0}, + 5: {1:1, 2:2, 5:3, 6:0}, 6: {3:1, 4:2, 7:3, 8:0}, + 7: {1:1, 2:2, 3:1, 4:2, 5:3, 6:0, 7:3,8:0}, 8: {1:1, 2:2, 5:3, 6:0} + } + } + + for port, configured_queues in tested_ports_counters_data.items(): + for queue_id in range(1, 8): + for counter_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, port, 2, queue_id, counter_id)) + 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.keys() and counter_id in configured_queues[queue_id]: + self.assertEqual(value0.type_, ValueType.COUNTER_64) + self.assertEqual(str(value0.name), str(oid)) + self.assertEqual(value0.data, configured_queues[queue_id][counter_id]) + 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): From aecfeb02b7e06d5d24d978565fd09b08cd0a62b9 Mon Sep 17 00:00:00 2001 From: davidza Date: Thu, 28 Dec 2023 16:05:09 +0200 Subject: [PATCH 7/9] Add support for multi-asic --- src/sonic_ax_impl/mibs/__init__.py | 1 - .../mibs/vendor/cisco/ciscoSwitchQosMIB.py | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index e849bfbc6..35e093ac3 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -451,7 +451,6 @@ def init_sync_d_queue_tables(db_conn): port_index = get_index_from_str(port_name) key = queue_key(port_index, queue_index) port_queues_map[key] = sai_id - queue_stat_name = queue_table(sai_id) queue_stat = db_conn.get_all(COUNTERS_DB, queue_stat_name, blocking=False) if queue_stat is not None: diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py index a3d50379f..31df647d0 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py @@ -46,6 +46,9 @@ def __init__(self): """ super().__init__() self.db_conn = Namespace.init_namespace_dbs() + # establish connection to state database. + Namespace.connect_all_dbs(self.db_conn, mibs.STATE_DB) + self.lag_name_if_name_map = {} self.if_name_lag_name_map = {} self.oid_lag_name_map = {} @@ -67,10 +70,6 @@ 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) @@ -137,8 +136,8 @@ def update_stats(self): # The first half of queue id is for ucast, and second half is for mcast # 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'] + port_max_queues = Namespace.dbs_get_all(self.db_conn, mibs.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: From ab65bd02d116d286fd73c2d762f1df24cd954dbb Mon Sep 17 00:00:00 2001 From: davidza Date: Thu, 28 Dec 2023 22:25:13 +0200 Subject: [PATCH 8/9] Add support for multi asic system Add UT for multi asic --- tests/mock_tables/asic0/appl_db.json | 4 + tests/mock_tables/asic0/counters_db.json | 70 +++++++++++++- tests/mock_tables/asic1/appl_db.json | 4 + tests/mock_tables/asic1/counters_db.json | 70 +++++++++++++- tests/mock_tables/asic2/appl_db.json | 5 + tests/mock_tables/asic2/counters_db.json | 111 +++++++++++++++++++++- tests/mock_tables/global_db/state_db.json | 9 ++ tests/namespace/test_queues_stat.py | 46 +++++++++ 8 files changed, 307 insertions(+), 12 deletions(-) diff --git a/tests/mock_tables/asic0/appl_db.json b/tests/mock_tables/asic0/appl_db.json index 6b0c146a1..5663ccab8 100644 --- a/tests/mock_tables/asic0/appl_db.json +++ b/tests/mock_tables/asic0/appl_db.json @@ -46,6 +46,10 @@ "alias": "etp2", "speed": 100000 }, + "PORT_TABLE:Ethernet24": { + "alias": "etp17", + "speed": 100000 + }, "PORT_TABLE:Ethernet-BP0": { "description": "snowflake", "alias": "etp3", diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 490b7d9b7..f7222c13d 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -311,7 +311,8 @@ "Ethernet-BP0": "oid:0x1000000000005", "Ethernet-BP4": "oid:0x1000000000006", "Ethernet-IB0": "oid:0x1000000000080", - "Ethernet-Rec0": "oid:0x1000000000081" + "Ethernet-Rec0": "oid:0x1000000000081", + "Ethernet24": "oid:0x1000000000014" }, "COUNTERS_LAG_NAME_MAP": { "PortChannel01": "oid:0x1000000000007" @@ -592,7 +593,13 @@ "Ethernet4:12": "oid:0x15000000010244", "Ethernet4:13": "oid:0x15000000010245", "Ethernet4:14": "oid:0x15000000010246", - "Ethernet4:15": "oid:0x15000000010247" + "Ethernet4:15": "oid:0x15000000010247", + "Ethernet24:0": "oid:0x15000000000260", + "Ethernet24:1": "oid:0x15000000000261", + "Ethernet24:2": "oid:0x15000000000262", + "Ethernet24:3": "oid:0x15000000000263", + "Ethernet24:4": "oid:0x15000000000264", + "Ethernet24:6": "oid:0x15000000000266" }, "COUNTERS_QUEUE_TYPE_MAP": { "oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST", @@ -626,7 +633,13 @@ "oid:0x15000000010244": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010245": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010246": "SAI_QUEUE_TYPE_MULTICAST", - "oid:0x15000000010247": "SAI_QUEUE_TYPE_MULTICAST" + "oid:0x15000000010247": "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", @@ -883,4 +896,53 @@ "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_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000261": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000262": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000263": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000264": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000266": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + } +} diff --git a/tests/mock_tables/asic1/appl_db.json b/tests/mock_tables/asic1/appl_db.json index f8d7f0aa9..741b2358b 100644 --- a/tests/mock_tables/asic1/appl_db.json +++ b/tests/mock_tables/asic1/appl_db.json @@ -49,6 +49,10 @@ "speed": 1000, "alias": "etp16" }, + "PORT_TABLE:Ethernet32": { + "speed": 1000, + "alias": "etp18" + }, "PORT_TABLE:Ethernet-BP8": { "alias": "etp7" }, diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 7304ffe10..4e7511f48 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -310,7 +310,8 @@ "Ethernet12": "oid:0x1000000000004", "Ethernet-BP8": "oid:0x1000000000005", "Ethernet-BP12": "oid:0x1000000000006", - "Ethernet16": "oid:0x1000000000010" + "Ethernet16": "oid:0x1000000000010", + "Ethernet32": "oid:0x1000000000011" }, "COUNTERS_LAG_NAME_MAP": { "PortChannel02": "oid:0x1000000000007" @@ -697,7 +698,13 @@ "Ethernet12:12": "oid:0x15000000010244", "Ethernet12:13": "oid:0x15000000010245", "Ethernet12:14": "oid:0x15000000010246", - "Ethernet12:15": "oid:0x15000000010247" + "Ethernet12:15": "oid:0x15000000010247", + "Ethernet32:8": "oid:0x15000000010270", + "Ethernet32:10": "oid:0x15000000010272", + "Ethernet32:11": "oid:0x15000000010273", + "Ethernet32:13": "oid:0x15000000010275", + "Ethernet32:14": "oid:0x15000000010276", + "Ethernet32:15": "oid:0x15000000010277" }, "COUNTERS_QUEUE_TYPE_MAP": { "oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST", @@ -731,7 +738,13 @@ "oid:0x15000000010244": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010245": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010246": "SAI_QUEUE_TYPE_MULTICAST", - "oid:0x15000000010247": "SAI_QUEUE_TYPE_MULTICAST" + "oid:0x15000000010247": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010270": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010272": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010273": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010275": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010276": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010277": "SAI_QUEUE_TYPE_MULTICAST" }, "COUNTERS:oid:0x15000000000230": { "SAI_QUEUE_STAT_PACKETS": "1", @@ -988,4 +1001,53 @@ "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" - }} + }, + "COUNTERS:oid:0x15000000010270": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010272": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010273": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010275": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010276": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010277": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + } +} diff --git a/tests/mock_tables/asic2/appl_db.json b/tests/mock_tables/asic2/appl_db.json index c99d60591..291a1c10b 100644 --- a/tests/mock_tables/asic2/appl_db.json +++ b/tests/mock_tables/asic2/appl_db.json @@ -47,6 +47,11 @@ "alias": "etp12", "speed": 100000 }, + "PORT_TABLE:Ethernet40": { + "description": "snowflake", + "alias": "etp19", + "speed": 100000 + }, "ROUTE_TABLE:10.1.0.32": { "nexthop": "", "ifname": "lo" diff --git a/tests/mock_tables/asic2/counters_db.json b/tests/mock_tables/asic2/counters_db.json index 36b0ff839..010184f57 100644 --- a/tests/mock_tables/asic2/counters_db.json +++ b/tests/mock_tables/asic2/counters_db.json @@ -309,7 +309,8 @@ "Ethernet-BP16": "oid:0x1000000000003", "Ethernet-BP20": "oid:0x1000000000004", "Ethernet-BP24": "oid:0x1000000000005", - "Ethernet-BP28": "oid:0x1000000000006" + "Ethernet-BP28": "oid:0x1000000000006", + "Ethernet40": "oid:0x100000000000d" }, "COUNTERS_LAG_NAME_MAP": { "PortChannel03": "oid:0x1000000000007", @@ -659,7 +660,18 @@ "Ethernet-BP20:12": "oid:0x15000000010244", "Ethernet-BP20:13": "oid:0x15000000010245", "Ethernet-BP20:14": "oid:0x15000000010246", - "Ethernet-BP20:15": "oid:0x15000000010247" + "Ethernet-BP20:15": "oid:0x15000000010247", + "Ethernet40:1": "oid:0x15000000000281", + "Ethernet40:2": "oid:0x15000000000282", + "Ethernet40:4": "oid:0x15000000000284", + "Ethernet40:6": "oid:0x15000000000286", + "Ethernet40:7": "oid:0x15000000000287", + "Ethernet40:8": "oid:0x15000000010280", + "Ethernet40:9": "oid:0x15000000010281", + "Ethernet40:11": "oid:0x15000000010283", + "Ethernet40:13": "oid:0x15000000010285", + "Ethernet40:14": "oid:0x15000000010286" + }, "COUNTERS_QUEUE_TYPE_MAP": { "oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST", @@ -693,7 +705,17 @@ "oid:0x15000000010244": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010245": "SAI_QUEUE_TYPE_MULTICAST", "oid:0x15000000010246": "SAI_QUEUE_TYPE_MULTICAST", - "oid:0x15000000010247": "SAI_QUEUE_TYPE_MULTICAST" + "oid:0x15000000010247": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000000281": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000282": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000284": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000286": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000000287": "SAI_QUEUE_TYPE_UNICAST", + "oid:0x15000000010280": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010281": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010283": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010285": "SAI_QUEUE_TYPE_MULTICAST", + "oid:0x15000000010286": "SAI_QUEUE_TYPE_MULTICAST" }, "COUNTERS:oid:0x15000000000230": { "SAI_QUEUE_STAT_PACKETS": "1", @@ -950,4 +972,85 @@ "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" - }} + }, + "COUNTERS:oid:0x15000000000281": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000282": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000284": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000286": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000000287": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010280": { + "SAI_QUEUE_STAT_PACKETS": "123459", + "SAI_QUEUE_STAT_BYTES": "23492723984237432", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010281": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010283": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010285": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + }, + "COUNTERS:oid:0x15000000010286": { + "SAI_QUEUE_STAT_PACKETS": "1", + "SAI_QUEUE_STAT_BYTES": "2", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "3", + "SAI_QUEUE_STAT_DISCARD_DROPPED_PACKETS": "4", + "SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES": "5", + "SAI_QUEUE_STAT_WATERMARK_BYTES": "6" + } +} diff --git a/tests/mock_tables/global_db/state_db.json b/tests/mock_tables/global_db/state_db.json index ed5387890..dde051ec1 100644 --- a/tests/mock_tables/global_db/state_db.json +++ b/tests/mock_tables/global_db/state_db.json @@ -141,5 +141,14 @@ }, "BUFFER_MAX_PARAM_TABLE|Ethernet-BP20": { "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet24": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet32": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet40": { + "max_queues": "16" } } diff --git a/tests/namespace/test_queues_stat.py b/tests/namespace/test_queues_stat.py index d97db2efa..5c24cc624 100644 --- a/tests/namespace/test_queues_stat.py +++ b/tests/namespace/test_queues_stat.py @@ -48,6 +48,52 @@ 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. + # Ethernet24 is created on mock_tables\asic0\counters_db.json with only counters for UC 0,1,2,3,4,6 + # Ethernet32 is created on mock_tables\asic1\counters_db.json with only counters for MC 0,2,3,5,6,7 + # Ethernet40 is created on mock_tables\asic2\counters_db.json with only counters for UC 1,2,4,6,7 and MC 0,1,3,5,6 + def test_getQueueCountersForPortWithAllCounters(self): + tested_ports_counters_data = { + 25: { 1: {1:1, 2:23492723984237432, 5:3,6:0}, 2: {1:1, 2:2, 5:3, 6:0}, + 3: {1:1, 2:2, 5:3, 6:0}, 4: {1:1, 2:2, 5:3, 6:0}, + 5: {1:1, 2:2, 5:3, 6:0}, 7: {1:1, 2:2, 5:3, 6:0} + }, + 33: { 1: {3:1, 4:2, 7:3, 8:0}, 3: {3:1, 4:2, 7:3, 8:0}, + 4: {3:1, 4:2, 7:3, 8:0}, 6: {3:1, 4:2, 7:3, 8:0}, + 7: {3:1, 4:2, 7:3, 8:0}, 8: {3:1, 4:2, 7:3, 8:0} + }, + 41: { 1: {3:123459, 4:23492723984237432, 7:3, 8:0}, 2: {1:1, 2:2, 3:1, 4:2, 5:3, 6:0, 7:3,8:0}, + 3: {1:1, 2:2, 5:3, 6:0}, 4: {3:1, 4:2, 7:3, 8:0}, + 5: {1:1, 2:2, 5:3, 6:0}, 6: {3:1, 4:2, 7:3, 8:0}, + 7: {1:1, 2:2, 3:1, 4:2, 5:3, 6:0, 7:3,8:0}, 8: {1:1, 2:2, 5:3, 6:0} + } + } + + for port, configured_queues in tested_ports_counters_data.items(): + for queue_id in range(1, 8): + for counter_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, port, 2, queue_id, counter_id)) + 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.keys() and counter_id in configured_queues[queue_id]: + self.assertEqual(value0.type_, ValueType.COUNTER_64) + self.assertEqual(str(value0.name), str(oid)) + self.assertEqual(value0.data, configured_queues[queue_id][counter_id]) + 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)) From db40166688def6285eae19f9a25971ff0b96e771 Mon Sep 17 00:00:00 2001 From: davidza Date: Sun, 7 Jan 2024 16:32:36 +0200 Subject: [PATCH 9/9] Move BUFFER_MAX_PARAM_TABLE from global db to asic dbs --- tests/mock_tables/asic0/state_db.json | 9 ++++++++ tests/mock_tables/asic1/state_db.json | 9 ++++++++ tests/mock_tables/asic2/state_db.json | 9 ++++++++ tests/mock_tables/global_db/state_db.json | 27 ----------------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/mock_tables/asic0/state_db.json b/tests/mock_tables/asic0/state_db.json index bf0405422..5c281f9f4 100644 --- a/tests/mock_tables/asic0/state_db.json +++ b/tests/mock_tables/asic0/state_db.json @@ -33,5 +33,14 @@ }, "NEIGH_STATE_TABLE|fec0::ffff:afa:07": { "state": "Active" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet0": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet4": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet24": { + "max_queues": "16" } } diff --git a/tests/mock_tables/asic1/state_db.json b/tests/mock_tables/asic1/state_db.json index 9af1a6316..026d90b49 100644 --- a/tests/mock_tables/asic1/state_db.json +++ b/tests/mock_tables/asic1/state_db.json @@ -30,5 +30,14 @@ }, "NEIGH_STATE_TABLE|10.10.0.4": { "state": "Established" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet8": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet12": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet32": { + "max_queues": "16" } } diff --git a/tests/mock_tables/asic2/state_db.json b/tests/mock_tables/asic2/state_db.json index 87ec6d4dd..be6fe9a42 100644 --- a/tests/mock_tables/asic2/state_db.json +++ b/tests/mock_tables/asic2/state_db.json @@ -4,5 +4,14 @@ }, "NEIGH_STATE_TABLE|10.10.0.5": { "state": "Established" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet-BP16": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet-BP20": { + "max_queues": "16" + }, + "BUFFER_MAX_PARAM_TABLE|Ethernet40": { + "max_queues": "16" } } diff --git a/tests/mock_tables/global_db/state_db.json b/tests/mock_tables/global_db/state_db.json index dde051ec1..0674d83ab 100644 --- a/tests/mock_tables/global_db/state_db.json +++ b/tests/mock_tables/global_db/state_db.json @@ -123,32 +123,5 @@ "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" - }, - "BUFFER_MAX_PARAM_TABLE|Ethernet24": { - "max_queues": "16" - }, - "BUFFER_MAX_PARAM_TABLE|Ethernet32": { - "max_queues": "16" - }, - "BUFFER_MAX_PARAM_TABLE|Ethernet40": { - "max_queues": "16" } }