-
Notifications
You must be signed in to change notification settings - Fork 109
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
Updated lldpRemManAddrTable to use all the management ip address associated with interface. #201
Changes from 3 commits
3194691
4dbc4dc
a0e0ef1
9749374
2b3ffc7
7f74185
448cad1
4aaa793
6956f42
09d41cf
341f548
80417ee
bab90f4
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 |
---|---|---|
|
@@ -494,10 +494,9 @@ def __init__(self): | |
# establish connection to application database. | ||
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
self.if_range = [] | ||
self.mgmt_ips = {} | ||
self.if_with_mgmt_ips = set() | ||
self.oid_name_map = {} | ||
self.mgmt_oid_name_map = {} | ||
self.mgmt_ip_str = None | ||
self.pubsub = [None] * len(self.db_conn) | ||
|
||
def update_rem_if_mgmt(self, if_oid, if_name): | ||
|
@@ -511,28 +510,26 @@ def update_rem_if_mgmt(self, if_oid, if_name): | |
if len(mgmt_ip_str) == 0: | ||
# the peer advertise an emtpy mgmt address | ||
return | ||
time_mark = int(lldp_kvs['lldp_rem_time_mark']) | ||
remote_index = int(lldp_kvs['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 set(mgmt_ip_str.split(',')): | ||
time_mark = int(lldp_kvs['lldp_rem_time_mark']) | ||
remote_index = int(lldp_kvs['lldp_rem_index']) | ||
subtype = self.get_subtype(mgmt_ip) | ||
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.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.split(':')]) | ||
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.
Seems you are trying to parse ipv6
but this is not working for general cases #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. @qiluo-msft Updated to use |
||
else: | ||
logger.warning("Invalid management IP {}".format(mgmt_ip_str)) | ||
SuvarnaMeenakshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
self.if_range.append((time_mark, | ||
if_oid, | ||
remote_index, | ||
subtype, | ||
*mgmt_ip_sub_oid)) | ||
self.if_with_mgmt_ips.add(if_name) | ||
|
||
except (KeyError, AttributeError) as e: | ||
logger.warning("Error updating remote mgmt addr: {}".format(e)) | ||
return | ||
|
@@ -577,7 +574,7 @@ def reinit_data(self): | |
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
|
||
self.if_range = [] | ||
self.mgmt_ips = {} | ||
self.if_with_mgmt_ips = set() | ||
for if_oid, if_name in self.oid_name_map.items(): | ||
self.update_rem_if_mgmt(if_oid, if_name) | ||
|
||
|
@@ -594,7 +591,7 @@ def lookup(self, sub_id, callable): | |
if sub_id 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 if_name not in self.if_with_mgmt_ips: | ||
# no data for this interface | ||
return None | ||
return callable(sub_id, if_name) | ||
|
@@ -623,15 +620,6 @@ def get_subtype(self, ip_str): | |
logger.warning("Invalid mgmt IP {}".format(ip_str)) | ||
return None | ||
|
||
def man_addr_subtype(self, sub_id, if_name): | ||
return self.mgmt_ips[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'] | ||
|
||
@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.
What is the benefit of
set
? Just use splited list? #ClosedThere 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.
this is just extra check in case if we have same ip's
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.
Please be aware that different ipv6 strings could be the same ipv6 address.
In reply to: 593529516 [](ancestors = 593529516)
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.
@qiluo-msft Updated.