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