Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accounting for ODL API changes. #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions python/topo/odl-topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/topo/topo.json
Original file line number Diff line number Diff line change
@@ -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}
{"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}