Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.flowcache.web; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | |
Jonathan Hart | 01f2d27 | 2013-04-04 20:03:46 -0700 | [diff] [blame] | 5 | import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.flowcache.IFlowService; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 7 | import net.floodlightcontroller.util.FlowId; |
Jonathan Hart | 01f2d27 | 2013-04-04 20:03:46 -0700 | [diff] [blame] | 8 | import net.floodlightcontroller.util.FlowPath; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 9 | |
| 10 | import org.restlet.resource.Get; |
| 11 | import org.restlet.resource.ServerResource; |
| 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
| 15 | public class GetSummaryFlowsResource extends ServerResource { |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 16 | protected static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 17 | |
| 18 | @Get("json") |
Jonathan Hart | 01f2d27 | 2013-04-04 20:03:46 -0700 | [diff] [blame] | 19 | public ArrayList<IFlowPath> retrieve() { |
| 20 | ArrayList<IFlowPath> result = null; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 21 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 22 | FlowId flowId; |
| 23 | int maxFlows = 0; |
| 24 | |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 25 | IFlowService flowService = (IFlowService)getContext().getAttributes().get(IFlowService.class.getCanonicalName()); |
| 26 | |
| 27 | if (flowService == null) { |
| 28 | log.debug("ONOS Flow Service not found"); |
| 29 | return result; |
| 30 | } |
| 31 | |
| 32 | // Extract the arguments |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 33 | String flowIdStr = (String) getRequestAttributes().get("flow-id"); |
| 34 | String maxFlowStr = (String) getRequestAttributes().get("max-flows"); |
| 35 | log.debug("Get Summary Flows starting flow-id: " + flowIdStr + " max-flows: " + maxFlowStr); |
| 36 | |
| 37 | flowId = new FlowId(flowIdStr); |
| 38 | maxFlows = Integer.parseInt(maxFlowStr); |
| 39 | if (maxFlows < 0) maxFlows = 0; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 40 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 41 | result = flowService.getAllFlowsSummary(flowId, maxFlows); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 42 | |
| 43 | return result; |
| 44 | } |
| 45 | } |