Added new method get_back_end_interface_set() to speed up back-end in… (#5731)

Added new MultiASIC util method "get_back_end_interface_set()" to speed up back-end interface check by allowing caller to cache the back-end intf into a set. This way the caller can use this set for all subsequent back-end interface check requests  instead of each time need to read from redis DB which become a scaling issue for cases such as checking for thousands of nexthop routes for filtering purpose.
This commit is contained in:
gechiang 2020-10-31 18:06:06 -07:00 committed by GitHub
parent dddf96933c
commit 908787d2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -321,6 +321,33 @@ def is_port_channel_internal(port_channel, namespace=None):
return False
# Allow user to get a set() of back-end interface and back-end LAG per namespace
# default is getting it for all name spaces if no namespace is specified
def get_back_end_interface_set(namespace=None):
bk_end_intf_list =[]
if not is_multi_asic():
return None
port_table = get_port_table(namespace)
for port, info in port_table.items():
if PORT_ROLE in info and info[PORT_ROLE] == INTERNAL_PORT:
bk_end_intf_list.append(port)
if len(bk_end_intf_list):
ns_list = get_namespace_list(namespace)
for ns in ns_list:
config_db = connect_config_db_for_ns(ns)
port_channels = config_db.get_table(PORT_CHANNEL_CFG_DB_TABLE)
# a back-end LAG must be configured with all of its member from back-end interfaces.
# mixing back-end and front-end interfaces is miss configuration and not allowed.
# To determine if a LAG is back-end LAG, just need to check its first member is back-end or not
# is sufficient. Note that a user defined LAG may have empty members so the list expansion logic
# need to ensure there are members before inspecting member[0].
bk_end_intf_list.extend([port_channel for port_channel, lag_info in port_channels.items()\
if 'members' in lag_info and lag_info['members'][0] in bk_end_intf_list])
a = set()
a.update(bk_end_intf_list)
return a
def is_bgp_session_internal(bgp_neigh_ip, namespace=None):