blob: 906a579dfecc5278e94de66a1769b56a5e92cdce [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;
HIGUCHI Yuta20514902013-06-12 11:24:16 -07008import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07009import net.onrc.onos.ofcontroller.util.DataPath;
10import net.onrc.onos.ofcontroller.util.Dpid;
11import net.onrc.onos.ofcontroller.util.Port;
12import net.onrc.onos.ofcontroller.util.SwitchPort;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080013
14import org.openflow.util.HexString;
15import org.restlet.resource.Get;
16import org.restlet.resource.ServerResource;
17import org.slf4j.Logger;
18import org.slf4j.LoggerFactory;
19
20public class RouteResource extends ServerResource {
21
22 protected static Logger log = LoggerFactory.getLogger(RouteResource.class);
23
24 @Get("json")
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080025 public DataPath retrieve() {
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -080026 ITopoRouteService topoRouteService =
27 (ITopoRouteService)getContext().getAttributes().
28 get(ITopoRouteService.class.getCanonicalName());
29 if (topoRouteService == null) {
30 log.debug("Topology Route Service not found");
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080031 return null;
32 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080034 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
35 String srcPortStr = (String) getRequestAttributes().get("src-port");
36 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
37 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080039 log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080040
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080041 Dpid srcDpid = new Dpid(srcDpidStr);
42 Port srcPort = new Port(Short.parseShort(srcPortStr));
43 Dpid dstDpid = new Dpid(dstDpidStr);
44 Port dstPort = new Port(Short.parseShort(dstPortStr));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080046 DataPath result =
47 topoRouteService.getShortestPath(new SwitchPort(srcDpid, srcPort),
48 new SwitchPort(dstDpid, dstPort));
49 if (result != null) {
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080050 return result;
51 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 log.debug("ERROR! no route found");
53 return null;
54 }
55 }
56}