def dbs_get_vlan_id_from_bvid(dbs, bvid): for db_conn in Namespace.get_non_host_dbs(dbs): db_conn.connect('ASIC_DB') vlan_obj = db_conn.keys('ASIC_DB', "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:" + bvid) if vlan_obj is not None: return port_util.get_vlan_id_from_bvid(db_conn, bvid)
def fdb_vlanmac(self, fdb): if 'vlan' in fdb: vlan_id = fdb["vlan"] elif 'bvid' in fdb: if fdb["bvid"] in self.bvid_vlan_map: vlan_id = self.bvid_vlan_map[fdb["bvid"]] else: vlan_id = port_util.get_vlan_id_from_bvid(self.db_conn, fdb["bvid"]) self.bvid_vlan_map[fdb["bvid"]] = vlan_id return (int(vlan_id),) + mac_decimals(fdb["mac"])
def fdb_vlanmac(self, fdb): if 'vlan' in fdb: vlan_id = fdb["vlan"] elif 'bvid' in fdb: if fdb["bvid"] in self.bvid_vlan_map: vlan_id = self.bvid_vlan_map[fdb["bvid"]] else: vlan_id = port_util.get_vlan_id_from_bvid( self.db_conn, fdb["bvid"]) self.bvid_vlan_map[fdb["bvid"]] = vlan_id return (int(vlan_id), ) + mac_decimals(fdb["mac"])
def nwi_get_fdb_info(oc_nwis, fill_info_bmp, key_ar, disp_args): # refer to /usr/bin/fdbshow key_mac = None key_vlan = None oc_nwi = None len_key_ar = len(key_ar) // 2 if len_key_ar > 3: return False for i in range(len_key_ar): if key_ar[i + len_key_ar] == 'name': if key_ar[i] in oc_nwis.network_instance: oc_nwi = oc_nwis.network_instance[key_ar[i]] else: return False elif key_ar[i + len_key_ar] == 'mac-address': key_mac = key_ar[i] elif key_ar[i + len_key_ar] == 'vlan': key_vlan = key_ar[i] else: return False # instance name is omitted if not oc_nwi: oc_nwi = oc_nwis.network_instance[DEFAULT_NWI_NAME] if_name_map, \ if_oid_map = port_util.get_interface_oid_map(disp_args.appdb) if_br_oid_map = port_util.get_bridge_port_map(disp_args.appdb) NEW_MAC_LST = [] global OLD_MAC_LST fdb_str = disp_args.appdb.keys(disp_args.appdb.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*") if fdb_str and if_br_oid_map: oid_pfx = len("oid:0x") for s in fdb_str: fdb_entry = s.decode() fdb = json.loads(fdb_entry.split(":", 2)[-1]) if not fdb: continue ent = disp_args.appdb.get_all('ASIC_DB', s, blocking=True) br_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][oid_pfx:] if br_port_id not in if_br_oid_map: continue port_id = if_br_oid_map[br_port_id] if_name = if_oid_map[port_id] if "vlan" not in fdb: if "bvid" in fdb: fdb["vlan"] = port_util.get_vlan_id_from_bvid( disp_args.appdb, fdb["bvid"]) else: continue #pdb.set_trace() # ex: # fdb["vlan"] : u'10' # fdb["mac"] : u'00:00:00:00:00:01' # if_name : 'Ethernet4' # oc_nwi.fdb.mac_table.entries.entry['00:00:00:00:00:01 10'] if key_mac and key_mac != fdb["mac"]: continue if key_vlan and key_vlan != fdb["vlan"]: continue mac_key = "%s %s" % (fdb["mac"], fdb["vlan"]) if mac_key in OLD_MAC_LST: OLD_MAC_LST.remove(mac_key) mac_entry = oc_nwi.fdb.mac_table.entries.entry[mac_key] else: mac_entry = oc_nwi.fdb.mac_table.entries.entry.add(mac_key) mac_entry.interface.interface_ref.config.interface = if_name mac_entry.state._set_entry_type('DYNAMIC') NEW_MAC_LST.append(mac_key) # remove old mac entries not used for mac_key in OLD_MAC_LST: oc_nwi.fdb.mac_table.entries.entry.delete(mac_key) OLD_MAC_LST = NEW_MAC_LST return True
def fdb_vlanmac(db_conn, fdb): if 'vlan' in fdb: vlan_id = fdb["vlan"] elif 'bvid' in fdb: vlan_id = port_util.get_vlan_id_from_bvid(db_conn, fdb["bvid"]) return (int(vlan_id), ) + mac_decimals(fdb["mac"])