blob: b8942b99addd0d919f7deb2eaeb08f47ff5ac813 [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager.web;
Pavlin Radoslavov916832f2013-03-14 17:48:41 -07002
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;
Pavlin Radoslavov916832f2013-03-14 17:48:41 -07005
Pavlin Radoslavov916832f2013-03-14 17:48:41 -07006import org.restlet.resource.Get;
7import org.restlet.resource.ServerResource;
8import org.slf4j.Logger;
9import org.slf4j.LoggerFactory;
10
admin944ef4f2013-10-08 17:48:37 -070011/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070012 * Flow Manager REST API implementation: Clear internal Flow state.
admin944ef4f2013-10-08 17:48:37 -070013 *
14 * The "{flow-id}" request attribute value can be either a specific Flow ID,
15 * or the keyword "all" to clear all Flows:
16 *
17 * GET /wm/flow/clear/{flow-id}/json
18 */
Pavlin Radoslavov916832f2013-03-14 17:48:41 -070019public class ClearFlowResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070020 protected final static Logger log = LoggerFactory.getLogger(ClearFlowResource.class);
Pavlin Radoslavov916832f2013-03-14 17:48:41 -070021
admin944ef4f2013-10-08 17:48:37 -070022 /**
23 * Implement the API.
24 *
25 * @return true on success, otehrwise false.
26 */
Pavlin Radoslavov916832f2013-03-14 17:48:41 -070027 @Get("json")
28 public Boolean retrieve() {
29 Boolean result = false;
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 Radoslavov916832f2013-03-14 17:48:41 -070042
43 // Process the request
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +000044 if (flowIdStr.equals("all")) {
45 log.debug("Clear All Flows");
46 result = flowService.clearAllFlows();
47 } else {
48 FlowId flowId = new FlowId(flowIdStr);
49 log.debug("Clear Flow Id: " + flowIdStr);
50 result = flowService.clearFlow(flowId);
51 }
Pavlin Radoslavov916832f2013-03-14 17:48:41 -070052 return result;
53 }
54}