Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: correctly handle that lldp_loc_man_addr contains only IPv6 address without IPv4 address #164

Merged
merged 5 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else block is not intended to match the right if block. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for-else structure, which is a critical change in this PR. If there is no IPv4 address matched in the for loop, we need to return soon. Otherwise future statement will fail since mgmt_ip_sub_oid==None


In reply to: 503552324 [](ancestors = 503552324)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thank you.

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):
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required. It just make code more robust.


In reply to: 503552127 [](ancestors = 503552127)

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