Skip to content

Commit e57e7f7

Browse files
authored
cache the bvid to vlan translations (sonic-net#1523)
Add lookup table for bvid to vlan translations. bvid_tlb will store previous successful translations from slow get_vlan_id_from_bvid() This patch does not change the output from the command, only speeds up it for case of 10k+ MAC tables.
1 parent 38f9f60 commit e57e7f7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/fdbshow

+15-9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class FdbShow(object):
8787
if not fdb_str:
8888
return
8989

90+
bvid_tlb = {}
9091
oid_pfx = len("oid:0x")
9192
for s in fdb_str:
9293
fdb_entry = s
@@ -111,15 +112,20 @@ class FdbShow(object):
111112
if 'bvid' not in fdb:
112113
# no possibility to find the Vlan id. skip the FDB entry
113114
continue
114-
try:
115-
vlan_id = port_util.get_vlan_id_from_bvid(self.db, fdb["bvid"])
116-
if vlan_id is None:
117-
# the situation could be faced if the system has an FDB entries,
118-
# which are linked to default Vlan(caused by untagged trafic)
119-
continue
120-
except Exception:
121-
vlan_id = fdb["bvid"]
122-
print("Failed to get Vlan id for bvid {}\n".format(fdb["bvid"]))
115+
bvid = fdb["bvid"]
116+
if bvid in bvid_tlb:
117+
vlan_id = bvid_tlb[bvid]
118+
else:
119+
try:
120+
vlan_id = port_util.get_vlan_id_from_bvid(self.db, bvid)
121+
bvid_tlb[bvid] = vlan_id
122+
if vlan_id is None:
123+
# the situation could be faced if the system has an FDB entries,
124+
# which are linked to default Vlan(caused by untagged trafic)
125+
continue
126+
except Exception:
127+
vlan_id = bvid
128+
print("Failed to get Vlan id for bvid {}\n".format(bvid))
123129
self.bridge_mac_list.append((int(vlan_id),) + (fdb["mac"],) + (if_name,) + (fdb_type,))
124130

125131
self.bridge_mac_list.sort(key = lambda x: x[0])

0 commit comments

Comments
 (0)