Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.flowcache.web; |
| 2 | |
| 3 | import net.floodlightcontroller.flowcache.IFlowService; |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 4 | import net.floodlightcontroller.util.CallerId; |
| 5 | import net.floodlightcontroller.util.DataPathEndpoints; |
| 6 | import net.floodlightcontroller.util.Dpid; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.util.FlowPath; |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 8 | import net.floodlightcontroller.util.Port; |
| 9 | import net.floodlightcontroller.util.SwitchPort; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 10 | |
| 11 | import org.restlet.resource.Get; |
| 12 | import org.restlet.resource.ServerResource; |
| 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; |
| 15 | |
| 16 | public class GetFlowByInstallerIdResource extends ServerResource { |
| 17 | protected static Logger log = LoggerFactory.getLogger(GetFlowByInstallerIdResource.class); |
| 18 | |
| 19 | @Get("json") |
| 20 | public FlowPath retrieve() { |
| 21 | FlowPath result = null; |
| 22 | |
| 23 | IFlowService flowService = |
| 24 | (IFlowService)getContext().getAttributes(). |
| 25 | get(IFlowService.class.getCanonicalName()); |
| 26 | |
| 27 | if (flowService == null) { |
| 28 | log.debug("ONOS Flow Service not found"); |
| 29 | return result; |
| 30 | } |
| 31 | |
| 32 | // Extract the arguments |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 33 | String installerIdStr = (String) getRequestAttributes().get("installer-id"); |
| 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"); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 38 | |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 39 | log.debug("Get Flow By Installer: " + installerIdStr + " Endpoints: " + |
| 40 | srcDpidStr + "--" + srcPortStr + "--" + |
| 41 | dstDpidStr + "--" + dstPortStr); |
| 42 | |
| 43 | CallerId installerId = new CallerId(installerIdStr); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 44 | Dpid srcDpid = new Dpid(srcDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 45 | Port srcPort = new Port(Short.parseShort(srcPortStr)); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 46 | Dpid dstDpid = new Dpid(dstDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 47 | Port dstPort = new Port(Short.parseShort(dstPortStr)); |
| 48 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 49 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
| 50 | DataPathEndpoints dataPathEndpoints = |
| 51 | new DataPathEndpoints(srcSwitchPort, dstSwitchPort); |
| 52 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 53 | result = flowService.getFlow(installerId, dataPathEndpoints); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 54 | |
| 55 | return result; |
| 56 | } |
| 57 | } |