destpath = [] # Store shortest path info in an array orgId = [] destId = [] revDestId = [] orgWeight = [] destWeight = [] revDestWeight = [] ordNodeString = str(ordNode) ordNodeString = ordNodeString[offset:] ordNodeString = ordNodeString + endingString ordNodeGraph = topo.getNode(ordNodeString) # Compute paths forwards and backwards firstShort = DijkstraShortestPath(graph, ordNodeGraph, destNodeGraph) firstpath = firstShort.getPathEdgeList() firstweight = firstShort.getPathLength() secondShort = DijkstraShortestPath(graph, destNodeGraph, ordNodeGraph) secondpath = secondShort.getPathEdgeList() secondWeight = secondShort.getPathLength() # Skip paths that give us a NoneType, but record into nonetype dictionary and increment counter if firstpath == None: Nonetypecounter += 1 # Create entry if not in dictionary, else increment value nonetype[ordNodeString.encode("ascii")] = nonetype.get( ordNodeString, 0) + 1 nonetype[destNodeString.encode("ascii")] = nonetype.get( destNodeString, 0) + 1 continue
orgId = [] destId = [] revDestId = [] orgWeight = [] destWeight = [] revDestWeight = [] ordNodeString = str(ordNode) ordNodeString = ordNodeString[offset:] ordNodeString = ordNodeString + endingString ordNodeGraph = topo.getNode(ordNodeString) # Compute paths forwards and backwards firstShort = DijkstraShortestPath(graph, ordNodeGraph, destNodeGraph) firstpath = firstShort.getPathEdgeList() firstweight = firstShort.getPathLength() secondShort = DijkstraShortestPath(graph, destNodeGraph, ordNodeGraph) secondpath = secondShort.getPathEdgeList() secondWeight = secondShort.getPathLength() # Skip paths that give us a NoneType, but record into nonetype dictionary and increment counter if firstpath == None: Nonetypecounter += 1 # Create entry if not in dictionary, else increment value nonetype[ordNodeString.encode("ascii")] = nonetype.get(ordNodeString, 0) + 1 nonetype[destNodeString.encode("ascii")] = nonetype.get(destNodeString, 0) + 1 continue if secondpath == None: nonetype[ordNodeString.encode("ascii")] = nonetype.get(ordNodeString, 0) + 1
# Syntax error print "Syntax error: path src@domain dst@domain" print " example: path [email protected] [email protected]" sys.exit() topology = TopologyFactory.instance() topo = topology.retrieveTopologyProvider("localLayer2") graph = topo.getGraph(TopologyProvider.WeightType.TrafficEngineering) nodes = topo.getNodes() srcNode = topo.getNode(command_args[2]) dstNode = topo.getNode(command_args[3]) path = DijkstraShortestPath.findPathBetween(graph, srcNode, dstNode) if path == None: print "No path between " + srcNode.getId() + " and " + dstNode.getId() sys.exit() start = DateTime.now() end = start.plusHours(2) reserved = OSCARSReservations(topo).getReserved(start, end) print "Start Node= " + srcNode.getId() maxReservable = -1 for link in path: node = topo.getNodeByLink(link.getId()) port = topo.getPortByLink(link.getId())
# Created by davidhua on 7/17/14. # # Run by calling viewtopo.py in netshell (No arguments); viewtopo.py [path] [source] [dest]; or viewtopo.py [bandwidth] [source] [dest]. topology = TopologyFactory.instance() topo = topology.retrieveTopologyProvider("localLayer2") command_args = sys.argv if len(command_args) == 2: graph = topo.getGraph(TopologyProvider.WeightType.TrafficEngineering) viewer = GraphViewer(graph) viewer.init() elif len(command_args) == 5: srcNode = topo.getNode(command_args[3]+"@es.net"); dstNode = topo.getNode(command_args[4]+"@es.net"); if command_args[2] == "path": graph = topo.getGraph(TopologyProvider.WeightType.TrafficEngineering) path = DijkstraShortestPath(graph, srcNode, dstNode) thispath = path.getPath() viewer = GraphViewer(thispath, graph) elif command_args[2] == "bandwidth": graph = topo.getGraph(TopologyProvider.WeightType.MaxBandwidth) md = ModifiedDijkstra(graph, srcNode, dstNode) maxBandwidth = md.getPath() viewer = GraphViewer(maxBandwidth, graph) viewer.init() else: sys.exit()
# Created by davidhua on 7/17/14. # # Run by calling viewtopo.py in netshell (No arguments); viewtopo.py [path] [source] [dest]; or viewtopo.py [bandwidth] [source] [dest]. topology = TopologyFactory.instance() topo = topology.retrieveTopologyProvider("localLayer2") command_args = sys.argv if len(command_args) == 2: graph = topo.getGraph(TopologyProvider.WeightType.TrafficEngineering) viewer = GraphViewer(graph) viewer.init() elif len(command_args) == 5: srcNode = topo.getNode(command_args[3] + "@es.net") dstNode = topo.getNode(command_args[4] + "@es.net") if command_args[2] == "path": graph = topo.getGraph(TopologyProvider.WeightType.TrafficEngineering) path = DijkstraShortestPath(graph, srcNode, dstNode) thispath = path.getPath() viewer = GraphViewer(thispath, graph) elif command_args[2] == "bandwidth": graph = topo.getGraph(TopologyProvider.WeightType.MaxBandwidth) md = ModifiedDijkstra(graph, srcNode, dstNode) maxBandwidth = md.getPath() viewer = GraphViewer(maxBandwidth, graph) viewer.init() else: sys.exit()