HIGUCHI Yuta | f0499b0 | 2013-06-14 15:01:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.topology.web; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 2 | |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService; |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame^] | 4 | import net.onrc.onos.ofcontroller.routing.TopoRouteService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 5 | import net.onrc.onos.ofcontroller.util.DataPath; |
| 6 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 7 | import net.onrc.onos.ofcontroller.util.Port; |
| 8 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 9 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 10 | import org.restlet.resource.Get; |
| 11 | import org.restlet.resource.ServerResource; |
| 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
| 15 | public class RouteResource extends ServerResource { |
| 16 | |
| 17 | protected static Logger log = LoggerFactory.getLogger(RouteResource.class); |
| 18 | |
| 19 | @Get("json") |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 20 | public DataPath retrieve() { |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame^] | 21 | ITopoRouteService topoRouteService = new TopoRouteService(""); |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 22 | if (topoRouteService == null) { |
| 23 | log.debug("Topology Route Service not found"); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 24 | return null; |
| 25 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 26 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 27 | String srcDpidStr = (String) getRequestAttributes().get("src-dpid"); |
| 28 | String srcPortStr = (String) getRequestAttributes().get("src-port"); |
| 29 | String dstDpidStr = (String) getRequestAttributes().get("dst-dpid"); |
| 30 | String dstPortStr = (String) getRequestAttributes().get("dst-port"); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 32 | log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 34 | Dpid srcDpid = new Dpid(srcDpidStr); |
| 35 | Port srcPort = new Port(Short.parseShort(srcPortStr)); |
| 36 | Dpid dstDpid = new Dpid(dstDpidStr); |
| 37 | Port dstPort = new Port(Short.parseShort(dstPortStr)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 38 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 39 | DataPath result = |
| 40 | topoRouteService.getShortestPath(new SwitchPort(srcDpid, srcPort), |
| 41 | new SwitchPort(dstDpid, dstPort)); |
| 42 | if (result != null) { |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 43 | return result; |
| 44 | } else { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 45 | log.debug("ERROR! no route found"); |
| 46 | return null; |
| 47 | } |
| 48 | } |
| 49 | } |