Skip to content

Commit

Permalink
cache the bvid to vlan translations (sonic-net#1523)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aystarik committed Apr 10, 2021
1 parent 38f9f60 commit e57e7f7
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions scripts/fdbshow
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class FdbShow(object):
if not fdb_str:
return

bvid_tlb = {}
oid_pfx = len("oid:0x")
for s in fdb_str:
fdb_entry = s
Expand All @@ -111,15 +112,20 @@ class FdbShow(object):
if 'bvid' not in fdb:
# no possibility to find the Vlan id. skip the FDB entry
continue
try:
vlan_id = port_util.get_vlan_id_from_bvid(self.db, fdb["bvid"])
if vlan_id is None:
# the situation could be faced if the system has an FDB entries,
# which are linked to default Vlan(caused by untagged trafic)
continue
except Exception:
vlan_id = fdb["bvid"]
print("Failed to get Vlan id for bvid {}\n".format(fdb["bvid"]))
bvid = fdb["bvid"]
if bvid in bvid_tlb:
vlan_id = bvid_tlb[bvid]
else:
try:
vlan_id = port_util.get_vlan_id_from_bvid(self.db, bvid)
bvid_tlb[bvid] = vlan_id
if vlan_id is None:
# the situation could be faced if the system has an FDB entries,
# which are linked to default Vlan(caused by untagged trafic)
continue
except Exception:
vlan_id = bvid
print("Failed to get Vlan id for bvid {}\n".format(bvid))
self.bridge_mac_list.append((int(vlan_id),) + (fdb["mac"],) + (if_name,) + (fdb_type,))

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

0 comments on commit e57e7f7

Please sign in to comment.