Skip to content
Snippets Groups Projects
Commit 4827ca5e authored by Rob Adams's avatar Rob Adams
Browse files

Merge branch 'master' of github.com:floodlight/floodlight

parents c325d3b7 e72de664
No related branches found
No related tags found
No related merge requests found
......@@ -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/topology-switch/{count}/json",
......
/**
* 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
......@@ -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());
}
}
......@@ -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);
}
}
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";
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment