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