diff --git a/hackfest/tapi/tapi_app/Figure_1.png b/hackfest/tapi/tapi_app/Figure_1.png deleted file mode 100644 index 19f6ed978fb270e2d29d8547e5704c7d094ce961..0000000000000000000000000000000000000000 Binary files a/hackfest/tapi/tapi_app/Figure_1.png and /dev/null differ diff --git a/hackfest/tapi/tapi_app/ols-topo.dot b/hackfest/tapi/tapi_app/ols-topo.dot new file mode 100644 index 0000000000000000000000000000000000000000..89122169f5d5b6c28fe365cec812aaca1eeeb476 --- /dev/null +++ b/hackfest/tapi/tapi_app/ols-topo.dot @@ -0,0 +1,16 @@ +strict digraph { +"node-1"; +"node-2"; +"node-3"; +"node-4"; +"node-1" -> "node-3"; +"node-1" -> "node-4"; +"node-2" -> "node-3"; +"node-2" -> "node-4"; +"node-3" -> "node-1"; +"node-3" -> "node-2"; +"node-3" -> "node-4"; +"node-4" -> "node-1"; +"node-4" -> "node-2"; +"node-4" -> "node-3"; +} diff --git a/hackfest/tapi/tapi_app/ols-topo.png b/hackfest/tapi/tapi_app/ols-topo.png new file mode 100644 index 0000000000000000000000000000000000000000..94ac969f94679d1bc9e7bad7f5810b153106a517 Binary files /dev/null and b/hackfest/tapi/tapi_app/ols-topo.png differ diff --git a/hackfest/tapi/tapi_app/requirements.sh b/hackfest/tapi/tapi_app/requirements.sh new file mode 100644 index 0000000000000000000000000000000000000000..95832bb6628447bb1d5d6e7cd8a477468ebe5ef6 --- /dev/null +++ b/hackfest/tapi/tapi_app/requirements.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sudo apt install graphviz +pip install -r requirements.txt diff --git a/hackfest/tapi/tapi_app/tapi_app.py b/hackfest/tapi/tapi_app/tapi_app.py index d9fc4b27926659a30bb984f48fdabfc3c4f4f24a..08d6facf4ab55be932e78003fdafe8336ced3bcf 100644 --- a/hackfest/tapi/tapi_app/tapi_app.py +++ b/hackfest/tapi/tapi_app/tapi_app.py @@ -4,11 +4,8 @@ import requests from requests.auth import HTTPBasicAuth import json -import matplotlib.pyplot as plt import networkx as nx -from networkx.drawing.nx_pydot import write_dot - IP = '127.0.0.1' PORT = 8080 USER = '' @@ -26,21 +23,32 @@ def retrieveTopology(ip, port, user, password, topo_uuid): print ("Retrieved Topology: " + json.dumps(response.json(), indent=4)) return topologies -def draw_topologies (topo) : - nwk_graph = nx.Graph() - - for node in topo[0]['node']: - if node['owned-node-edge-point']: - nwk_graph.add_node(node['uuid']) - - for link in topo[0]['link']: - node1 = link['node-edge-point'][0]['node-uuid'] - node2 = link['node-edge-point'][1]['node-uuid'] - nwk_graph.add_edge(node1, node2) - - nx.draw(nwk_graph, pos=nx.spring_layout(nwk_graph, scale=500)) - plt.show(block=False) - plt.savefig('{:s}.png'.format(TOPO_UUID), format='PNG') +def draw_topologies (topologies): + nwk_graph = nx.DiGraph() + + for topo in topologies: + topo_uuid = topo['uuid'] + for node in topo['node']: + if node['owned-node-edge-point']: + nwk_graph.add_node(node['uuid']) + + for link in topo['link']: + node1 = link['node-edge-point'][0]['node-uuid'] + node2 = link['node-edge-point'][1]['node-uuid'] + nwk_graph.add_edge(node1, node2) + + # Using Matplotlib + #import matplotlib.pyplot as plt + #nx.draw(nwk_graph, pos=nx.spring_layout(nwk_graph, scale=500)) + #plt.show(block=False) + #plt.savefig('{:s}.png'.format(TOPO_UUID), format='PNG') + + # Using Pydot and Graphviz + from networkx.drawing.nx_pydot import write_dot, to_pydot + write_dot(nwk_graph, '{:s}.dot'.format(topo_uuid)) + dot_graph = to_pydot(nwk_graph) + with open('{:s}.png'.format(topo_uuid), 'wb') as f: + f.write(dot_graph.create(format='png')) if __name__ == "__main__": topologies = retrieveTopology(IP, PORT, USER, PASS, TOPO_UUID)