blob: 5ad892b7b758111349d679a30ce61b0c02fb40f1 [file] [log] [blame]
HIGUCHI Yutaf0499b02013-06-14 15:01:10 -07001package net.onrc.onos.ofcontroller.topology.web;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
HIGUCHI Yuta20514902013-06-12 11:24:16 -07003import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07004import net.onrc.onos.ofcontroller.util.DataPath;
5import net.onrc.onos.ofcontroller.util.Dpid;
6import net.onrc.onos.ofcontroller.util.Port;
7import net.onrc.onos.ofcontroller.util.SwitchPort;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08008
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08009import org.restlet.resource.Get;
10import org.restlet.resource.ServerResource;
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
14public class RouteResource extends ServerResource {
15
16 protected static Logger log = LoggerFactory.getLogger(RouteResource.class);
17
18 @Get("json")
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080019 public DataPath retrieve() {
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -080020 ITopoRouteService topoRouteService =
21 (ITopoRouteService)getContext().getAttributes().
22 get(ITopoRouteService.class.getCanonicalName());
23 if (topoRouteService == null) {
24 log.debug("Topology Route Service not found");
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080025 return null;
26 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080027
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080028 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
29 String srcPortStr = (String) getRequestAttributes().get("src-port");
30 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
31 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080033 log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080035 Dpid srcDpid = new Dpid(srcDpidStr);
36 Port srcPort = new Port(Short.parseShort(srcPortStr));
37 Dpid dstDpid = new Dpid(dstDpidStr);
38 Port dstPort = new Port(Short.parseShort(dstPortStr));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080039
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080040 DataPath result =
41 topoRouteService.getShortestPath(new SwitchPort(srcDpid, srcPort),
42 new SwitchPort(dstDpid, dstPort));
43 if (result != null) {
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080044 return result;
45 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 log.debug("ERROR! no route found");
47 return null;
48 }
49 }
50}