# How to get shortest path between two hosts?

Hi all, I need to find shortest and best optimal path between two hosts. I dont find any API for that. I found that Dijkstra's algorithm is used in ODL. Can anyone help me to find the REST API call which will return the shortest Path?

edit retag close merge delete

## 3 answers

Sort by ยป oldest newest most voted

You can try to explore the l2-switch code. The loopremover module has the code related to implementation of Dijkstra algorithm but currently it is disabled.

more

## Comments

Thnx subhas,I checked.Its there disabled.And 1.How to create my Own REST api?which calls the Dijkstra's function and return the shortest path. How to do that?

( 2015-09-10 23:45:19 -0700 )edit

follow some sample application (e.g. toaster) to define your rest api.

( 2015-09-11 00:24:47 -0700 )edit

yes ! by modifying l2switch code we can get the shortest path between two hosts !! I got it .

( 2016-03-21 05:48:28 -0700 )edit

I could get the shortest path between two hosts with ODL topology REST API & Python Networkx module. I used mininet simulator and created a custom network topology with multipath.

1. From ODL network topology REST api response, extracted hosts, switch & links details. You can even use ODL python client SDK python-odl to get the topology information

  GET http://192.168.1.124:8181/restconf/operational/network-topology:network-topology

2. With the links details, i generated a Graph using python networkx module.

  import networkx as nx
graph = nx.Graph()
graph.add_edges_from(graph_links)

3. Then by using Dijkstra's Algorithm, can find the shortest path between any two hosts in the topology

 path = nx.dijkstra_path(graph, source_node, dest_node)


Even we can find the list of shortest paths available for a set of hosts

     nx.all_shortest_paths(graph, source=source, target=dest)


Please share your comments on this approach.

Thanks.

more

## Comments

Hi @jayaprakash , Good to know that you found the path . I also developed a java application which will find the path between 2 hosts from the topology details. But Now i am trying to do the same as MD-SAL application which will be shown as restconf API

( 2016-02-11 01:19:19 -0700 )edit

Hi @jayaprakash can i have your email to ask some questions ?

( 2017-03-06 02:21:23 -0700 )edit

Hi @jayaprakash, how are you pushing the shortest path information (using your java code) back to the controller?

( 2017-07-15 09:57:48 -0700 )edit

Hi@jayaprakash,how did you use the link details to generate a graph??

( 2017-07-19 03:28:55 -0700 )edit

Hi, I think there is no rest api present at odl which will give you shortest path. u need to write application for that by consuming dijkstra's algorithm.

Regards, Ashwini

more

## Comments

Thnx Ashwini

( 2015-09-10 23:45:42 -0700 )edit

Hi @Ashwini_Mhatre@subhash , Can you answer for this question? https://ask.opendaylight.org/question/7896/how-to-use-add-repo/

( 2016-02-11 01:22:01 -0700 )edit

## Stats

Asked: 2015-09-10 22:11:21 -0700

Seen: 1,186 times

Last updated: Feb 02 '16