-
Notifications
You must be signed in to change notification settings - Fork 113
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
Support multiple IP addresses in LLDPRemManAddrTable #136
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -511,26 +511,28 @@ def update_rem_if_mgmt(self, if_oid, if_name): | |
return | ||
time_mark = int(lldp_kvs[b'lldp_rem_time_mark']) | ||
remote_index = int(lldp_kvs[b'lldp_rem_index']) | ||
subtype = self.get_subtype(mgmt_ip_str) | ||
ip_hex = self.get_ip_hex(mgmt_ip_str, subtype) | ||
if subtype == ManAddrConst.man_addr_subtype_ipv4: | ||
addr_subtype_sub_oid = 4 | ||
mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip_str.split('.')]) | ||
elif subtype == ManAddrConst.man_addr_subtype_ipv6: | ||
addr_subtype_sub_oid = 6 | ||
mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i, 16) if i else 0 for i in mgmt_ip_str.split(':')]) | ||
else: | ||
logger.warning("Invalid management IP {}".format(mgmt_ip_str)) | ||
return | ||
self.if_range.append((time_mark, | ||
if_oid, | ||
remote_index, | ||
subtype, | ||
*mgmt_ip_sub_oid)) | ||
|
||
self.mgmt_ips.update({if_name: {"ip_str": mgmt_ip_str, | ||
"addr_subtype": subtype, | ||
"addr_hex": ip_hex}}) | ||
|
||
for mgmt_ip in mgmt_ip_str.split(','): | ||
ipa = ipaddress.ip_address(mgmt_ip) | ||
subtype = self.get_subtype(mgmt_ip) | ||
ip_hex = self.get_ip_hex(mgmt_ip, subtype) | ||
|
||
if subtype == ManAddrConst.man_addr_subtype_ipv4: | ||
addr_subtype_sub_oid = 4 | ||
elif subtype == ManAddrConst.man_addr_subtype_ipv6: | ||
addr_subtype_sub_oid = 16 | ||
else: | ||
logger.warning("Invalid management IP {}".format(mgmt_ip_str)) | ||
return | ||
|
||
mgmt_ip_sub_oid = (addr_subtype_sub_oid,) + tuple(i for i in ipa.packed) | ||
sub_id = (if_oid,) + (remote_index,) + (subtype,) + mgmt_ip_sub_oid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You don't need first element in other places, why not just remove? #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I tried to do it. But to maintain the uniformity with other OS, I kept it this way. Also, during testing, I faced issues to pass some test cases which is currently not part of the current repo like test_ipv6_rem_man_addr, test_ipv4_rem_man_addr etc. as those test cases were removed from repo by #112 PR. |
||
self.if_range.append( (time_mark, *sub_id)) | ||
|
||
self.mgmt_ips[sub_id] = {if_name: {"ip_str": mgmt_ip, | ||
"addr_subtype": subtype, | ||
"addr_hex": ip_hex}} | ||
|
||
except (KeyError, AttributeError) as e: | ||
logger.warning("Error updating remote mgmt addr: {}".format(e)) | ||
return | ||
|
@@ -591,11 +593,11 @@ def get_next(self, sub_id): | |
def lookup(self, sub_id, callable): | ||
if len(sub_id) == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What happened |
||
return None | ||
sub_id = sub_id[1] | ||
if sub_id not in self.oid_name_map: | ||
sub_id_part = sub_id[1] | ||
if sub_id_part not in self.oid_name_map: | ||
return None | ||
if_name = self.oid_name_map[sub_id] | ||
if if_name not in self.mgmt_ips: | ||
if_name = self.oid_name_map[sub_id_part] | ||
if if_name not in self.mgmt_ips[sub_id[1:]]: | ||
# no data for this interface | ||
return None | ||
return callable(sub_id, if_name) | ||
|
@@ -625,14 +627,14 @@ def get_subtype(self, ip_str): | |
return None | ||
|
||
def man_addr_subtype(self, sub_id, if_name): | ||
return self.mgmt_ips[if_name]['addr_subtype'] | ||
return self.mgmt_ips[sub_id[1:]][if_name]['addr_subtype'] | ||
|
||
def man_addr(self, sub_id, if_name): | ||
""" | ||
:param sub_id: | ||
:return: MGMT IP in HEX | ||
""" | ||
return self.mgmt_ips[if_name]['addr_hex'] | ||
return self.mgmt_ips[sub_id[1:]][if_name]['addr_hex'] | ||
|
||
@staticmethod | ||
def man_addr_if_subtype(sub_id, _): return ManAddrConst.man_addr_if_subtype | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you double check whether it is 6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I checked other OS like cisco and did the snmpwalk for the same oid i.e.
1.0.8802.1.1.2.1.4.2
. It's 16.