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