Skip to content

Commit 9f3c578

Browse files
committed
JIRA-JRTC-2248: [fast-reboot] Fix the backup fdb entries(fdb.json) will be empty during fast-reboot process
In PR: sonic-net#890 > It adds an mechansim to filter out some entries to reduce the size of fdb.json. But it has a code defect which causes all fdb entries will be filtered out in some cases. Merge PR: sonic-net#1059 to fix the above issue.
1 parent 32cb6e4 commit 9f3c578

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

scripts/filter_fdb_entries.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python
22

3+
import argparse
34
import json
4-
import sys
55
import os
6-
import argparse
6+
import sys
77
import syslog
8-
import traceback
98
import time
9+
import traceback
1010

11-
from ipaddress import ip_address, ip_network, ip_interface
1211
from collections import defaultdict
12+
from ipaddress import ip_address, ip_network, ip_interface
1313

1414
def get_vlan_cidr_map(filename):
1515
"""
@@ -35,7 +35,9 @@ def get_vlan_cidr_map(filename):
3535
continue
3636
vlan, cidr = tuple(vlan_key.split('|'))
3737
if vlan in config_db_entries["VLAN"]:
38-
vlan_cidr[vlan] = ip_interface(cidr).network
38+
if vlan not in vlan_cidr:
39+
vlan_cidr[vlan] = {4: ip_address("0.0.0.0".decode()), 6: ip_address("::".decode())}
40+
vlan_cidr[vlan][ip_interface(cidr).version] = ip_interface(cidr).network
3941

4042
return vlan_cidr
4143

@@ -65,8 +67,9 @@ def get_arp_entries_map(arp_filename, config_db_filename):
6567
continue
6668
table, vlan, ip = tuple(key.split(':'))
6769
if "NEIGH_TABLE" in table and vlan in vlan_cidr.keys() \
68-
and ip_address(ip) in ip_network(vlan_cidr[vlan]) and "neigh" in config.keys():
69-
arp_map[config["neigh"].replace(':', '-')] = ""
70+
and ip_address(ip) in ip_network(vlan_cidr[vlan][ip_interface(ip).version]) \
71+
and "neigh" in config.keys():
72+
arp_map[config["neigh"].replace(':', '-').upper()] = ""
7073

7174
return arp_map
7275

@@ -94,7 +97,7 @@ def filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_fi
9497
def filter_fdb_entry(fdb_entry):
9598
for key, _ in fdb_entry.items():
9699
if 'FDB_TABLE' in key:
97-
return key.split(':')[-1] in arp_map
100+
return key.split(':')[-1].upper() in arp_map
98101

99102
# malformed entry, default to False so it will be deleted
100103
return False

sonic-utilities-tests/filter_fdb_input/config_db.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,9 @@
11251125
}
11261126
},
11271127
"VLAN_INTERFACE": {
1128-
"Vlan1000|192.168.0.1/21": {}
1128+
"Vlan1000": {},
1129+
"Vlan1000|192.168.0.1/21": {},
1130+
"Vlan1000|fc02:1000::1/64": {}
11291131
},
11301132
"BUFFER_PG": {
11311133
"Ethernet4|0": {

sonic-utilities-tests/filter_fdb_input/expected_fdb.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@
181181
},
182182
"OP": "SET"
183183
},
184+
{
185+
"FDB_TABLE:Vlan1000:24-8A-07-4C-F5-18": {
186+
"type": "dynamic",
187+
"port": "Ethernet24"
188+
},
189+
"OP": "SET"
190+
},
184191
{
185192
"FDB_TABLE:Vlan1000:72-06-00-01-02-72": {
186193
"type": "dynamic",
@@ -398,4 +405,4 @@
398405
},
399406
"OP": "SET"
400407
}
401-
]
408+
]

sonic-utilities-tests/filter_fdb_input/test_vectors.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"Vlan1000": {}
4444
},
4545
"VLAN_INTERFACE": {
46-
"Vlan1000|192.168.0.1/21": {}
46+
"Vlan1000": {},
47+
"Vlan1000|192.168.0.1/21": {},
48+
"Vlan1000|fc02:1000::1/64": {}
4749
},
4850
},
4951
"expected_fdb": [
@@ -80,7 +82,8 @@
8082
"Vlan1000": {}
8183
},
8284
"VLAN_INTERFACE": {
83-
"Vlan1000|192.168.0.1/21": {}
85+
"Vlan1000|192.168.0.1/21": {},
86+
"Vlan1000|fc02:1000::1/64": {}
8487
},
8588
},
8689
"expected_fdb": [
@@ -154,7 +157,9 @@
154157
"Vlan1": {}
155158
},
156159
"VLAN_INTERFACE": {
157-
"Vlan1|25.103.178.1/21": {}
160+
"Vlan1|25.103.178.1/21": {},
161+
"Vlan1": {},
162+
"Vlan1|fc02:1000::1/64": {}
158163
},
159164
},
160165
"expected_fdb": [

0 commit comments

Comments
 (0)