Skip to content

Commit 6e4a796

Browse files
authored
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()
1 parent 0f772ce commit 6e4a796

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/sonic_ax_impl/mibs/ieee802_1ab.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ def reinit_data(self):
317317
if '.' in mgmt_ip:
318318
mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip.split('.')])
319319
break
320+
else:
321+
logger.error("Could not find IPv4 address in lldp_loc_man_addr")
322+
return
320323
except ValueError:
321324
logger.error("Invalid local mgmt IP {}".format(self.mgmt_ip_str))
322325
return
@@ -334,12 +337,12 @@ def update_data(self):
334337

335338
def get_next(self, sub_id):
336339
right = bisect_right(self.man_addr_list, sub_id)
337-
if right == len(self.man_addr_list):
340+
if right >= len(self.man_addr_list):
338341
return None
339342
return self.man_addr_list[right]
340343

341344
def lookup(self, sub_id, callable):
342-
if len(sub_id) == 0:
345+
if sub_id not in self.man_addr_list:
343346
return None
344347
return callable(sub_id)
345348

tests/namespace/test_lldp.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ def test_subtype_lldp_loc_sys_data(self):
110110
print(ret)
111111

112112
def test_subtype_lldp_loc_man_addr_table(self):
113-
for entry in range(3, 7):
114-
mib_entry = self.lut[(1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, entry)]
115-
ret = mib_entry(sub_id=(1,))
116-
self.assertIsNotNone(ret)
117-
print(ret)
113+
oid = ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4))
114+
get_pdu = GetNextPDU(
115+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
116+
oids=[oid]
117+
)
118+
119+
response = get_pdu.make_response(self.lut)
120+
value0 = response.values[0]
121+
self.assertEqual(value0.type_, ValueType.INTEGER)
122+
self.assertEqual(value0.data, 5)
123+
118124

119125
def test_subtype_lldp_rem_man_addr_table(self):
120126
for entry in range(3, 6):

tests/test_lldp.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ def test_subtype_lldp_loc_sys_data(self):
8989
print(ret)
9090

9191
def test_subtype_lldp_loc_man_addr_table(self):
92-
for entry in range(3, 7):
93-
mib_entry = self.lut[(1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, entry)]
94-
ret = mib_entry(sub_id=(1,))
95-
self.assertIsNotNone(ret)
96-
print(ret)
92+
oid = ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4))
93+
get_pdu = GetNextPDU(
94+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
95+
oids=[oid]
96+
)
97+
98+
response = get_pdu.make_response(self.lut)
99+
value0 = response.values[0]
100+
self.assertEqual(value0.type_, ValueType.INTEGER)
101+
self.assertEqual(value0.data, 5)
102+
97103

98104
def test_subtype_lldp_rem_man_addr_table(self):
99105
for entry in range(3, 6):

0 commit comments

Comments
 (0)