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 | |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.flowmanager.IFlowService; |
Pavlin Radoslavov | 1278ac7 | 2013-10-16 04:43:49 -0700 | [diff] [blame] | 4 | import net.onrc.onos.ofcontroller.topology.ITopologyNetService; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 5 | import net.onrc.onos.ofcontroller.topology.TopologyManager; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.util.DataPath; |
| 7 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 8 | import net.onrc.onos.ofcontroller.util.Port; |
| 9 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 10 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 11 | import org.restlet.resource.Get; |
| 12 | import org.restlet.resource.ServerResource; |
| 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; |
| 15 | |
| 16 | public class RouteResource extends ServerResource { |
| 17 | |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 18 | protected final static Logger log = LoggerFactory.getLogger(RouteResource.class); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 19 | |
| 20 | @Get("json") |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 21 | public DataPath retrieve() { |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 22 | // Get the services that are needed for the computation |
| 23 | ITopologyNetService topologyNetService = |
| 24 | (ITopologyNetService)getContext().getAttributes(). |
| 25 | get(ITopologyNetService.class.getCanonicalName()); |
| 26 | IFlowService flowService = |
| 27 | (IFlowService)getContext().getAttributes(). |
| 28 | get(IFlowService.class.getCanonicalName()); |
| 29 | |
Pavlin Radoslavov | 1278ac7 | 2013-10-16 04:43:49 -0700 | [diff] [blame] | 30 | if (topologyNetService == null) { |
| 31 | log.debug("Topology Net Service not found"); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 32 | return null; |
| 33 | } |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 34 | if (flowService == null) { |
| 35 | log.debug("Flow Service not found"); |
| 36 | return null; |
| 37 | } |
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 | String srcDpidStr = (String) getRequestAttributes().get("src-dpid"); |
| 40 | String srcPortStr = (String) getRequestAttributes().get("src-port"); |
| 41 | String dstDpidStr = (String) getRequestAttributes().get("dst-dpid"); |
| 42 | String dstPortStr = (String) getRequestAttributes().get("dst-port"); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 43 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 44 | log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 45 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 46 | Dpid srcDpid = new Dpid(srcDpidStr); |
| 47 | Port srcPort = new Port(Short.parseShort(srcPortStr)); |
| 48 | Dpid dstDpid = new Dpid(dstDpidStr); |
| 49 | Port dstPort = new Port(Short.parseShort(dstPortStr)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 50 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 51 | DataPath result = |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 52 | topologyNetService.getTopologyShortestPath( |
| 53 | flowService.getTopology(), |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 54 | new SwitchPort(srcDpid, srcPort), |
| 55 | new SwitchPort(dstDpid, dstPort)); |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 56 | if (result != null) { |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 57 | return result; |
| 58 | } else { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 59 | log.debug("ERROR! no route found"); |
| 60 | return null; |
| 61 | } |
| 62 | } |
| 63 | } |