Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.topology.web; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.routing.IRoutingService; |
| 7 | import net.floodlightcontroller.routing.Route; |
| 8 | import net.floodlightcontroller.topology.NodePortTuple; |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 9 | import net.floodlightcontroller.util.DataPath; |
| 10 | import net.floodlightcontroller.util.Dpid; |
| 11 | import net.floodlightcontroller.util.Port; |
| 12 | import net.floodlightcontroller.util.SwitchPort; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 13 | |
| 14 | import org.openflow.util.HexString; |
| 15 | import org.restlet.resource.Get; |
| 16 | import org.restlet.resource.ServerResource; |
| 17 | import org.slf4j.Logger; |
| 18 | import org.slf4j.LoggerFactory; |
| 19 | |
| 20 | public class RouteResource extends ServerResource { |
| 21 | |
| 22 | protected static Logger log = LoggerFactory.getLogger(RouteResource.class); |
| 23 | |
| 24 | @Get("json") |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 25 | public DataPath retrieve() { |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 26 | ITopoRouteService topoRouteService = |
| 27 | (ITopoRouteService)getContext().getAttributes(). |
| 28 | get(ITopoRouteService.class.getCanonicalName()); |
| 29 | if (topoRouteService == null) { |
| 30 | log.debug("Topology Route Service not found"); |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 31 | return null; |
| 32 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 34 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 38 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 39 | log.debug( srcDpidStr + "--" + srcPortStr + "--" + dstDpidStr + "--" + dstPortStr); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 40 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 41 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 45 | |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 46 | DataPath result = |
| 47 | topoRouteService.getShortestPath(new SwitchPort(srcDpid, srcPort), |
| 48 | new SwitchPort(dstDpid, dstPort)); |
| 49 | if (result != null) { |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 50 | return result; |
| 51 | } else { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 52 | log.debug("ERROR! no route found"); |
| 53 | return null; |
| 54 | } |
| 55 | } |
| 56 | } |