blob: 0d33b271ec532196dc83d9a5186e06abf70608b4 [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
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -08003import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
Pavlin Radoslavov1278ac72013-10-16 04:43:49 -07004import net.onrc.onos.ofcontroller.topology.ITopologyNetService;
Pavlin Radoslavove1b37bc2013-10-16 03:57:06 -07005import net.onrc.onos.ofcontroller.topology.TopologyManager;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07006import net.onrc.onos.ofcontroller.util.DataPath;
7import net.onrc.onos.ofcontroller.util.Dpid;
8import net.onrc.onos.ofcontroller.util.Port;
9import net.onrc.onos.ofcontroller.util.SwitchPort;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080010
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080011import org.restlet.resource.Get;
12import org.restlet.resource.ServerResource;
13import org.slf4j.Logger;
14import org.slf4j.LoggerFactory;
15
16public class RouteResource extends ServerResource {
17
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070018 protected final static Logger log = LoggerFactory.getLogger(RouteResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20 @Get("json")
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080021 public DataPath retrieve() {
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080022 // Get the services that are needed for the computation
23 ITopologyNetService topologyNetService =
24 (ITopologyNetService)getContext().getAttributes().
25 get(ITopologyNetService.class.getCanonicalName());
26 IFlowService flowService =
27 (IFlowService)getContext().getAttributes().
28 get(IFlowService.class.getCanonicalName());
29
Pavlin Radoslavov1278ac72013-10-16 04:43:49 -070030 if (topologyNetService == null) {
31 log.debug("Topology Net Service not found");
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080032 return null;
33 }
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080034 if (flowService == null) {
35 log.debug("Flow Service not found");
36 return null;
37 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080039 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
40 String srcPortStr = (String) getRequestAttributes().get("src-port");
41 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
42 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080044 log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080046 Dpid srcDpid = new Dpid(srcDpidStr);
47 Port srcPort = new Port(Short.parseShort(srcPortStr));
48 Dpid dstDpid = new Dpid(dstDpidStr);
49 Port dstPort = new Port(Short.parseShort(dstPortStr));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080050
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080051 DataPath result =
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080052 topologyNetService.getTopologyShortestPath(
53 flowService.getTopology(),
Pavlin Radoslavov15954d42013-10-19 15:29:04 -070054 new SwitchPort(srcDpid, srcPort),
55 new SwitchPort(dstDpid, dstPort));
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080056 if (result != null) {
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080057 return result;
58 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080059 log.debug("ERROR! no route found");
60 return null;
61 }
62 }
63}