From 1d6e98141a527728c18a399723be6764a3f70cbd Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Fri, 5 Sep 2014 09:17:06 -0700 Subject: [PATCH 1/3] Accounting for ODL API changes. --- python/topo/odl-topo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/topo/odl-topo.py b/python/topo/odl-topo.py index d35d167..f17b43c 100644 --- a/python/topo/odl-topo.py +++ b/python/topo/odl-topo.py @@ -16,7 +16,7 @@ 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) @@ -24,9 +24,9 @@ # Put nodes and edges into a graph graph = nx.Graph() for node in odlNodes: - graph.add_node(node['node']['@id']) + graph.add_node(node['node']['id']) 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) # Print out graph info as a sanity check print graph.number_of_nodes() From a3d28fefab8f726b0f39a2451177cb6ecbbecc1e Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Fri, 5 Sep 2014 16:07:59 -0700 Subject: [PATCH 2/3] Adding hosts to the topo. --- python/topo/odl-topo.py | 28 +++++++++++++++++++--------- python/topo/topo.json | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/python/topo/odl-topo.py b/python/topo/odl-topo.py index f17b43c..58b170e 100644 --- a/python/topo/odl-topo.py +++ b/python/topo/odl-topo.py @@ -13,28 +13,38 @@ 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 + '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']) + +# Put all the edges between switches for edge in odlEdges: e = (edge['edge']['headNodeConnector']['node']['id'], edge['edge']['tailNodeConnector']['node']['id']) 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) +# 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 "Number of nodes add in the graph:", graph.number_of_nodes() +print "Nodes are:", graph.nodes() # 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..8375bec 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": 3}, {"source": 0, "target": 6}, {"source": 0, "target": 8}, {"source": 1, "target": 2}, {"source": 1, "target": 5}, {"source": 1, "target": 3}, {"source": 1, "target": 7}, {"source": 2, "target": 4}, {"source": 3, "target": 4}], "multigraph": false} \ No newline at end of file From 52e2018022f40e0ef7c16b514652f617e9eb116a Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Fri, 5 Sep 2014 16:31:10 -0700 Subject: [PATCH 3/3] Now computing all paths between interesting s/d pairs --- python/topo/odl-topo.py | 10 ++++++++++ python/topo/topo.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/topo/odl-topo.py b/python/topo/odl-topo.py index 58b170e..66e9775 100644 --- a/python/topo/odl-topo.py +++ b/python/topo/odl-topo.py @@ -46,6 +46,16 @@ 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) json.dump(d, open('topo.json','w')) diff --git a/python/topo/topo.json b/python/topo/topo.json index 8375bec..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: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": 3}, {"source": 0, "target": 6}, {"source": 0, "target": 8}, {"source": 1, "target": 2}, {"source": 1, "target": 5}, {"source": 1, "target": 3}, {"source": 1, "target": 7}, {"source": 2, "target": 4}, {"source": 3, "target": 4}], "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