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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding hosts to the topo.
gopchandani committed Sep 5, 2014
commit a3d28fefab8f726b0f39a2451177cb6ecbbecc1e
28 changes: 19 additions & 9 deletions python/topo/odl-topo.py
Original file line number Diff line number Diff line change
@@ -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)
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": 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}