Skip to content

Commit

Permalink
[debug dump util] FDB debug dump util changes (sonic-net#1968)
Browse files Browse the repository at this point in the history
What I did
Added FDB debug dump module

How I did it
Used debug dump infra to add the FDB debug dump utility

How to verify it
Added Unit test cases to verify it
  • Loading branch information
dgsudharsan authored Dec 22, 2021
1 parent 3b642c9 commit ed2fa69
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 0 deletions.
96 changes: 96 additions & 0 deletions dump/plugins/fdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from dump.match_infra import MatchRequest
from dump.helper import create_template_dict
from .executor import Executor


class Fdb(Executor):
"""
Debug Dump Plugin for FDB Module
"""
ARG_NAME = "Vlan:fdb_entry"

def __init__(self, match_engine=None):
super().__init__(match_engine)

def get_all_args(self, ns=""):
req = MatchRequest(db="STATE_DB", table="FDB_TABLE", key_pattern="*", ns=ns)
ret = self.match_engine.fetch(req)
fdb_entries = ret["keys"]
return [key.split("|")[-1] for key in fdb_entries]

def execute(self, params):
self.ret_temp = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"])
fdb_entry = params[Fdb.ARG_NAME]
self.ns = params["namespace"]
self.init_fdb_appl_info(fdb_entry)
self.init_asic_fdb_info(fdb_entry)
self.init_state_fdb_info(fdb_entry)
return self.ret_temp

def init_state_fdb_info(self, fdb_name):
req = MatchRequest(db="STATE_DB", table="FDB_TABLE", key_pattern=fdb_name, ns=self.ns)
ret = self.match_engine.fetch(req)
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"])

def init_fdb_appl_info(self, fdb_name):
req = MatchRequest(db="APPL_DB", table="FDB_TABLE", key_pattern=fdb_name, ns=self.ns)
ret = self.match_engine.fetch(req)
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"], False)
req = MatchRequest(db="APPL_DB", table="VXLAN_FDB_TABLE", key_pattern=fdb_name, ns=self.ns)
ret = self.match_engine.fetch(req)
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"], False)
req = MatchRequest(db="APPL_DB", table="MCLAG_FDB_TABLE", key_pattern=fdb_name, ns=self.ns)
ret = self.match_engine.fetch(req)
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"], False)

def init_asic_fdb_info(self, fdb_name):
# One colon between Vlan and MAC and 5 colons in mac address are expected in key
if fdb_name.count(':') != 6:
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY")
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")
return

key_split = fdb_name.split(":",1)
vlan_name = key_split[0]
mac = key_split[1]
if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric():
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY")
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")
return

vlan_num = int(vlan_name[4:])
# Find the table named "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:*" in which SAI_VLAN_AT'TR_VLAN_ID = vlan_num
req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN", key_pattern="*", field="SAI_VLAN_ATTR_VLAN_ID",
value=str(vlan_num), ns=self.ns)
ret = self.match_engine.fetch(req)
if not ret["error"] and len(ret["keys"]) == 1:
vlan_obj = ret["keys"][0].split(":",2)[-1]
else:
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY")
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")
return

# ASIC_DB FDB format is bvid:vlan_obj + mac:mac_address + switch id which is wildcard here
fdb_key = '{"bvid":"' + vlan_obj + '","mac":"' + mac.upper() + '"*}'
req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", key_pattern=fdb_key,
return_fields=["SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"], ns=self.ns)
ret = self.match_engine.fetch(req)
bridge_port_id = ""
if not ret["error"] and len(ret["keys"]) != 0:
asic_fdb_key = ret["keys"][0]
if asic_fdb_key in ret["return_values"] and "SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" in ret["return_values"][asic_fdb_key]:
bridge_port_id = ret["return_values"][asic_fdb_key]["SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"]
else:
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")

if bridge_port_id:
bridge_port_req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT",
key_pattern = bridge_port_id, ns = self.ns)
bridge_ret = self.match_engine.fetch(bridge_port_req)
if not bridge_ret["error"] and len(bridge_ret["keys"]) != 0:
self.ret_temp[bridge_port_req.db]["keys"].append(bridge_ret["keys"][0])
else:
self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")


self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"])
15 changes: 15 additions & 0 deletions tests/dump_input/fdb/appl_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"FDB_TABLE:Vlan10:04:3f:72:ce:80:8b":{
"port" : "Ethernet252",
"type" : "static"
},
"VXLAN_FDB_TABLE:Vlan10:04:3f:72:ce:80:8c":{
"port" : "Ethernet252",
"type" : "dynamic",
"end_point_ip" : "192.234.11.233"
},
"MCLAG_FDB_TABLE:Vlan10:04:3f:72:ce:80:8d":{
"port" : "Ethernet252",
"type" : "dynamic"
}
}
48 changes: 48 additions & 0 deletions tests/dump_input/fdb/asic_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bvid\":\"oid:0x26000000000d22\",\"mac\":\"04:3F:72:E3:70:08\",\"switch_id\":\"oid:0x21000000000000\"}":{
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" : "oid:0x3a000000000d23",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC",
"SAI_FDB_ENTRY_ATTR_PACKET_ACTION" : "SAI_PACKET_ACTION_FORWARD"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bvid\":\"oid:0x26000000000d20\",\"mac\":\"04:3F:72:CE:80:8B\",\"switch_id\":\"oid:0x21000000000000\"}":{
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" : "oid:0x3a000000000d18",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_STATIC",
"SAI_FDB_ENTRY_ATTR_PACKET_ACTION" : "SAI_PACKET_ACTION_FORWARD"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bvid\":\"oid:0x26000000000d20\",\"mac\":\"04:3F:72:CE:80:8C\",\"switch_id\":\"oid:0x21000000000000\"}":{
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" : "oid:0x3a000000000d18",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC",
"SAI_FDB_ENTRY_ATTR_PACKET_ACTION" : "SAI_PACKET_ACTION_FORWARD"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bvid\":\"oid:0x26000000000d20\",\"mac\":\"04:3F:72:CE:80:8D\",\"switch_id\":\"oid:0x21000000000000\"}":{
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" : "oid:0x3a000000000d18",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC",
"SAI_FDB_ENTRY_ATTR_PACKET_ACTION" : "SAI_PACKET_ACTION_FORWARD"
},
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bvid\":\"oid:0x26000000000d1c\",\"mac\":\"04:3F:72:CE:80:8B\",\"switch_id\":\"oid:0x21000000000000\"}":{
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID" : "oid:0x3a000000000d55",
"SAI_FDB_ENTRY_ATTR_TYPE": "SAI_FDB_ENTRY_TYPE_DYNAMIC",
"SAI_FDB_ENTRY_ATTR_PACKET_ACTION" : "SAI_PACKET_ACTION_FORWARD"
},
"ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000d22": {
"SAI_VLAN_ATTR_VLAN_ID" : "50"
},
"ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000d20": {
"SAI_VLAN_ATTR_VLAN_ID" : "10"
},
"ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000d1c": {
"SAI_VLAN_ATTR_VLAN_ID" : "690"
},
"ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000d23":{
"SAI_BRIDGE_PORT_ATTR_TYPE" : "SAI_BRIDGE_PORT_TYPE_PORT",
"SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x100000000093e",
"SAI_BRIDGE_PORT_ATTR_ADMIN_STATE" : "true",
"SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE" : "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW"
},
"ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000d18":{
"SAI_BRIDGE_PORT_ATTR_TYPE" : "SAI_BRIDGE_PORT_TYPE_PORT",
"SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x100000000053f",
"SAI_BRIDGE_PORT_ATTR_ADMIN_STATE" : "true",
"SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE" : "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW"
}
}
30 changes: 30 additions & 0 deletions tests/dump_input/fdb/state_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"FDB_TABLE|Vlan50:04:3f:72:e3:70:08":{
"port" : "Ethernet0",
"type" : "dynamic"
},
"FDB_TABLE|Vlan10:04:3f:72:ce:80:8b":{
"port" : "Ethernet252",
"type" : "static"
},
"FDB_TABLE|Vlan10:04:3f:72:ce:80:8c":{
"port" : "Ethernet252",
"type" : "dynamic"
},
"FDB_TABLE|Vlan10:04:3f:72:ce:80:8d":{
"port" : "Ethernet252",
"type" : "dynamic"
},
"FDB_TABLE|Vlan690:04:3f:72:ce:80:8b":{
"port" : "Ethernet248",
"type" : "dynamic"
},
"FDB_TABLE|Vlan40:04:3f:72:e3:70:09":{
"port" : "PortChannel0002",
"type" : "dynamic"
},
"FDB_TABLE|Vlan691:04:3f:72:ce:80:8b":{
"port" : "Ethernet248",
"type" : "dynamic"
}
}
Loading

0 comments on commit ed2fa69

Please sign in to comment.