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