示例#1
0
    def routing_compute_util(self, state):
        self.add_previous_jobs()
        cloned_links = self.graph.copy_links()
        valid = True
        paths_used = []
        util = 0
        job_config = JobConfig()

        for p in state:
            bw, links = p[0], p[1]
            for l in range(len(links) - 1):
                link_id = Link.get_id(links[l], links[l + 1])
                link = cloned_links[link_id]
                link_bandwidth = link.get_bandwidth()

                if link_bandwidth < bw:
                    valid = False
                    break

                link.set_bandwidth(link_bandwidth - bw)

            if not valid:
                # logging.debug(str(state) + " cannot be built")
                break
            else:
                paths_used.append(p)

        if valid:
            self.graph.set_links(cloned_links)
            all_paths_used = deepcopy(paths_used)
            for job in self.jobs_config.values():
                all_paths_used.extend(job.get_used_paths())
            self.graph.set_flow(all_paths_used)

            util = 0
            total_util = 0
            for p in paths_used:
                flow = self.graph.get_flow(Flow.get_id(p[1][0], p[1][-1]))
                util += (flow.get_requested_bandwidth() + flow.get_effective_bandwidth())

            for p in all_paths_used:
                flow = self.graph.get_flow(Flow.get_id(p[1][0], p[1][-1]))
                total_util += (flow.get_requested_bandwidth() + flow.get_effective_bandwidth())

            job_config = JobConfig(util, total_util, copy_links(cloned_links), paths_used)
            self.reset()

        return job_config
示例#2
0
    def update_jobs_utilization(self):
        used_paths = []

        self.add_previous_jobs()

        for job in self.jobs_config.values():
            used_paths.extend(job.get_used_paths())
        self.graph.set_flow(used_paths)

        for job in self.jobs_config.values():
            util = 0
            for p in job.get_used_paths():
                flow = self.graph.get_flow(Flow.get_id(p[1][0], p[1][-1]))
                util += (flow.get_requested_bandwidth() + flow.get_effective_bandwidth())

            job.set_util(util)

        self.reset()
    def set_flow(self, chosen_paths):
        self.flows = {}
        # print "chosen_paths: ", chosen_paths

        # Create Flow Objects
        for cp in self.comm_pattern:
            fl = Flow(cp[0], cp[1], cp[2])
            self.flows[fl.get_end_points()] = fl

        for p in chosen_paths:
            path = p[1]

            link_list = []
            for i in range(len(path)-1):
                l = self.links[Link.get_id(path[i], path[i+1])]
                link_list.append(l)

            fl = self.flows[Flow.get_id(path[0], path[-1])]
            fl.set_path(link_list)

        for link in self.get_links().values():
            link.adjust_flow_bandwidths()
    def set_flow(self, chosen_paths):
        self.flows = {}
        # print "chosen_paths: ", chosen_paths

        # Create Flow Objects
        for cp in self.comm_pattern:
            fl = Flow(cp[0], cp[1], cp[2])
            self.flows[fl.get_end_points()] = fl

        for p in chosen_paths:
            path = p[1]

            link_list = []
            for i in range(len(path) - 1):
                l = self.links[Link.get_id(path[i], path[i + 1])]
                link_list.append(l)

            fl = self.flows[Flow.get_id(path[0], path[-1])]
            fl.set_path(link_list)

        for link in self.get_links().values():
            link.adjust_flow_bandwidths()