diff --git a/scripts/fast-reboot b/scripts/fast-reboot index ba397e5ea0..eb64f8653e 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -26,10 +26,14 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) # Load kernel into the memory /sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" -# Dump the ARP and FDB tables to files +# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6 /usr/bin/fast-reboot-dump.py docker cp /tmp/fdb.json swss:/ docker cp /tmp/arp.json swss:/ +if [ -e /tmp/default_routes.json ] +then + docker cp /tmp/default_routes.json swss:/ +fi # Kill bgpd to enable graceful restart of BGP docker exec -ti bgp killall -9 watchquagga diff --git a/scripts/fast-reboot-dump.py b/scripts/fast-reboot-dump.py index 910851d9b2..e112b3f52e 100644 --- a/scripts/fast-reboot-dump.py +++ b/scripts/fast-reboot-dump.py @@ -4,6 +4,7 @@ import json import socket import struct +import os from fcntl import ioctl import binascii @@ -213,10 +214,48 @@ def garp_send(arp_entries, map_mac_ip_per_vlan): return +def get_default_entries(db, route): + key = 'ROUTE_TABLE:%s' % route + keys = db.keys(db.APPL_DB, key) + if keys is None: + return None + + entry = db.get_all(db.APPL_DB, key) + obj = { + key: entry, + 'OP': 'SET' + } + + return obj + +def generate_default_route_entries(filename): + db = swsssdk.SonicV2Connector() + db.connect(db.APPL_DB, False) # Make one attempt only + + default_routes_output = [] + + ipv4_default = get_default_entries(db, '0.0.0.0/0') + if ipv4_default is not None: + default_routes_output.append(ipv4_default) + + ipv6_default = get_default_entries(db, '::/0') + if ipv6_default is not None: + default_routes_output.append(ipv6_default) + + db.close(db.APPL_DB) + + if len(default_routes_output) > 0: + with open(filename, 'w') as fp: + json.dump(default_routes_output, fp, indent=2, separators=(',', ': ')) + else: + if os.path.isfile(filename): + os.unlink(filename) + def main(): all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries('/tmp/fdb.json') arp_entries = generate_arp_entries('/tmp/arp.json', all_available_macs) + generate_default_route_entries('/tmp/default_routes.json') garp_send(arp_entries, map_mac_ip_per_vlan) return