diff --git a/src/sonic_ax_impl/mibs/ieee802_1ab.py b/src/sonic_ax_impl/mibs/ieee802_1ab.py index 9959cb2d3dad..c61b19d4fa9f 100644 --- a/src/sonic_ax_impl/mibs/ieee802_1ab.py +++ b/src/sonic_ax_impl/mibs/ieee802_1ab.py @@ -95,6 +95,8 @@ def poll_lldp_entry_updates(pubsub): return ret return data, interface, if_index +def parse_sys_capability(sys_cap): + return bytearray([int (x, 16) for x in sys_cap.split()]) class LLDPLocalSystemDataUpdater(MIBUpdater): def __init__(self): @@ -110,7 +112,8 @@ def reinit_data(self): # establish connection to application database. self.db_conn.connect(mibs.APPL_DB) self.loc_chassis_data = self.db_conn.get_all(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE) - + self.loc_chassis_data[b'lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_supported']) + self.loc_chassis_data[b'lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_enabled']) def update_data(self): """ Avoid NotImplementedError @@ -432,7 +435,8 @@ def update_data(self): self.if_range.append((time_mark, if_oid, remote_index)) - + lldp_kvs[b'lldp_rem_sys_cap_supported'] = parse_sys_capability(lldp_kvs[b'lldp_rem_sys_cap_supported']) + lldp_kvs[b'lldp_rem_sys_cap_enabled'] = parse_sys_capability(lldp_kvs[b'lldp_rem_sys_cap_enabled']) self.lldp_counters.update({if_name: lldp_kvs}) except (KeyError, AttributeError) as e: logger.warning("Exception when updating lldpRemTable: {}".format(e)) diff --git a/tests/mock_tables/appl_db.json b/tests/mock_tables/appl_db.json index 1c67a487a43d..45dfe89f7e80 100644 --- a/tests/mock_tables/appl_db.json +++ b/tests/mock_tables/appl_db.json @@ -466,6 +466,8 @@ "lldp_loc_chassis_id": "00:11:22:AB:CD:EF", "lldp_loc_sys_name": "SONiC", "lldp_loc_sys_desc": "Gotta go Fast!", + "lldp_loc_sys_cap_enabled": "28 00", + "lldp_loc_sys_cap_supported": "28 00", "lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c" }, "PORT_TABLE:Ethernet0": { diff --git a/tests/test_lldp.py b/tests/test_lldp.py index ba252e43b27a..ea845df6e20e 100644 --- a/tests/test_lldp.py +++ b/tests/test_lldp.py @@ -202,3 +202,59 @@ def test_getnextpdu_noeth(self): print(response) value0 = response.values[0] self.assertEqual(value0.type_, ValueType.END_OF_MIB_VIEW) + + def test_getnextpdu_lldpLocSysCapSupported(self): + oid = ObjectIdentifier(9, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 5)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 5)))) + self.assertEqual(str(value0.data), "\x28\x00") + + def test_getnextpdu_lldpLocSysCapEnabled(self): + oid = ObjectIdentifier(9, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 6)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 6)))) + self.assertEqual(str(value0.data), "\x28\x00") + + def test_getnextpdu_lldpRemSysCapSupported(self): + oid = ObjectIdentifier(12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 11, 1, 1)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 11, 1, 1)))) + self.assertEqual(str(value0.data), "\x28\x00") + + def test_getnextpdu_lldpRemSysCapEnabled(self): + oid = ObjectIdentifier(12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 12, 1, 1)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 12, 1, 1)))) + self.assertEqual(str(value0.data), "\x28\x00") \ No newline at end of file