diff --git a/dump/plugins/evpn.py b/dump/plugins/evpn.py new file mode 100644 index 000000000000..0bf83194f0ff --- /dev/null +++ b/dump/plugins/evpn.py @@ -0,0 +1,120 @@ +from dump.match_infra import MatchRequest +from dump.helper import create_template_dict +from .executor import Executor + + +class Evpn(Executor): + """ + Debug Dump Plugin for EVPN Module + """ + ARG_NAME = "Remote VNI" + + def __init__(self, match_engine=None): + super().__init__(match_engine) + self.ret_temp = {} + self.ns = '' + self.remote_ip = '' + self.vlan = '' + self.tunnel_obj = '' + self.encap_mappers = [] + self.decap_mappers = [] + self.asic_tunnel_cache = {} + self.asic_tunnel_term_cache = {} + self.asic_tunnel_map_cache = {} + + def get_all_args(self, ns=""): + req = MatchRequest(db="APPL_DB", table="VXLAN_REMOTE_VNI_TABLE", key_pattern="*", ns=ns) + ret = self.match_engine.fetch(req) + evpns = ret["keys"] + return [key.split(":", 1)[-1] for key in evpns] + + def execute(self, params): + self.ret_temp = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + evpn_name = params[Evpn.ARG_NAME] + self.remote_ip = evpn_name.split(':')[-1] + self.remote_vlan = evpn_name.split(':')[0] + self.ns = params["namespace"] + self.init_evpn_appl_info(evpn_name) + self.init_asic_evpn_info() + self.init_asic_evpn_map_info() + self.init_asic_evpn_term_info() + self.init_state_evpn_info(evpn_name) + return self.ret_temp + + def add_to_ret_template(self, table, db, keys, err): + if not err and keys: + self.ret_temp[db]["keys"].extend(keys) + return True + else: + self.ret_temp[db]["tables_not_found"].extend([table]) + return False + + def init_evpn_appl_info(self, evpn_name): + req = MatchRequest(db="APPL_DB", table="VXLAN_REMOTE_VNI_TABLE", key_pattern=evpn_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_state_evpn_info(self, evpn_name): + state_key = "EVPN_" + self.remote_ip + req = MatchRequest(db="STATE_DB", table="VXLAN_TUNNEL_TABLE", key_pattern=state_key, ns=self.ns) + ret = self.match_engine.fetch(req) + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_evpn_info(self): + if not self.remote_ip: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + return None + if self.remote_ip in self.asic_tunnel_cache: + ret = self.asic_tunnel_cache[self.remote_ip] + else: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL", + field="SAI_TUNNEL_ATTR_ENCAP_DST_IP", value=self.remote_ip, ns=self.ns, + return_fields=["SAI_TUNNEL_ATTR_TYPE", "SAI_TUNNEL_ATTR_ENCAP_MAPPERS", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS"]) + ret = self.match_engine.fetch(req) + self.asic_tunnel_cache[self.remote_ip] = ret + ret["keys"] = [x for x in ret["keys"] if ret["return_values"][x]["SAI_TUNNEL_ATTR_TYPE"] == "SAI_TUNNEL_TYPE_VXLAN"] + if ret["keys"]: + asic_key = ret["keys"][0] + self.tunnel_obj = asic_key.replace("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:", "") + if ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_ENCAP_MAPPERS"]: + self.encap_mappers = ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_ENCAP_MAPPERS"].split(':', 1)[-1].split(',') + if ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_DECAP_MAPPERS"]: + self.decap_mappers = ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_DECAP_MAPPERS"].split(':', 1)[-1].split(',') + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_evpn_term_info(self): + if not self.tunnel_obj: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + return None + if self.tunnel_obj in self.asic_tunnel_term_cache: + ret = self.asic_tunnel_term_cache[self.tunnel_obj] + else: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY", + field="SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID", value=self.tunnel_obj, ns=self.ns) + ret = self.match_engine.fetch(req) + self.asic_tunnel_term_cache[self.tunnel_obj] = ret + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_evpn_map_info(self): + if not (self.encap_mappers or self.decap_mappers): + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + return None + for key in self.encap_mappers: + if key in self.asic_tunnel_map_cache: + ret = self.asic_tunnel_map_cache[key] + else: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP", + key_pattern=key, ns=self.ns) + ret = self.match_engine.fetch(req) + self.asic_tunnel_map_cache[key] = ret + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + for key in self.decap_mappers: + if key in self.asic_tunnel_map_cache: + ret = self.asic_tunnel_map_cache[key] + else: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP", + key_pattern=key, ns=self.ns) + ret = self.match_engine.fetch(req) + self.asic_tunnel_map_cache[key] = ret + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) diff --git a/dump/plugins/vxlan_tunnel.py b/dump/plugins/vxlan_tunnel.py new file mode 100644 index 000000000000..7e42218ccef5 --- /dev/null +++ b/dump/plugins/vxlan_tunnel.py @@ -0,0 +1,110 @@ +from dump.match_infra import MatchRequest +from dump.helper import create_template_dict +from .executor import Executor + + +class Vxlan_tunnel(Executor): + """ + Debug Dump Plugin for Vxlan Tunnel Module + """ + ARG_NAME = "vxlan_tunnel_name" + + def __init__(self, match_engine=None): + super().__init__(match_engine) + self.ret_temp = {} + self.ns = '' + self.src_ip = '' + self.dst_ip = '' + self.tunnel_obj = '' + self.encap_mappers = [] + self.decap_mappers = [] + + def get_all_args(self, ns=""): + req = MatchRequest(db="CONFIG_DB", table="VXLAN_TUNNEL", key_pattern="*", ns=ns) + ret = self.match_engine.fetch(req) + vxlan_tunnels = ret["keys"] + return [key.split("|")[-1] for key in vxlan_tunnels] + + def execute(self, params): + self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + vxlan_tunnel_name = params[Vxlan_tunnel.ARG_NAME] + self.ns = params["namespace"] + self.init_vxlan_tunnel_config_info(vxlan_tunnel_name) + self.init_vxlan_tunnel_appl_info(vxlan_tunnel_name) + self.init_asic_vxlan_tunnel_info() + self.init_asic_vxlan_tunnel_map_info() + self.init_asic_vxlan_tunnel_term_info() + self.init_state_vxlan_tunnel_info(vxlan_tunnel_name) + return self.ret_temp + + def add_to_ret_template(self, table, db, keys, err): + if not err and keys: + self.ret_temp[db]["keys"].extend(keys) + return True + else: + self.ret_temp[db]["tables_not_found"].extend([table]) + return False + + def init_vxlan_tunnel_config_info(self, vxlan_tunnel_name): + req = MatchRequest(db="CONFIG_DB", table="VXLAN_TUNNEL", key_pattern=vxlan_tunnel_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_vxlan_tunnel_appl_info(self, vxlan_tunnel_name): + req = MatchRequest(db="APPL_DB", table="VXLAN_TUNNEL_TABLE", key_pattern=vxlan_tunnel_name, ns=self.ns, + return_fields=["src_ip", "dst_ip"]) + ret = self.match_engine.fetch(req) + if ret["keys"]: + app_key = ret["keys"][0] + self.src_ip = ret["return_values"][app_key]["src_ip"] + self.dst_ip = ret["return_values"][app_key]["dst_ip"] + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_state_vxlan_tunnel_info(self, vxlan_tunnel_name): + req = MatchRequest(db="STATE_DB", table="VXLAN_TUNNEL_TABLE", key_pattern=vxlan_tunnel_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_asic_vxlan_tunnel_info(self): + if not self.src_ip: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + return None + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL", field="SAI_TUNNEL_ATTR_ENCAP_SRC_IP", value=self.src_ip, ns=self.ns, + return_fields=["SAI_TUNNEL_ATTR_TYPE", "SAI_TUNNEL_ATTR_ENCAP_DST_IP", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS", "SAI_TUNNEL_ATTR_DECAP_MAPPERS"]) + ret = self.match_engine.fetch(req) + ret["keys"] = [x for x in ret["keys"] if ret["return_values"][x]["SAI_TUNNEL_ATTR_TYPE"] == "SAI_TUNNEL_TYPE_VXLAN"] + ret["keys"] = [x for x in ret["keys"] if not self.dst_ip and ret["return_values"][x]["SAI_TUNNEL_ATTR_ENCAP_DST_IP"] == "" or + ret["return_values"][x]["SAI_TUNNEL_ATTR_ENCAP_DST_IP"] == self.dst_ip] + if ret["keys"]: + asic_key = ret["keys"][0] + self.tunnel_obj = asic_key.replace("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:", "") + if ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_ENCAP_MAPPERS"]: + self.encap_mappers = ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_ENCAP_MAPPERS"].split(':', 1)[-1].split(',') + if ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_DECAP_MAPPERS"]: + self.decap_mappers = ret["return_values"][asic_key]["SAI_TUNNEL_ATTR_DECAP_MAPPERS"].split(':', 1)[-1].split(',') + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_vxlan_tunnel_term_info(self): + if not self.tunnel_obj: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + return None + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY", + field="SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID", value=self.tunnel_obj, ns=self.ns) + ret = self.match_engine.fetch(req) + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_vxlan_tunnel_map_info(self): + if not (self.encap_mappers or self.decap_mappers): + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + return None + for key in self.encap_mappers: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP", + key_pattern=key, ns=self.ns) + ret = self.match_engine.fetch(req) + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + for key in self.decap_mappers: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP", + key_pattern=key, ns=self.ns) + ret = self.match_engine.fetch(req) + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) diff --git a/dump/plugins/vxlan_tunnel_map.py b/dump/plugins/vxlan_tunnel_map.py new file mode 100644 index 000000000000..a021ed4c4395 --- /dev/null +++ b/dump/plugins/vxlan_tunnel_map.py @@ -0,0 +1,85 @@ +from dump.match_infra import MatchRequest +from dump.helper import create_template_dict +from .executor import Executor + + +class Vxlan_tunnel_map(Executor): + """ + Debug Dump Plugin for Vxlan Tunnel Map Module + """ + ARG_NAME = "vxlan_tunnel_map_name" + + def __init__(self, match_engine=None): + super().__init__(match_engine) + self.ret_temp = {} + self.ns = '' + self.vlan = '' + self.vni = '' + self.tunnel_map_obj = '' + self.encap_mappers = [] + self.decap_mappers = [] + + def get_all_args(self, ns=""): + req = MatchRequest(db="CONFIG_DB", table="VXLAN_TUNNEL_MAP", key_pattern="*", ns=ns) + ret = self.match_engine.fetch(req) + vxlan_tunnel_maps = ret["keys"] + return [key.split("|", 1)[-1] for key in vxlan_tunnel_maps] + + def execute(self, params): + self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB"]) + vxlan_tunnel_map_name = params[Vxlan_tunnel_map.ARG_NAME] + self.ns = params["namespace"] + self.init_vxlan_tunnel_map_config_info(vxlan_tunnel_map_name) + self.init_vxlan_tunnel_map_appl_info(vxlan_tunnel_map_name) + self.init_asic_vxlan_tunnel_map_entry_info() + self.init_asic_vxlan_tunnel_map_info() + return self.ret_temp + + def add_to_ret_template(self, table, db, keys, err): + if not err and keys: + self.ret_temp[db]["keys"].extend(keys) + return True + else: + self.ret_temp[db]["tables_not_found"].extend([table]) + return False + + def init_vxlan_tunnel_map_config_info(self, vxlan_tunnel_map_name): + req = MatchRequest(db="CONFIG_DB", table="VXLAN_TUNNEL_MAP", key_pattern=vxlan_tunnel_map_name, ns=self.ns, + return_fields=["vlan", "vni"]) + ret = self.match_engine.fetch(req) + if ret["keys"]: + cfg_key = ret["keys"][0] + self.vlan = ret["return_values"][cfg_key]["vlan"].replace("Vlan", "") + self.vni = ret["return_values"][cfg_key]["vni"] + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_vxlan_tunnel_map_appl_info(self, vxlan_tunnel_map_name): + app_vxlan_tunnel_map_name = vxlan_tunnel_map_name.replace('|', ':') + req = MatchRequest(db="APPL_DB", table="VXLAN_TUNNEL_MAP_TABLE", key_pattern=app_vxlan_tunnel_map_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_asic_vxlan_tunnel_map_entry_info(self): + if not self.vlan: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY") + return None + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY", + field="SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE", value=self.vlan, ns=self.ns, + return_fields=["SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE", + "SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY", + "SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP"]) + ret = self.match_engine.fetch(req) + ret["keys"] = [x for x in ret["keys"] if ret["return_values"][x]["SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE"] == "SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID"] + ret["keys"] = [x for x in ret["keys"] if ret["return_values"][x]["SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY"] == self.vni] + if ret["keys"]: + self.tunnel_map_obj = ret["return_values"][ret["keys"][0]]["SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP"] + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) + + def init_asic_vxlan_tunnel_map_info(self): + if not self.tunnel_map_obj: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + return None + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP", + key_pattern=self.tunnel_map_obj, value=self.vlan, ns=self.ns) + ret = self.match_engine.fetch(req) + self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) diff --git a/tests/dump_input/vxlan/appl_db.json b/tests/dump_input/vxlan/appl_db.json new file mode 100644 index 000000000000..cf370baff4eb --- /dev/null +++ b/tests/dump_input/vxlan/appl_db.json @@ -0,0 +1,34 @@ +{ + "VXLAN_TUNNEL_MAP_TABLE:vtep_1336:map_1336_Vlan2345": { + "vlan": "Vlan2345", + "vni": "1336" + }, + "VXLAN_TUNNEL_MAP_TABLE:vtep_1336:map_1337_Vlan2346": { + "vlan": "Vlan2346", + "vni": "1337" + }, + "VXLAN_TUNNEL_TABLE:vtep_1111": { + "src_ip": "10.1.0.31" + }, + "VXLAN_TUNNEL_TABLE:vtep_1336": { + "src_ip": "10.1.0.32" + }, + "VXLAN_TUNNEL_TABLE:vtep_2312": { + "src_ip": "10.1.0.33" + }, + "VXLAN_TUNNEL_TABLE:vtep_1000": { + "src_ip": "10.1.0.34" + }, + "VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.32": { + "vni": "1336" + }, + "VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.33": { + "vni": "1336" + }, + "VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.34": { + "vni": "1336" + }, + "VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.35": { + "vni": "1336" + } +} diff --git a/tests/dump_input/vxlan/asic_db.json b/tests/dump_input/vxlan/asic_db.json new file mode 100644 index 000000000000..552ef9ead5e4 --- /dev/null +++ b/tests/dump_input/vxlan/asic_db.json @@ -0,0 +1,126 @@ +{ + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a00000000079a": { + "SAI_TUNNEL_ATTR_OVERLAY_INTERFACE": "oid:0x6000000000799", + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_DECAP_ECN_MODE": "SAI_TUNNEL_DECAP_ECN_MODE_STANDARD", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_IPINIP", + "SAI_TUNNEL_ATTR_DECAP_TTL_MODE": "SAI_TUNNEL_TTL_MODE_PIPE_MODEL", + "SAI_TUNNEL_ATTR_DECAP_DSCP_MODE": "SAI_TUNNEL_DSCP_MODE_UNIFORM_MODEL" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007ee": { + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID": "oid:0x2a0000000007ed", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE": "SAI_TUNNEL_TYPE_VXLAN", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID": "oid:0x3000000000010", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP": "10.1.0.32", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE": "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007e1": { + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID": "oid:0x2a0000000007e1", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE": "SAI_TUNNEL_TYPE_VXLAN", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID": "oid:0x3000000000010", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP": "10.1.0.32", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP": "11.1.0.32", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE": "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2P" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007e3": { + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID": "oid:0x2a0000000007e3", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE": "SAI_TUNNEL_TYPE_VXLAN", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID": "oid:0x3000000000010", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP": "10.1.0.32", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP": "11.1.0.35", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE": "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2P" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007ef": { + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID": "oid:0x2a0000000007ee", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE": "SAI_TUNNEL_TYPE_VXLAN", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID": "oid:0x3000000000010", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP": "10.1.0.34", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE": "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b00000000079b": { + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID": "oid:0x2a00000000079a", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE": "SAI_TUNNEL_TYPE_IPINIP", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID": "oid:0x3000000000010", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP": "10.1.0.32", + "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE": "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ec": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ea": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VLAN_ID_TO_VNI" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007eb": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007b9": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007bc": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ba": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VLAN_ID_TO_VNI" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007bb": { + "SAI_TUNNEL_MAP_ATTR_TYPE": "SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY:oid:0x3b0000000007ef": { + "SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP": "oid:0x290000000007e9", + "SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE": "SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID", + "SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY": "1336", + "SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE": "2345" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ed": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2MP", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS": "2:oid:0x290000000007e9,oid:0x290000000007eb", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.32", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS": "2:oid:0x290000000007ea,oid:0x290000000007ec", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e1": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2P", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS": "2:oid:0x290000000007e9,oid:0x290000000007eb", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.32", + "SAI_TUNNEL_ATTR_ENCAP_DST_IP": "11.1.0.32", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS": "2:oid:0x290000000007ea,oid:0x290000000007ec", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e2": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2P", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS": "2:oid:0x290000000007e9,oid:0x290000000007eb", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.32", + "SAI_TUNNEL_ATTR_ENCAP_DST_IP": "11.1.0.34", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS": "2:oid:0x290000000007ea,oid:0x290000000007ec", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e3": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2P", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS": "2:oid:0x290000000007e9,oid:0x290000000007eb", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.32", + "SAI_TUNNEL_ATTR_ENCAP_DST_IP": "11.1.0.35", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS": "2:oid:0x290000000007ea,oid:0x290000000007ec", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ef": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2MP", + "SAI_TUNNEL_ATTR_DECAP_MAPPERS": "2:oid:0x290000000007b9,oid:0x290000000007bb", + "SAI_TUNNEL_ATTR_ENCAP_MAPPERS": "2:oid:0x290000000007ba,oid:0x290000000007bc", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.34", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ee": { + "SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE": "oid:0x600000000056a", + "SAI_TUNNEL_ATTR_PEER_MODE": "SAI_TUNNEL_PEER_MODE_P2MP", + "SAI_TUNNEL_ATTR_ENCAP_SRC_IP": "10.1.0.31", + "SAI_TUNNEL_ATTR_TYPE": "SAI_TUNNEL_TYPE_VXLAN" + } +} diff --git a/tests/dump_input/vxlan/config_db.json b/tests/dump_input/vxlan/config_db.json new file mode 100644 index 000000000000..ffe51877f1bf --- /dev/null +++ b/tests/dump_input/vxlan/config_db.json @@ -0,0 +1,29 @@ +{ + "VXLAN_TUNNEL_MAP|vtep_1336|map_1336_Vlan2345": { + "vlan": "Vlan2345", + "vni": "1336" + }, + "VXLAN_TUNNEL_MAP|vtep_1336|map_1337_Vlan2346": { + "vlan": "Vlan2346", + "vni": "1337" + }, + "VXLAN_TUNNEL_MAP|vtep_1338|map_1338_Vlan2347": { + "vlan": "Vlan2347", + "vni": "1338" + }, + "VXLAN_TUNNEL|vtep_1336": { + "src_ip": "10.1.0.32" + }, + "VXLAN_TUNNEL|vtep_1111": { + "src_ip": "10.1.0.31" + }, + "VXLAN_TUNNEL|vtep_1000": { + "src_ip": "10.1.0.34" + }, + "VXLAN_TUNNEL|vtep_2312": { + "src_ip": "10.1.0.33" + }, + "VXLAN_TUNNEL|vtep_1234": { + "src_ip": "10.1.0.35" + } +} diff --git a/tests/dump_input/vxlan/state_db.json b/tests/dump_input/vxlan/state_db.json new file mode 100644 index 000000000000..c5d6ecd5568b --- /dev/null +++ b/tests/dump_input/vxlan/state_db.json @@ -0,0 +1,20 @@ +{ + "VXLAN_TUNNEL_TABLE|EVPN_11.1.0.32": { + "src_ip": "10.1.0.32", + "dst_ip": "11.1.0.32", + "tnl_src": "EVPN", + "operstatus": "up" + }, + "VXLAN_TUNNEL_TABLE|EVPN_11.1.0.33": { + "src_ip": "10.1.0.32", + "dst_ip": "11.1.0.33", + "tnl_src": "EVPN", + "operstatus": "down" + }, + "VXLAN_TUNNEL_TABLE|EVPN_11.1.0.34": { + "src_ip": "10.1.0.32", + "dst_ip": "11.1.0.34", + "tnl_src": "EVPN", + "operstatus": "up" + } +} diff --git a/tests/dump_tests/module_tests/evpn_test.py b/tests/dump_tests/module_tests/evpn_test.py new file mode 100644 index 000000000000..77dffd95164a --- /dev/null +++ b/tests/dump_tests/module_tests/evpn_test.py @@ -0,0 +1,165 @@ +import json +import os +import pytest +from deepdiff import DeepDiff +from dump.helper import create_template_dict +from dump.plugins.evpn import Evpn +from dump.match_infra import MatchEngine, ConnectionPool +from swsscommon.swsscommon import SonicV2Connector + +# Location for dedicated db's used for UT +module_tests_path = os.path.dirname(__file__) +dump_tests_path = os.path.join(module_tests_path, "../") +tests_path = os.path.join(dump_tests_path, "../") +dump_test_input = os.path.join(tests_path, "dump_input") +evpn_files_path = os.path.join(dump_test_input, "vxlan") + +# Define the mock files to read from +dedicated_dbs = {} +dedicated_dbs['APPL_DB'] = os.path.join(evpn_files_path, "appl_db.json") +dedicated_dbs['ASIC_DB'] = os.path.join(evpn_files_path, "asic_db.json") +dedicated_dbs['STATE_DB'] = os.path.join(evpn_files_path, "state_db.json") + + +def populate_mock(db, db_names): + for db_name in db_names: + db.connect(db_name) + # Delete any default data + db.delete_all_by_pattern(db_name, "*") + with open(dedicated_dbs[db_name]) as f: + mock_json = json.load(f) + for key in mock_json: + for field, value in mock_json[key].items(): + db.set(db_name, key, field, value) + + +@pytest.fixture(scope="class", autouse=True) +def match_engine(): + + print("SETUP") + os.environ["VERBOSE"] = "1" + + # Monkey Patch the SonicV2Connector Object + from ...mock_tables import dbconnector + db = SonicV2Connector() + + # popualate the db with mock data + db_names = list(dedicated_dbs.keys()) + try: + populate_mock(db, db_names) + except Exception as e: + assert False, "Mock initialization failed: " + str(e) + + # Initialize connection pool + conn_pool = ConnectionPool() + DEF_NS = '' # Default Namespace + conn_pool.cache = {DEF_NS: {'conn': db, + 'connected_to': set(db_names)}} + + # Initialize match_engine + match_engine = MatchEngine(conn_pool) + yield match_engine + print("TEARDOWN") + os.environ["VERBOSE"] = "0" + + +@pytest.mark.usefixtures("match_engine") +class TestEvpnModule: + def test_working_state(self, match_engine): + """ + Scenario: When the appl info is properly applied and propagated + """ + params = {Evpn.ARG_NAME: "Vlan2345:11.1.0.32", "namespace": ""} + m_evpn = Evpn(match_engine) + returned = m_evpn.execute(params) + expect = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["APPL_DB"]["keys"].append("VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.32") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e1") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007e1") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ea") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ec") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007eb") + expect["STATE_DB"]["keys"].append("VXLAN_TUNNEL_TABLE|EVPN_11.1.0.32") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_evpn_info(self, match_engine): + """ + Scenario: When the application table is present and asic_db tables are missing + """ + params = {Evpn.ARG_NAME: "Vlan2345:11.1.0.33", "namespace": ""} + m_evpn = Evpn(match_engine) + returned = m_evpn.execute(params) + expect = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["APPL_DB"]["keys"].append("VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.33") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["STATE_DB"]["keys"].append("VXLAN_TUNNEL_TABLE|EVPN_11.1.0.33") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_evpn_term(self, match_engine): + """ + Scenario: When the application table is applied and only SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY is missing + """ + params = {Evpn.ARG_NAME: "Vlan2345:11.1.0.34", "namespace": ""} + m_evpn = Evpn(match_engine) + returned = m_evpn.execute(params) + expect = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["APPL_DB"]["keys"].append("VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.34") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e2") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ea") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ec") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007eb") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["STATE_DB"]["keys"].append("VXLAN_TUNNEL_TABLE|EVPN_11.1.0.34") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_state(self, match_engine): + """ + Scenario: When the application table is applied and state_db table is missing + """ + params = {Evpn.ARG_NAME: "Vlan2345:11.1.0.35", "namespace": ""} + m_evpn = Evpn(match_engine) + returned = m_evpn.execute(params) + expect = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["APPL_DB"]["keys"].append("VXLAN_REMOTE_VNI_TABLE:Vlan2345:11.1.0.35") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007e3") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007e3") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ea") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ec") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007eb") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_no_evpn(self, match_engine): + """ + Scenario: When the application table is not present + """ + params = {Evpn.ARG_NAME: "Vlan2345:11.1.0.36", "namespace": ""} + m_evpn = Evpn(match_engine) + returned = m_evpn.execute(params) + expect = create_template_dict(dbs=["APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["APPL_DB"]["tables_not_found"].append("VXLAN_REMOTE_VNI_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_all_args(self, match_engine): + """ + Scenario: Verify Whether the get_all_args method is working as expected + """ + m_evpn = Evpn(match_engine) + returned = m_evpn.get_all_args("") + expect = ["Vlan2345:11.1.0.32", "Vlan2345:11.1.0.33", "Vlan2345:11.1.0.34", "Vlan2345:11.1.0.35"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff diff --git a/tests/dump_tests/module_tests/vxlan_tunnel_map_test.py b/tests/dump_tests/module_tests/vxlan_tunnel_map_test.py new file mode 100644 index 000000000000..771ed57cd360 --- /dev/null +++ b/tests/dump_tests/module_tests/vxlan_tunnel_map_test.py @@ -0,0 +1,136 @@ +import json +import os +import pytest +from deepdiff import DeepDiff +from dump.helper import create_template_dict +from dump.plugins.vxlan_tunnel_map import Vxlan_tunnel_map +from dump.match_infra import MatchEngine, ConnectionPool +from swsscommon.swsscommon import SonicV2Connector + +# Location for dedicated db's used for UT +module_tests_path = os.path.dirname(__file__) +dump_tests_path = os.path.join(module_tests_path, "../") +tests_path = os.path.join(dump_tests_path, "../") +dump_test_input = os.path.join(tests_path, "dump_input") +vxlan_tunnel_map_files_path = os.path.join(dump_test_input, "vxlan") + +# Define the mock files to read from +dedicated_dbs = {} +dedicated_dbs['CONFIG_DB'] = os.path.join(vxlan_tunnel_map_files_path, "config_db.json") +dedicated_dbs['APPL_DB'] = os.path.join(vxlan_tunnel_map_files_path, "appl_db.json") +dedicated_dbs['ASIC_DB'] = os.path.join(vxlan_tunnel_map_files_path, "asic_db.json") + + +def populate_mock(db, db_names): + for db_name in db_names: + db.connect(db_name) + # Delete any default data + db.delete_all_by_pattern(db_name, "*") + with open(dedicated_dbs[db_name]) as f: + mock_json = json.load(f) + for key in mock_json: + for field, value in mock_json[key].items(): + db.set(db_name, key, field, value) + + +@pytest.fixture(scope="class", autouse=True) +def match_engine(): + + print("SETUP") + os.environ["VERBOSE"] = "1" + + # Monkey Patch the SonicV2Connector Object + from ...mock_tables import dbconnector + db = SonicV2Connector() + + # popualate the db with mock data + db_names = list(dedicated_dbs.keys()) + try: + populate_mock(db, db_names) + except Exception as e: + assert False, "Mock initialization failed: " + str(e) + + # Initialize connection pool + conn_pool = ConnectionPool() + DEF_NS = '' # Default Namespace + conn_pool.cache = {DEF_NS: {'conn': db, + 'connected_to': set(db_names)}} + + # Initialize match_engine + match_engine = MatchEngine(conn_pool) + yield match_engine + print("TEARDOWN") + os.environ["VERBOSE"] = "0" + + +@pytest.mark.usefixtures("match_engine") +class TestVxlantunnelmapModule: + def test_working_state(self, match_engine): + """ + Scenario: When the config is properly applied and propagated + """ + params = {Vxlan_tunnel_map.ARG_NAME: "vtep_1336|map_1336_Vlan2345", "namespace": ""} + m_vxlan_tunnel_map = Vxlan_tunnel_map(match_engine) + returned = m_vxlan_tunnel_map.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL_MAP|vtep_1336|map_1336_Vlan2345") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_MAP_TABLE:vtep_1336:map_1336_Vlan2345") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY:oid:0x3b0000000007ef") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_vxlan_tunnel_map_entry(self, match_engine): + """ + Scenario: When the config was applied and asic db tables are missing + """ + params = {Vxlan_tunnel_map.ARG_NAME: "vtep_1336|map_1337_Vlan2346", "namespace": ""} + m_vxlan_tunnel_map = Vxlan_tunnel_map(match_engine) + returned = m_vxlan_tunnel_map.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL_MAP|vtep_1336|map_1337_Vlan2346") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_MAP_TABLE:vtep_1336:map_1337_Vlan2346") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_appl(self, match_engine): + """ + Scenario: When the config was applied and it did not propagate to other db's + """ + params = {Vxlan_tunnel_map.ARG_NAME: "vtep_1338|map_1338_Vlan2347", "namespace": ""} + m_vxlan_tunnel_map = Vxlan_tunnel_map(match_engine) + returned = m_vxlan_tunnel_map.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL_MAP|vtep_1338|map_1338_Vlan2347") + expect["APPL_DB"]["tables_not_found"].append("VXLAN_TUNNEL_MAP_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_no_vxlan_tunnel_map(self, match_engine): + """ + Scenario: When the config was not present + """ + params = {Vxlan_tunnel_map.ARG_NAME: "vtep_1338|map_1339_Vlan2348", "namespace": ""} + m_vxlan_tunnel_map = Vxlan_tunnel_map(match_engine) + returned = m_vxlan_tunnel_map.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VXLAN_TUNNEL_MAP") + expect["APPL_DB"]["tables_not_found"].append("VXLAN_TUNNEL_MAP_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_all_args(self, match_engine): + """ + Scenario: Verify Whether the get_all_args method is working as expected + """ + m_vxlan_tunnel_map = Vxlan_tunnel_map(match_engine) + returned = m_vxlan_tunnel_map.get_all_args("") + expect = ["vtep_1336|map_1336_Vlan2345", "vtep_1336|map_1337_Vlan2346", "vtep_1338|map_1338_Vlan2347"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff diff --git a/tests/dump_tests/module_tests/vxlan_tunnel_test.py b/tests/dump_tests/module_tests/vxlan_tunnel_test.py new file mode 100644 index 000000000000..22e4cc35e254 --- /dev/null +++ b/tests/dump_tests/module_tests/vxlan_tunnel_test.py @@ -0,0 +1,184 @@ +import json +import os +import pytest +from deepdiff import DeepDiff +from dump.helper import create_template_dict +from dump.plugins.vxlan_tunnel import Vxlan_tunnel +from dump.match_infra import MatchEngine, ConnectionPool +from swsscommon.swsscommon import SonicV2Connector + +# Location for dedicated db's used for UT +module_tests_path = os.path.dirname(__file__) +dump_tests_path = os.path.join(module_tests_path, "../") +tests_path = os.path.join(dump_tests_path, "../") +dump_test_input = os.path.join(tests_path, "dump_input") +vxlan_tunnel_files_path = os.path.join(dump_test_input, "vxlan") + +# Define the mock files to read from +dedicated_dbs = {} +dedicated_dbs['CONFIG_DB'] = os.path.join(vxlan_tunnel_files_path, "config_db.json") +dedicated_dbs['APPL_DB'] = os.path.join(vxlan_tunnel_files_path, "appl_db.json") +dedicated_dbs['ASIC_DB'] = os.path.join(vxlan_tunnel_files_path, "asic_db.json") + + +def populate_mock(db, db_names): + for db_name in db_names: + db.connect(db_name) + # Delete any default data + db.delete_all_by_pattern(db_name, "*") + with open(dedicated_dbs[db_name]) as f: + mock_json = json.load(f) + for key in mock_json: + for field, value in mock_json[key].items(): + db.set(db_name, key, field, value) + + +@pytest.fixture(scope="class", autouse=True) +def match_engine(): + + print("SETUP") + os.environ["VERBOSE"] = "1" + + # Monkey Patch the SonicV2Connector Object + from ...mock_tables import dbconnector + db = SonicV2Connector() + + # popualate the db with mock data + db_names = list(dedicated_dbs.keys()) + try: + populate_mock(db, db_names) + except Exception as e: + assert False, "Mock initialization failed: " + str(e) + + # Initialize connection pool + conn_pool = ConnectionPool() + DEF_NS = '' # Default Namespace + conn_pool.cache = {DEF_NS: {'conn': db, + 'connected_to': set(db_names)}} + + # Initialize match_engine + match_engine = MatchEngine(conn_pool) + yield match_engine + print("TEARDOWN") + os.environ["VERBOSE"] = "0" + + +@pytest.mark.usefixtures("match_engine") +class TestVxlantunnelModule: + def test_working_state(self, match_engine): + """ + Scenario: When the config is properly applied and propagated + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_1336", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL|vtep_1336") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_TABLE:vtep_1336") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ed") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007ee") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ea") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007e9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ec") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007eb") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_vxlan_tunnel(self, match_engine): + """ + Scenario: When the config was applied and the asic_db tables are missing + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_2312", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL|vtep_2312") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_TABLE:vtep_2312") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_vxlan_tunnel_term(self, match_engine): + """ + Scenario: When the config was applied and just SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY is missing in the asic db + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_1000", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL|vtep_1000") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_TABLE:vtep_1000") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ef") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007ba") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007b9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007bc") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP:oid:0x290000000007bb") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_vxlan_tunnel_map(self, match_engine): + """ + Scenario: When the config was applied and just SAI_OBJECT_TYPE_TUNNEL_MAP is missing in the asic db + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_1111", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL|vtep_1111") + expect["APPL_DB"]["keys"].append("VXLAN_TUNNEL_TABLE:vtep_1111") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL:oid:0x2a0000000007ee") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY:oid:0x2b0000000007ef") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_missing_appl(self, match_engine): + """ + Scenario: When the config was applied and it did not propagate to other db's + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_1234", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VXLAN_TUNNEL|vtep_1234") + expect["APPL_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_no_vxlan_tunnel(self, match_engine): + """ + Scenario: When the config was not present + """ + params = {Vxlan_tunnel.ARG_NAME: "vtep_5555", "namespace": ""} + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VXLAN_TUNNEL") + expect["APPL_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP") + expect["STATE_DB"]["tables_not_found"].append("VXLAN_TUNNEL_TABLE") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_all_args(self, match_engine): + """ + Scenario: Verify Whether the get_all_args method is working as expected + """ + m_vxlan_tunnel = Vxlan_tunnel(match_engine) + returned = m_vxlan_tunnel.get_all_args("") + expect = ["vtep_1336", "vtep_1111", "vtep_1000", "vtep_2312", "vtep_1234"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff