...
A module is defined as a class that implements the IFloodlightModule interface.
Code Block |
---|
|
/**
* Defines an interface for loadable Floodlight modules.
*
* At a high level, these functions are called in the following order:
* <ol>
* <li> getServices() : what services does this module provide
* <li> getDependencies() : list the dependencies
* <li> init() : internal initializations (don't touch other modules)
* <li> startUp() : external initializations (<em>do</em> touch other modules)
* </ol>
*
* @author alexreimers
*/
public interface IFloodlightModule {
/**
* Return the list of interfaces that this module implements.
* All interfaces must inherit IFloodlightService
* @return
*/
public Collection<Class<? extends IFloodlightService>> getModuleServices();
/**
* Instantiate (as needed) and return objects that implement each
* of the services exported by this module. The map returned maps
* the implemented service to the object. The object could be the
* same object or different objects for different exported services.
* @return The map from service interface class to service implementation
*/
public Map<Class<? extends IFloodlightService>,
IFloodlightService> getServiceImpls();
/**
* Get a list of Modules that this module depends on. The module system
* will ensure that each these dependencies is resolved before the
* subsequent calls to init().
* @return The Collection of IFloodlightServices that this module depnds
* on.
*/
public Collection<Class<? extends IFloodlightService>> getModuleDependencies();
/**
* This is a hook for each module to do its <em>internal</em> initialization,
* e.g., call setService(context.getService("Service"))
*
* All module dependencies are resolved when this is called, but not every module
* is initialized.
*
* @param context
* @throws FloodlightModuleException
*/
void init(FloodlightModuleContext context) throws FloodlightModuleException;
/**
* This is a hook for each module to do its <em>external</em> initializations,
* e.g., register for callbacks or query for state in other modules
*
* It is expected that this function will not block and that modules that want
* non-event driven CPU will spawn their own threads.
*
* @param context
*/
void startUp(FloodlightModuleContext context);
}
|
Services
A module may export one ore or more services. A service is defined as an interface that extends the IFloodlightService interface.
Code Block |
---|
|
/**
* This is the base interface for any IFloodlightModule package that provides
* a service.
* @author alexreimers
*
*/
public abstract interface IFloodlightService {
// This space is intentionally left blank....don't touch it
}
|
...
The configuration file specifies which modules to explicitly load. The format is standard Java properties. It uses a key value pair. For the module list we use the key "floodlight.modules". The value is a comma separated list on modules either on one line or using the \ delimiter. Here is the default configuration for Floodlight.
Code Block |
---|
|
floodlight.modules = net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,\
net.floodlightcontroller.forwarding.Forwarding,\
net.floodlightcontroller.jython.JythonDebugInterface
|
...
To find the modules in the classpath we use Java's ServiceLoader. This requires us to list all of the classes in a file. The format of the file is the fully qualified name of the module on it's own line. The file is located in src/main/resources/META-INFO/services/net.floodlightcontroller.module.IFloodlightModule. This is a sample file.
Code Block |
---|
|
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
net.floodlightcontroller.learningswitch.LearningSwitch
net.floodlightcontroller.hub.Hub
net.floodlightcontroller.jython.JythonDebugInterface
|
...
If you want to run Floodlight in it's default configuration, the easiest way is to just run it via this command line.
Code Block |
---|
|
java -jar floodlight.jar
|
Using multiple Jars
It is also possible to run Floodlight using multiple jars. This is useful if you want to offer another package for distribution. The command to run it is slightly different.
Code Block |
---|
|
java -cp floodlight.jar:/path/to/other.jar net.floodlightcontroller.core.Main
|
...
With both of the methods you can also specify a different configuration file. This is used using the -cf option.
Code Block |
---|
|
java -cp floodlight.jar:/path/to/other.jar net.floodlightcontroller.core.Main -cf path/to/config/file.properties
|
...
For example if we want to specify the REST API port in the configuration file we add this to the property file we are using.
Code Block |
---|
|
net.floodlightcontroller.restserver.RestApiServer.port = 8080
|
In RestApiServer.java's init() method we parse the option.
Code Block |
---|
|
// read our config options
Map<String, String> configOptions = context.getConfigParams(this);
String port = configOptions.get("port");
if (port != null) {
restPort = Integer.parseInt(port);
}
|
...
Options can also be specified via the command line as Java properties. These will override anything specified in a Floodlight properties file.
Code Block |
---|
|
java -Dnet.floodlightcontroller.restserver.RestApiServer.port=8080 -jar floodlight.jar
|
...