Skip to content
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

[fast-reboot]: Dump default routes from APPL_DB table before fast-reboot #203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import socket
import struct
import os
from fcntl import ioctl
import binascii

Expand Down Expand Up @@ -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
Expand Down