diff --git a/src/main/java/net/floodlightcontroller/core/CoreModule.java b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java similarity index 95% rename from src/main/java/net/floodlightcontroller/core/CoreModule.java rename to src/main/java/net/floodlightcontroller/core/FloodlightProvider.java index 587e41e0b91a2013ddec47f404a8761a698c12a8..2e315ac51aeb240e73f5866462c26bef7615f1f3 100644 --- a/src/main/java/net/floodlightcontroller/core/CoreModule.java +++ b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java @@ -15,7 +15,7 @@ import net.floodlightcontroller.perfmon.IPktInProcessingTimeService; import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.storage.IStorageSourceService; -public class CoreModule implements IFloodlightModule { +public class FloodlightProvider implements IFloodlightModule { Controller controller; @Override @@ -60,7 +60,7 @@ public class CoreModule implements IFloodlightModule { context.getServiceImpl(ICounterStoreService.class)); controller.setRestApiService( context.getServiceImpl(IRestApiService.class)); - controller.init(); + controller.init(context.getConfigParams(this)); } @Override diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index 0343d8d5450536de506ccf0510d84808321ad3ce..891a0956c3f4a8b3048662363c0c614399bce52b 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; -import net.floodlightcontroller.core.internal.CmdLineSettings; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.packet.Ethernet; @@ -156,12 +155,6 @@ public interface IFloodlightProviderService extends IFloodlightService { * Run the main I/O loop of the Controller. */ public void run(); - - /** - * Sets the command line settings - */ - public void setCmdLineOptions(CmdLineSettings settings); - /** * Add an info provider of a particular type diff --git a/src/main/java/net/floodlightcontroller/core/Main.java b/src/main/java/net/floodlightcontroller/core/Main.java index 7e1d6a91783228cbdf4e220badded90f4ff75501..91b317a2f75bad78d4f6a959f560c76eeafb4699 100644 --- a/src/main/java/net/floodlightcontroller/core/Main.java +++ b/src/main/java/net/floodlightcontroller/core/Main.java @@ -21,6 +21,7 @@ public class Main { * @throws FloodlightModuleException */ public static void main(String[] args) throws FloodlightModuleException { + // Setup logger System.setProperty("org.restlet.engine.loggerFacadeClass", "org.restlet.ext.slf4j.Slf4jLoggerFacade"); @@ -33,13 +34,16 @@ public class Main { System.exit(1); } + // Load modules FloodlightModuleLoader fml = new FloodlightModuleLoader(); IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); + // Run REST server IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class); - restApi.run(settings.getRestPort()); + restApi.run(); + // Run the main floodlight module IFloodlightProviderService controller = moduleContext.getServiceImpl(IFloodlightProviderService.class); - controller.setCmdLineOptions(settings); + // This call blocks, it has to be the last line in the main controller.run(); } } diff --git a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java index dc81f044ba08c5dae1a5f22e6b984a2247e3457b..7641a7c7ec392b9247d7ef552d1f0d42c27c745e 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java +++ b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java @@ -6,33 +6,12 @@ import org.kohsuke.args4j.Option; * Expresses the port settings of OpenFlow controller. */ public class CmdLineSettings { - public static final int DEFAULT_OPENFLOW_PORT = 6633; - public static final int DEFAULT_REST_PORT = 8080; - public static final String DEFAULT_CONFIG_FILE = "floodlightdefault.properties"; - private final int DEFAULT_WORKER_THREADS = 0; + public static final String DEFAULT_CONFIG_FILE = "config/floodlight.properties"; - @Option(name="-ofp", aliases="--openFlowPort",metaVar="PORT", usage="Port number for OpenFlow") - private int openFlowPort = DEFAULT_OPENFLOW_PORT; - @Option(name="-rp", aliases="--restPort", metaVar="PORT", usage="Port number for REST API") - private int restPort = DEFAULT_REST_PORT; @Option(name="-cf", aliases="--configFile", metaVar="FILE", usage="Floodlight configuration file") private String configFile = DEFAULT_CONFIG_FILE; - @Option(name="-wt", aliases="--workerThreads", metaVar="THREADS", usage="Number of worker threads") - private int workerThreads = DEFAULT_WORKER_THREADS; - - public int getOpenFlowPort() { - return openFlowPort; - } - - public int getRestPort() { - return restPort; - } public String getModuleFile() { return configFile; } - - public int getWorkerThreads() { - return workerThreads; - } } diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index 0f4145f056de10e1dcb0874d3c80c966e118d811..f5b9aa3d20991a1574de6e0f281c30408c976e74 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -161,7 +161,7 @@ public class Controller // Configuration options protected int openFlowPort = 6633; protected long ptWarningThresholdInNano; - protected int workerThreads; + protected int workerThreads = 0; // The current role of the controller. // If the controller isn't configured to support roles, then this is null. @@ -1569,7 +1569,7 @@ public class Controller */ public void run() { try { - final ServerBootstrap bootstrap = createServerBootStrap(workerThreads); + final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); bootstrap.setOption("child.keepAlive", true); @@ -1615,8 +1615,8 @@ public class Controller } } - private ServerBootstrap createServerBootStrap(int threads) { - if (threads == 0) { + private ServerBootstrap createServerBootStrap() { + if (workerThreads == 0) { return new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), @@ -1625,9 +1625,22 @@ public class Controller return new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), - Executors.newCachedThreadPool(), threads)); + Executors.newCachedThreadPool(), workerThreads)); } } + + public void setConfigParams(Map<String, String> configParams) { + String ofPort = configParams.get("openflowport"); + if (ofPort != null) { + this.openFlowPort = Integer.parseInt(ofPort); + } + log.info("OpenFlow port set to {}", this.openFlowPort); + String threads = configParams.get("workerthreads"); + if (threads != null) { + this.workerThreads = Integer.parseInt(threads); + } + log.info("Number of worker threads port set to {}", this.workerThreads); + } private void initVendorMessages() { // Configure openflowj to be able to parse the role request/reply @@ -1650,7 +1663,7 @@ public class Controller /** * Initialize internal data structures */ - public void init() { + public void init(Map<String, String> configParams) { // These data structures are initialized here because other // module's startUp() might be called before ours this.messageListeners = @@ -1663,6 +1676,7 @@ public class Controller this.updates = new LinkedBlockingQueue<Update>(); this.factory = new BasicFactory(); this.providerMap = new HashMap<String, List<IInfoProvider>>(); + setConfigParams(configParams); this.setRole(getInitialRole()); initVendorMessages(); } @@ -1708,11 +1722,6 @@ public class Controller // Add our REST API restApi.addRestletRoutable(new CoreWebRoutable()); } - - @Override - public void setCmdLineOptions(CmdLineSettings settings) { - this.openFlowPort = settings.getOpenFlowPort(); - } @Override public void addInfoProvider(String type, IInfoProvider provider) { diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java index 2f90c3a33dd4e49590c050218c7c535e61228fe9..9b8533d835bb349f32a74b394202f0479c73d22b 100644 --- a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java @@ -3,6 +3,7 @@ package net.floodlightcontroller.core.module; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * The service registry for an IFloodlightProvider. @@ -10,6 +11,7 @@ import java.util.Map; */ public class FloodlightModuleContext implements IFloodlightModuleContext { protected Map<Class<? extends IFloodlightService>, IFloodlightService> serviceMap; + protected Map<Class<? extends IFloodlightModule>, Map<String, String>> configParams; /** * Creates the ModuleContext for use with this IFloodlightProvider. @@ -19,6 +21,9 @@ public class FloodlightModuleContext implements IFloodlightModuleContext { serviceMap = new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); + configParams = + new HashMap<Class<? extends IFloodlightModule>, + Map<String, String>>(); } /** @@ -42,4 +47,33 @@ public class FloodlightModuleContext implements IFloodlightModuleContext { public Collection<Class<? extends IFloodlightService>> getAllServices() { return serviceMap.keySet(); } + + @Override + public Map<String, String> getConfigParams(IFloodlightModule module) { + return configParams.get(module.getClass()); + } + + /** + * Adds a configuration parameter for a module + * @param mod The fully qualified module name to add the parameter to + * @param key The configuration parameter key + * @param value The configuration parameter value + */ + public void addConfigParam(IFloodlightModule mod, String key, String value) { + Map<String, String> moduleParams = configParams.get(mod.getClass()); + moduleParams.put(key, value); + } + + /** + * We initialize empty configuration maps for each module to be loaded. + * This way each module doens't have to null check their map. + * @param moduleSet The modules to initialize maps for + */ + public void createConfigMaps(Set<IFloodlightModule> moduleSet) { + for (IFloodlightModule mod : moduleSet) { + Map<String, String> moduleParams = new HashMap<String, String>(); + System.out.println(); + configParams.put(mod.getClass(), moduleParams); + } + } } diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java index ed06fed55f91b4bcf45668847e7a601e7b9bceb0..2ecb51064b60babd6075138026dee47b9fcd51ca 100644 --- a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java @@ -1,11 +1,14 @@ package net.floodlightcontroller.core.module; +import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -16,9 +19,6 @@ import java.util.Queue; import java.util.ServiceLoader; import java.util.Set; - -import net.floodlightcontroller.core.internal.CmdLineSettings; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +41,9 @@ public class FloodlightModuleLoader { protected FloodlightModuleContext floodlightModuleContext; + public static final String COMPILED_CONF_FILE = + "floodlightdefault.properties"; + public FloodlightModuleLoader() { floodlightModuleContext = new FloodlightModuleContext(); } @@ -105,35 +108,33 @@ public class FloodlightModuleLoader { throws FloodlightModuleException { Properties prop = new Properties(); - // Load defaults if no properties file exists - if (fName == null) { - logger.debug("No module file specified, using defaults"); - String[] mList = new String[2]; - mList[0] = "net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher"; - mList[1] = "net.floodlightcontroller.forwarding.Forwarding"; - return loadModulesFromList(mList); - } else { + File f = new File(fName); + if (f.isFile()) { + logger.info("Loading modules from file " + fName); try { - if (fName == CmdLineSettings.DEFAULT_CONFIG_FILE) { - logger.debug("Loading default module file " + fName); - InputStream is = this.getClass().getClassLoader().getResourceAsStream(fName); - if (is == null) { - logger.error("Could not find default properties file!"); - System.exit(1); - } - prop.load(is); - } else { - logger.debug("Loading modules from file " + fName); - prop.load(new FileInputStream(fName)); - } - } catch (IOException ex) { - logger.debug("Properties file " + fName + " not found!"); - ex.printStackTrace(); + prop.load(new FileInputStream(fName)); + } catch (FileNotFoundException e) { + // should not happen + e.printStackTrace(); + } catch (IOException e) { + // should not happen + e.printStackTrace(); + } + } else { + logger.debug("Loading default modules"); + InputStream is = this.getClass().getClassLoader(). + getResourceAsStream(COMPILED_CONF_FILE); + try { + prop.load(is); + } catch (IOException e) { + logger.error("Error, could not load default modules"); + e.printStackTrace(); System.exit(1); } - String props = prop.getProperty("floodlight.modules").replaceAll("\\s", ""); - return loadModulesFromList(props.split(",")); - } + } + + String moduleList = prop.getProperty("floodlight.modules").replaceAll("\\s", ""); + return loadModulesFromList(moduleList.split(","), prop); } /** @@ -142,7 +143,7 @@ public class FloodlightModuleLoader { * @return The ModuleContext containing all the loaded modules * @throws FloodlightModuleException */ - public IFloodlightModuleContext loadModulesFromList(String[] mList) + public IFloodlightModuleContext loadModulesFromList(String[] mList, Properties prop) throws FloodlightModuleException { logger.debug("Starting module loader"); findAllModules(); @@ -210,6 +211,8 @@ public class FloodlightModuleLoader { } } + floodlightModuleContext.createConfigMaps(moduleSet); + parseConfigParameters(prop); initModules(moduleSet); startupModules(moduleSet); @@ -287,4 +290,35 @@ public class FloodlightModuleLoader { m.startUp(floodlightModuleContext); } } + + /** + * Parses configuration parameters for each module + * @param prop The properties file to use + */ + protected void parseConfigParameters(Properties prop) { + Enumeration<?> e = prop.propertyNames(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + String configValue = null; + int lastPeriod = key.lastIndexOf("."); + String moduleName = key.substring(0, lastPeriod); + String configKey = key.substring(lastPeriod + 1); + // Check to see if it's overridden on the command line + String systemKey = System.getProperty(key); + if (systemKey != null) { + configValue = systemKey; + } else { + configValue = prop.getProperty(key); + } + + IFloodlightModule mod = moduleNameMap.get(moduleName); + if (mod == null) { + logger.warn("Module {} not found or loaded. " + + "Not adding configuration option {} = {}", + new Object[]{moduleName, configKey, configValue}); + } else { + floodlightModuleContext.addConfigParam(mod, configKey, configValue); + } + } + } } diff --git a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java index a22c3807201b42d6db2997e1f54f1357e0296ffb..ba7c6588c47886243c9bbe40fb4bcee6153d6cc3 100644 --- a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java +++ b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java @@ -1,6 +1,7 @@ package net.floodlightcontroller.core.module; import java.util.Collection; +import java.util.Map; public interface IFloodlightModuleContext { @@ -18,4 +19,11 @@ public interface IFloodlightModuleContext { * @return A collection of service classes that have been loaded */ public Collection<Class<? extends IFloodlightService>> getAllServices(); + + /** + * Gets module specific configuration parameters. + * @param module The module to get the configuration parameters for + * @return A key, value map of the configuration options + */ + public Map<String, String> getConfigParams(IFloodlightModule module); } diff --git a/src/main/java/net/floodlightcontroller/restserver/IRestApiService.java b/src/main/java/net/floodlightcontroller/restserver/IRestApiService.java index bd4d573d80390dd9b611797f565f51fe014ef227..d90679580e0adfbc645368dac58c179ef1490846 100644 --- a/src/main/java/net/floodlightcontroller/restserver/IRestApiService.java +++ b/src/main/java/net/floodlightcontroller/restserver/IRestApiService.java @@ -12,5 +12,5 @@ public interface IRestApiService extends IFloodlightService { /** * Runs the REST API server */ - public void run(int restPort); + public void run(); } diff --git a/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java b/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java index 369c758c53988c319cdc853ab4a8330a98466a0c..f4071c824d3dfeff219ce2be9d4da6df4258a227 100644 --- a/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java +++ b/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java @@ -31,6 +31,7 @@ public class RestApiServer protected static Logger logger = LoggerFactory.getLogger(RestApiServer.class); protected List<RestletRoutable> restlets; protected FloodlightModuleContext fmlContext; + protected int restPort = 8080; // *********** // Application @@ -107,7 +108,7 @@ public class RestApiServer } @Override - public void run(int restPort) { + public void run() { RestApplication restApp = new RestApplication(); restApp.run(fmlContext, restPort); } @@ -148,6 +149,14 @@ public class RestApiServer // startUp methods will be called this.restlets = new ArrayList<RestletRoutable>(); this.fmlContext = context; + + // read our config options + Map<String, String> configOptions = context.getConfigParams(this); + String port = configOptions.get("port"); + if (port != null) { + restPort = Integer.parseInt(port); + } + logger.info("REST port set to {}", restPort); } @Override diff --git a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule index b28500aa118ad8efae001c3444f0d8454c5df428..21df0f4bcbc2d595a2ae9e12ab4957bf126dbc25 100644 --- a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule +++ b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule @@ -1,4 +1,4 @@ -net.floodlightcontroller.core.CoreModule +net.floodlightcontroller.core.FloodlightProvider net.floodlightcontroller.storage.memory.MemoryStorageSource net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties index 113a74a544c0906eb3c186bb148c2b3a977ddefb..ff39a03c06c74b626f21f8c2a02cb5092c747031 100644 --- a/src/main/resources/floodlightdefault.properties +++ b/src/main/resources/floodlightdefault.properties @@ -3,3 +3,5 @@ net.floodlightcontroller.forwarding.Forwarding,\ net.floodlightcontroller.jython.JythonDebugInterface,\ net.floodlightcontroller.counter.CounterStore,\ net.floodlightcontroller.perfmon.PktInProcessingTime +net.floodlightcontroller.restserver.RestApiServer.port = 8080 +net.floodlightcontroller.core.FloodlightProvider.openflowport = 6633 \ No newline at end of file diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 0187e5dce3bfe90f71353c77fa70852cf44ae790..e0576fa0d1d031f68276d34b7c09c596441074bc 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -24,11 +24,12 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import net.floodlightcontroller.core.CoreModule; +import net.floodlightcontroller.core.FloodlightProvider; import net.floodlightcontroller.core.FloodlightContext; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFMessageFilterManagerService; @@ -37,6 +38,7 @@ import net.floodlightcontroller.core.IOFMessageListener.Command; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.OFMessageFilterManager; import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.test.MockFloodlightProvider; import net.floodlightcontroller.counter.CounterStore; import net.floodlightcontroller.counter.ICounterStoreService; @@ -80,17 +82,30 @@ public class ControllerTest extends FloodlightTestCase { public void setUp() throws Exception { super.setUp(); FloodlightModuleContext fmc = new FloodlightModuleContext(); - CoreModule cm = new CoreModule(); + Set<IFloodlightModule> modSet = new HashSet<IFloodlightModule>(); + + FloodlightProvider cm = new FloodlightProvider(); controller = (Controller)cm.getServiceImpls().get(IFloodlightProviderService.class); fmc.addService(IFloodlightProviderService.class, controller); + modSet.add(cm); + MemoryStorageSource memstorage = new MemoryStorageSource(); fmc.addService(IStorageSourceService.class, memstorage); + modSet.add(memstorage); + RestApiServer restApi = new RestApiServer(); fmc.addService(IRestApiService.class, restApi); + modSet.add(restApi); + CounterStore cs = new CounterStore(); fmc.addService(ICounterStoreService.class, cs); + modSet.add(cs); + PktInProcessingTime ppt = new PktInProcessingTime(); fmc.addService(IPktInProcessingTimeService.class, ppt); + modSet.add(ppt); + + fmc.createConfigMaps(modSet); ppt.init(fmc); restApi.init(fmc); memstorage.init(fmc); diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index f4b34d2f6c00fbb5dbfa12e1c63fb012442560a5..ea885554c4f00f60fc6c774dfad56cb7f6842940 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -34,7 +34,6 @@ import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitchFilter; import net.floodlightcontroller.core.IOFSwitchListener; import net.floodlightcontroller.core.IOFMessageListener.Command; -import net.floodlightcontroller.core.internal.CmdLineSettings; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; @@ -207,11 +206,6 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro // no-op } - @Override - public void setCmdLineOptions(CmdLineSettings settings) { - // no-op - } - @Override public Collection<Class<? extends IFloodlightService>> getModuleServices() { // TODO Auto-generated method stub diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index 229e77dc5dadedd7ff0384f6739a75b2cd48469d..14cfe32e0c90d9a88ddc779bfcc3f0c454ebd39c 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -19,7 +19,9 @@ package net.floodlightcontroller.devicemanager.internal; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; @@ -31,6 +33,7 @@ import static org.easymock.EasyMock.verify; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.test.MockFloodlightProvider; import net.floodlightcontroller.devicemanager.Device; import net.floodlightcontroller.devicemanager.DeviceAttachmentPoint; @@ -74,14 +77,20 @@ public class DeviceManagerImplTest extends FloodlightTestCase { super.setUp(); FloodlightModuleContext fmc = new FloodlightModuleContext(); + Set<IFloodlightModule> modSet = new HashSet<IFloodlightModule>(); RestApiServer restApi = new RestApiServer(); + modSet.add(restApi); mockFloodlightProvider = getMockFloodlightProvider(); + modSet.add(mockFloodlightProvider); deviceManager = new DeviceManagerImpl(); + modSet.add(deviceManager); fmc.addService(IDeviceManagerService.class, deviceManager); storageSource = new MemoryStorageSource(); + modSet.add(storageSource); fmc.addService(IStorageSourceService.class, storageSource); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); fmc.addService(IRestApiService.class, restApi); + fmc.createConfigMaps(modSet); restApi.init(fmc); storageSource.init(fmc); deviceManager.init(fmc); diff --git a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java index 65c88294846203f066eca5c0242fa02f425482ee..b9c06a4aaf9637ce38cbeadfadd577cb8d42ad35 100644 --- a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java +++ b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java @@ -23,7 +23,9 @@ import org.openflow.util.HexString; import net.floodlightcontroller.core.FloodlightContext; import net.floodlightcontroller.core.IOFSwitch; +import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; +import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.test.MockFloodlightProvider; import net.floodlightcontroller.test.FloodlightTestCase; import net.floodlightcontroller.restserver.RestApiServer; @@ -176,6 +178,9 @@ public class StaticFlowTests extends FloodlightTestCase { staticFlowEntryPusher.setStorageSource(storage); + FloodlightModuleContext fmc = new FloodlightModuleContext(); + Set<IFloodlightModule> modSet = new HashSet<IFloodlightModule>(); + MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider(); Map<Long, IOFSwitch> switchMap = new HashMap<Long, IOFSwitch>(); switchMap.put(dpid, mockSwitch); @@ -183,8 +188,10 @@ public class StaticFlowTests extends FloodlightTestCase { mockFloodlightProvider.setSwitches(switchMap); staticFlowEntryPusher.setFloodlightProvider(mockFloodlightProvider); RestApiServer restApi = new RestApiServer(); + modSet.add(restApi); + fmc.createConfigMaps(modSet); try { - restApi.init(null); + restApi.init(fmc); } catch (FloodlightModuleException e) { e.printStackTrace(); } diff --git a/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java b/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java index c2500662218deb316fcb2cb620f766c04012c3a6..127a9f0f7f7e3d3f7e76d54d53141848cc15bd39 100644 --- a/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java +++ b/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java @@ -17,7 +17,11 @@ package net.floodlightcontroller.storage.memory.tests; +import java.util.HashSet; +import java.util.Set; + import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.restserver.RestApiServer; import net.floodlightcontroller.storage.memory.MemoryStorageSource; @@ -32,6 +36,10 @@ public class MemoryStorageTest extends StorageTest { restApi = new RestApiServer(); FloodlightModuleContext fmc = new FloodlightModuleContext(); fmc.addService(IRestApiService.class, restApi); + Set<IFloodlightModule> modSet = new HashSet<IFloodlightModule>(); + modSet.add(restApi); + modSet.add(storageSource); + fmc.createConfigMaps(modSet); restApi.init(fmc); storageSource.init(fmc); restApi.startUp(fmc);