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 | |
| 5 | import net.floodlightcontroller.routing.IRoutingService; |
| 6 | import net.floodlightcontroller.routing.Route; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.routing.TopoRouteService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 8 | import net.floodlightcontroller.topology.NodePortTuple; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 9 | import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 10 | |
| 11 | import org.openflow.util.HexString; |
| 12 | import org.restlet.resource.Get; |
| 13 | import org.restlet.resource.ServerResource; |
| 14 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; |
| 16 | |
| 17 | public class RouteResource extends ServerResource { |
| 18 | |
| 19 | protected static Logger log = LoggerFactory.getLogger(RouteResource.class); |
| 20 | |
| 21 | @Get("json") |
| 22 | public List<NodePortTuple> retrieve() { |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 23 | /* |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 24 | IRoutingService routing = |
| 25 | (IRoutingService)getContext().getAttributes(). |
| 26 | get(IRoutingService.class.getCanonicalName()); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 27 | */ |
| 28 | ITopoRouteService onos_routing = new TopoRouteService(); |
| 29 | if (onos_routing == null) { |
| 30 | log.debug("ONOS Route Service not found"); |
| 31 | return null; |
| 32 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | |
| 34 | String srcDpid = (String) getRequestAttributes().get("src-dpid"); |
| 35 | String srcPort = (String) getRequestAttributes().get("src-port"); |
| 36 | String dstDpid = (String) getRequestAttributes().get("dst-dpid"); |
| 37 | String dstPort = (String) getRequestAttributes().get("dst-port"); |
| 38 | |
| 39 | log.debug( srcDpid + "--" + srcPort + "--" + dstDpid + "--" + dstPort); |
| 40 | |
| 41 | long longSrcDpid = HexString.toLong(srcDpid); |
| 42 | short shortSrcPort = Short.parseShort(srcPort); |
| 43 | long longDstDpid = HexString.toLong(dstDpid); |
| 44 | short shortDstPort = Short.parseShort(dstPort); |
| 45 | |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 46 | /* |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 47 | Route result = routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort); |
| 48 | |
| 49 | if (result!=null) { |
| 50 | return routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort).getPath(); |
| 51 | } |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 52 | */ |
| 53 | List<NodePortTuple> result = |
Pankaj Berde | 1cde50b | 2013-02-19 20:16:06 -0800 | [diff] [blame] | 54 | onos_routing.getShortestPath(new NodePortTuple(longSrcDpid, shortSrcPort), |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 55 | new NodePortTuple(longDstDpid, shortDstPort)); |
| 56 | if ((result != null) && (result.size() > 0)) { |
| 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 | } |