blob: 56c9bf3bfc1b45a1ba965fc328a19bef4554d080 [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;
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -08007import net.floodlightcontroller.routing.TopoRouteService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08008import net.floodlightcontroller.topology.NodePortTuple;
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -08009import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080010
11import org.openflow.util.HexString;
12import org.restlet.resource.Get;
13import org.restlet.resource.ServerResource;
14import org.slf4j.Logger;
15import org.slf4j.LoggerFactory;
16
17public class RouteResource extends ServerResource {
18
19 protected static Logger log = LoggerFactory.getLogger(RouteResource.class);
20
21 @Get("json")
22 public List<NodePortTuple> retrieve() {
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080023 /*
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080024 IRoutingService routing =
25 (IRoutingService)getContext().getAttributes().
26 get(IRoutingService.class.getCanonicalName());
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080027 */
28 ITopoRouteService onos_routing = new TopoRouteService();
29 if (onos_routing == null) {
30 log.debug("ONOS Route Service not found");
31 return null;
32 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033
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 Radoslavov382b22a2013-01-28 09:24:04 -080046 /*
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080047 Route result = routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort);
48
49 if (result!=null) {
50 return routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort).getPath();
51 }
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080052 */
53 List<NodePortTuple> result =
54 onos_routing.GetShortestpath(new NodePortTuple(longSrcDpid, shortSrcPort),
55 new NodePortTuple(longDstDpid, shortDstPort));
56 if ((result != null) && (result.size() > 0)) {
57 return result;
58 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080059 log.debug("ERROR! no route found");
60 return null;
61 }
62 }
63}