From 6e4a796b245a99da29f8390fe01d09a37d32ec4f Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Mon, 12 Oct 2020 15:12:53 -0700 Subject: [PATCH] Fix: correctly handle that lldp_loc_man_addr contains only IPv6 address without IPv4 address (#164) * Fix mgmt_ip_sub_oid default value to prevent later exception * Refix * Reimplement LLDPLocManAddrUpdater * Fix test case * Revert some back and fix lookup() --- src/sonic_ax_impl/mibs/ieee802_1ab.py | 7 +++++-- tests/namespace/test_lldp.py | 16 +++++++++++----- tests/test_lldp.py | 16 +++++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/sonic_ax_impl/mibs/ieee802_1ab.py b/src/sonic_ax_impl/mibs/ieee802_1ab.py index 8770e2d5561c..bccaa5544a65 100644 --- a/src/sonic_ax_impl/mibs/ieee802_1ab.py +++ b/src/sonic_ax_impl/mibs/ieee802_1ab.py @@ -317,6 +317,9 @@ def reinit_data(self): if '.' in mgmt_ip: mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip.split('.')]) break + else: + logger.error("Could not find IPv4 address in lldp_loc_man_addr") + return except ValueError: logger.error("Invalid local mgmt IP {}".format(self.mgmt_ip_str)) return @@ -334,12 +337,12 @@ def update_data(self): def get_next(self, sub_id): right = bisect_right(self.man_addr_list, sub_id) - if right == len(self.man_addr_list): + if right >= len(self.man_addr_list): return None return self.man_addr_list[right] def lookup(self, sub_id, callable): - if len(sub_id) == 0: + if sub_id not in self.man_addr_list: return None return callable(sub_id) diff --git a/tests/namespace/test_lldp.py b/tests/namespace/test_lldp.py index 7b2f228d5dfd..4b39ad982098 100644 --- a/tests/namespace/test_lldp.py +++ b/tests/namespace/test_lldp.py @@ -110,11 +110,17 @@ def test_subtype_lldp_loc_sys_data(self): print(ret) def test_subtype_lldp_loc_man_addr_table(self): - for entry in range(3, 7): - mib_entry = self.lut[(1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, entry)] - ret = mib_entry(sub_id=(1,)) - self.assertIsNotNone(ret) - print(ret) + oid = ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(value0.data, 5) + def test_subtype_lldp_rem_man_addr_table(self): for entry in range(3, 6): diff --git a/tests/test_lldp.py b/tests/test_lldp.py index 7a8393a801f3..e3e47d37cf79 100644 --- a/tests/test_lldp.py +++ b/tests/test_lldp.py @@ -89,11 +89,17 @@ def test_subtype_lldp_loc_sys_data(self): print(ret) def test_subtype_lldp_loc_man_addr_table(self): - for entry in range(3, 7): - mib_entry = self.lut[(1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, entry)] - ret = mib_entry(sub_id=(1,)) - self.assertIsNotNone(ret) - print(ret) + oid = ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(value0.data, 5) + def test_subtype_lldp_rem_man_addr_table(self): for entry in range(3, 6):