Skip to content

Commit

Permalink
Fix system capabilities parsing issue. (sonic-net#111)
Browse files Browse the repository at this point in the history
* Fix system capabilities parsing issue.
For lldp_rem_sys_cap_supported, lldp_rem_sys_cap_enabled, lldp_loc_sys_cap_supported, and lldp_loc_sys_cap_enabled objects,
shall converts string to hex bytes.
* Extract as a function for system capability parsing
* Add mock data and test case for lldpLocSysCapSupported
* Add test cases for lldpLocSysCapEnabled, lldpRemSysCapSupported, and lldpRemSysCapEnabled.
  • Loading branch information
chenkelly authored and qiluo-msft committed Nov 1, 2019
1 parent e364884 commit 28f9e5d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
56 changes: 56 additions & 0 deletions tests/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 28f9e5d

Please sign in to comment.