def find_path_sdn(self): # Get SDN interfaces for (SRC, DST) SE interface negative_filter = ["tnrm"] for path_source in self.mapping_tn_se_of: for src_dst_value in self.src_dst_values: # Domains connected through VPN may not have SE links (skip) if "se" not in path_source[src_dst_value]: return # possitive_filter_of_switches = [ FormatUtils.\ # remove_port_cid(f) for f in getattr(self, \ # "%s_of_cids" % src_dst_value) ] se_interface = path_source[src_dst_value]["se"] # Possible SE-SDN links sdn_candidates = [] if se_interface is not None and len(se_interface) > 0: # Search for *every* connection between SE and SDN devices se_node = FormatUtils.remove_port_cid(se_interface) sdn_candidates = self.find_se_sdn_links_for_se_node( se_node, negative_filter) for se_sdn_link in sdn_candidates: se_sdn_link = \ FormatUtils.format_verify_se_sdn_links(se_sdn_link) path_source[src_dst_value]["links"].append(se_sdn_link)
def find_sdn_interfaces_for_se_interface(se_links, se_interface, negative_filter=[], possitive_filter=[""]): sdn_interfaces_match = set() for se_link in se_links: se_link_interfaces = [ iface.get("component_id") for iface in se_link.get("interface_ref") ] se_link_interfaces_match = any([ PathFinderTNtoSDNFormatUtils.remove_port_cid(se_interface) in se_link_interface for se_link_interface in se_link_interfaces ]) if se_link_interfaces_match: # Retrieve link interfaces from SDN switches that are connected with any SE interface # Search for some SDN link connected to the passed SE component id (without port!) se_interface_noport = PathFinderTNtoSDNFormatUtils.remove_port_cid( se_interface) # Also, avoid adding links SE-TN (this would introduce a never-ending loop) if se_interface_noport in se_link_interfaces[0] \ and not any([ param in se_link_interfaces[1] for param in negative_filter ]) \ and any([ param in se_link_interfaces[1] for param in possitive_filter ]): sdn_interfaces_match.add(se_link_interfaces[1]) elif se_interface_noport in se_link_interfaces[1] \ and not any([ param in se_link_interfaces[0] for param in negative_filter ]) \ and any([ param in se_link_interfaces[0] for param in possitive_filter ]): sdn_interfaces_match.add(se_link_interfaces[0]) # Convert from set to tuple to avoid unhashable problems later on return tuple(sdn_interfaces_match)
def find_se_interfaces_for_tn_interface(se_links, tn_interface): se_interfaces_match = set() for se_link in se_links: #if tn_interface in se_link.get("component_id"): se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] if tn_interface in se_link_interfaces: se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Remove link interface that matches with the passed TN interface se_link_interfaces.pop(se_link_interfaces.index(tn_interface)) se_interfaces_match.add(se_link_interfaces[0]) # Convert from set to tuple to avoid unhashable problems later on return tuple(se_interfaces_match)
def get_tn_interfaces_cids(self, clean=False): # Return a list with the component_id values for the TN interfaces tn_interfaces = set() for tn_node in self.tn_nodes: tn_interfaces.update( FormatUtils.get_tn_interfaces_cid_from_node(tn_node, clean)) return tn_interfaces
def format_verify_tn_interface(self, tn_interface): # Ensure that the TN interfaces match with their original names # under resource.tn.node. This is performed to restore the # component_id values, previously changed tn_interfaces_cids = self.get_tn_interfaces_cids(clean=False) return FormatUtils.format_verify_tn_interface(tn_interfaces_cids, tn_interface)
def format_verify_tn_interface(self, tn_interface): # Ensure that the TN interfaces match with their original names # under resource.tn.node. This is performed to restore the # component_id values, previously changed tn_interfaces_cids = self.get_tn_interfaces_cids(clean=False) return FormatUtils.format_verify_tn_interface( tn_interfaces_cids, tn_interface)
def find_se_interfaces_for_tn_interface(se_links, tn_interface): se_interfaces_match = set() for se_link in se_links: #if tn_interface in se_link.get("component_id"): se_link_interfaces = [ FormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Checks: # 1. TN interface is connected to some SE interface # 2. Same authority for both (e.g. control AIST/AIST2 DC case) if tn_interface in se_link_interfaces \ and OrgUtils.check_auth_alt_se_in_mappings(se_link_interfaces): se_link_interfaces = [ FormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Remove link interface that matches with the passed TN interface se_link_interfaces.pop(se_link_interfaces.index(tn_interface)) se_interfaces_match.add(se_link_interfaces[0]) # Convert from set to tuple to avoid unhashable problems later on return tuple(se_interfaces_match)
def find_se_interfaces_for_domain_names(se_links, mappings, src_domain, dst_domain): se_interfaces_matches = set() for se_link in se_links: #if tn_interface in se_link.get("component_id"): se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Both source and destination must exist in an SE-SE link src_alias = [ src_domain ] src_alias.extend([ dom for dom in PathFinderTNtoSDNFilterUtils.get_organisation_mappings(mappings, src_domain) ]) src_alias_match = any([ alias in iface for alias in src_alias for iface in se_link_interfaces ]) dst_alias = [ dst_domain ] dst_alias.extend([ dom for dom in PathFinderTNtoSDNFilterUtils.get_organisation_mappings(mappings, dst_domain) ]) dst_alias_match = any([ alias in iface for alias in dst_alias for iface in se_link_interfaces ]) if src_alias_match and dst_alias_match: se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid(iface.get("component_id")) for iface in se_link.get("interface_ref") ] candidate_set = (se_link_interfaces[0], se_link_interfaces[1]) if not set(candidate_set).issubset(se_interfaces_matches): se_interfaces_matches.add(tuple(candidate_set)) # Convert from set to tuple to avoid unhashable problems later on return tuple(se_interfaces_matches)
def get_se_interfaces_cid_from_link(se_link, clean=False): # Return a list with a set of two component_id values for the given SE link interfaces = se_link.get("interface_ref", {}) processed_interfaces = [] for interface in interfaces: processed_interface = interface.get("component_id", "") if clean == True: # Some of the SE links are SE-TN links processed_interface = FormatUtils.clean_tn_stp_cid(processed_interface) processed_interfaces.append(processed_interface) return list(set(processed_interfaces))
def find_se_interfaces_for_tn_interface(se_links, tn_interface): se_interfaces_match = set() for se_link in se_links: #if tn_interface in se_link.get("component_id"): se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid( iface.get("component_id")) for iface in se_link.get("interface_ref") ] if tn_interface in se_link_interfaces: se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid( iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Remove link interface that matches with the passed TN interface se_link_interfaces.pop(se_link_interfaces.index(tn_interface)) se_interfaces_match.add(se_link_interfaces[0]) # Convert from set to tuple to avoid unhashable problems later on return tuple(se_interfaces_match)
def find_sdn_interfaces_for_se_interface(se_links, se_interface, negative_filter=[], possitive_filter=[""]): sdn_interfaces_match = set() for se_link in se_links: se_link_interfaces = [ iface.get("component_id") for iface in se_link.get("interface_ref") ] se_link_interfaces_match = any([ FormatUtils.remove_port_cid(se_interface) in se_link_interface for se_link_interface in se_link_interfaces ]) if se_link_interfaces_match: # Retrieve link interfaces from SDN switches that are connected with any SE interface # Search for some SDN link connected to the passed SE component id (without port!) se_interface_noport = FormatUtils.remove_port_cid(se_interface) # Also, avoid adding links SE-TN (this would introduce a never-ending loop) if se_interface_noport in se_link_interfaces[0] \ and not any([ param in se_link_interfaces[1] for param in negative_filter ]) \ and any([ param in se_link_interfaces[1] for param in possitive_filter ]): sdn_interfaces_match.add(se_link_interfaces[1]) elif se_interface_noport in se_link_interfaces[1] \ and not any([ param in se_link_interfaces[0] for param in negative_filter ]) \ and any([ param in se_link_interfaces[0] for param in possitive_filter ]): sdn_interfaces_match.add(se_link_interfaces[0]) # Convert from set to tuple to avoid unhashable problems later on return tuple(sdn_interfaces_match)
def get_se_interfaces_cid_from_link(se_link, clean=False): # Return a list with a set of two component_id values for the given SE link interfaces = se_link.get("interface_ref", {}) processed_interfaces = [] for interface in interfaces: processed_interface = interface.get("component_id", "") if clean == True: # Some of the SE links are SE-TN links processed_interface = PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid( processed_interface) processed_interfaces.append(processed_interface) return list(set(processed_interfaces))
def find_se_interfaces_for_domain_names(se_links, mappings, src_domain, dst_domain): se_interfaces_matches = set() for se_link in se_links: #if tn_interface in se_link.get("component_id"): se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid( iface.get("component_id")) for iface in se_link.get("interface_ref") ] # Both source and destination must exist in an SE-SE link src_alias = [src_domain] src_alias.extend([ dom for dom in PathFinderTNtoSDNFilterUtils. get_organisation_mappings(mappings, src_domain) ]) src_alias_match = any([ alias in iface for alias in src_alias for iface in se_link_interfaces ]) dst_alias = [dst_domain] dst_alias.extend([ dom for dom in PathFinderTNtoSDNFilterUtils. get_organisation_mappings(mappings, dst_domain) ]) dst_alias_match = any([ alias in iface for alias in dst_alias for iface in se_link_interfaces ]) if src_alias_match and dst_alias_match: se_link_interfaces = [ PathFinderTNtoSDNFormatUtils.clean_tn_stp_cid( iface.get("component_id")) for iface in se_link.get("interface_ref") ] candidate_set = (se_link_interfaces[0], se_link_interfaces[1]) if not set(candidate_set).issubset(se_interfaces_matches): se_interfaces_matches.add(tuple(candidate_set)) # Convert from set to tuple to avoid unhashable problems later on return tuple(se_interfaces_matches)
def find_path_tn(self): # Retrieve list of CIDs for TNRM interfaces tn_interfaces_cids = self.get_tn_interfaces_cids(clean=True) # Get proper TN interfaces for both SRC and DST TN interfaces self.mapping_tn_se_of_src_partial = {} self.mapping_tn_se_of_dst_partial = {} # Get proper TN interfaces for (SRC, DST) TN interface for src_dst_value in self.src_dst_values: # Do a first clean of SRC and DST interface src_dst_cid = FormatUtils.clean_tn_stp_cid(getattr(self, "%s_dom" % src_dst_value)) dst_src_tn_interface_found = False # Playing a bit with the language to be able # to have all the processing in a single place for tn_interface_cid in tn_interfaces_cids: if src_dst_cid in tn_interface_cid and src_dst_cid.startswith("urn"): dst_src_tn_interface_found = True break if dst_src_tn_interface_found == True: setattr(self, "tn_candidates_%s" % src_dst_value, [ src_dst_cid ]) else: # Set is converted to list for easyness list_interfaces = map(list, self.find_tn_interfaces_for_domain(src_dst_cid))[0] # NOTE: only the first TN interface is retrieved... # Filter by link type, if requested by user setattr(self, "tn_candidates_%s" % src_dst_value, list(\ self.filter_tn_interfaces_by_type(list_interfaces, self.link_type))) # Initialize structure with dictionary and append SRC and DST interfaces to the set setattr(self, "mapping_tn_se_of_%s_partial" % src_dst_value, { "tn": set() }) for tn_candidate in getattr(self, "tn_candidates_%s" % src_dst_value): mapping_partial = getattr(self, "mapping_tn_se_of_%s_partial" % src_dst_value) mapping_partial["tn"].add(tn_candidate) # Place every path into the final structure #combinations_src_dst_stps = zip(self.mapping_tn_se_of_src_partial["tn"], self.mapping_tn_se_of_dst_partial["tn"]) # Find all possible combinations (order-independent) src_stps = self.mapping_tn_se_of_src_partial["tn"] dst_stps = self.mapping_tn_se_of_dst_partial["tn"] combinations_src_dst_stps = CombinationUtils.yield_combinations_stp_pairs(src_stps, dst_stps) # Filter out combinations whose STP have different types (i.e. NSI-GRE) combinations_src_dst_stps_filter = [] for src_dst_stp in combinations_src_dst_stps: stp_link_tmp = FilterUtils.ensure_same_type_tn_interfaces([src_dst_stp[0], src_dst_stp[1]]) if len(stp_link_tmp) == 2: combinations_src_dst_stps_filter.append(stp_link_tmp) combinations_src_dst_stps = combinations_src_dst_stps_filter for tn_src_dst_pair in combinations_src_dst_stps: # Tuple: 1st element (src), 2nd element (dst) self.mapping_tn_se_of.append({"src": {"tn": tn_src_dst_pair[0]}, "dst": {"tn": tn_src_dst_pair[1]}})
def find_path_sdn(self): # Get SDN interfaces for (SRC, DST) SE interface negative_filter = ["tnrm"] for path_source in self.mapping_tn_se_of: for src_dst_value in self.src_dst_values: # Domains connected through the VPN may not have SE links (skip) if "se" not in path_source[src_dst_value]: return #possitive_filter_of_switches = [ FormatUtils.remove_port_cid(f) for f in getattr(self, "%s_of_cids" % src_dst_value) ] se_interface = path_source[src_dst_value]["se"] # Possible SE-SDN links sdn_candidates = [] if se_interface is not None and len(se_interface) > 0: # Search for *every* connection between SE and SDN devices se_node = FormatUtils.remove_port_cid(se_interface) sdn_candidates = self.find_se_sdn_links_for_se_node( se_node, negative_filter) for se_sdn_link in sdn_candidates: se_sdn_link = FormatUtils.format_verify_se_sdn_links( se_sdn_link) path_source[src_dst_value]["links"].append(se_sdn_link)
def find_path_tn(self): # Retrieve list of CIDs for TNRM interfaces tn_interfaces_cids = self.get_tn_interfaces_cids(clean=True) # Get proper TN interfaces for both SRC and DST TN interfaces self.mapping_tn_se_of_src_partial = {} self.mapping_tn_se_of_dst_partial = {} # Get proper TN interfaces for (SRC, DST) TN interface for src_dst_value in self.src_dst_values: # Do a first clean of SRC and DST interface src_dst_cid = FormatUtils.clean_tn_stp_cid( getattr(self, "%s_dom" % src_dst_value)) dst_src_tn_interface_found = False # Playing a bit with the language to be able # to have all the processing in a single place for tn_interface_cid in tn_interfaces_cids: if src_dst_cid in tn_interface_cid and src_dst_cid.startswith( "urn"): dst_src_tn_interface_found = True break if dst_src_tn_interface_found == True: setattr(self, "tn_candidates_%s" % src_dst_value, [src_dst_cid]) else: # Set is converted to list for easyness list_interfaces = map( list, self.find_tn_interfaces_for_domain(src_dst_cid))[0] # NOTE: only the first TN interface is retrieved... # Filter by link type, if requested by user setattr(self, "tn_candidates_%s" % src_dst_value, list(\ self.filter_tn_interfaces_by_type(list_interfaces, self.link_type))) # Initialize structure with dictionary and append SRC and DST interfaces to the set setattr(self, "mapping_tn_se_of_%s_partial" % src_dst_value, {"tn": set()}) for tn_candidate in getattr(self, "tn_candidates_%s" % src_dst_value): mapping_partial = getattr( self, "mapping_tn_se_of_%s_partial" % src_dst_value) mapping_partial["tn"].add(tn_candidate) # Place every path into the final structure #combinations_src_dst_stps = zip(self.mapping_tn_se_of_src_partial["tn"], self.mapping_tn_se_of_dst_partial["tn"]) # Find all possible combinations (order-independent) src_stps = self.mapping_tn_se_of_src_partial["tn"] dst_stps = self.mapping_tn_se_of_dst_partial["tn"] combinations_src_dst_stps = CombinationUtils.yield_combinations_stp_pairs( src_stps, dst_stps) # Filter out combinations whose STP have different types (i.e. NSI-GRE) combinations_src_dst_stps_filter = [] for src_dst_stp in combinations_src_dst_stps: stp_link_tmp = FilterUtils.ensure_same_type_tn_interfaces( [src_dst_stp[0], src_dst_stp[1]]) if len(stp_link_tmp) == 2: combinations_src_dst_stps_filter.append(stp_link_tmp) combinations_src_dst_stps = combinations_src_dst_stps_filter for tn_src_dst_pair in combinations_src_dst_stps: # Tuple: 1st element (src), 2nd element (dst) self.mapping_tn_se_of.append({ "src": { "tn": tn_src_dst_pair[0] }, "dst": { "tn": tn_src_dst_pair[1] } })