Skip to content

Commit

Permalink
Dump default routes from APPL_DB table before fast-reboot (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-shirshov authored Feb 15, 2018
1 parent 2a0defb commit 7a7c285
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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

0 comments on commit 7a7c285

Please sign in to comment.