blob: de625d710b1364219ad1e43222e9aa879ccf1154 [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager.web;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08002
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07003import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
Brian O'Connor0d9963f2014-01-14 14:44:21 -08004import net.onrc.onos.ofcontroller.flowmanager.PerformanceMonitor;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07005import net.onrc.onos.ofcontroller.util.FlowId;
6import net.onrc.onos.ofcontroller.util.FlowPath;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08007
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08008import org.restlet.resource.Get;
9import org.restlet.resource.ServerResource;
10import org.slf4j.Logger;
11import org.slf4j.LoggerFactory;
12
admin944ef4f2013-10-08 17:48:37 -070013/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070014 * Flow Manager REST API implementation: Get a single Flow state.
admin944ef4f2013-10-08 17:48:37 -070015 *
16 * The "{flow-id}" request attribute value is the Flow ID of the flow to get:
17 *
Pavlin Radoslavov598635c2013-12-18 19:43:12 -080018 * GET /wm/onos/flows/get/{flow-id}/json
admin944ef4f2013-10-08 17:48:37 -070019 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080020public class GetFlowByIdResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070021 protected final static Logger log = LoggerFactory.getLogger(GetFlowByIdResource.class);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080022
admin944ef4f2013-10-08 17:48:37 -070023 /**
24 * Implement the API.
25 *
26 * @return the Flow state if the flow is found, otherwise null.
27 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080028 @Get("json")
29 public FlowPath retrieve() {
30 FlowPath result = null;
31
32 IFlowService flowService =
33 (IFlowService)getContext().getAttributes().
34 get(IFlowService.class.getCanonicalName());
35
36 if (flowService == null) {
37 log.debug("ONOS Flow Service not found");
38 return result;
39 }
40
41 // Extract the arguments
42 String flowIdStr = (String) getRequestAttributes().get("flow-id");
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080043 FlowId flowId = new FlowId(flowIdStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080044
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -080045 log.debug("Get Flow Id: {}", flowIdStr);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080046
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080047 result = flowService.getFlow(flowId);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080048
49 return result;
50 }
51}