HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [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; |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.util.FlowPath; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 7 | import net.onrc.onos.ofcontroller.util.FlowId; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 8 | |
| 9 | import org.restlet.resource.Get; |
| 10 | import org.restlet.resource.ServerResource; |
| 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 14 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 15 | * Flow Manager REST API implementation: Get summary of all installed |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 16 | * flows by all installers in a given range. |
| 17 | * |
| 18 | * The "{flow-id}" request attribute value is the Flow ID of the flow in the |
| 19 | * flow range to get. |
| 20 | * The "{max-flows}" request attribute value is the maximum number of flows |
| 21 | * to be returned. |
| 22 | * |
Pavlin Radoslavov | 598635c | 2013-12-18 19:43:12 -0800 | [diff] [blame] | 23 | * GET /wm/onos/flows/getsummary/{flow-id}/{max-flows}/json" |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 24 | */ |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 25 | public class GetSummaryFlowsResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 26 | protected final static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 27 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Implement the API. |
| 30 | * |
| 31 | * @return the collection of Flow states if any found, otherwise null. |
| 32 | */ |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 33 | @Get("json") |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 34 | public ArrayList<FlowPath> retrieve() { |
| 35 | ArrayList<FlowPath> result = null; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 36 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 37 | FlowId flowId; |
| 38 | int maxFlows = 0; |
| 39 | |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 40 | IFlowService flowService = (IFlowService)getContext().getAttributes().get(IFlowService.class.getCanonicalName()); |
| 41 | |
| 42 | if (flowService == null) { |
| 43 | log.debug("ONOS Flow Service not found"); |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | // Extract the arguments |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 48 | String flowIdStr = (String) getRequestAttributes().get("flow-id"); |
| 49 | String maxFlowStr = (String) getRequestAttributes().get("max-flows"); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 50 | log.debug("Get Summary Flows starting flow-id: {} max-flows: {}" ,flowIdStr, maxFlowStr); |
| 51 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 52 | flowId = new FlowId(flowIdStr); |
| 53 | maxFlows = Integer.parseInt(maxFlowStr); |
| 54 | if (maxFlows < 0) maxFlows = 0; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 55 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 56 | result = flowService.getAllFlowsSummary(flowId, maxFlows); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 57 | |
| 58 | return result; |
| 59 | } |
| 60 | } |