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 0000000000000000000000000000000000000000..adb57d6b7c32eba2660f81f10b87d7005b02b5cc --- /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 0000000000000000000000000000000000000000..67a9680b99a945d641e3010bd2a564a723c504da --- /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 6cf9515b9fcfa2c350f5bae11b392dce34a81d93..a9547e84fcc9af4dc2b6586afabd62ecfee644bb 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 0000000000000000000000000000000000000000..ccf0c3ff554bac16c9235f734e0e79ef444d4d31 --- /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 0000000000000000000000000000000000000000..f217118b3951f71d6beec12aa5e928de4ccecc7c --- /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 52b4fdefc31729782f2251061c582e86d81a8db1..142586e7d2124a29eda065f29c14384dc6a84e55 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 a6b4197e884544402119328fe36abc0d464234ff..ac7e59f83eaeb0a06f1a33d434b00cc3105acfd1 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 0000000000000000000000000000000000000000..309a94bdfa1bf088ca712e0a666dcc4b79911675 --- /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 0000000000000000000000000000000000000000..20ccc86d478d0869f71251025960bda89060fd50 --- /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 0000000000000000000000000000000000000000..3681ef26a112a4642c5dccebe5348924dac8f4ae --- /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 0000000000000000000000000000000000000000..ee307fc776a7a2acb964de972e52b7e3fd3d13f0 --- /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 0000000000000000000000000000000000000000..6be257a52c72a43709f65ab28274358016891ff8 --- /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 fb680d7c94b4a6af0cfdad5fd288c095e2c3ffd1..124cd5b16a902afd42f7f7afeac5171f134cdf2d 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 143121417dc2ba0a715395ae3dcb2fbeb96fe435..a371cd892e3a2274a3072b25d260850239dd9b7c 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 cdec1e0ed3e2e036af82c96fe35b100510296166..7a7443d0dc9e3da040cc20766216f6ad00ea19bb 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 fa45862e8b938cad6a5b7e57600861986a68f7ff..7bd26a7c11a7b7330db54e8fbf11693bbbf079de 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 c94e5bc613b66767903165ce74d8dec26ce8e4d0..0f06e8258a50383dfc42ab8cf93070de20b87714 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 0da77e20088bf59851a427b6bd686884885b8495..a2c31e38b15ac74a8c9b908843444dc8860b1454 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 625bebdc34fb26bee9c3bd3f279de70fe0867a97..242273b54a328f453993ba80f970abcf155f4aef 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 d4aadaf833feb50e7a32a2638d1e231dfe73631b..34615ee096a023b63dee0f32a66a948ac90e4006 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 89be34653c8b5b92c5e68a89edcaf66adb5877b1..e7e6c68599be670fdb8a2f2a0a7ffb075f039cb3 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 fe713ac7f238f5e4bcffc9445c83dc629ab341d2..88dc0ab7f8502638d50a178a136b6caed4e9c836 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 0c1a383380da6708fe228ad3c7a686f4be4ec8cd..a03c4df2b84f771b8861314d975a069a7f861699 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 41dfc36246f47538e87f6877c5ad983f89408667..f59991ba43dccb3e49c8a1347c49c1e12f9b46e9 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 d1a34212d3aa1be9e0dd5b35d24ca0016a90c140..d212e69f4602e2b92df156f024715044c979a480 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 9962b391bd2f1e627667435e5ef4c9ba6f210edf..f25c06fd8e02afbd62f5c992e4707d5552e0e474 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 585c948adbd2ea1672fb927880548c2b3a582ece..e280e7b55cb7197b678ab6e8eec13340047d558a 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 ecf33eb9cce1825e74180cf6821646300254e684..cdf1ac23852920661bd124639ab396a4d8c826bc 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 f1f29f8afb3a184fcbbf3b90e3fcb739032621fe..475737ead19aa9bc815a1acec3965b8e702a5828 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 17d129444d95ca9890688679fe83721ab34954f4..39e2bbe8204c69ca08f59a216c8de0d98a8283c3 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 464996f167e4f1ff13c377120bab6369f7e13429..d27a1aa5fdade6b419e9eff7283f9af2e7584470 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 fcd99d0caedb9c5a1bf756a4fdd0c9297b0b7e97..c8dd10e8e437f75e1d736a2feeb23b73d0c404c7 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 3a0e414b5f1fdd5924c7a0a99c8e53dc488046e1..ce1c5926c451e0295822ed9a2a9eed1da4ceeaff 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 48b2f664870de232a968e2fd8cf7065bdb4a92c3..eb1b6d95014729766682623cafd70a17262b7049 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 ce95c979ed0601d01718d7f6556654075d17044c..857d57de9046fb02abb5778f63b2666dcd15d446 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 b5fca505005c86b54a15641c6d1171a22249d10d..c4d98c2aac9e3866f6d63a76ef19f4d14873e005 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 5690749933472dfcdc174e38010733aacf1a4b56..13b3ab675fa579440fec0c36dcaac8941990eb00 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 30e36c8db04f89e6972ff589a51f52c2eac00f51..d657e103562f029438b096b6e6676a87a76870d4 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 45584e2270f59556324275739f1137bfffe6283b..be6fd96967464a95d8d099fafaf3e6934dd23193 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 ed15dd8c9d08f9132ab11175b2ce541f602e07bd..8bec5d93fe6882bffab0b44c688c111d8600aad2 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();