Skip to content

Commit

Permalink
Fix: correctly handle that lldp_loc_man_addr contains only IPv6 addre…
Browse files Browse the repository at this point in the history
…ss 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()
  • Loading branch information
qiluo-msft authored and abdosi committed Dec 31, 2020
1 parent c910863 commit 005cf2e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
16 changes: 11 additions & 5 deletions tests/namespace/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 11 additions & 5 deletions tests/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 005cf2e

Please sign in to comment.