diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java index e0830bb09f5541dca29bcfcfbf9c62697b68d522..6df4b779f305ab5b727b66e54585761430f9065b 100644 --- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java +++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java @@ -43,7 +43,6 @@ public class CoreWebRoutable implements RestletRoutable { router.attach("/counter/{switchId}/{counterName}/json", SwitchCounterResource.class); router.attach("/counter/categories/{switchId}/{counterName}/{layer}/json", SwitchCounterCategoriesResource.class); router.attach("/memory/json", ControllerMemoryResource.class); - router.attach("/staticflowentrypusher/json", StaticFlowEntryPusherResource.class); router.attach("/packettrace/json", PacketTraceResource.class); // Get the last {count} events from the event histories router.attach("/event-history/attachment-point/{count}/json", diff --git a/src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResourceBase.java b/src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResourceBase.java deleted file mode 100644 index 61254552261ed868edde881ca3b30abcc1ab779e..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResourceBase.java +++ /dev/null @@ -1,34 +0,0 @@ -/** -* 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.core.web; - -import org.restlet.resource.ResourceException; -import org.restlet.resource.ServerResource; -import net.floodlightcontroller.staticflowentry.*; - -public class StaticFlowEntryPusherResourceBase extends ServerResource { - protected StaticFlowEntryPusher staticFlowEntryPusher; - - @Override - protected void doInit() throws ResourceException { - super.doInit(); - staticFlowEntryPusher = - (StaticFlowEntryPusher)getContext().getAttributes(). - get(IStaticFlowEntryPusherService.class); - } -} \ No newline at end of file diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java index 15cb5309156a89a299868ffad9fc8481bcac18db..688afe50cfbcb951150108d312f8d404c23ef13c 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java @@ -40,6 +40,8 @@ import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightService; +import net.floodlightcontroller.restserver.IRestApiService; +import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.JsonParser; @@ -71,6 +73,7 @@ public class StaticFlowEntryPusher protected static Logger log = LoggerFactory.getLogger(StaticFlowEntryPusher.class); protected IFloodlightProviderService floodlightProvider; + protected IRestApiService restApi; protected ArrayList<String> flowmodList; protected ArrayList<IOFSwitch> activeSwitches; @@ -167,7 +170,9 @@ public class StaticFlowEntryPusher * */ public void addEntry(long dpid, String name, boolean active, OFFlowMod fm) { - log.debug("addEntry: add dpid: {}, name: {}", dpid, name); + if (log.isDebugEnabled()) { + log.debug("addEntry: add dpid: {}, name: {}", dpid, name); + } /* * For now, we do not add inactive flow-mods since they will need to be added again @@ -639,6 +644,7 @@ public class StaticFlowEntryPusher Collection<Class<? extends IFloodlightService>> l = new ArrayList<Class<? extends IFloodlightService>>(); l.add(IFloodlightProviderService.class); + l.add(IRestApiService.class); return l; } @@ -648,17 +654,15 @@ public class StaticFlowEntryPusher // Wire up all our dependencies floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); + restApi = + context.getServiceImpl(IRestApiService.class); + flowmodList = new ArrayList<String>(); + flowmods = new HashMap<Long, HashMap<String, OFFlowMod>>(); + activeSwitches = new ArrayList<IOFSwitch>(); } @Override public void startUp(FloodlightModuleContext context) { - // This is our 'constructor' - if (log.isDebugEnabled()) { - log.debug("Starting " + this.getClass().getCanonicalName()); - } - flowmodList = new ArrayList<String>(); - flowmods = new HashMap<Long, HashMap<String, OFFlowMod>>(); - activeSwitches = new ArrayList<IOFSwitch>(); floodlightProvider.addOFSwitchListener(this); pushEntriesTimer = new Runnable() { @Override @@ -677,5 +681,6 @@ public class StaticFlowEntryPusher floodlightProvider.getScheduledExecutor().schedule(pushEntriesTimer, pushEntriesFrequency, TimeUnit.MILLISECONDS); + restApi.addRestletRoutable(new StaticFlowEntryWebRoutable()); } } diff --git a/src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResource.java b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java similarity index 55% rename from src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResource.java rename to src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java index d34f2a00e09dbd266fa1b73b1bd75e9cb87227cf..e25452c119dba69fc6901f502db0dbf615b6ccfc 100644 --- a/src/main/java/net/floodlightcontroller/core/web/StaticFlowEntryPusherResource.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java @@ -15,26 +15,29 @@ * under the License. **/ -package net.floodlightcontroller.core.web; +package net.floodlightcontroller.staticflowentry.web; import org.restlet.resource.Delete; import org.restlet.resource.Post; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.restlet.resource.ServerResource; -import net.floodlightcontroller.core.internal.Controller; -import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher; +import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService; -public class StaticFlowEntryPusherResource extends StaticFlowEntryPusherResourceBase { - protected static Logger log = LoggerFactory.getLogger(Controller.class); - +public class StaticFlowEntryPusherResource extends ServerResource { + @Post public void store(String flowmod) { - ((StaticFlowEntryPusher)this.staticFlowEntryPusher).addEntry(flowmod); + IStaticFlowEntryPusherService sfp = + (IStaticFlowEntryPusherService)getContext().getAttributes(). + get(IStaticFlowEntryPusherService.class.getCanonicalName()); + sfp.addEntry(flowmod); } @Delete public void del(String flowmod) { - ((StaticFlowEntryPusher)this.staticFlowEntryPusher).removeEntry(flowmod); + IStaticFlowEntryPusherService sfp = + (IStaticFlowEntryPusherService)getContext().getAttributes(). + get(IStaticFlowEntryPusherService.class.getCanonicalName()); + sfp.removeEntry(flowmod); } } diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java new file mode 100644 index 0000000000000000000000000000000000000000..badd9d9268427bcf94fc99f456cd0689b60f9392 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryWebRoutable.java @@ -0,0 +1,27 @@ +package net.floodlightcontroller.staticflowentry.web; + +import net.floodlightcontroller.restserver.RestletRoutable; + +import org.restlet.Context; +import org.restlet.Restlet; +import org.restlet.routing.Router; + +public class StaticFlowEntryWebRoutable implements RestletRoutable { + /** + * Create the Restlet router and bind to the proper resources. + */ + @Override + public Restlet getRestlet(Context context) { + Router router = new Router(context); + router.attach("/json", StaticFlowEntryPusherResource.class); + return router; + } + + /** + * Set the base path for the Topology + */ + @Override + public String basePath() { + return "/wm/staticflowentrypusher"; + } +} diff --git a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusherTest.java b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusherTest.java index 825f2f1194f9bb1639f13dabd362c76cf18b435a..66ed127f513d7700f32e58b3648a31635c6e7657 100644 --- a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusherTest.java +++ b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusherTest.java @@ -12,8 +12,12 @@ import java.util.List; import java.util.Map; import net.floodlightcontroller.core.FloodlightContext; +import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; +import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.test.MockFloodlightProvider; +import net.floodlightcontroller.restserver.IRestApiService; +import net.floodlightcontroller.restserver.RestApiServer; import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher; import net.floodlightcontroller.test.FloodlightTestCase; @@ -48,11 +52,16 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase { "\"active\": \"true\", " + "\"actions\": \"output=3\"}"; + FloodlightModuleContext fmc = new FloodlightModuleContext(); + fmc.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); + RestApiServer restApi = new RestApiServer(); + fmc.addService(IRestApiService.class, restApi); staticFlowEntryPusher = new StaticFlowEntryPusher(); - staticFlowEntryPusher.floodlightProvider = - getMockFloodlightProvider(); + staticFlowEntryPusher.init(fmc); + restApi.init(fmc); staticFlowEntryPusher.setFlowPushTime(200); - staticFlowEntryPusher.startUp(null); + staticFlowEntryPusher.startUp(fmc); + restApi.startUp(fmc); } @Test