blob: aa31abd3710515548b2360d71534784e9df430fc [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager.web;
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -07002
3import java.util.ArrayList;
4
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07005import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -08006import net.onrc.onos.ofcontroller.util.FlowPath;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07007import net.onrc.onos.ofcontroller.util.FlowId;
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -07008
9import org.restlet.resource.Get;
10import org.restlet.resource.ServerResource;
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
admin944ef4f2013-10-08 17:48:37 -070014/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070015 * Flow Manager REST API implementation: Get summary of all installed
admin944ef4f2013-10-08 17:48:37 -070016 * 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 Radoslavov598635c2013-12-18 19:43:12 -080023 * GET /wm/onos/flows/getsummary/{flow-id}/{max-flows}/json"
admin944ef4f2013-10-08 17:48:37 -070024 */
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070025public class GetSummaryFlowsResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070026 protected final static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class);
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070027
admin944ef4f2013-10-08 17:48:37 -070028 /**
29 * Implement the API.
30 *
31 * @return the collection of Flow states if any found, otherwise null.
32 */
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070033 @Get("json")
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -080034 public ArrayList<FlowPath> retrieve() {
35 ArrayList<FlowPath> result = null;
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070036
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070037 FlowId flowId;
38 int maxFlows = 0;
39
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070040 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 Krishnaswamy57a32a92013-03-21 14:21:15 -070048 String flowIdStr = (String) getRequestAttributes().get("flow-id");
49 String maxFlowStr = (String) getRequestAttributes().get("max-flows");
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -080050 log.debug("Get Summary Flows starting flow-id: {} max-flows: {}" ,flowIdStr, maxFlowStr);
51
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070052 flowId = new FlowId(flowIdStr);
53 maxFlows = Integer.parseInt(maxFlowStr);
54 if (maxFlows < 0) maxFlows = 0;
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070055
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070056 result = flowService.getAllFlowsSummary(flowId, maxFlows);
Umesh Krishnaswamye7a682b2013-03-21 14:16:28 -070057
58 return result;
59 }
60}