From 74eec3bb249ed93189b0a2ff137fb869c75a5310 Mon Sep 17 00:00:00 2001 From: Alex Reimers <alex@bigswitch.com> Date: Wed, 25 Jan 2012 15:22:37 -0800 Subject: [PATCH] Fir checkin for Floodlight module loading system. Conflicts: src/main/java/net/floodlightcontroller/util/TimedCache.java --- ...htcontroller.core.module.IFloodlightModule | 1 + .../floodlightcontroller/core/CoreModule.java | 49 ++++++ .../core/IFloodlightProvider.java | 2 +- .../core/IFloodlightService.java | 12 ++ .../net/floodlightcontroller/core/Main.java | 25 +++ .../core/internal/CmdLineSettings.java | 9 +- .../core/internal/Controller.java | 35 +++-- .../core/module/FloodlightModuleContext.java | 63 ++++++++ .../module/FloodlightModuleException.java | 9 ++ .../core/module/FloodlightModuleLoader.java | 147 ++++++++++++++++++ .../core/module/IFloodlightModule.java | 67 ++++++++ .../core/module/IFloodlightModuleContext.java | 13 ++ .../core/web/CounterResource.java | 10 +- .../core/web/SwitchCounterResource.java | 4 +- .../counter/ConcurrentCounter.java | 4 +- .../counter/CountBuffer.java | 2 +- .../counter/CountSeries.java | 2 +- .../counter/CounterStore.java | 18 +-- .../{ICounter.java => ICounterService.java} | 4 +- .../counter/SimpleCounter.java | 4 +- ...anager.java => IDeviceManagerService.java} | 4 +- .../internal/DeviceManagerImpl.java | 22 ++- .../learningswitch/LearningSwitch.java | 8 +- .../routing/ForwardingBase.java | 16 +- .../routing/dijkstra/RoutingImpl.java | 4 +- ...ava => IStaticFlowEntryPusherService.java} | 2 +- .../StaticFlowEntryPusher.java | 2 +- .../storage/AbstractStorageSource.java | 2 +- ...Source.java => IStorageSourceService.java} | 3 +- .../storage/web/StorageNotifyResource.java | 6 +- ...ologyAware.java => ITopologyListener.java} | 7 +- .../{ITopology.java => ITopologyService.java} | 7 +- .../topology/internal/TopologyImpl.java | 29 ++-- .../topology/web/LinksResource.java | 4 +- .../floodlightcontroller/util/TimedCache.java | 7 +- .../internal/DeviceManagerImplTest.java | 10 +- .../devicemanager/test/MockDeviceManager.java | 4 +- .../forwarding/ForwardingTest.java | 12 +- .../storage/tests/StorageTest.java | 4 +- .../topology/internal/TopologyImplTest.java | 4 +- 40 files changed, 524 insertions(+), 113 deletions(-) create mode 100644 src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule create mode 100644 src/main/java/net/floodlightcontroller/core/CoreModule.java create mode 100644 src/main/java/net/floodlightcontroller/core/IFloodlightService.java create mode 100644 src/main/java/net/floodlightcontroller/core/Main.java create mode 100644 src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java create mode 100644 src/main/java/net/floodlightcontroller/core/module/FloodlightModuleException.java create mode 100644 src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java create mode 100644 src/main/java/net/floodlightcontroller/core/module/IFloodlightModule.java create mode 100644 src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java rename src/main/java/net/floodlightcontroller/counter/{ICounter.java => ICounterService.java} (93%) rename src/main/java/net/floodlightcontroller/devicemanager/{IDeviceManager.java => IDeviceManagerService.java} (93%) rename src/main/java/net/floodlightcontroller/staticflowentry/{IStaticFlowEntryPusher.java => IStaticFlowEntryPusherService.java} (98%) rename src/main/java/net/floodlightcontroller/storage/{IStorageSource.java => IStorageSourceService.java} (98%) rename src/main/java/net/floodlightcontroller/topology/{ITopologyAware.java => ITopologyListener.java} (92%) rename src/main/java/net/floodlightcontroller/topology/{ITopology.java => ITopologyService.java} (92%) diff --git a/src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule new file mode 100644 index 000000000..adb57d6b7 --- /dev/null +++ b/src/main/java/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule @@ -0,0 +1 @@ +net.floodlightcontroller.core.CoreModule diff --git a/src/main/java/net/floodlightcontroller/core/CoreModule.java b/src/main/java/net/floodlightcontroller/core/CoreModule.java new file mode 100644 index 000000000..67a9680b9 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/CoreModule.java @@ -0,0 +1,49 @@ +package net.floodlightcontroller.core; + +import java.util.ArrayList; +import java.util.Collection; + +import net.floodlightcontroller.core.internal.Controller; +import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.FloodlightModuleException; +import net.floodlightcontroller.core.module.IFloodlightModule; + +public class CoreModule implements IFloodlightModule { + protected static Collection<Class<? extends IFloodlightService>> services; + Controller controller; + + static { + services = new ArrayList<Class<? extends IFloodlightService>>(1); + services.add(IFloodlightProvider.class); + } + + @Override + public Collection<Class<? extends IFloodlightService>> getServices() { + return services; + } + + @Override + public Collection<IFloodlightService> getServiceImpls() { + Collection<IFloodlightService> l = new ArrayList<IFloodlightService>(1); + controller = new Controller(); + l.add(controller); + return l; + } + + @Override + public Collection<? extends IFloodlightService> getDependencies() { + return null; + } + + @Override + public void init(FloodlightModuleContext context) throws FloodlightModuleException { + controller.init(); + } + + @Override + public void startUp(FloodlightModuleContext context) { + controller.startupComponents(); + controller.run(); + } + +} diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProvider.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProvider.java index 6cf9515b9..a9547e84f 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProvider.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProvider.java @@ -33,7 +33,7 @@ import org.openflow.protocol.factory.BasicFactory; * * @author David Erickson (daviderickson@cs.stanford.edu) */ -public interface IFloodlightProvider { +public interface IFloodlightProvider extends IFloodlightService { /** * A value stored in the floodlight context containing a parsed packet diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightService.java new file mode 100644 index 000000000..ccf0c3ff5 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightService.java @@ -0,0 +1,12 @@ +package net.floodlightcontroller.core; + +/** + * This is the base interface for any IFloodlightModule package that provides + * a service. + * @author alexreimers + * + */ +// TODO change this to IFloodlightExclusiveService +public abstract interface IFloodlightService { + // This space is intentionally left blank....don't touch it +} diff --git a/src/main/java/net/floodlightcontroller/core/Main.java b/src/main/java/net/floodlightcontroller/core/Main.java new file mode 100644 index 000000000..f217118b3 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/Main.java @@ -0,0 +1,25 @@ +package net.floodlightcontroller.core; + +import net.floodlightcontroller.core.module.FloodlightModuleException; +import net.floodlightcontroller.core.module.FloodlightModuleLoader; + +/** + * Host for the Floodlight main method + * @author alexreimers + */ +public class Main { + + /** + * Main method to load configuration and modules + * @param args + * @throws FloodlightModuleException + */ + public static void main(String[] args) throws FloodlightModuleException { + System.setProperty("org.restlet.engine.loggerFacadeClass", + "org.restlet.ext.slf4j.Slf4jLoggerFacade"); + + FloodlightModuleLoader fml = new FloodlightModuleLoader(); + fml.loadModulesFromConfig(); + } + +} diff --git a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java index 52b4fdefc..142586e7d 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java +++ b/src/main/java/net/floodlightcontroller/core/internal/CmdLineSettings.java @@ -8,11 +8,14 @@ import org.kohsuke.args4j.Option; public class CmdLineSettings { private final int DEFAULT_OPENFLOW_PORT = 6633; private final int DEFAULT_REST_PORT = 8080; - + private static String DEFAULT_MODULE_FILE = "modules.json"; + @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="-mf", aliases="--moduleFile", metaVar="FILE", usage="Module configuration file") + private String moduleFile = DEFAULT_MODULE_FILE; public int getOpenFlowPort() { return openFlowPort; @@ -21,4 +24,8 @@ public class CmdLineSettings { public int getRestPort() { return restPort; } + + public String getModuleFile() { + return moduleFile; + } } diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index a6b4197e8..ac7e59f83 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -61,7 +61,7 @@ import net.floodlightcontroller.core.web.JacksonCustomConverter; import net.floodlightcontroller.core.web.RestletRoutable; import static net.floodlightcontroller.counter.CounterValue.CounterType; import net.floodlightcontroller.counter.CounterStore; -import net.floodlightcontroller.counter.ICounter; +import net.floodlightcontroller.counter.ICounterService; import net.floodlightcontroller.counter.CounterStore.NetworkLayer; import net.floodlightcontroller.devicemanager.IDeviceManagerAware; import net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl; @@ -74,12 +74,12 @@ import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher; import net.floodlightcontroller.perfmon.PktinProcessingTime; import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IStorageExceptionHandler; -import net.floodlightcontroller.storage.IStorageSource; +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.storage.web.StorageWebRoutable; -import net.floodlightcontroller.topology.ITopologyAware; +import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.internal.TopologyImpl; import net.floodlightcontroller.topology.web.TopologyWebRouteable; @@ -166,7 +166,7 @@ public class Controller protected ScheduledExecutorService executor = Executors.newScheduledThreadPool(5); - protected IStorageSource storageSource; + protected IStorageSourceService storageSource; protected TopologyImpl topology; protected DeviceManagerImpl deviceManager; protected RoutingImpl routingEngine; @@ -178,9 +178,12 @@ public class Controller protected List<RestletRoutable> restlets; + // Configuration options protected int restPort; protected int openFlowPort; + protected String moduleFile; + // Storage table names protected static final String CONTROLLER_TABLE_NAME = "controller_controller"; protected static final String CONTROLLER_ID = "id"; @@ -234,6 +237,7 @@ public class Controller this.restlets = new ArrayList<RestletRoutable>(); this.restPort = settings.getRestPort(); this.openFlowPort = settings.getOpenFlowPort(); + this.moduleFile = settings.getModuleFile(); } // ********************** @@ -644,28 +648,28 @@ public class Controller NetworkLayer.L3); try { - ICounter portCounter = + ICounterService portCounter = counterStore.getCounter(portCounterName); if (portCounter == null) { portCounter = counterStore.createCounter(portCounterName, CounterType.LONG); } - ICounter switchCounter = + ICounterService switchCounter = counterStore.getCounter(switchCounterName); if (switchCounter == null) { switchCounter = counterStore.createCounter(switchCounterName, CounterType.LONG); } - ICounter portL3Counter = + ICounterService portL3Counter = counterStore.getCounter(portL3CategoryCounterName); if (portL3Counter == null) { portL3Counter = counterStore.createCounter(portL3CategoryCounterName, CounterType.LONG); } - ICounter switchL3Counter = + ICounterService switchL3Counter = counterStore.getCounter(switchL3CategoryCounterName); if (switchL3Counter == null) { switchL3Counter = @@ -699,14 +703,14 @@ public class Controller l4Type, NetworkLayer.L4); - ICounter portL4Counter = + ICounterService portL4Counter = counterStore.getCounter(portL4CategoryCounterName); if (portL4Counter == null) { portL4Counter = counterStore.createCounter(portL4CategoryCounterName, CounterType.LONG); } - ICounter switchL4Counter = + ICounterService switchL4Counter = counterStore.getCounter(switchL4CategoryCounterName); if (switchL4Counter == null) { switchL4Counter = @@ -1111,7 +1115,6 @@ public class Controller // ************** // Initialization // ************** - /** * Call after init() has run, but before this.run() * @throws IOException @@ -1150,7 +1153,7 @@ public class Controller log.info("Shutdown complete"); } - protected void setStorageSource(IStorageSource storageSource) { + protected void setStorageSource(IStorageSourceService storageSource) { this.storageSource = storageSource; IStorageExceptionHandler handler = new TerminationStorageExceptionHandler(this); @@ -1332,7 +1335,7 @@ public class Controller * Tell controller that we're ready to accept switches loop * @throws IOException */ - protected void run() { + public void run() { try { // Start listening for REST requests final Component component = new Component(); @@ -1406,7 +1409,7 @@ public class Controller * Initialize all of the controller's components; override me for * new components */ - protected void init() { + public void init() { topology = new TopologyImpl(); deviceManager = new DeviceManagerImpl(); counterStore = new CounterStore(); @@ -1428,7 +1431,7 @@ public class Controller // call this explicitly because it does setup this.setStorageSource(storageSource); - HashSet<ITopologyAware> topologyAware = new HashSet<ITopologyAware>(); + HashSet<ITopologyListener> topologyAware = new HashSet<ITopologyListener>(); topologyAware.add(deviceManager); topologyAware.add(routingEngine); topology.setTopologyAware(topologyAware); @@ -1496,7 +1499,7 @@ public class Controller /** * Startup all of the controller's components */ - protected void startupComponents() { + public void startupComponents() { // now, do our own init try { log.debug("Doing controller internal setup"); diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java new file mode 100644 index 000000000..309a94bdf --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleContext.java @@ -0,0 +1,63 @@ +package net.floodlightcontroller.core.module; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import net.floodlightcontroller.core.IFloodlightService; + +/** + * The service registry for an IFloodlightProvider. + * @author alexreimers + */ +public class FloodlightModuleContext implements IFloodlightModuleContext { + protected Map<Class<? extends IFloodlightService>, IFloodlightService> serviceMap; + protected Collection<IFloodlightModule> modules; + + /** + * Creates the ModuleContext for use with this IFloodlightProvider. + * This will be used as a module registry for all IFloodlightModule(s). + */ + public FloodlightModuleContext() { + serviceMap = new ConcurrentHashMap<Class<? extends IFloodlightService>, IFloodlightService>(); + modules = new ArrayList<IFloodlightModule>(); + } + + /** + * Adds a IFloodlightModule for this Context. + * @param module The IFloodlightModule to add to the registry + * @param name The fully qualified name for the module that describes + * the service it provides, i.e. "deviceManager.floodlight" + */ + public void addService(IFloodlightService service) { + Class<? extends IFloodlightService> serviceClass = service.getClass(); + serviceMap.put(serviceClass, service); + } + + /** + * Retrieves a casted version of a module from the registry. + * @param name The IFloodlightService object type + * @return The IFloodlightService + * @throws FloodlightModuleException If the module was not found or a ClassCastException was encountered. + */ + public IFloodlightService getService(Class<? extends IFloodlightService> service) { + return serviceMap.get(service); + } + + /** + * Add a module to the list of initialized modules + * @param module + */ + public void addModule(IFloodlightModule module) { + modules.add(module); + } + + /** + * Get the list of initialized modules. + * @return the list of modules that have been initialized + */ + public Collection<IFloodlightModule> getModules() { + return modules; + } + } diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleException.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleException.java new file mode 100644 index 000000000..20ccc86d4 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleException.java @@ -0,0 +1,9 @@ +package net.floodlightcontroller.core.module; + +public class FloodlightModuleException extends Exception { + private static final long serialVersionUID = 1L; + + public FloodlightModuleException(String error) { + super(error); + } +} diff --git a/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java new file mode 100644 index 000000000..3681ef26a --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/module/FloodlightModuleLoader.java @@ -0,0 +1,147 @@ +package net.floodlightcontroller.core.module; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; + +import net.floodlightcontroller.core.IFloodlightService; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * TODO fill this in + * @author alexreimers + * + */ +public class FloodlightModuleLoader { + protected static Logger logger = + LoggerFactory.getLogger(FloodlightModuleLoader.class); + + protected FloodlightModuleContext floodlightModuleContext; + protected Map<Class<? extends IFloodlightService>, + Collection<IFloodlightModule>> serviceMap; + protected Map<String, IFloodlightModule> moduleNameMap; + + public FloodlightModuleLoader() { + floodlightModuleContext = new FloodlightModuleContext(); + serviceMap = + new HashMap<Class<? extends IFloodlightService>, + Collection<IFloodlightModule>>(); + moduleNameMap = new HashMap<String, IFloodlightModule>(); + } + + public IFloodlightModuleContext getModules() + throws FloodlightModuleException { + findAllModules(); + + + return floodlightModuleContext; + } + + /** + * Finds all IFloodlightModule(s) in the classpath. + */ + protected void findAllModules() throws FloodlightModuleException { + // Get all the current modules in the classpath + ServiceLoader<IFloodlightModule> moduleLoader + = ServiceLoader.load(IFloodlightModule.class); + // Iterate for each module, iterate through and add it's services + for (IFloodlightModule m : moduleLoader) { + logger.debug("Found module " + m.getClass().getName()); + + // Set up moduleNameMap + moduleNameMap.put(m.getClass().getCanonicalName(), m); + + // Set up serviceMap + Collection<Class<? extends IFloodlightService>> servs = + m.getServices(); + if (servs != null) { + for (Class<? extends IFloodlightService> s : servs) { + Collection<IFloodlightModule> mods = + serviceMap.get(s); + if (mods == null) { + mods = new ArrayList<IFloodlightModule>(); + serviceMap.put(s, mods); + } + mods.add(m); + } + } + } + } + + public void loadModulesFromConfig() throws FloodlightModuleException { + findAllModules(); + initModule("net.floodlightcontroller.core.CoreModule"); + startupModules(); + + /* + * first read modules.json + * go through modules 1 by 1 + * take name of module + * call loadModules(); + * call module.init(); + * + * for each module: + * call module.startUp(); + * + */ + } + + protected void startupModules() { + for (IFloodlightModule m : floodlightModuleContext.getModules()) { + m.startUp(floodlightModuleContext); + } + } + + protected void initModule(String moduleName) throws FloodlightModuleException { + IFloodlightModule module = moduleNameMap.get(moduleName); + if (module == null) { + throw new FloodlightModuleException("Module " + + moduleName + " not found"); + } + Collection<? extends IFloodlightService> deps = + module.getDependencies(); + if (deps != null) { + for (IFloodlightService dep : deps) { + Class<? extends IFloodlightService> c = dep.getClass(); + IFloodlightService s = floodlightModuleContext.getService(c); + if (s == null) { + Collection<IFloodlightModule> mods = serviceMap.get(dep); + // Make sure only one module is loaded + if ((mods == null) || (mods.size() == 0)) { + throw new FloodlightModuleException("ERROR! Could not " + + "find IFloodlightModule that provides service " + + dep.getClass().toString()); + } else if (mods.size() == 1) { + // Recursively load the module's dependencies recursively + initModule(mods.iterator().next().getClass().toString()); + } else { + throw new FloodlightModuleException("ERROR! Found more " + + "than one IFloodlightModule that provides " + + "service " + dep.getClass().toString() + + ". Please resolve this in the config"); + } + } + // else it's already loaded + } + } + + // Get the module's service impls + Collection<IFloodlightService> simpls = + module.getServiceImpls(); + + // init the module + module.init(floodlightModuleContext); + + // add the module's services to the context + floodlightModuleContext.addModule(module); + if (simpls != null) { + for (IFloodlightService s : simpls) { + floodlightModuleContext.addService(s); + } + } + } +} diff --git a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModule.java b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModule.java new file mode 100644 index 000000000..ee307fc77 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModule.java @@ -0,0 +1,67 @@ +package net.floodlightcontroller.core.module; + +import java.util.Collection; + +import net.floodlightcontroller.core.IFloodlightService; + +/** + * 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>> getServices(); + + public Collection<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 + */ + + public Collection<? extends IFloodlightService> getDependencies(); + + /** + * 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); + + // TODO add getName() getId() + +} diff --git a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java new file mode 100644 index 000000000..6be257a52 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java @@ -0,0 +1,13 @@ +package net.floodlightcontroller.core.module; + +import net.floodlightcontroller.core.IFloodlightService; + +public interface IFloodlightModuleContext { + //TODO FIX THIS COMMENT + /** + * Retrieves a casted version of a module from the registry. + * @return The module casted to the correct type + */ + public IFloodlightService getService( + Class<? extends IFloodlightService> service); +} diff --git a/src/main/java/net/floodlightcontroller/core/web/CounterResource.java b/src/main/java/net/floodlightcontroller/core/web/CounterResource.java index fb680d7c9..124cd5b16 100644 --- a/src/main/java/net/floodlightcontroller/core/web/CounterResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/CounterResource.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.Map.Entry; import net.floodlightcontroller.counter.CounterValue; -import net.floodlightcontroller.counter.ICounter; +import net.floodlightcontroller.counter.ICounterService; import org.restlet.resource.Get; @@ -35,12 +35,12 @@ public class CounterResource extends CounterResourceBase { Map<String, Object> model = new HashMap<String,Object>(); CounterValue v; if (counterTitle.equalsIgnoreCase("all")) { - Map<String, ICounter> counters = this.counterStore.getAll(); + Map<String, ICounterService> counters = this.counterStore.getAll(); if (counters != null) { - Iterator<Map.Entry<String, ICounter>> it = + Iterator<Map.Entry<String, ICounterService>> it = counters.entrySet().iterator(); while (it.hasNext()) { - Entry<String, ICounter> entry = it.next(); + Entry<String, ICounterService> entry = it.next(); String counterName = entry.getKey(); v = entry.getValue().getCounterValue(); @@ -52,7 +52,7 @@ public class CounterResource extends CounterResourceBase { } } } else { - ICounter counter = this.counterStore.getCounter(counterTitle); + ICounterService counter = this.counterStore.getCounter(counterTitle); if (counter != null) { v = counter.getCounterValue(); } else { diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java index 143121417..a371cd892 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java @@ -27,7 +27,7 @@ import org.restlet.resource.Get; import net.floodlightcontroller.core.IFloodlightProvider; import net.floodlightcontroller.counter.CounterStore; -import net.floodlightcontroller.counter.ICounter; +import net.floodlightcontroller.counter.ICounterService; /** * Get counters for a particular switch @@ -68,7 +68,7 @@ public class SwitchCounterResource extends CounterResourceBase { //Just leave counterTitle undecoded if there is an issue - fail silently } - ICounter counter = this.counterStore.getCounter(fullCounterName); + ICounterService counter = this.counterStore.getCounter(fullCounterName); Map<String, Long> sample = new HashMap<String, Long> (); if (counter != null) { sample.put(counter.getCounterDate().toString(), diff --git a/src/main/java/net/floodlightcontroller/counter/ConcurrentCounter.java b/src/main/java/net/floodlightcontroller/counter/ConcurrentCounter.java index cdec1e0ed..7a7443d0d 100644 --- a/src/main/java/net/floodlightcontroller/counter/ConcurrentCounter.java +++ b/src/main/java/net/floodlightcontroller/counter/ConcurrentCounter.java @@ -53,7 +53,7 @@ import net.floodlightcontroller.counter.CounterValue.CounterType; * @author kyle * */ -public class ConcurrentCounter implements ICounter { +public class ConcurrentCounter implements ICounterService { protected static final Map<DateSpan, Integer> MAX_HISTORY = new HashMap<DateSpan, Integer>(); static { @@ -110,7 +110,7 @@ public class ConcurrentCounter implements ICounter { * @param startDate * @return */ - public static ICounter createCounter(Date startDate) { + public static ICounterService createCounter(Date startDate) { ConcurrentCounter cc = new ConcurrentCounter(startDate); ConcurrentCounter.liveCounters.add(cc); return cc; diff --git a/src/main/java/net/floodlightcontroller/counter/CountBuffer.java b/src/main/java/net/floodlightcontroller/counter/CountBuffer.java index fa45862e8..7bd26a7c1 100644 --- a/src/main/java/net/floodlightcontroller/counter/CountBuffer.java +++ b/src/main/java/net/floodlightcontroller/counter/CountBuffer.java @@ -19,7 +19,7 @@ package net.floodlightcontroller.counter; import java.util.Date; -import net.floodlightcontroller.counter.ICounter.DateSpan; +import net.floodlightcontroller.counter.ICounterService.DateSpan; /** diff --git a/src/main/java/net/floodlightcontroller/counter/CountSeries.java b/src/main/java/net/floodlightcontroller/counter/CountSeries.java index c94e5bc61..0f06e8258 100644 --- a/src/main/java/net/floodlightcontroller/counter/CountSeries.java +++ b/src/main/java/net/floodlightcontroller/counter/CountSeries.java @@ -20,7 +20,7 @@ package net.floodlightcontroller.counter; import java.util.Arrays; import java.util.Date; -import net.floodlightcontroller.counter.ICounter.DateSpan; +import net.floodlightcontroller.counter.ICounterService.DateSpan; /** * Simple immutable class to store a series of historic counter values diff --git a/src/main/java/net/floodlightcontroller/counter/CounterStore.java b/src/main/java/net/floodlightcontroller/counter/CounterStore.java index 0da77e200..a2c31e38b 100644 --- a/src/main/java/net/floodlightcontroller/counter/CounterStore.java +++ b/src/main/java/net/floodlightcontroller/counter/CounterStore.java @@ -46,7 +46,7 @@ public class CounterStore { } protected class CounterEntry { - protected ICounter counter; + protected ICounterService counter; String title; } @@ -56,8 +56,8 @@ public class CounterStore { protected Map<String, CounterEntry> nameToCEIndex = new ConcurrentHashMap<String, CounterEntry>(); - protected ICounter heartbeatCounter; - protected ICounter randomCounter; + protected ICounterService heartbeatCounter; + protected ICounterService randomCounter; /** * Counter Categories grouped by network layers @@ -143,9 +143,9 @@ public class CounterStore { * @param type * @return */ - public ICounter createCounter(String key, CounterValue.CounterType type) { + public ICounterService createCounter(String key, CounterValue.CounterType type) { CounterEntry ce; - ICounter c; + ICounterService c; if (!nameToCEIndex.containsKey(key)) { c = SimpleCounter.createCounter(new Date(), type); @@ -178,7 +178,7 @@ public class CounterStore { /** * Retrieves a counter with the given title, or null if none can be found. */ - public ICounter getCounter(String key) { + public ICounterService getCounter(String key) { CounterEntry counter = nameToCEIndex.get(key); if (counter != null) { return counter.counter; @@ -192,11 +192,11 @@ public class CounterStore { * * (Note - this method may be slow - primarily for debugging/UI) */ - public Map<String, ICounter> getAll() { - Map<String, ICounter> ret = new ConcurrentHashMap<String, ICounter>(); + public Map<String, ICounterService> getAll() { + Map<String, ICounterService> ret = new ConcurrentHashMap<String, ICounterService>(); for(Map.Entry<String, CounterEntry> counterEntry : this.nameToCEIndex.entrySet()) { String key = counterEntry.getKey(); - ICounter counter = counterEntry.getValue().counter; + ICounterService counter = counterEntry.getValue().counter; ret.put(key, counter); } return ret; diff --git a/src/main/java/net/floodlightcontroller/counter/ICounter.java b/src/main/java/net/floodlightcontroller/counter/ICounterService.java similarity index 93% rename from src/main/java/net/floodlightcontroller/counter/ICounter.java rename to src/main/java/net/floodlightcontroller/counter/ICounterService.java index 625bebdc3..242273b54 100644 --- a/src/main/java/net/floodlightcontroller/counter/ICounter.java +++ b/src/main/java/net/floodlightcontroller/counter/ICounterService.java @@ -23,11 +23,13 @@ package net.floodlightcontroller.counter; import java.util.Date; +import net.floodlightcontroller.core.IFloodlightService; + /** * @author kyle * */ -public interface ICounter { +public interface ICounterService extends IFloodlightService { /** * Most commonly used method diff --git a/src/main/java/net/floodlightcontroller/counter/SimpleCounter.java b/src/main/java/net/floodlightcontroller/counter/SimpleCounter.java index d4aadaf83..34615ee09 100644 --- a/src/main/java/net/floodlightcontroller/counter/SimpleCounter.java +++ b/src/main/java/net/floodlightcontroller/counter/SimpleCounter.java @@ -32,7 +32,7 @@ import java.util.Date; * @author Kanzhe * */ -public class SimpleCounter implements ICounter { +public class SimpleCounter implements ICounterService { protected CounterValue counter; protected Date samplingTime; @@ -44,7 +44,7 @@ public class SimpleCounter implements ICounter { * @param startDate * @return */ - public static ICounter createCounter(Date startDate, CounterValue.CounterType type) { + public static ICounterService createCounter(Date startDate, CounterValue.CounterType type) { SimpleCounter cc = new SimpleCounter(startDate, type); return cc; diff --git a/src/main/java/net/floodlightcontroller/devicemanager/IDeviceManager.java b/src/main/java/net/floodlightcontroller/devicemanager/IDeviceManagerService.java similarity index 93% rename from src/main/java/net/floodlightcontroller/devicemanager/IDeviceManager.java rename to src/main/java/net/floodlightcontroller/devicemanager/IDeviceManagerService.java index 89be34653..e7e6c6859 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/IDeviceManager.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/IDeviceManagerService.java @@ -25,12 +25,14 @@ package net.floodlightcontroller.devicemanager; import java.util.List; +import net.floodlightcontroller.core.IFloodlightService; + /** * Used to interact with DeviceManager implementations * * @author David Erickson (daviderickson@cs.stanford.edu) */ -public interface IDeviceManager { +public interface IDeviceManagerService extends IFloodlightService { /** * Returns a device for the given data layer address diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index fe713ac7f..88dc0ab7f 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -47,7 +47,7 @@ import net.floodlightcontroller.core.util.SingletonTask; import net.floodlightcontroller.devicemanager.Device; import net.floodlightcontroller.devicemanager.DeviceAttachmentPoint; import net.floodlightcontroller.devicemanager.DeviceNetworkAddress; -import net.floodlightcontroller.devicemanager.IDeviceManager; +import net.floodlightcontroller.devicemanager.IDeviceManagerService; import net.floodlightcontroller.devicemanager.IDeviceManagerAware; import net.floodlightcontroller.packet.ARP; import net.floodlightcontroller.packet.DHCP; @@ -56,11 +56,11 @@ import net.floodlightcontroller.packet.IPv4; import net.floodlightcontroller.packet.UDP; import net.floodlightcontroller.routing.ForwardingBase; import net.floodlightcontroller.storage.IResultSet; -import net.floodlightcontroller.storage.IStorageSource; +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; -import net.floodlightcontroller.topology.ITopology; -import net.floodlightcontroller.topology.ITopologyAware; +import net.floodlightcontroller.topology.ITopologyService; +import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.SwitchPortTuple; import net.floodlightcontroller.util.EventHistory; import net.floodlightcontroller.util.EventHistory.EvAction; @@ -84,15 +84,13 @@ import org.slf4j.LoggerFactory; * * @author David Erickson (daviderickson@cs.stanford.edu) */ -public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, - IOFSwitchListener, ITopologyAware { +public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListener, + IOFSwitchListener, ITopologyListener { protected static Logger log = LoggerFactory.getLogger(DeviceManagerImpl.class); protected IFloodlightProvider floodlightProvider; - - /** * Class to maintain all the device manager maps which consists of four * main maps. @@ -546,9 +544,9 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, protected ReentrantReadWriteLock lock; protected volatile boolean shuttingDown = false; - protected ITopology topology; + protected ITopologyService topology; protected LinkedList<Update> updates; - protected IStorageSource storageSource; + protected IStorageSourceService storageSource; protected Runnable deviceAgingTimer; protected SingletonTask deviceUpdateTask; @@ -1077,7 +1075,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, /** * @param topology the topology to set */ - public void setTopology(ITopology topology) { + public void setTopology(ITopologyService topology) { this.topology = topology; } @@ -1208,7 +1206,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, this.deviceManagerAware = deviceManagerAware; } - public void setStorageSource(IStorageSource storageSource) { + public void setStorageSource(IStorageSourceService storageSource) { this.storageSource = storageSource; storageSource.createTable(DEVICE_TABLE_NAME, null); storageSource.setTablePrimaryKeyName( diff --git a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java index 0c1a38338..a03c4df2b 100644 --- a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java +++ b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java @@ -40,7 +40,7 @@ import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.counter.CounterStore; import net.floodlightcontroller.counter.CounterValue; -import net.floodlightcontroller.counter.ICounter; +import net.floodlightcontroller.counter.ICounterService; import net.floodlightcontroller.packet.Ethernet; import org.openflow.protocol.OFError; @@ -142,7 +142,7 @@ public class LearningSwitch implements IOFMessageListener { // flowmod is per switch. portid = -1 String counterName = CounterStore.createCounterName(sw.getStringId(), -1, packetName); try { - ICounter counter = counterStore.getCounter(counterName); + ICounterService counter = counterStore.getCounter(counterName); if (counter == null) { counter = counterStore.createCounter(counterName, CounterValue.CounterType.LONG); } @@ -257,7 +257,7 @@ public class LearningSwitch implements IOFMessageListener { } } - private Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi) { + private Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { // Read in packet data headers by using OFMatch OFMatch match = new OFMatch(); match.loadFromPacket(pi.getPacketData(), pi.getInPort(), sw.getId()); @@ -378,7 +378,7 @@ public class LearningSwitch implements IOFMessageListener { public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { switch (msg.getType()) { case PACKET_IN: - return this.processPacketInMessage(sw, (OFPacketIn) msg); + return this.processPacketInMessage(sw, (OFPacketIn) msg, cntx); case PORT_STATUS: return this.processPortStatusMessage(sw, (OFPortStatus) msg); case FLOW_REMOVED: diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java index 41dfc3624..f59991ba4 100644 --- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java +++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java @@ -28,17 +28,17 @@ import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.counter.CounterStore; import net.floodlightcontroller.counter.CounterValue; -import net.floodlightcontroller.counter.ICounter; +import net.floodlightcontroller.counter.ICounterService; import net.floodlightcontroller.devicemanager.Device; import net.floodlightcontroller.devicemanager.DeviceNetworkAddress; -import net.floodlightcontroller.devicemanager.IDeviceManager; +import net.floodlightcontroller.devicemanager.IDeviceManagerService; import net.floodlightcontroller.devicemanager.IDeviceManagerAware; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.routing.IRoutingEngine; import net.floodlightcontroller.routing.IRoutingDecision; import net.floodlightcontroller.routing.Link; import net.floodlightcontroller.routing.Route; -import net.floodlightcontroller.topology.ITopology; +import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.SwitchPortTuple; import org.openflow.protocol.OFFlowMod; @@ -61,9 +61,9 @@ public abstract class ForwardingBase implements IOFMessageListener, IDeviceManag public static final short FLOWMOD_DEFAULT_HARD_TIMEOUT=5; // in seconds protected IFloodlightProvider floodlightProvider; - protected IDeviceManager deviceManager; + protected IDeviceManagerService deviceManager; protected IRoutingEngine routingEngine; - protected ITopology topology; + protected ITopologyService topology; protected CounterStore counterStore; // flow-mod - for use in the cookie @@ -117,7 +117,7 @@ public abstract class ForwardingBase implements IOFMessageListener, IDeviceManag // flowmod is per switch. portid = -1 String counterName = CounterStore.createCounterName(sw.getStringId(), -1, packetName); try { - ICounter counter = counterStore.getCounter(counterName); + ICounterService counter = counterStore.getCounter(counterName); if (counter == null) { counter = counterStore.createCounter(counterName, CounterValue.CounterType.LONG); } @@ -349,14 +349,14 @@ public abstract class ForwardingBase implements IOFMessageListener, IDeviceManag /** * @param deviceManager the deviceManager to set */ - public void setDeviceManager(IDeviceManager deviceManager) { + public void setDeviceManager(IDeviceManagerService deviceManager) { this.deviceManager = deviceManager; } /** * @param topology the topology to set */ - public void setTopology(ITopology topology) { + public void setTopology(ITopologyService topology) { this.topology = topology; } diff --git a/src/main/java/net/floodlightcontroller/routing/dijkstra/RoutingImpl.java b/src/main/java/net/floodlightcontroller/routing/dijkstra/RoutingImpl.java index d1a34212d..d212e69f4 100644 --- a/src/main/java/net/floodlightcontroller/routing/dijkstra/RoutingImpl.java +++ b/src/main/java/net/floodlightcontroller/routing/dijkstra/RoutingImpl.java @@ -35,14 +35,14 @@ import net.floodlightcontroller.routing.IRoutingEngine; import net.floodlightcontroller.routing.Link; import net.floodlightcontroller.routing.Route; import net.floodlightcontroller.routing.RouteId; -import net.floodlightcontroller.topology.ITopologyAware; +import net.floodlightcontroller.topology.ITopologyListener; /** * Floodlight component to find shortest paths based on dijkstra's algorithm * * @author Mandeep Dhami (mandeep.dhami@bigswitch.com) */ -public class RoutingImpl implements IRoutingEngine, ITopologyAware { +public class RoutingImpl implements IRoutingEngine, ITopologyListener { public static final int MAX_LINK_WEIGHT = 1000; public static final int MAX_PATH_WEIGHT = Integer.MAX_VALUE - MAX_LINK_WEIGHT - 1; diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusherService.java similarity index 98% rename from src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusher.java rename to src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusherService.java index 9962b391b..f25c06fd8 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/IStaticFlowEntryPusherService.java @@ -27,7 +27,7 @@ import org.openflow.protocol.OFFlowMod; * Represents the parts of the staticflowentry that are exposed as a service to other floodlight apps * */ -public interface IStaticFlowEntryPusher { +public interface IStaticFlowEntryPusherService { /** * Pushes a flow-mod to this switch as a one-time push * diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java index 585c948ad..e280e7b55 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java @@ -51,7 +51,7 @@ import org.openflow.util.U16; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchListener { +public class StaticFlowEntryPusher implements IStaticFlowEntryPusherService, IOFSwitchListener { // Utility data structure private class FlowModFields { diff --git a/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java b/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java index ecf33eb9c..cdf1ac238 100644 --- a/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java +++ b/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java @@ -30,7 +30,7 @@ import java.util.concurrent.Future; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractStorageSource implements IStorageSource { +public abstract class AbstractStorageSource implements IStorageSourceService { protected static Logger logger = LoggerFactory.getLogger(AbstractStorageSource.class); // Shared instance of the executor to use to execute the storage tasks. diff --git a/src/main/java/net/floodlightcontroller/storage/IStorageSource.java b/src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java similarity index 98% rename from src/main/java/net/floodlightcontroller/storage/IStorageSource.java rename to src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java index f1f29f8af..475737ead 100644 --- a/src/main/java/net/floodlightcontroller/storage/IStorageSource.java +++ b/src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java @@ -22,9 +22,10 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Future; +import net.floodlightcontroller.core.IFloodlightService; import net.floodlightcontroller.perfmon.PktinProcessingTime; -public interface IStorageSource { +public interface IStorageSourceService extends IFloodlightService { /** Set the column to be used as the primary key for a table. This should * be guaranteed to be unique for all of the rows in the table, although the diff --git a/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java b/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java index 17d129444..39e2bbe82 100644 --- a/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java +++ b/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java @@ -21,7 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import net.floodlightcontroller.storage.IStorageSource; +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.StorageSourceNotification; import org.codehaus.jackson.map.ObjectMapper; @@ -42,8 +42,8 @@ public class StorageNotifyResource extends ServerResource { mapper.readValue(entity, new TypeReference<List<StorageSourceNotification>>(){}); - IStorageSource storageSource = - (IStorageSource)getContext().getAttributes().get("storageSource"); + IStorageSourceService storageSource = + (IStorageSourceService)getContext().getAttributes().get("storageSource"); storageSource.notifyListeners(notifications); HashMap<String, Object> model = new HashMap<String,Object>(); diff --git a/src/main/java/net/floodlightcontroller/topology/ITopologyAware.java b/src/main/java/net/floodlightcontroller/topology/ITopologyListener.java similarity index 92% rename from src/main/java/net/floodlightcontroller/topology/ITopologyAware.java rename to src/main/java/net/floodlightcontroller/topology/ITopologyListener.java index 464996f16..d27a1aa5f 100644 --- a/src/main/java/net/floodlightcontroller/topology/ITopologyAware.java +++ b/src/main/java/net/floodlightcontroller/topology/ITopologyListener.java @@ -24,7 +24,7 @@ import net.floodlightcontroller.core.IOFSwitch; * * @author David Erickson (daviderickson@cs.stanford.edu) */ -public interface ITopologyAware { +public interface ITopologyListener { /** * @param srcSw the source switch * @param srcPort the source port from the source switch @@ -56,9 +56,12 @@ public interface ITopologyAware { IOFSwitch dstSw, short dstPort); /** - * @param sw + * @param sw The IOFSwitch that has been updated */ public void updatedSwitch(IOFSwitch sw); + /** + * Happens when the switch clusters are recomputed + */ void clusterMerged(); } diff --git a/src/main/java/net/floodlightcontroller/topology/ITopology.java b/src/main/java/net/floodlightcontroller/topology/ITopologyService.java similarity index 92% rename from src/main/java/net/floodlightcontroller/topology/ITopology.java rename to src/main/java/net/floodlightcontroller/topology/ITopologyService.java index fcd99d0ca..c8dd10e8e 100644 --- a/src/main/java/net/floodlightcontroller/topology/ITopology.java +++ b/src/main/java/net/floodlightcontroller/topology/ITopologyService.java @@ -25,6 +25,8 @@ package net.floodlightcontroller.topology; import java.util.Map; import java.util.Set; + +import net.floodlightcontroller.core.IFloodlightService; import net.floodlightcontroller.core.IOFSwitch; /** @@ -32,7 +34,7 @@ import net.floodlightcontroller.core.IOFSwitch; * * @author David Erickson (daviderickson@cs.stanford.edu) */ -public interface ITopology { +public interface ITopologyService extends IFloodlightService { /** * Query to determine if the specified switch id and port tuple are * connected to another switch or not. If so, this means the link @@ -83,4 +85,7 @@ public interface ITopology { * as an endpoint. */ public Map<IOFSwitch, Set<LinkTuple>> getSwitchLinks(); + + // gets called in startup method + public void addTopologyListener(ITopologyListener listener); } diff --git a/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java b/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java index 3a0e414b5..ce1c5926c 100644 --- a/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java +++ b/src/main/java/net/floodlightcontroller/topology/internal/TopologyImpl.java @@ -46,12 +46,12 @@ import net.floodlightcontroller.packet.LLDPTLV; import net.floodlightcontroller.routing.BroadcastTree; import net.floodlightcontroller.routing.IRoutingEngine; import net.floodlightcontroller.storage.IResultSet; -import net.floodlightcontroller.storage.IStorageSource; +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.IStorageSourceListener; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; -import net.floodlightcontroller.topology.ITopology; -import net.floodlightcontroller.topology.ITopologyAware; +import net.floodlightcontroller.topology.ITopologyService; +import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.LinkInfo; import net.floodlightcontroller.topology.LinkTuple; import net.floodlightcontroller.topology.SwitchCluster; @@ -98,7 +98,7 @@ import org.slf4j.LoggerFactory; * @author David Erickson (daviderickson@cs.stanford.edu) */ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, - IStorageSourceListener, ITopology { + IStorageSourceListener, ITopologyService { protected static Logger log = LoggerFactory.getLogger(TopologyImpl.class); // Names of table/fields for links in the storage API @@ -116,7 +116,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, private static final String SWITCH_CORE_SWITCH = "core_switch"; protected IFloodlightProvider floodlightProvider; - protected IStorageSource storageSource; + protected IStorageSourceService storageSource; protected IRoutingEngine routingEngine; /** @@ -139,7 +139,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, * Map from switch id to a set of all links with it as an endpoint */ protected Map<IOFSwitch, Set<LinkTuple>> switchLinks; - protected Set<ITopologyAware> topologyAware; + protected Set<ITopologyListener> topologyAware; protected BlockingQueue<Update> updates; protected Thread updatesThread; @@ -226,7 +226,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, do { Update update = updates.take(); if (topologyAware != null) { - for (ITopologyAware ta : topologyAware) { + for (ITopologyListener ta : topologyAware) { if (log.isDebugEnabled()) { log.debug("Dispatching topology update {} {} {} {} {}", new Object[]{update.operation, @@ -527,11 +527,12 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, } } + // TODO get rid of this @Override public String getName() { return "topology"; } - + @Override public int getId() { return FlListenerID.TOPOLOGYIMPL; @@ -1365,7 +1366,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, /** * @param topologyAware the topologyAware to set */ - public void setTopologyAware(Set<ITopologyAware> topologyAware) { + public void setTopologyAware(Set<ITopologyListener> topologyAware) { // TODO make this a copy on write set or lock it somehow this.topologyAware = topologyAware; } @@ -1374,7 +1375,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, * Sets the IStorageSource to use for ITology * @param storageSource the storage source to use */ - public void setStorageSource(IStorageSource storageSource) { + public void setStorageSource(IStorageSourceService storageSource) { this.storageSource = storageSource; storageSource.createTable(LINK_TABLE_NAME, null); storageSource.setTablePrimaryKeyName(LINK_TABLE_NAME, LINK_ID); @@ -1384,7 +1385,7 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, * Gets the storage source for this ITopology * @return The IStorageSource ITopology is writing to */ - public IStorageSource getStorageSource() { + public IStorageSourceService getStorageSource() { return storageSource; } @@ -1462,4 +1463,10 @@ public class TopologyImpl implements IOFMessageListener, IOFSwitchListener, public void rowsDeleted(String tableName, Set<Object> rowKeys) { // Ignore delete events, the switch delete will do the right thing on it's own } + + @Override + public void addTopologyListener(ITopologyListener listener) { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/net/floodlightcontroller/topology/web/LinksResource.java b/src/main/java/net/floodlightcontroller/topology/web/LinksResource.java index 48b2f6648..eb1b6d950 100644 --- a/src/main/java/net/floodlightcontroller/topology/web/LinksResource.java +++ b/src/main/java/net/floodlightcontroller/topology/web/LinksResource.java @@ -3,7 +3,7 @@ package net.floodlightcontroller.topology.web; import java.util.HashSet; import java.util.Set; -import net.floodlightcontroller.topology.ITopology; +import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.LinkTuple; import org.restlet.resource.Get; @@ -12,7 +12,7 @@ import org.restlet.resource.ServerResource; public class LinksResource extends ServerResource { @Get("json") public Set<LinkTuple> retrieve() { - ITopology topo = (ITopology)getContext().getAttributes().get("topology"); + ITopologyService topo = (ITopologyService)getContext().getAttributes().get("topology"); Set <LinkTuple> links = new HashSet<LinkTuple>(); if (topo != null) { for (Set<LinkTuple> linkSet : topo.getSwitchLinks().values()) { diff --git a/src/main/java/net/floodlightcontroller/util/TimedCache.java b/src/main/java/net/floodlightcontroller/util/TimedCache.java index ce95c979e..857d57de9 100644 --- a/src/main/java/net/floodlightcontroller/util/TimedCache.java +++ b/src/main/java/net/floodlightcontroller/util/TimedCache.java @@ -20,7 +20,6 @@ package net.floodlightcontroller.util; import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import java.util.concurrent.ConcurrentMap; - /** * The key is any object/hash-code * The value is time-stamp in milliseconds @@ -29,9 +28,7 @@ import java.util.concurrent.ConcurrentMap; * * @param <K> Type of the values in this cache */ -public class TimedCache<K> { - private static final long serialVersionUID = 1L; - +public class TimedCache<K> { private final long timeoutInterval; //specified in milliseconds. private ConcurrentMap<K, Long> cache; private long cacheHits; @@ -87,4 +84,4 @@ public class TimedCache<K> { this.cacheHits++; return true; } -} \ No newline at end of file +} diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index b5fca5050..c4d98c2aa 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -37,7 +37,7 @@ import net.floodlightcontroller.packet.IPacket; import net.floodlightcontroller.packet.IPv4; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.test.FloodlightTestCase; -import net.floodlightcontroller.topology.ITopology; +import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.SwitchPortTuple; import org.junit.Before; @@ -176,7 +176,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { IOFSwitch mockSwitch = createMock(IOFSwitch.class); expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); - ITopology mockTopology = createMock(ITopology.class); + ITopologyService mockTopology = createMock(ITopologyService.class); expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 1))).andReturn(false); deviceManager.setTopology(mockTopology); @@ -236,7 +236,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); - ITopology mockTopology = createNiceMock(ITopology.class); + ITopologyService mockTopology = createNiceMock(ITopologyService.class); expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); @@ -316,7 +316,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { // Mock up our expected behavior IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class); expect(mockSwitch.getId()).andReturn(1L).atLeastOnce(); - ITopology mockTopology = createNiceMock(ITopology.class); + ITopologyService mockTopology = createNiceMock(ITopologyService.class); //expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 1))).andReturn(false); deviceManager.setTopology(mockTopology); @@ -359,7 +359,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { IOFSwitch mockSwitch = createMock(IOFSwitch.class); expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); - ITopology mockTopology = createMock(ITopology.class); + ITopologyService mockTopology = createMock(ITopologyService.class); expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 1))) .andReturn(false).atLeastOnce(); expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 2))) diff --git a/src/test/java/net/floodlightcontroller/devicemanager/test/MockDeviceManager.java b/src/test/java/net/floodlightcontroller/devicemanager/test/MockDeviceManager.java index 569074993..13b3ab675 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/test/MockDeviceManager.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/test/MockDeviceManager.java @@ -26,10 +26,10 @@ import java.util.Map; import java.util.Map.Entry; import net.floodlightcontroller.devicemanager.Device; -import net.floodlightcontroller.devicemanager.IDeviceManager; +import net.floodlightcontroller.devicemanager.IDeviceManagerService; import net.floodlightcontroller.packet.Ethernet; -public class MockDeviceManager implements IDeviceManager { +public class MockDeviceManager implements IDeviceManagerService { protected Map<Long, Device> devices; public MockDeviceManager() { diff --git a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java index 30e36c8db..d657e1035 100644 --- a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java +++ b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java @@ -36,7 +36,7 @@ import net.floodlightcontroller.core.IFloodlightProvider; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.test.MockFloodlightProvider; import net.floodlightcontroller.devicemanager.Device; -import net.floodlightcontroller.devicemanager.IDeviceManager; +import net.floodlightcontroller.devicemanager.IDeviceManagerService; import net.floodlightcontroller.packet.Data; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.IPacket; @@ -46,7 +46,7 @@ import net.floodlightcontroller.routing.IRoutingEngine; import net.floodlightcontroller.routing.Link; import net.floodlightcontroller.routing.Route; import net.floodlightcontroller.test.FloodlightTestCase; -import net.floodlightcontroller.topology.ITopology; +import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.SwitchPortTuple; import net.floodlightcontroller.forwarding.Forwarding; @@ -67,10 +67,10 @@ import org.openflow.protocol.action.OFActionOutput; public class ForwardingTest extends FloodlightTestCase { protected MockFloodlightProvider mockFloodlightProvider; protected FloodlightContext cntx; - protected IDeviceManager deviceManager; + protected IDeviceManagerService deviceManager; protected IRoutingEngine routingEngine; protected Forwarding forwarding; - protected ITopology topology; + protected ITopologyService topology; protected IOFSwitch sw1, sw2; protected Device srcDevice, dstDevice; protected OFPacketIn packetIn; @@ -88,9 +88,9 @@ public class ForwardingTest extends FloodlightTestCase { cntx = new FloodlightContext(); mockFloodlightProvider = getMockFloodlightProvider(); forwarding = getForwarding(); - deviceManager = createMock(IDeviceManager.class); + deviceManager = createMock(IDeviceManagerService.class); routingEngine = createMock(IRoutingEngine.class); - topology = createMock(ITopology.class); + topology = createMock(ITopologyService.class); forwarding.setFloodlightProvider(mockFloodlightProvider); forwarding.setDeviceManager(deviceManager); forwarding.setRoutingEngine(routingEngine); diff --git a/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java b/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java index 45584e227..be6fd9696 100644 --- a/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java +++ b/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java @@ -37,7 +37,7 @@ import net.floodlightcontroller.storage.IPredicate; import net.floodlightcontroller.storage.IQuery; import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IRowMapper; -import net.floodlightcontroller.storage.IStorageSource; +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.IStorageSourceListener; import net.floodlightcontroller.storage.NullValueStorageException; import net.floodlightcontroller.storage.OperatorPredicate; @@ -48,7 +48,7 @@ import org.junit.Test; public abstract class StorageTest extends FloodlightTestCase { - protected IStorageSource storageSource; + protected IStorageSourceService storageSource; protected String PERSON_TABLE_NAME = "Person"; diff --git a/src/test/java/net/floodlightcontroller/topology/internal/TopologyImplTest.java b/src/test/java/net/floodlightcontroller/topology/internal/TopologyImplTest.java index ed15dd8c9..8bec5d93f 100644 --- a/src/test/java/net/floodlightcontroller/topology/internal/TopologyImplTest.java +++ b/src/test/java/net/floodlightcontroller/topology/internal/TopologyImplTest.java @@ -38,7 +38,7 @@ import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.routing.dijkstra.RoutingImpl; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.test.FloodlightTestCase; -import net.floodlightcontroller.topology.ITopologyAware; +import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.LinkInfo; import net.floodlightcontroller.topology.LinkTuple; @@ -67,7 +67,7 @@ public class TopologyImplTest extends FloodlightTestCase { topology.setStorageSource(new MemoryStorageSource()); RoutingImpl routingEngine = new RoutingImpl(); topology.setRoutingEngine(routingEngine); - HashSet<ITopologyAware> topologyAware = new HashSet<ITopologyAware>(); + HashSet<ITopologyListener> topologyAware = new HashSet<ITopologyListener>(); topologyAware.add(routingEngine); topology.setTopologyAware(topologyAware); topology.startUp(); -- GitLab