diff --git a/python/topo/odl-topo.py b/python/topo/odl-topo.py index d35d167..66e9775 100644 --- a/python/topo/odl-topo.py +++ b/python/topo/odl-topo.py @@ -13,28 +13,48 @@ resp, content = h.request(baseUrl + 'topology/' + containerName, "GET") edgeProperties = json.loads(content) odlEdges = edgeProperties['edgeProperties'] -print json.dumps(odlEdges, indent = 2) # Get all the nodes/switches -resp, content = h.request(baseUrl + 'switch/' + containerName + 'nodes/', "GET") +resp, content = h.request(baseUrl + 'switchmanager/' + containerName + 'nodes/', "GET") nodeProperties = json.loads(content) odlNodes = nodeProperties['nodeProperties'] -print json.dumps(odlNodes, indent = 2) -# Put nodes and edges into a graph +# Get all the actie hosts +resp, content = h.request(baseUrl + 'hosttracker/' + containerName + 'hosts/active', "GET") +hostProperties = json.loads(content) +hosts = hostProperties["hostConfig"] + +# Initialize the graph graph = nx.Graph() + +# Put switches in the graph for node in odlNodes: - graph.add_node(node['node']['@id']) + graph.add_node(node['node']['id']) + +# Put all the edges between switches for edge in odlEdges: - e = (edge['edge']['headNodeConnector']['node']['@id'], edge['edge']['tailNodeConnector']['node']['@id']) + e = (edge['edge']['headNodeConnector']['node']['id'], edge['edge']['tailNodeConnector']['node']['id']) graph.add_edge(*e) + +# Put hosts in the graph and the relevant edges +for host in hosts: + graph.add_node(host['networkAddress']) + e = (host['networkAddress'], host['nodeId']) + graph.add_edge(*e) + # Print out graph info as a sanity check -print graph.number_of_nodes() -print graph.nodes() -#print json.dumps(odlNodes, indent = 2) -# These JSON dumps were handy when trying to parse the responses -#print json.dumps(topo[0], indent = 2) +print "Number of nodes add in the graph:", graph.number_of_nodes() +print "Nodes are:", graph.nodes() + +print "Paths from 10.0.0.1 -> 10.0.0.3" +asp = nx.all_simple_paths(graph, source="10.0.0.1", target="10.0.0.3") +for p in asp: + print p +print "Paths from 10.0.0.2 -> 10.0.0.4" +asp = nx.all_simple_paths(graph, source="10.0.0.2", target="10.0.0.4") +for p in asp: + print p # write json formatted data to use in visualization d = json_graph.node_link_data(graph) diff --git a/python/topo/topo.json b/python/topo/topo.json index 6e3d8a9..f55635f 100644 --- a/python/topo/topo.json +++ b/python/topo/topo.json @@ -1 +1 @@ -{"directed": false, "graph": [], "nodes": [{"id": "00:00:00:00:00:00:00:01"}, {"id": "00:00:00:00:00:00:00:03"}, {"id": "00:00:00:00:00:00:00:02"}, {"id": "00:00:00:00:00:00:00:05"}, {"id": "00:00:00:00:00:00:00:04"}, {"id": "00:00:00:00:00:00:00:07"}, {"id": "00:00:00:00:00:00:00:06"}], "links": [{"source": 0, "target": 2}, {"source": 0, "target": 3}, {"source": 1, "target": 2}, {"source": 2, "target": 4}, {"source": 3, "target": 5}, {"source": 3, "target": 6}], "multigraph": false} \ No newline at end of file +{"directed": false, "graph": [], "nodes": [{"id": "00:00:00:00:00:00:00:14"}, {"id": "00:00:00:00:00:00:00:15"}, {"id": "00:00:00:00:00:00:00:0a"}, {"id": "00:00:00:00:00:00:00:0b"}, {"id": "00:00:ba:80:5d:e6:7a:40"}, {"id": "10.0.0.4"}, {"id": "10.0.0.1"}, {"id": "10.0.0.3"}, {"id": "10.0.0.2"}], "links": [{"source": 0, "target": 2}, {"source": 0, "target": 5}, {"source": 0, "target": 3}, {"source": 0, "target": 6}, {"source": 1, "target": 2}, {"source": 1, "target": 3}, {"source": 1, "target": 7}, {"source": 2, "target": 4}, {"source": 3, "target": 4}, {"source": 3, "target": 8}], "multigraph": false} \ No newline at end of file