Skip to content

Commit 7a7c285

Browse files
Dump default routes from APPL_DB table before fast-reboot (sonic-net#203)
1 parent 2a0defb commit 7a7c285

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

scripts/fast-reboot

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
2626
# Load kernel into the memory
2727
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
2828

29-
# Dump the ARP and FDB tables to files
29+
# Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6
3030
/usr/bin/fast-reboot-dump.py
3131
docker cp /tmp/fdb.json swss:/
3232
docker cp /tmp/arp.json swss:/
33+
if [ -e /tmp/default_routes.json ]
34+
then
35+
docker cp /tmp/default_routes.json swss:/
36+
fi
3337

3438
# Kill bgpd to enable graceful restart of BGP
3539
docker exec -ti bgp killall -9 watchquagga

scripts/fast-reboot-dump.py

+39
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import socket
66
import struct
7+
import os
78
from fcntl import ioctl
89
import binascii
910

@@ -213,10 +214,48 @@ def garp_send(arp_entries, map_mac_ip_per_vlan):
213214

214215
return
215216

217+
def get_default_entries(db, route):
218+
key = 'ROUTE_TABLE:%s' % route
219+
keys = db.keys(db.APPL_DB, key)
220+
if keys is None:
221+
return None
222+
223+
entry = db.get_all(db.APPL_DB, key)
224+
obj = {
225+
key: entry,
226+
'OP': 'SET'
227+
}
228+
229+
return obj
230+
231+
def generate_default_route_entries(filename):
232+
db = swsssdk.SonicV2Connector()
233+
db.connect(db.APPL_DB, False) # Make one attempt only
234+
235+
default_routes_output = []
236+
237+
ipv4_default = get_default_entries(db, '0.0.0.0/0')
238+
if ipv4_default is not None:
239+
default_routes_output.append(ipv4_default)
240+
241+
ipv6_default = get_default_entries(db, '::/0')
242+
if ipv6_default is not None:
243+
default_routes_output.append(ipv6_default)
244+
245+
db.close(db.APPL_DB)
246+
247+
if len(default_routes_output) > 0:
248+
with open(filename, 'w') as fp:
249+
json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))
250+
else:
251+
if os.path.isfile(filename):
252+
os.unlink(filename)
253+
216254

217255
def main():
218256
all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries('/tmp/fdb.json')
219257
arp_entries = generate_arp_entries('/tmp/arp.json', all_available_macs)
258+
generate_default_route_entries('/tmp/default_routes.json')
220259
garp_send(arp_entries, map_mac_ip_per_vlan)
221260

222261
return

0 commit comments

Comments
 (0)