path_generators.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:ez-segway 作者: thanh-nguyen-dang 项目源码 文件源码
def generate_path(self, topo, flow, link_caps):
        path = []
        count = 0
        self.log.debug("Flow%d: %d --> %d: %s" % (flow.flow_id, flow.src, flow.dst, str(flow.vol)))
        while len(path) == 0 and count < self.attempts - 3:
            try:
                from_srcs = defaultdict()
                bfs_src = nx.bfs_successors(topo.graph, flow.src)
                self.get_node_with_distance(bfs_src, flow.src, 0, 2, deque([]), from_srcs, False)

                to_dsts = defaultdict()
                bfs_dst = nx.bfs_successors(topo.graph, flow.dst)
                self.get_node_with_distance(bfs_dst, flow.dst, 0, 2, deque([]), to_dsts, True)
            except nx.exception.NetworkXNoPath:
                count += 1
                continue

            if not self.create_with_middlebox(topo, flow, from_srcs, to_dsts, link_caps):
                if not self.create_with_shortest_path(topo, flow, from_srcs, to_dsts, link_caps):
                    count += 1
                    continue
            return True
        if count == self.attempts - 3:
            self.log.debug("Fail hard")
            return False
        return path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号