Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.staticflowentry.web; |
| 2 | |
| 3 | import net.floodlightcontroller.core.web.ControllerSwitchesResource; |
| 4 | import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService; |
| 5 | |
| 6 | import org.openflow.util.HexString; |
| 7 | import org.restlet.data.Status; |
| 8 | import org.restlet.resource.Get; |
| 9 | import org.restlet.resource.ServerResource; |
| 10 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; |
| 12 | |
| 13 | public class ClearStaticFlowEntriesResource extends ServerResource { |
| 14 | protected static Logger log = LoggerFactory.getLogger(ClearStaticFlowEntriesResource.class); |
| 15 | |
| 16 | @Get |
| 17 | public void ClearStaticFlowEntries() { |
| 18 | IStaticFlowEntryPusherService sfpService = |
| 19 | (IStaticFlowEntryPusherService)getContext().getAttributes(). |
| 20 | get(IStaticFlowEntryPusherService.class.getCanonicalName()); |
| 21 | |
| 22 | String param = (String) getRequestAttributes().get("switch"); |
| 23 | if (log.isDebugEnabled()) |
| 24 | log.debug("Clearing all static flow entires for switch: " + param); |
| 25 | |
| 26 | if (param.toLowerCase().equals("all")) { |
| 27 | sfpService.deleteAllFlows(); |
| 28 | } else { |
| 29 | try { |
| 30 | sfpService.deleteFlowsForSwitch(HexString.toLong(param)); |
| 31 | } catch (NumberFormatException e){ |
| 32 | setStatus(Status.CLIENT_ERROR_BAD_REQUEST, |
| 33 | ControllerSwitchesResource.DPID_ERROR); |
| 34 | return; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |