Skip to content

Commit 10de91d

Browse files
[config reload]: On dual ToR systems, cache ARP and FDB tables (#1465)
Use the fast-reboot-dump and filter_fdb_entries scripts to cache the current ARP and FDB tables in /host/config-reload. Also create a file in the same directory to indicate to SWSS that it should restore from the cache. Signed-off-by: Lawrence Lee <[email protected]>
1 parent 10a359a commit 10de91d

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

config/main.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,38 @@ def update_sonic_environment():
793793
display_cmd=True
794794
)
795795

796+
def cache_arp_entries():
797+
success = True
798+
cache_dir = '/host/config-reload'
799+
click.echo('Caching ARP table to {}'.format(cache_dir))
800+
801+
if not os.path.exists(cache_dir):
802+
os.mkdir(cache_dir)
803+
804+
arp_cache_cmd = '/usr/local/bin/fast-reboot-dump.py -t {}'.format(cache_dir)
805+
cache_proc = subprocess.Popen(arp_cache_cmd, shell=True, text=True, stdout=subprocess.PIPE)
806+
_, cache_err = cache_proc.communicate()
807+
if cache_err:
808+
click.echo("Could not cache ARP and FDB info prior to reloading")
809+
success = False
810+
811+
if not cache_err:
812+
fdb_cache_file = os.path.join(cache_dir, 'fdb.json')
813+
arp_cache_file = os.path.join(cache_dir, 'arp.json')
814+
fdb_filter_cmd = '/usr/local/bin/filter_fdb_entries -f {} -a {} -c /etc/sonic/configdb.json'.format(fdb_cache_file, arp_cache_file)
815+
filter_proc = subprocess.Popen(fdb_filter_cmd, shell=True, text=True, stdout=subprocess.PIPE)
816+
_, filter_err = filter_proc.communicate()
817+
if filter_err:
818+
click.echo("Could not filter FDB entries prior to reloading")
819+
success = False
820+
821+
# If we are able to successfully cache ARP table info, signal SWSS to restore from our cache
822+
# by creating /host/config-reload/needs-restore
823+
if success:
824+
restore_flag_file = os.path.join(cache_dir, 'needs-restore')
825+
open(restore_flag_file, 'w').close()
826+
return success
827+
796828
# This is our main entrypoint - the main 'config' command
797829
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
798830
@click.pass_context
@@ -953,9 +985,10 @@ def load(filename, yes):
953985
@click.option('-y', '--yes', is_flag=True)
954986
@click.option('-l', '--load-sysinfo', is_flag=True, help='load system default information (mac, portmap etc) first.')
955987
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
988+
@click.option('-d', '--disable_arp_cache', default=False, is_flag=True, help='Do not cache ARP table before reloading (applies to dual ToR systems only)')
956989
@click.argument('filename', required=False)
957990
@clicommon.pass_db
958-
def reload(db, filename, yes, load_sysinfo, no_service_restart):
991+
def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cache):
959992
"""Clear current configuration and import a previous saved config DB dump file.
960993
<filename> : Names of configuration file(s) to load, separated by comma with no spaces in between
961994
"""
@@ -994,6 +1027,13 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart):
9941027
else:
9951028
cfg_hwsku = cfg_hwsku.strip()
9961029

1030+
# For dual ToR devices, cache ARP and FDB info
1031+
localhost_metadata = db.cfgdb.get_table('DEVICE_METADATA')['localhost']
1032+
cache_arp_table = not disable_arp_cache and 'subtype' in localhost_metadata and localhost_metadata['subtype'].lower() == 'dualtor'
1033+
1034+
if cache_arp_table:
1035+
cache_arp_entries()
1036+
9971037
#Stop services before config push
9981038
if not no_service_restart:
9991039
log.log_info("'reload' stopping services...")

0 commit comments

Comments
 (0)