HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 5 | import net.onrc.onos.ofcontroller.flowmanager.IFlowService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.util.CallerId; |
| 7 | import net.onrc.onos.ofcontroller.util.DataPathEndpoints; |
| 8 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 9 | import net.onrc.onos.ofcontroller.util.FlowPath; |
| 10 | import net.onrc.onos.ofcontroller.util.Port; |
| 11 | import net.onrc.onos.ofcontroller.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 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 18 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 19 | * Flow Manager REST API implementation: Get all Flow state for a given |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 20 | * Installer ID and given source and destination switches and ports. |
| 21 | * |
| 22 | * The "{installer-id}" request attribute value is the Installer ID of the |
| 23 | * flows to get. |
| 24 | * The "{src-dpid}" request attribute value is the source DPID of the flows to |
| 25 | * get. |
| 26 | * The "{src-port}" request attribute value is the source port of the flows to |
| 27 | * get. |
| 28 | * The "{dst-dpid}" request attribute value is the destination DPID of the |
| 29 | * flows to get. |
| 30 | * The "{dst-port}" request attribute value is the destination port of the |
| 31 | * flows to get. |
| 32 | * |
| 33 | * GET /wm/flow/getall-by-installer-id/{installer-id}/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json" |
| 34 | */ |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 35 | public class GetAllFlowsByInstallerIdResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 36 | protected final static Logger log = LoggerFactory.getLogger(GetAllFlowsByInstallerIdResource.class); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 37 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Implement the API. |
| 40 | * |
| 41 | * @return the collection of Flow states if any found, otherwise null. |
| 42 | */ |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 43 | @Get("json") |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 44 | public ArrayList<FlowPath> retrieve() { |
| 45 | ArrayList<FlowPath> result = null; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 46 | |
| 47 | IFlowService flowService = |
| 48 | (IFlowService)getContext().getAttributes(). |
| 49 | get(IFlowService.class.getCanonicalName()); |
| 50 | |
| 51 | if (flowService == null) { |
| 52 | log.debug("ONOS Flow Service not found"); |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | // Extract the arguments |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 57 | String installerIdStr = (String) getRequestAttributes().get("installer-id"); |
| 58 | String srcDpidStr = (String) getRequestAttributes().get("src-dpid"); |
| 59 | String srcPortStr = (String) getRequestAttributes().get("src-port"); |
| 60 | String dstDpidStr = (String) getRequestAttributes().get("dst-dpid"); |
| 61 | String dstPortStr = (String) getRequestAttributes().get("dst-port"); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 62 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 63 | log.debug("Get All Flow By Installer: " + installerIdStr + |
| 64 | " Endpoints: " + |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 65 | srcDpidStr + "--" + srcPortStr + "--" + |
| 66 | dstDpidStr + "--" + dstPortStr); |
| 67 | |
| 68 | CallerId installerId = new CallerId(installerIdStr); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 69 | Dpid srcDpid = new Dpid(srcDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 70 | Port srcPort = new Port(Short.parseShort(srcPortStr)); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 71 | Dpid dstDpid = new Dpid(dstDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 72 | Port dstPort = new Port(Short.parseShort(dstPortStr)); |
| 73 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 74 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
| 75 | DataPathEndpoints dataPathEndpoints = |
| 76 | new DataPathEndpoints(srcSwitchPort, dstSwitchPort); |
| 77 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 78 | result = flowService.getAllFlows(installerId, dataPathEndpoints); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 79 | |
| 80 | return result; |
| 81 | } |
| 82 | } |