blob: 5b2bad488d993d015efe97853197c7e36ffac873 [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;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08005
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08006import 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: Delete 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 delete all Flows:
16 *
17 * GET /wm/flow/delete/{flow-id}/json
18 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080019public class DeleteFlowResource extends ServerResource {
20 protected static Logger log = LoggerFactory.getLogger(DeleteFlowResource.class);
21
admin944ef4f2013-10-08 17:48:37 -070022 /**
23 * Implement the API.
24 *
25 * @return true on success, otehrwise false.
26 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080027 @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 Radoslavov5ab68512013-02-18 09:59:33 -080042
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080043 // Process the request
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +000044 if (flowIdStr.equals("all")) {
45 log.debug("Delete All Flows");
46 result = flowService.deleteAllFlows();
47 } else {
48 FlowId flowId = new FlowId(flowIdStr);
49 log.debug("Delete Flow Id: " + flowIdStr);
50 result = flowService.deleteFlow(flowId);
51 }
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080052 return result;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080053 }
54}