diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryDeleteResource.java b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryDeleteResource.java new file mode 100644 index 0000000000000000000000000000000000000000..8c8baa3e3fd4dc0a7bac6210a366cb4e617b0574 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryDeleteResource.java @@ -0,0 +1,74 @@ +/** +* Copyright 2011, Big Switch Networks, Inc. +* Originally created by David Erickson, Stanford University +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. You may obtain +* a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations +* under the License. +**/ + +package net.floodlightcontroller.staticflowentry.web; + +import java.io.IOException; + +import org.restlet.resource.Post; +import org.restlet.resource.ServerResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import net.floodlightcontroller.core.annotations.LogMessageCategory; +import net.floodlightcontroller.core.annotations.LogMessageDoc; +import net.floodlightcontroller.staticflowentry.StaticFlowEntries; +import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher; +import net.floodlightcontroller.storage.IStorageSourceService; + +/** + * Deletes a static flow entry to the storage source + * @author alexreimers + * + * @author Henrique Rodrigues <hsr@cs.ucsd.edu> + * Contributed with splitting StaticFlowEntryPusherResource into + * two, to make Floodlight's StaticFlowEntryPusher restlet resource + * REST compliant. + * + */ +@LogMessageCategory("Static Flow Pusher Delete Resource") +public class StaticFlowEntryDeleteResource extends ServerResource { + protected static Logger log = LoggerFactory.getLogger(StaticFlowEntryDeleteResource.class); + + @Post + @LogMessageDoc(level="ERROR", + message="Error deleting flow mod request: {request}", + explanation="An invalid delete request was sent to static flow pusher", + recommendation="Fix the format of the static flow mod request") + public String del(String fmJson) { + IStorageSourceService storageSource = + (IStorageSourceService)getContext().getAttributes(). + get(IStorageSourceService.class.getCanonicalName()); + String fmName = null; + if (fmJson == null) { + return "{\"status\" : \"Error! No data posted.\"}"; + } + try { + fmName = StaticFlowEntries.getEntryNameFromJson(fmJson); + if (fmName == null) { + return "{\"status\" : \"Error deleting entry, no name provided\"}"; + } + } catch (IOException e) { + log.error("Error deleting flow mod request: " + fmJson, e); + return "{\"status\" : \"Error deleting entry, see log for details\"}"; + } + + storageSource.deleteRowAsync(StaticFlowEntryPusher.TABLE_NAME, fmName); + return "{\"status\" : \"Entry " + fmName + " deleted\"}"; + } +} diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java index 35e2a16239e16ca8b432b79208b0cf353c983635..e8a578c63de3287652d12ddbb130b48d77fa15be 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java @@ -30,6 +30,8 @@ public class StaticFlowEntryWebRoutable implements RestletRoutable { public Restlet getRestlet(Context context) { Router router = new Router(context); router.attach("/json", StaticFlowEntryPusherResource.class); + router.attach("/json/store", StaticFlowEntryPusherResource.class); + router.attach("/json/delete", StaticFlowEntryDeleteResource.class); router.attach("/clear/{switch}/json", ClearStaticFlowEntriesResource.class); router.attach("/list/{switch}/json", ListStaticFlowEntriesResource.class); return router;