Skip to content
Snippets Groups Projects
Commit aaa9e7d1 authored by Alex Reimers's avatar Alex Reimers
Browse files

Configuration file for module loading.

parent 2cef2562
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
......@@ -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
(
......
......@@ -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 =
......
......@@ -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;
......
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");
}
......
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
floodlight.modules = net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,net.floodlightcontroller.forwarding.Forwarding
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