blob: 70e406fcc25946a4c1275c2e351c6c4513838932 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.topology.web;
2
3import java.util.List;
4
5import net.floodlightcontroller.routing.IRoutingService;
6import net.floodlightcontroller.routing.Route;
7import net.floodlightcontroller.topology.NodePortTuple;
8
9import org.openflow.util.HexString;
10import org.restlet.resource.Get;
11import org.restlet.resource.ServerResource;
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15public class RouteResource extends ServerResource {
16
17 protected static Logger log = LoggerFactory.getLogger(RouteResource.class);
18
19 @Get("json")
20 public List<NodePortTuple> retrieve() {
21 IRoutingService routing =
22 (IRoutingService)getContext().getAttributes().
23 get(IRoutingService.class.getCanonicalName());
24
25 String srcDpid = (String) getRequestAttributes().get("src-dpid");
26 String srcPort = (String) getRequestAttributes().get("src-port");
27 String dstDpid = (String) getRequestAttributes().get("dst-dpid");
28 String dstPort = (String) getRequestAttributes().get("dst-port");
29
30 log.debug( srcDpid + "--" + srcPort + "--" + dstDpid + "--" + dstPort);
31
32 long longSrcDpid = HexString.toLong(srcDpid);
33 short shortSrcPort = Short.parseShort(srcPort);
34 long longDstDpid = HexString.toLong(dstDpid);
35 short shortDstPort = Short.parseShort(dstPort);
36
37 Route result = routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort);
38
39 if (result!=null) {
40 return routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort).getPath();
41 }
42 else {
43 log.debug("ERROR! no route found");
44 return null;
45 }
46 }
47}