HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 2 | |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.flowmanager.IFlowService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 4 | import net.onrc.onos.ofcontroller.util.FlowId; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 5 | |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 6 | import org.restlet.resource.Get; |
| 7 | import org.restlet.resource.ServerResource; |
| 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; |
| 10 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 11 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 12 | * Flow Manager REST API implementation: Delete Flow state. |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 13 | * |
| 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 Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 19 | public class DeleteFlowResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 20 | protected final static Logger log = LoggerFactory.getLogger(DeleteFlowResource.class); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 21 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Implement the API. |
| 24 | * |
| 25 | * @return true on success, otehrwise false. |
| 26 | */ |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 27 | @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 Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 42 | |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 43 | // Process the request |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 44 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 52 | return result; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 53 | } |
| 54 | } |