Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.topology.web; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame^] | 5 | import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.routing.IRoutingService; |
| 7 | import net.floodlightcontroller.routing.Route; |
| 8 | import net.floodlightcontroller.topology.NodePortTuple; |
| 9 | |
| 10 | import org.openflow.util.HexString; |
| 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 | |
| 18 | protected static Logger log = LoggerFactory.getLogger(RouteResource.class); |
| 19 | |
| 20 | @Get("json") |
| 21 | public List<NodePortTuple> retrieve() { |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame^] | 22 | ITopoRouteService topoRouteService = |
| 23 | (ITopoRouteService)getContext().getAttributes(). |
| 24 | get(ITopoRouteService.class.getCanonicalName()); |
| 25 | if (topoRouteService == null) { |
| 26 | log.debug("Topology Route Service not found"); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 27 | return null; |
| 28 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 29 | |
| 30 | String srcDpid = (String) getRequestAttributes().get("src-dpid"); |
| 31 | String srcPort = (String) getRequestAttributes().get("src-port"); |
| 32 | String dstDpid = (String) getRequestAttributes().get("dst-dpid"); |
| 33 | String dstPort = (String) getRequestAttributes().get("dst-port"); |
| 34 | |
| 35 | log.debug( srcDpid + "--" + srcPort + "--" + dstDpid + "--" + dstPort); |
| 36 | |
| 37 | long longSrcDpid = HexString.toLong(srcDpid); |
| 38 | short shortSrcPort = Short.parseShort(srcPort); |
| 39 | long longDstDpid = HexString.toLong(dstDpid); |
| 40 | short shortDstPort = Short.parseShort(dstPort); |
| 41 | |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 42 | List<NodePortTuple> result = |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame^] | 43 | topoRouteService.getShortestPath(new NodePortTuple(longSrcDpid, shortSrcPort), |
| 44 | new NodePortTuple(longDstDpid, shortDstPort)); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 45 | if ((result != null) && (result.size() > 0)) { |
| 46 | return result; |
| 47 | } else { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 48 | log.debug("ERROR! no route found"); |
| 49 | return null; |
| 50 | } |
| 51 | } |
| 52 | } |