blob: 89e5b01b6a74bdfa0aa6e2fa201a799fa1aaacba [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 Yuta20514902013-06-12 11:24:16 -07005import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07006import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
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 *
23 * GET /wm/flow/getsummary/{flow-id}/{max-flows}/json"
24 */
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")
Jonathan Hart01f2d272013-04-04 20:03:46 -070034 public ArrayList<IFlowPath> retrieve() {
35 ArrayList<IFlowPath> 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");
50 log.debug("Get Summary Flows starting flow-id: " + flowIdStr + " max-flows: " + maxFlowStr);
51
52 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}