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… #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
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,
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
Expand Down
55 changes: 52 additions & 3 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
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": {
"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"
}
}
14 changes: 13 additions & 1 deletion tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
26 changes: 26 additions & 0 deletions tests/test_queues_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down