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
评论列表
文章目录