Skip to content

Commit

Permalink
Added new method get_back_end_interface_set() to speed up back-end in… (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
gechiang authored and abdosi committed Nov 1, 2020
1 parent ecd10b9 commit 55be531
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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):

Expand Down

0 comments on commit 55be531

Please sign in to comment.