blob: 1cbeece20cc5a3fe8c2cfcba576aeac9b0563576 [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;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07004import net.onrc.onos.ofcontroller.util.FlowId;
5import net.onrc.onos.ofcontroller.util.FlowPath;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08006
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08007import org.restlet.resource.Get;
8import org.restlet.resource.ServerResource;
9import org.slf4j.Logger;
10import org.slf4j.LoggerFactory;
11
admin944ef4f2013-10-08 17:48:37 -070012/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070013 * Flow Manager REST API implementation: Get a single Flow state.
admin944ef4f2013-10-08 17:48:37 -070014 *
15 * The "{flow-id}" request attribute value is the Flow ID of the flow to get:
16 *
Pavlin Radoslavov598635c2013-12-18 19:43:12 -080017 * GET /wm/onos/flows/get/{flow-id}/json
admin944ef4f2013-10-08 17:48:37 -070018 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080019public class GetFlowByIdResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070020 protected final static Logger log = LoggerFactory.getLogger(GetFlowByIdResource.class);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080021
admin944ef4f2013-10-08 17:48:37 -070022 /**
23 * Implement the API.
24 *
25 * @return the Flow state if the flow is found, otherwise null.
26 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080027 @Get("json")
28 public FlowPath retrieve() {
29 FlowPath result = null;
30
31 IFlowService flowService =
32 (IFlowService)getContext().getAttributes().
33 get(IFlowService.class.getCanonicalName());
34
35 if (flowService == null) {
36 log.debug("ONOS Flow Service not found");
37 return result;
38 }
39
40 // Extract the arguments
41 String flowIdStr = (String) getRequestAttributes().get("flow-id");
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080042 FlowId flowId = new FlowId(flowIdStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080043
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -080044 log.debug("Get Flow Id: {}", flowIdStr);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080045
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080046 result = flowService.getFlow(flowId);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080047
48 return result;
49 }
50}