blob: 3fa751060d3b435800edef901a234085eae8ccae [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.topology.web;
2
3import java.util.List;
4
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -08005import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08006import net.floodlightcontroller.routing.IRoutingService;
7import net.floodlightcontroller.routing.Route;
8import net.floodlightcontroller.topology.NodePortTuple;
9
10import org.openflow.util.HexString;
11import org.restlet.resource.Get;
12import org.restlet.resource.ServerResource;
13import org.slf4j.Logger;
14import org.slf4j.LoggerFactory;
15
16public class RouteResource extends ServerResource {
17
18 protected static Logger log = LoggerFactory.getLogger(RouteResource.class);
19
20 @Get("json")
21 public List<NodePortTuple> retrieve() {
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -080022 ITopoRouteService topoRouteService =
23 (ITopoRouteService)getContext().getAttributes().
24 get(ITopoRouteService.class.getCanonicalName());
25 if (topoRouteService == null) {
26 log.debug("Topology Route Service not found");
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080027 return null;
28 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080029
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 Radoslavov382b22a2013-01-28 09:24:04 -080042 List<NodePortTuple> result =
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -080043 topoRouteService.getShortestPath(new NodePortTuple(longSrcDpid, shortSrcPort),
44 new NodePortTuple(longDstDpid, shortDstPort));
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080045 if ((result != null) && (result.size() > 0)) {
46 return result;
47 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080048 log.debug("ERROR! no route found");
49 return null;
50 }
51 }
52}