import time If_VLAN_Map_List = [] MPP_If_List = {} #system parameters ACTOR_NUMBERS = 4 SYSTEM_IF_NUMBERS = 18 #start of vlan id for south-neighbor-if and north-actors-if SOUTH_NEIGHBOR_VLAN_START = 1000 NORTH_VSR_VLAN_START = 200 NORTH_FRR1_VLAN_START = 300 NORTH_FRR2_VLAN_START = 400 NORTH_FRR3_VLAN_START = 500 NORTH_FRR4_VLAN_START = 600 #mpp if MPP_SOUTH_IFNAME = 'ens8' MPP_NORTH_IFNAME = 'ens8f5' #actors status FULL = 1 DOWN = 0 #Database parameters DB_HOST_IP = '172.27.0.7' DB_USER_NAME = 'root' DB_PASSWORD = 'mimic' DB_NAME = 'mimic' Actor_List = [] def create_actor_list(): for i in range(ACTOR_NUMBERS): Actor_List_Entry = {} Actor_List_Entry["actorid"] = i Actor_List_Entry["available"] = time.time() Actor_List.append(Actor_List_Entry) print("Actor_List:",Actor_List) return Actor_List def get_north_vlan_by_south(neighbor_vlan): if_map_entry = {} for i in range(len(If_VLAN_Map_List)): if If_VLAN_Map_List[i]['south_neighbor_if_vlan'] == neighbor_vlan: if_map_entry = If_VLAN_Map_List[i] break return if_map_entry def get_south_vlan_by_north(actor_vlan): if_map_entry = {} for i in range(len(If_VLAN_Map_List)): if If_VLAN_Map_List[i]['north_actor0_if_vlan'] == actor_vlan: if_map_entry = If_VLAN_Map_List[i] break elif If_VLAN_Map_List[i]['north_actor1_if_vlan'] == actor_vlan: if_map_entry = If_VLAN_Map_List[i] break elif If_VLAN_Map_List[i]['north_actor2_if_vlan'] == actor_vlan: if_map_entry = If_VLAN_Map_List[i] break elif If_VLAN_Map_List[i]['north_actor3_if_vlan'] == actor_vlan: if_map_entry = If_VLAN_Map_List[i] break elif If_VLAN_Map_List[i]['north_actor4_if_vlan'] == actor_vlan: if_map_entry = If_VLAN_Map_List[i] break continue return if_map_entry def search_actorid_by_vlanid(actor_vlan): for i in range(len(If_VLAN_Map_List)): if If_VLAN_Map_List[i]['north_actor0_if_vlan'] == actor_vlan: return 0 elif If_VLAN_Map_List[i]['north_actor1_if_vlan'] == actor_vlan: return 1 elif If_VLAN_Map_List[i]['north_actor2_if_vlan'] == actor_vlan: return 2 elif If_VLAN_Map_List[i]['north_actor3_if_vlan'] == actor_vlan: return 3 elif If_VLAN_Map_List[i]['north_actor4_if_vlan'] == actor_vlan: return 4 return None def print_if_vlan_mpp_list(): print("if_vlan_mpp_list len = ",len(If_VLAN_Map_List)) for i in range(len(If_VLAN_Map_List)): print ("south_neighbor_if_vlan:",If_VLAN_Map_List[i]['south_neighbor_if_vlan']) print ("north_actor0_if_vlan:",If_VLAN_Map_List[i]['north_actor0_if_vlan']) print ("north_actor1_if_vlan:",If_VLAN_Map_List[i]['north_actor1_if_vlan']) print ("north_actor2_if_vlan:",If_VLAN_Map_List[i]['north_actor2_if_vlan']) print ("north_actor3_if_vlan:",If_VLAN_Map_List[i]['north_actor3_if_vlan']) print ("north_actor4_if_vlan:",If_VLAN_Map_List[i]['north_actor4_if_vlan']) def Get_if_vlan_map(): i = 1 while i <= SYSTEM_IF_NUMBERS: if_map_entry = {} #interface vlan id of actors if_map_entry['south_neighbor_if_vlan'] = SOUTH_NEIGHBOR_VLAN_START + i if_map_entry['north_actor0_if_vlan'] = NORTH_VSR_VLAN_START + i #vsr if_map_entry['north_actor1_if_vlan'] = NORTH_FRR1_VLAN_START + i #frr1 if_map_entry['north_actor2_if_vlan'] = NORTH_FRR2_VLAN_START + i #frr2 if_map_entry['north_actor3_if_vlan'] = NORTH_FRR3_VLAN_START + i #frr3 if_map_entry['north_actor4_if_vlan'] = NORTH_FRR4_VLAN_START + i #frr4 If_VLAN_Map_List.append(if_map_entry) i = i+1 print("if_map_entry:",if_map_entry) #read MPP interface from config def Get_MPP_if(): MPP_If_List['mpp_south_if_name'] = MPP_SOUTH_IFNAME MPP_If_List['mpp_north_if_name'] = MPP_NORTH_IFNAME #read initialized info from config def init_from_config(): create_actor_list() Get_if_vlan_map() Get_MPP_if()