Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SNMP dropping some of the queue counter when create_only_config_d… #303

12 changes: 12 additions & 0 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
DavidZagury marked this conversation as resolved.
Show resolved Hide resolved
self.statedb.connect(self.statedb.STATE_DB)


def reinit_connection(self):
Namespace.connect_namespace_dbs(self.db_conn)

Expand Down Expand Up @@ -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,
DavidZagury marked this conversation as resolved.
Show resolved Hide resolved
mibs.buffer_max_parm_table(self.oid_name_map[if_index]))['max_queues']
pq_count = math.ceil(int(port_max_queues) / 2)
DavidZagury marked this conversation as resolved.
Show resolved Hide resolved

for queue in if_queues:
# Get queue type and statistics
Expand Down
227 changes: 224 additions & 3 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,29 @@
"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",
"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"
},
DavidZagury marked this conversation as resolved.
Show resolved Hide resolved
"COUNTERS_QUEUE_TYPE_MAP": {
"oid:0x15000000000230": "SAI_QUEUE_TYPE_UNICAST",
Expand Down Expand Up @@ -3605,7 +3627,29 @@
"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",
"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",
Expand Down Expand Up @@ -3990,4 +4034,181 @@
"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"
},
"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_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"
}
}
18 changes: 18 additions & 0 deletions tests/mock_tables/global_db/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,23 @@
"TEMPERATURE_INFO|thermal1": {
"temperature": "20.5",
"is_replaceable": "False"
},
"BUFFER_MAX_PARAM_TABLE|Ethernet0": {
DavidZagury marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
}
20 changes: 19 additions & 1 deletion tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,23 @@
},
"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"
},
"BUFFER_MAX_PARAM_TABLE|Ethernet24": {
"max_queues": "16"
},
"BUFFER_MAX_PARAM_TABLE|Ethernet32": {
"max_queues": "16"
}
}
45 changes: 45 additions & 0 deletions tests/test_queues_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,51 @@ def test_getQueueCounters(self):
self.assertEqual(str(value0.name), str(oid))
self.assertEqual(value0.data, 1)

DavidZagury marked this conversation as resolved.
Show resolved Hide resolved
# 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):
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):
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))
Expand Down