diff --git a/build.xml b/build.xml index 3093f956856f9b2ca13bf9e67fe37d573ee1f609..cdea14c7ef4982b658d8e0ce0fe74198c3154cc5 100644 --- a/build.xml +++ b/build.xml @@ -27,10 +27,11 @@ <property name="build-test" location="${target}/bin-test"/> <property name="test-output" location="${target}/test"/> <property name="source" location="src/main/java"/> + <property name="resources" location="src/main/resources/"/> <property name="source-test" location="src/test/java"/> <property name="python-src" location="src/main/python"/> <property name="docs" location="${target}/docs"/> - <property name="main-class" value="net.floodlightcontroller.core.internal.Controller"/> + <property name="main-class" value="net.floodlightcontroller.core.Main"/> <property name="packetstreamer-gen" location="${target}/gen-java" /> <property name="packetstreamer-gen-build" location="${target}/gen-java-bin"/> <property name="packetstreamer-thrift-jar" location="${target}/lib/packetstreamer-thrift.jar"/> @@ -102,6 +103,7 @@ <target name="compile-tests" depends="compile-test"/> <target name="compile-test" depends="compile"> + <fileset dir="${resources}"/> <javac includeAntRuntime="false" debug="true" srcdir="${source-test}" classpath="${build}" @@ -159,6 +161,7 @@ <attribute name="Class-Path" value="."/> </manifest> <fileset dir="${build}"/> + <fileset dir="${resources}"/> <fileset dir="${python-src}"> <include name="**/*.py"/> </fileset> @@ -174,6 +177,7 @@ <attribute name="Class-Path" value="."/> </manifest> <fileset dir="${build-test}"/> + <fileset dir="${resources}"/> <zipgroupfileset dir="lib"> <patternset refid="lib-test"/> </zipgroupfileset> diff --git a/setup-eclipse.sh b/setup-eclipse.sh index d7e9a06fb126b99ffe22cc670926f34d28a3bc9d..bdf87200a57a97a7d618303da714356cc86d53a6 100755 --- a/setup-eclipse.sh +++ b/setup-eclipse.sh @@ -31,6 +31,7 @@ cat >$d/.classpath <<EOF <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java" output="target/bin"/> + <classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" path="src/test/java" output="target/bin-test"/> EOF ( diff --git a/src/main/java/net/floodlightcontroller/core/Main.java b/src/main/java/net/floodlightcontroller/core/Main.java index e35c0b546916e5140df21588fe8fa272a9c8b2b8..10ad853e1a18adf0e695c65afabe4ea3965dbb95 100644 --- a/src/main/java/net/floodlightcontroller/core/Main.java +++ b/src/main/java/net/floodlightcontroller/core/Main.java @@ -34,7 +34,7 @@ public class Main { } FloodlightModuleLoader fml = new FloodlightModuleLoader(); - IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(); + IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class); restApi.run(); IFloodlightProviderService controller = diff --git a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java index 9a4468b3b7b50db9632feb60918522d690405c32..29c3f0fce700a1682f4227de03c76b59a3d278c7 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java +++ b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java @@ -6,9 +6,9 @@ import org.kohsuke.args4j.Option; * Expresses the port settings of OpenFlow controller. */ public class CmdLineSettings { - private final int DEFAULT_OPENFLOW_PORT = 6633; - private final int DEFAULT_REST_PORT = 8080; - private static String DEFAULT_CONFIG_FILE = "floodlightconfig.json"; + 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"; @Option(name="-ofp", aliases="--openFlowPort",metaVar="PORT", usage="Port number for OpenFlow") private int openFlowPort = DEFAULT_OPENFLOW_PORT; diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java index 840774b21bfa0567452df7fd3936d7cd898482b9..8ec66d98c58ebf224ef2ac58f5ac28d70bbaf508 100644 --- a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java @@ -1,15 +1,21 @@ package net.floodlightcontroller.core.module; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Properties; import java.util.ServiceLoader; import java.util.Set; +import net.floodlightcontroller.core.internal.CmdLineSettings; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,8 +58,9 @@ public class FloodlightModuleLoader { moduleNameMap = new HashMap<String, IFloodlightModule>(); // Get all the current modules in the classpath + ClassLoader cl = Thread.currentThread().getContextClassLoader(); //new SecureClassLoader(); ServiceLoader<IFloodlightModule> moduleLoader - = ServiceLoader.load(IFloodlightModule.class); + = ServiceLoader.load(IFloodlightModule.class, cl); // Iterate for each module, iterate through and add it's services for (IFloodlightModule m : moduleLoader) { if (logger.isDebugEnabled()) { @@ -82,23 +89,38 @@ public class FloodlightModuleLoader { } } - public IFloodlightModuleContext loadModulesFromConfig() + public IFloodlightModuleContext loadModulesFromConfig(String fName) throws FloodlightModuleException { - logger.debug("Starting module loader"); - findAllModules(); - - Set<IFloodlightModule> moduleSet = new HashSet<IFloodlightModule>(); - Map<Class<? extends IFloodlightService>, IFloodlightModule> moduleMap = - new HashMap<Class<? extends IFloodlightService>, - IFloodlightModule>(); - - calculateModuleDeps(moduleMap, moduleSet, "net.floodlightcontroller.forwarding.Forwarding"); - calculateModuleDeps(moduleMap, moduleSet, "net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher"); + Properties prop = new Properties(); - initModules(moduleSet); - startupModules(moduleSet); - - return floodlightModuleContext; + // 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 { + 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(); + System.exit(1); + } + return loadModulesFromList(prop.getProperty("floodlight.modules").split(",")); + } } /** @@ -187,7 +209,7 @@ public class FloodlightModuleLoader { mod.getClass().getCanonicalName()); } else { throw new FloodlightModuleException("ERROR! Found more " + - "than one IFloodlightModule that provides " + + "than one (" + mods.size() + ") IFloodlightModules that provides " + "service " + c.toString() + ". Please resolve this in the config"); } diff --git a/src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/java/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule similarity index 100% rename from src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule rename to src/main/java/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule 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 new file mode 100644 index 0000000000000000000000000000000000000000..1207638607366e0818a2c375d8b16f68a2ee760e --- /dev/null +++ b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule @@ -0,0 +1,10 @@ +net.floodlightcontroller.core.CoreModule +net.floodlightcontroller.storage.memory.MemoryStorageSource +net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl +net.floodlightcontroller.topology.internal.TopologyImpl +net.floodlightcontroller.routing.dijkstra.RoutingImpl +net.floodlightcontroller.forwarding.Forwarding +net.floodlightcontroller.core.OFMessageFilterManager +net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher +net.floodlightcontroller.perfmon.PktInProcessingTime +net.floodlightcontroller.restserver.RestApiServer \ No newline at end of file diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties new file mode 100644 index 0000000000000000000000000000000000000000..6d2dbca087f960ab50baae674e40c72fce4c1ef5 --- /dev/null +++ b/src/main/resources/floodlightdefault.properties @@ -0,0 +1 @@ +floodlight.modules = net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,net.floodlightcontroller.forwarding.Forwarding