From 7d7c4e9b959d7ed07e2ebaa2fb2f08fee6151958 Mon Sep 17 00:00:00 2001 From: dimitris Date: Mon, 12 Aug 2019 22:25:52 +0300 Subject: [PATCH] Added getShortestPath functionality (not tested) --- .../ApplicationMenu/applicationMenu.js | 52 +++++++++++++++++-- net-man-app/src/services/networkApi.js | 16 +++++- net-man-app/src/utilities/ODL_utilities.js | 2 +- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/net-man-app/src/containers/ApplicationMenu/applicationMenu.js b/net-man-app/src/containers/ApplicationMenu/applicationMenu.js index e4e185f..ea3fa64 100644 --- a/net-man-app/src/containers/ApplicationMenu/applicationMenu.js +++ b/net-man-app/src/containers/ApplicationMenu/applicationMenu.js @@ -7,6 +7,8 @@ import { Link } from 'react-router-dom'; import styles from './applicationMenu.module.css'; import { openDaylightApi } from '../../services/openDaylightApi'; +import { networkApi } from '../../services/networkApi'; +import { getODLnodes, getODLlinks } from '../../utilities/ODL_utilities'; class CreateNetwork extends Component { @@ -27,6 +29,48 @@ class CreateNetwork extends Component { } + getODLinfo = () => { + openDaylightApi.getTopology() + .then(data => { + console.log('openDaylight data:'); + console.log(data['network-topology'].topology); + + const topologies = data['network-topology'].topology; + + const nodes = getODLnodes(topologies); + const links = getODLlinks(topologies); + + const node_source = nodes[0]; + const node_dest = nodes[1]; + + console.log("nodes: ", nodes); + console.log("--------------"); + console.log("links: ", links); + console.log("--------------"); + console.log("node source: ", node_source); + console.log("node dest: ", node_dest); + console.log("--------------"); + + const requestData = { + nodes: nodes, + links: links, + node_source: node_source, + node_dest: node_dest + } + + console.log(requestData); + // return; + + networkApi.getShortestPath(requestData) + .then(data => { + alert("Shortest path calculated"); + console.log("shortest path: ", data.shortest_path) + }); + + + }); + } + render() { return ( @@ -53,9 +97,9 @@ class CreateNetwork extends Component { {/* */} - - {/* */} - + {/* */} + + {/* */}

Application 2

- + {/* */} {/* diff --git a/net-man-app/src/services/networkApi.js b/net-man-app/src/services/networkApi.js index e8abad7..a4364ab 100644 --- a/net-man-app/src/services/networkApi.js +++ b/net-man-app/src/services/networkApi.js @@ -4,7 +4,8 @@ import handleError from './handleError'; export const networkApi = { createNetwork, deleteNetwork, - networkExists + networkExists, + getShortestPath }; function createNetwork(jsonRequest) { @@ -47,4 +48,17 @@ function networkExists() { handleError(error) } ); +} + +function getShortestPath(jsonRequest) { + return axios.post('/shortest_path', jsonRequest) + .then( + response => { + return response.data; + }, + error => { + console.log('Error in network creation'); + handleError(error) + } + ); } \ No newline at end of file diff --git a/net-man-app/src/utilities/ODL_utilities.js b/net-man-app/src/utilities/ODL_utilities.js index 3c1009f..39e1cc9 100644 --- a/net-man-app/src/utilities/ODL_utilities.js +++ b/net-man-app/src/utilities/ODL_utilities.js @@ -14,7 +14,7 @@ export const getODLnodes = (topologies) => { export const getODLlinks = (topologies) => { const topo = topologies[0]; let retLinks = []; - for (let link of topo.links) + for (let link of topo.link) { retLinks.push([link.source['source-node'], link.destination['dest-node']]); }