def _update_link_latency(links_dict, n1, n2, latency): edge_str = LinkHelper.get_edge(n1, n2) latency_before = links_dict[edge_str][GnInfo.LATENCY] log.info('update link latency {}: {} => {}'.format( edge_str, latency_before, latency)) # update link latency edge_str = LinkHelper.get_edge(n1, n2) links_dict[edge_str][GnInfo.LATENCY] = latency edge_str = LinkHelper.get_edge(n2, n1) links_dict[edge_str][GnInfo.LATENCY] = latency
def _update_link_dst(links_dict, n1, n2, new_n2, new_latency): log.info('update link {n1} <-> {n2} => {n1} <-> {new_n2}'.format( n1=n1, n2=n2, new_n2=new_n2)) # delete link edge_str = LinkHelper.get_edge(n1, n2) del links_dict[edge_str] edge_str = LinkHelper.get_edge(n2, n1) del links_dict[edge_str] # add link edge_str = LinkHelper.get_edge(n1, new_n2) links_dict[edge_str] = {GnInfo.LATENCY: new_latency} edge_str = LinkHelper.get_edge(new_n2, n1) links_dict[edge_str] = {GnInfo.LATENCY: new_latency}
def _derive_device_graph_edge_info(Gn, device_nodes): edge_info = {} for src in device_nodes: for dst in device_nodes: if src == dst: continue try: path = nx.shortest_path(Gn, source=src, target=dst, weight=GnInfo.LATENCY) min_bw = Const.INT_MAX total_latency = 0 n1 = path[0] for i in range(1, len(path)): n2 = path[i] total_latency += Gn[n1][n2][GnInfo.LATENCY] min_bw = min(min_bw, Gn[n1][n2][GnInfo.BANDWIDTH]) n1 = n2 edge_str = LinkHelper.get_edge(src, dst) edge_info[edge_str] = { GdInfo.LATENCY: total_latency, GdInfo.BANDWIDTH: min_bw, } except nx.NetworkXNoPath: continue return edge_info
def _gen_update_info(result_mapping, Gt, Gd): node_info = {} for task, device in iteritems(result_mapping): if Gt.node[task][GtInfo.DEVICE]: assert device == Gt.node[task][GtInfo.DEVICE] device_type = Gd.node[device][GdInfo.DEVICE_TYPE] latency_info = Gt.node[task][GtInfo.LATENCY_INFO] exec_cmd = deepcopy(Gt.node[task][GtInfo.EXEC_CMD]) compute_latency = 0 if not latency_info else (listvalues( latency_info[device_type])[0]) node_info[task] = { GtInfo.CUR_DEVICE: device, GtInfo.CUR_LATENCY: compute_latency, GtInfo.EXEC_CMD: exec_cmd } edge_info = {} for edge in Gt.edges(): t1, t2 = edge d1 = node_info[t1][GtInfo.CUR_DEVICE] d2 = node_info[t2][GtInfo.CUR_DEVICE] transmission_latency = Gd[d1][d2][GdInfo.LATENCY] edge_info[LinkHelper.get_edge(t1, t2)] = { GtInfo.CUR_LATENCY: transmission_latency, } return node_info, edge_info
def _derive_edge_info(nw_device_spec, nw_device_inventory, links): inventory = InventoryManager(nw_device_inventory, spec=nw_device_spec) edge_info = {} for edge_str, edge_data in iteritems(links): n1, n2 = LinkHelper.get_nodes(edge_str) link_type1 = edge_data[GnInfo.SRC_LINK_TYPE] link_type2 = edge_data[GnInfo.DST_LINK_TYPE] latency = edge_data[GnInfo.LATENCY] ul1, dl1, prot1 = _get_link_info(inventory, n1, link_type1) ul2, dl2, prot2 = _get_link_info(inventory, n2, link_type2) assert prot1 == prot2 edge_info[edge_str] = { GnInfo.SRC_LINK_TYPE: link_type1, GnInfo.DST_LINK_TYPE: link_type2, GnInfo.BANDWIDTH: min(ul1, dl2), GnInfo.LATENCY: latency, GnInfo.PROTOCOL: prot1, } return edge_info
def _derive_edge_info(device_spec, device_inventory, links, nw_device_spec, nw_device_inventory): log.info('create default edge (link) info') dev_inventory = InventoryManager(device_inventory, spec=device_spec) nw_inventory = InventoryManager(nw_device_inventory, spec=nw_device_spec) edge_info = {} for edge_str, edge_data in iteritems(links): n1, n2 = LinkHelper.get_nodes(edge_str) link_type = LinkType.LAN latency = edge_data[GnInfo.LATENCY] ul1, dl1, prot1 = _get_link_info(dev_inventory, nw_inventory, n1, link_type) ul2, dl2, prot2 = _get_link_info(dev_inventory, nw_inventory, n2, link_type) assert prot1 == prot2 edge_info[edge_str] = { GnInfo.SRC_LINK_TYPE: link_type, GnInfo.DST_LINK_TYPE: link_type, GnInfo.BANDWIDTH: min(ul1, dl2), GnInfo.LATENCY: latency, GnInfo.PROTOCOL: prot1, } return edge_info