Exemplo n.º 1
0
    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]}})
Exemplo n.º 2
0
    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]
                }
            })