blob: 540c47de964cbbd4788d6ff99e5721a0d9eb0d63 [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;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07005import net.onrc.onos.ofcontroller.util.DataPath;
6import net.onrc.onos.ofcontroller.util.Dpid;
7import net.onrc.onos.ofcontroller.util.Port;
8import net.onrc.onos.ofcontroller.util.SwitchPort;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08009
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080010import org.restlet.resource.Get;
11import org.restlet.resource.ServerResource;
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15public class RouteResource extends ServerResource {
16
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070017 protected final static Logger log = LoggerFactory.getLogger(RouteResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080018
19 @Get("json")
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080020 public DataPath retrieve() {
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080021 // Get the services that are needed for the computation
22 ITopologyNetService topologyNetService =
23 (ITopologyNetService)getContext().getAttributes().
24 get(ITopologyNetService.class.getCanonicalName());
25 IFlowService flowService =
26 (IFlowService)getContext().getAttributes().
27 get(IFlowService.class.getCanonicalName());
28
Pavlin Radoslavov1278ac72013-10-16 04:43:49 -070029 if (topologyNetService == null) {
30 log.debug("Topology Net Service not found");
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080031 return null;
32 }
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080033 if (flowService == null) {
34 log.debug("Flow Service not found");
35 return null;
36 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080037
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080038 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
39 String srcPortStr = (String) getRequestAttributes().get("src-port");
40 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
41 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080042
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -080043 log.debug( "{}--{}--{}--{}", srcDpidStr, srcPortStr, dstDpidStr, dstPortStr);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080044
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080045 Dpid srcDpid = new Dpid(srcDpidStr);
46 Port srcPort = new Port(Short.parseShort(srcPortStr));
47 Dpid dstDpid = new Dpid(dstDpidStr);
48 Port dstPort = new Port(Short.parseShort(dstPortStr));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080049
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080050 DataPath result =
Pavlin Radoslavoved0f4a82013-11-04 16:38:36 -080051 topologyNetService.getTopologyShortestPath(
52 flowService.getTopology(),
Pavlin Radoslavov15954d42013-10-19 15:29:04 -070053 new SwitchPort(srcDpid, srcPort),
54 new SwitchPort(dstDpid, dstPort));
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080055 if (result != null) {
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -080056 return result;
57 } else {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 log.debug("ERROR! no route found");
59 return null;
60 }
61 }
62}