blob: 20f39d4bb93376129e6f0e9bace69965efb64fd4 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.topology.web;
2
3import java.util.List;
4
Pavlin Radoslavovd7d8b792013-02-22 10:24:38 -08005import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08006import net.floodlightcontroller.routing.IRoutingService;
7import net.floodlightcontroller.routing.Route;
8import net.floodlightcontroller.topology.NodePortTuple;
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -08009import net.floodlightcontroller.util.DataPath;
10import net.floodlightcontroller.util.Dpid;
11import net.floodlightcontroller.util.Port;
12import net.floodlightcontroller.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}