diff --git a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java index 2e315ac51aeb240e73f5866462c26bef7615f1f3..347bf5bb9bcbd167c3b812804f40dbac05154bf3 100644 --- a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java +++ b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java @@ -14,6 +14,7 @@ import net.floodlightcontroller.counter.ICounterStoreService; import net.floodlightcontroller.perfmon.IPktInProcessingTimeService; import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.storage.IStorageSourceService; +import net.floodlightcontroller.threadpool.IThreadPoolService; public class FloodlightProvider implements IFloodlightModule { Controller controller; @@ -47,6 +48,7 @@ public class FloodlightProvider implements IFloodlightModule { dependencies.add(IPktInProcessingTimeService.class); dependencies.add(IRestApiService.class); dependencies.add(ICounterStoreService.class); + dependencies.add(IThreadPoolService.class); return dependencies; } @@ -60,6 +62,8 @@ public class FloodlightProvider implements IFloodlightModule { context.getServiceImpl(ICounterStoreService.class)); controller.setRestApiService( context.getServiceImpl(IRestApiService.class)); + controller.setThreadPoolService( + context.getServiceImpl(IThreadPoolService.class)); controller.init(context.getConfigParams(this)); } diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index 684a0e77579468c5616dc6493b0f56a0a4732216..a24f774cbe051d4a27020c9054aedd0ced94474f 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -19,7 +19,6 @@ package net.floodlightcontroller.core; import java.util.List; import java.util.Map; -import java.util.concurrent.ScheduledExecutorService; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.packet.Ethernet; @@ -105,14 +104,6 @@ public interface IFloodlightProviderService extends IFloodlightService { */ public Map<OFType, List<IOFMessageListener>> getListeners(); - /** - * Get the master scheduled thread pool executor maintained by the - * floodlight provider. This can be used by other modules as a centralized - * way to schedule tasks. - * @return - */ - public ScheduledExecutorService getScheduledExecutor(); - /** * Terminate the process */ diff --git a/src/main/java/net/floodlightcontroller/core/OFMessageFilterManager.java b/src/main/java/net/floodlightcontroller/core/OFMessageFilterManager.java index e569a8a9a032e8fe6d931400b06a2db07ed612af..de6cbc94fc7560371c55097cabb7719fe4b0619e 100644 --- a/src/main/java/net/floodlightcontroller/core/OFMessageFilterManager.java +++ b/src/main/java/net/floodlightcontroller/core/OFMessageFilterManager.java @@ -54,6 +54,7 @@ import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packetstreamer.thrift.*; +import net.floodlightcontroller.threadpool.IThreadPoolService; public class OFMessageFilterManager implements IOFMessageListener, IFloodlightModule, IOFMessageFilterManagerService { @@ -70,6 +71,7 @@ public class OFMessageFilterManager protected static PacketStreamer.Client packetClient = null; protected IFloodlightProviderService floodlightProvider = null; + protected IThreadPoolService threadPool = null; // filter List is a key value pair. Key is the session id, value is the filter rules. protected ConcurrentHashMap<String, ConcurrentHashMap<String,String>> filterMap = null; protected ConcurrentHashMap<String, Long> filterTimeoutMap = null; @@ -337,7 +339,7 @@ public class OFMessageFilterManager public class TimeoutFilterTask extends TimerTask { OFMessageFilterManager filterManager; - ScheduledExecutorService ses = floodlightProvider.getScheduledExecutor(); + ScheduledExecutorService ses = threadPool.getScheduledExecutor(); public TimeoutFilterTask(OFMessageFilterManager manager) { filterManager = manager; @@ -460,6 +462,7 @@ public class OFMessageFilterManager Collection<Class<? extends IFloodlightService>> l = new ArrayList<Class<? extends IFloodlightService>>(); l.add(IFloodlightProviderService.class); + l.add(IThreadPoolService.class); return l; } @@ -468,6 +471,8 @@ public class OFMessageFilterManager throws FloodlightModuleException { this.floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); + this.threadPool = + context.getServiceImpl(IThreadPoolService.class); } @Override diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index d62a6c1ba533e144a13a312adf0e5ea8521fe8d6..03d1dab539b69ceac3a1730001fd55e00dc34cda 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -43,7 +43,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -67,6 +66,7 @@ import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; +import net.floodlightcontroller.threadpool.IThreadPoolService; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.buffer.ChannelBuffer; @@ -132,7 +132,6 @@ public class Controller implements IFloodlightProviderService, IOFController { protected static Logger log = LoggerFactory.getLogger(Controller.class); - protected ICounterStoreService counterStore = null; protected BasicFactory factory; protected ConcurrentMap<OFType, @@ -150,13 +149,13 @@ public class Controller protected Set<IOFSwitchListener> switchListeners; protected Map<String, List<IInfoProvider>> providerMap; protected BlockingQueue<Update> updates; - protected IRestApiService restApi; - - protected ScheduledExecutorService executor = - Executors.newScheduledThreadPool(5); + // Module dependencies + protected IRestApiService restApi; + protected ICounterStoreService counterStore = null; protected IStorageSourceService storageSource; protected IPktInProcessingTimeService pktinProcTime; + protected IThreadPoolService threadPool; // Configuration options protected int openFlowPort = 6633; @@ -230,6 +229,10 @@ public class Controller public void setRestApiService(IRestApiService restApi) { this.restApi = restApi; } + + public void setThreadPoolService(IThreadPoolService tp) { + this.threadPool = tp; + } @Override public synchronized Role getRole() { @@ -349,6 +352,7 @@ public class Controller sw = new OFSwitchImpl(); sw.setChannel(e.getChannel()); sw.setFloodlightProvider(Controller.this); + sw.setThreadPoolService(threadPool); List<OFMessage> msglist = new ArrayList<OFMessage>(1); msglist.add(factory.getMessage(OFType.HELLO)); @@ -1306,11 +1310,6 @@ public class Controller return true; } - @Override - public ScheduledExecutorService getScheduledExecutor() { - return executor; - } - @Override public synchronized void terminate() { log.info("Calling System.exit"); diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFMessageFuture.java b/src/main/java/net/floodlightcontroller/core/internal/OFMessageFuture.java index 9f8b30e141ae0b915f006fad251a1bb8bc1fa724..c24ed5bd34cc7106e38366e7a7dd72544a658f89 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFMessageFuture.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFMessageFuture.java @@ -30,6 +30,7 @@ import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IOFSwitchFilter; import net.floodlightcontroller.core.IOFSwitchListener; +import net.floodlightcontroller.threadpool.IThreadPoolService; /** * A Future object used to retrieve asynchronous OFMessage replies. Unregisters @@ -43,6 +44,7 @@ public abstract class OFMessageFuture<T,V> implements Future<V>, IOFSwitchFilter, IOFSwitchListener { protected IFloodlightProviderService floodlightProvider; + protected IThreadPoolService threadPool; protected volatile boolean canceled; protected CountDownLatch latch; protected OFType responseType; @@ -51,14 +53,15 @@ public abstract class OFMessageFuture<T,V> implements Future<V>, protected Runnable timeoutTimer; protected int transactionId; - public OFMessageFuture(IFloodlightProviderService floodlightProvider, IOFSwitch sw, - OFType responseType, int transactionId) { - this(floodlightProvider, sw, responseType, transactionId, 60, TimeUnit.SECONDS); + public OFMessageFuture(IFloodlightProviderService floodlightProvider, IThreadPoolService tp, + IOFSwitch sw, OFType responseType, int transactionId) { + this(floodlightProvider, tp, sw, responseType, transactionId, 60, TimeUnit.SECONDS); } - public OFMessageFuture(IFloodlightProviderService floodlightProvider, IOFSwitch sw, - OFType responseType, int transactionId, long timeout, TimeUnit unit) { + public OFMessageFuture(IFloodlightProviderService floodlightProvider, IThreadPoolService tp, + IOFSwitch sw, OFType responseType, int transactionId, long timeout, TimeUnit unit) { this.floodlightProvider = floodlightProvider; + this.threadPool = tp; this.canceled = false; this.latch = new CountDownLatch(1); this.responseType = responseType; @@ -73,7 +76,7 @@ public abstract class OFMessageFuture<T,V> implements Future<V>, future.cancel(true); } }; - floodlightProvider.getScheduledExecutor().schedule(timeoutTimer, timeout, unit); + threadPool.getScheduledExecutor().schedule(timeoutTimer, timeout, unit); } protected void unRegister() { diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFStatisticsFuture.java b/src/main/java/net/floodlightcontroller/core/internal/OFStatisticsFuture.java index 306d38eeabb4e7f91219cb829fb909826a17a489..525adcad97f7a3888263e943c99c3e1f75235aaf 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFStatisticsFuture.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFStatisticsFuture.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; +import net.floodlightcontroller.threadpool.IThreadPoolService; import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFStatisticsReply; @@ -40,15 +41,15 @@ public class OFStatisticsFuture extends protected volatile boolean finished; - public OFStatisticsFuture(IFloodlightProviderService floodlightProvider, IOFSwitch sw, - int transactionId) { - super(floodlightProvider, sw, OFType.STATS_REPLY, transactionId); + public OFStatisticsFuture(IFloodlightProviderService floodlightProvider, IThreadPoolService tp, + IOFSwitch sw, int transactionId) { + super(floodlightProvider, tp, sw, OFType.STATS_REPLY, transactionId); init(); } - public OFStatisticsFuture(IFloodlightProviderService floodlightProvider, IOFSwitch sw, - int transactionId, long timeout, TimeUnit unit) { - super(floodlightProvider, sw, OFType.STATS_REPLY, transactionId, timeout, unit); + public OFStatisticsFuture(IFloodlightProviderService floodlightProvider, IThreadPoolService tp, + IOFSwitch sw, int transactionId, long timeout, TimeUnit unit) { + super(floodlightProvider, tp, sw, OFType.STATS_REPLY, transactionId, timeout, unit); init(); } diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index 46233ca5c3a1716bbeffe9421475813375d6a159..9aaf1fbf60cc1262eeff2ff557c49aecc2100d29 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -36,6 +36,7 @@ import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IFloodlightProviderService.Role; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.types.MacVlanPair; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.util.TimedCache; import org.jboss.netty.channel.Channel; @@ -66,6 +67,7 @@ public class OFSwitchImpl implements IOFSwitch { protected ConcurrentMap<Object, Object> attributes; protected IFloodlightProviderService floodlightProvider; + protected IThreadPoolService threadPool; protected Date connectedSince; protected OFFeaturesReply featuresReply; protected String stringId; @@ -310,7 +312,7 @@ public class OFSwitchImpl implements IOFSwitch { @Override public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request) throws IOException { request.setXid(getNextTransactionId()); - OFStatisticsFuture future = new OFStatisticsFuture(floodlightProvider, this, request.getXid()); + OFStatisticsFuture future = new OFStatisticsFuture(floodlightProvider, threadPool, this, request.getXid()); this.statsFutureMap.put(request.getXid(), future); this.floodlightProvider.addOFSwitchListener(future); List<OFMessage> msglist = new ArrayList<OFMessage>(1); @@ -348,6 +350,10 @@ public class OFSwitchImpl implements IOFSwitch { public void setFloodlightProvider(IFloodlightProviderService floodlightProvider) { this.floodlightProvider = floodlightProvider; } + + public void setThreadPoolService(IThreadPoolService tp) { + this.threadPool = tp; + } @Override public synchronized void addToPortMap(Long mac, Short vlan, short portVal) { diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index d718c2f9fb23fbb2b648c5d764b64a68de9ba271..50fe564923b01cde283173cd1d7490bda5916ba1 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -60,16 +60,15 @@ import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryListener; import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; import net.floodlightcontroller.linkdiscovery.SwitchPortTuple; import net.floodlightcontroller.packet.ARP; -import net.floodlightcontroller.packet.DHCP; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.IPv4; -import net.floodlightcontroller.packet.UDP; import net.floodlightcontroller.routing.ForwardingBase; import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IStorageSourceListener; import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.util.EventHistory; import net.floodlightcontroller.util.EventHistory.EvAction; @@ -631,6 +630,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe protected ILinkDiscoveryService linkDiscovery; protected ITopologyService topology; protected IStorageSourceService storageSource; + protected IThreadPoolService threadPool; protected Runnable deviceAgingTimer; protected SingletonTask deviceUpdateTask; @@ -1929,12 +1929,12 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe if (deviceAgingTimer != null) { ScheduledExecutorService ses = - floodlightProvider.getScheduledExecutor(); + threadPool.getScheduledExecutor(); ses.schedule(this, DEVICE_AGING_TIMER, TimeUnit.MINUTES); } } }; - floodlightProvider.getScheduledExecutor().schedule( + threadPool.getScheduledExecutor().schedule( deviceAgingTimer, DEVICE_AGING_TIMER_INTERVAL, TimeUnit.SECONDS); } @@ -2105,6 +2105,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe l.add(ITopologyService.class); l.add(ILinkDiscoveryService.class); l.add(IStorageSourceService.class); + l.add(IThreadPoolService.class); return l; } @@ -2120,6 +2121,8 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe context.getServiceImpl(ILinkDiscoveryService.class); storageSource = context.getServiceImpl(IStorageSourceService.class); + threadPool = + context.getServiceImpl(IThreadPoolService.class); // We create this here because there is no ordering guarantee this.deviceManagerAware = new HashSet<IDeviceManagerAware>(); @@ -2159,7 +2162,7 @@ public class DeviceManagerImpl implements IDeviceManagerService, IOFMessageListe PORT_CHANNEL_TABLE_NAME, PC_ID_COLUMN_NAME); storageSource.addListener(PORT_CHANNEL_TABLE_NAME, this); - ScheduledExecutorService ses = floodlightProvider.getScheduledExecutor(); + ScheduledExecutorService ses = threadPool.getScheduledExecutor(); deviceUpdateTask = new SingletonTask(ses, new DeviceUpdateWorker()); // Register for the OpenFlow messages we want diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java index 158ada191e7ca7d31869cf3dccb6cf0544fdbf82..b4e21cfd0cf17620842fd2c6f49a6d46b7f2ef67 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java @@ -72,6 +72,7 @@ import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.IStorageSourceListener; import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.web.TopologyWebRoutable; import net.floodlightcontroller.util.EventHistory; @@ -141,6 +142,7 @@ public class LinkDiscoveryManager protected IStorageSourceService storageSource; protected IRoutingService routingEngine; protected IRestApiService restApi; + protected IThreadPoolService threadPool; private static final String LLDP_STANDARD_DST_MAC_STRING = "01:80:c2:00:00:00"; // BigSwitch OUI is 5C:16:C7, so 5D:16:C7 is the multicast version @@ -1300,6 +1302,7 @@ public class LinkDiscoveryManager l.add(IStorageSourceService.class); l.add(IRoutingService.class); l.add(IRestApiService.class); + l.add(IThreadPoolService.class); return l; } @@ -1310,6 +1313,7 @@ public class LinkDiscoveryManager storageSource = context.getServiceImpl(IStorageSourceService.class); routingEngine = context.getServiceImpl(IRoutingService.class); restApi = context.getServiceImpl(IRestApiService.class); + threadPool = context.getServiceImpl(IThreadPoolService.class); // We create this here because there is no ordering guarantee this.topologyAware = new ArrayList<ITopologyListener>(); @@ -1342,7 +1346,7 @@ public class LinkDiscoveryManager log.error("Error in installing listener for switch table - {}", SWITCH_TABLE_NAME); } - ScheduledExecutorService ses = floodlightProvider.getScheduledExecutor(); + ScheduledExecutorService ses = threadPool.getScheduledExecutor(); // Setup sending out LLDPs Runnable lldpSendTimer = new Runnable() { @@ -1353,7 +1357,7 @@ public class LinkDiscoveryManager if (!shuttingDown) { ScheduledExecutorService ses = - floodlightProvider.getScheduledExecutor(); + threadPool.getScheduledExecutor(); ses.schedule(this, lldpFrequency, TimeUnit.MILLISECONDS); } @@ -1376,7 +1380,7 @@ public class LinkDiscoveryManager timeoutLinks(); if (!shuttingDown) { ScheduledExecutorService ses = - floodlightProvider.getScheduledExecutor(); + threadPool.getScheduledExecutor(); ses.schedule(this, lldpTimeout, TimeUnit.MILLISECONDS); } } catch (StorageException e) { diff --git a/src/main/java/net/floodlightcontroller/threadpool/IThreadPoolService.java b/src/main/java/net/floodlightcontroller/threadpool/IThreadPoolService.java new file mode 100644 index 0000000000000000000000000000000000000000..a537a3a7a3d40e52696de0fe3ce916d4dce92686 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/threadpool/IThreadPoolService.java @@ -0,0 +1,15 @@ +package net.floodlightcontroller.threadpool; + +import java.util.concurrent.ScheduledExecutorService; + +import net.floodlightcontroller.core.module.IFloodlightService; + +public interface IThreadPoolService extends IFloodlightService { + /** + * Get the master scheduled thread pool executor maintained by the + * ThreadPool provider. This can be used by other modules as a centralized + * way to schedule tasks. + * @return + */ + public ScheduledExecutorService getScheduledExecutor(); +} diff --git a/src/main/java/net/floodlightcontroller/threadpool/ThreadPool.java b/src/main/java/net/floodlightcontroller/threadpool/ThreadPool.java new file mode 100644 index 0000000000000000000000000000000000000000..aa426a73fcd40df448bdb60d64e7ddcd8fdf894a --- /dev/null +++ b/src/main/java/net/floodlightcontroller/threadpool/ThreadPool.java @@ -0,0 +1,64 @@ +package net.floodlightcontroller.threadpool; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.FloodlightModuleException; +import net.floodlightcontroller.core.module.IFloodlightModule; +import net.floodlightcontroller.core.module.IFloodlightService; + +public class ThreadPool implements IThreadPoolService, IFloodlightModule { + protected ScheduledExecutorService executor = null; + + // IThreadPoolService + + @Override + public ScheduledExecutorService getScheduledExecutor() { + return executor; + } + + // IFloodlightModule + + @Override + public Collection<Class<? extends IFloodlightService>> getModuleServices() { + Collection<Class<? extends IFloodlightService>> l = + new ArrayList<Class<? extends IFloodlightService>>(); + l.add(IThreadPoolService.class); + return l; + } + + @Override + public Map<Class<? extends IFloodlightService>, IFloodlightService> + getServiceImpls() { + Map<Class<? extends IFloodlightService>, + IFloodlightService> m = + new HashMap<Class<? extends IFloodlightService>, + IFloodlightService>(); + m.put(IThreadPoolService.class, this); + // We are the class that implements the service + return m; + } + + @Override + public Collection<Class<? extends IFloodlightService>> + getModuleDependencies() { + // No dependencies + return null; + } + + @Override + public void init(FloodlightModuleContext context) + throws FloodlightModuleException { + executor = Executors.newScheduledThreadPool(15); + } + + @Override + public void startUp(FloodlightModuleContext context) { + // no-op + } +} diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java index e36d08df2001fd4e6a7187017fd46f7aacbdb1ad..c856d0d18650df0b53eb697da19cba53e22ed058 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java @@ -11,7 +11,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; @@ -23,6 +22,7 @@ import net.floodlightcontroller.routing.BroadcastTree; import net.floodlightcontroller.routing.IRoutingService; import net.floodlightcontroller.routing.Link; import net.floodlightcontroller.routing.Route; +import net.floodlightcontroller.threadpool.IThreadPoolService; import org.openflow.protocol.OFPhysicalPort.OFPortState; @@ -46,7 +46,7 @@ IRoutingService, ILinkDiscoveryListener { protected Map<NodePortTuple, Set<Link>> tunnelLinks; // set of tunnel links protected ILinkDiscoveryService linkDiscovery; protected ArrayList<ITopologyListener> topologyAware; - protected IFloodlightProviderService floodlightProvider; + protected IThreadPoolService threadPool; protected BlockingQueue<LDUpdate> ldUpdates; protected TopologyInstance currentInstance; @@ -309,29 +309,30 @@ IRoutingService, ILinkDiscoveryListener { getModuleDependencies() { Collection<Class<? extends IFloodlightService>> l = new ArrayList<Class<? extends IFloodlightService>>(); - l.add(IFloodlightProviderService.class); l.add(ILinkDiscoveryService.class); + l.add(IThreadPoolService.class); return l; } @Override public void init(FloodlightModuleContext context) throws FloodlightModuleException { - floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); + threadPool = context.getServiceImpl(IThreadPoolService.class); + switchPorts = new HashMap<Long,Set<Short>>(); switchPortLinks = new HashMap<NodePortTuple, Set<Link>>(); portBroadcastDomainLinks = new HashMap<NodePortTuple, Set<Link>>(); tunnelLinks = new HashMap<NodePortTuple, Set<Link>>(); topologyAware = new ArrayList<ITopologyListener>(); ldUpdates = new LinkedBlockingQueue<LDUpdate>(); - ScheduledExecutorService ses = floodlightProvider.getScheduledExecutor(); + + ScheduledExecutorService ses = threadPool.getScheduledExecutor(); newInstanceTask = new SingletonTask(ses, new NewInstanceWorker()); } @Override public void startUp(FloodlightModuleContext context) { - // TODO Auto-generated method stub linkDiscovery.addListener(this); newInstanceTask.reschedule(1, TimeUnit.MILLISECONDS); } diff --git a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule index 21df0f4bcbc2d595a2ae9e12ab4957bf126dbc25..71f93e28124c9f17bd5426b9ac817b232786e992 100644 --- a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule +++ b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule @@ -13,4 +13,5 @@ net.floodlightcontroller.learningswitch.LearningSwitch net.floodlightcontroller.hub.Hub net.floodlightcontroller.jython.JythonDebugInterface net.floodlightcontroller.counter.CounterStore -net.floodlightcontroller.counter.NullCounterStore \ No newline at end of file +net.floodlightcontroller.counter.NullCounterStore +net.floodlightcontroller.threadpool.ThreadPool \ No newline at end of file diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 5c010a1b68d6ac9513ac60936e37769909705ac2..58b92ea9bf97b6d58cd8283654383f1a10d34b59 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -38,6 +38,7 @@ import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.OFMessageFilterManager; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.test.MockFloodlightProvider; +import net.floodlightcontroller.core.test.MockThreadPoolService; import net.floodlightcontroller.counter.CounterStore; import net.floodlightcontroller.counter.ICounterStoreService; import net.floodlightcontroller.packet.ARP; @@ -51,6 +52,7 @@ import net.floodlightcontroller.restserver.RestApiServer; import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.test.FloodlightTestCase; +import net.floodlightcontroller.threadpool.IThreadPoolService; import org.jboss.netty.channel.Channel; import org.junit.Test; @@ -75,6 +77,7 @@ import org.openflow.protocol.statistics.OFStatisticsType; */ public class ControllerTest extends FloodlightTestCase { private Controller controller; + private MockThreadPoolService tp; @Override public void setUp() throws Exception { @@ -97,14 +100,19 @@ public class ControllerTest extends FloodlightTestCase { PktInProcessingTime ppt = new PktInProcessingTime(); fmc.addService(IPktInProcessingTimeService.class, ppt); + tp = new MockThreadPoolService(); + fmc.addService(IThreadPoolService.class, tp); + ppt.init(fmc); restApi.init(fmc); memstorage.init(fmc); cm.init(fmc); + tp.init(fmc); ppt.startUp(fmc); restApi.startUp(fmc); memstorage.startUp(fmc); cm.startUp(fmc); + tp.startUp(fmc); } public Controller getController() { @@ -240,7 +248,7 @@ public class ControllerTest extends FloodlightTestCase { MockFloodlightProvider mbp = new MockFloodlightProvider(); IOFSwitch sw = createMock(IOFSwitch.class); sw.cancelStatisticsReply(1); - OFStatisticsFuture sf = new OFStatisticsFuture(mbp, sw, 1); + OFStatisticsFuture sf = new OFStatisticsFuture(mbp, tp, sw, 1); mbp.addOFSwitchListener(sf); replay(sw); @@ -260,7 +268,7 @@ public class ControllerTest extends FloodlightTestCase { reset(sw); sw.cancelStatisticsReply(1); - sf = new OFStatisticsFuture(mbp, sw, 1); + sf = new OFStatisticsFuture(mbp, tp, sw, 1); mbp.addOFSwitchListener(sf); replay(sw); @@ -279,7 +287,7 @@ public class ControllerTest extends FloodlightTestCase { // Test cancellation reset(sw); sw.cancelStatisticsReply(1); - sf = new OFStatisticsFuture(mbp, sw, 1); + sf = new OFStatisticsFuture(mbp, tp, sw, 1); mbp.addOFSwitchListener(sf); replay(sw); @@ -297,7 +305,7 @@ public class ControllerTest extends FloodlightTestCase { // Test self timeout reset(sw); sw.cancelStatisticsReply(1); - sf = new OFStatisticsFuture(mbp, sw, 1, 1, TimeUnit.SECONDS); + sf = new OFStatisticsFuture(mbp, tp, sw, 1, 1, TimeUnit.SECONDS); mbp.addOFSwitchListener(sf); replay(sw); @@ -317,8 +325,10 @@ public class ControllerTest extends FloodlightTestCase { FloodlightModuleContext fmCntx = new FloodlightModuleContext(); MockFloodlightProvider mfp = new MockFloodlightProvider(); OFMessageFilterManager mfm = new OFMessageFilterManager(); + MockThreadPoolService mtp = new MockThreadPoolService(); fmCntx.addService(IOFMessageFilterManagerService.class, mfm); fmCntx.addService(IFloodlightProviderService.class, mfp); + fmCntx.addService(IThreadPoolService.class, mtp); String sid = null; diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index ea885554c4f00f60fc6c774dfad56cb7f6842940..e903c5ea3f7e613c22648c7e005b416ab3bd27a8 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ScheduledExecutorService; import net.floodlightcontroller.core.FloodlightContext; import net.floodlightcontroller.core.IFloodlightProviderService; @@ -54,9 +53,6 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro protected List<IOFSwitchListener> switchListeners; protected Map<Long, IOFSwitch> switches; protected BasicFactory factory; - - protected ScheduledExecutorService mockExecutor = - new MockScheduledExecutor(); /** * @@ -175,15 +171,6 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro public void terminate() { } - /** - * Return a mock executor that will simply execute each task - * synchronously once. - */ - @Override - public ScheduledExecutorService getScheduledExecutor() { - return mockExecutor; - } - @Override public boolean injectOfMessage(IOFSwitch sw, OFMessage msg) { dispatchMessage(sw, msg); diff --git a/src/test/java/net/floodlightcontroller/core/test/MockThreadPoolService.java b/src/test/java/net/floodlightcontroller/core/test/MockThreadPoolService.java new file mode 100644 index 0000000000000000000000000000000000000000..67bee3048fd22d3856fdc7263cedec4409e78217 --- /dev/null +++ b/src/test/java/net/floodlightcontroller/core/test/MockThreadPoolService.java @@ -0,0 +1,67 @@ +package net.floodlightcontroller.core.test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ScheduledExecutorService; + +import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.module.FloodlightModuleException; +import net.floodlightcontroller.core.module.IFloodlightModule; +import net.floodlightcontroller.core.module.IFloodlightService; +import net.floodlightcontroller.threadpool.IThreadPoolService; + +public class MockThreadPoolService implements IFloodlightModule, IThreadPoolService { + + protected ScheduledExecutorService mockExecutor = new MockScheduledExecutor(); + + /** + * Return a mock executor that will simply execute each task + * synchronously once. + */ + @Override + public ScheduledExecutorService getScheduledExecutor() { + return mockExecutor; + } + + // IFloodlightModule + + @Override + public Collection<Class<? extends IFloodlightService>> getModuleServices() { + Collection<Class<? extends IFloodlightService>> l = + new ArrayList<Class<? extends IFloodlightService>>(); + l.add(IThreadPoolService.class); + return l; + } + + @Override + public Map<Class<? extends IFloodlightService>, IFloodlightService> + getServiceImpls() { + Map<Class<? extends IFloodlightService>, + IFloodlightService> m = + new HashMap<Class<? extends IFloodlightService>, + IFloodlightService>(); + m.put(IThreadPoolService.class, this); + // We are the class that implements the service + return m; + } + + @Override + public Collection<Class<? extends IFloodlightService>> + getModuleDependencies() { + // No dependencies + return null; + } + + @Override + public void init(FloodlightModuleContext context) + throws FloodlightModuleException { + } + + @Override + public void startUp(FloodlightModuleContext context) { + // no-op + } + +} diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index 759494ad5dbc53a6781b056db890e181127db97c..19f5e8b2fdae298b65c0e067baa47e650c917579 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -32,6 +32,7 @@ import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.test.MockFloodlightProvider; +import net.floodlightcontroller.core.test.MockThreadPoolService; import net.floodlightcontroller.devicemanager.Device; import net.floodlightcontroller.devicemanager.DeviceAttachmentPoint; import net.floodlightcontroller.devicemanager.IDeviceManagerService; @@ -45,6 +46,7 @@ import net.floodlightcontroller.restserver.RestApiServer; import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.test.FloodlightTestCase; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.ITopologyService; import org.junit.Before; @@ -75,6 +77,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase { FloodlightModuleContext fmc = new FloodlightModuleContext(); RestApiServer restApi = new RestApiServer(); + MockThreadPoolService tp = new MockThreadPoolService(); + fmc.addService(IThreadPoolService.class, tp); mockFloodlightProvider = getMockFloodlightProvider(); deviceManager = new DeviceManagerImpl(); fmc.addService(IDeviceManagerService.class, deviceManager); @@ -82,11 +86,13 @@ public class DeviceManagerImplTest extends FloodlightTestCase { fmc.addService(IStorageSourceService.class, storageSource); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); fmc.addService(IRestApiService.class, restApi); + tp.init(fmc); restApi.init(fmc); storageSource.init(fmc); deviceManager.init(fmc); storageSource.startUp(fmc); deviceManager.startUp(fmc); + tp.startUp(fmc); // Build our test packet this.testARPReplyPacket_1 = new Ethernet() diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java index 2c727a34599c1b6ec3687455349687626e14f17f..c46889e4896e90d9d32af111f8d4e3b05be4c4b5 100644 --- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java +++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java @@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.module.FloodlightModuleContext; +import net.floodlightcontroller.core.test.MockThreadPoolService; import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryListener; import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; import net.floodlightcontroller.linkdiscovery.LinkInfo; @@ -40,6 +41,7 @@ import net.floodlightcontroller.routing.IRoutingService; import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.memory.MemoryStorageSource; import net.floodlightcontroller.test.FloodlightTestCase; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.ITopologyListener; import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.TopologyManager; @@ -71,13 +73,17 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase { TopologyManager routingEngine = new TopologyManager(); topology.topologyAware = new ArrayList<ITopologyListener>(); topology.linkDiscoveryAware = new ArrayList<ILinkDiscoveryListener>(); + MockThreadPoolService tp = new MockThreadPoolService(); + cntx.addService(IThreadPoolService.class, tp); cntx.addService(IRoutingService.class, routingEngine); cntx.addService(ILinkDiscoveryService.class, topology); cntx.addService(ITopologyService.class, topology); cntx.addService(IStorageSourceService.class, new MemoryStorageSource()); cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); + tp.init(cntx); routingEngine.init(cntx); topology.init(cntx); + tp.startUp(cntx); routingEngine.startUp(cntx); topology.startUp(cntx); } diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java index 0092125d3117bac691dcbe33cd4b5016740b4b07..be2d226749fe08529846b5569798a351541b5bbc 100644 --- a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java +++ b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java @@ -10,7 +10,9 @@ import static org.junit.Assert.*; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.test.MockFloodlightProvider; +import net.floodlightcontroller.core.test.MockThreadPoolService; import net.floodlightcontroller.linkdiscovery.ILinkDiscovery; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.NodePortTuple; import net.floodlightcontroller.topology.TopologyInstance; import net.floodlightcontroller.topology.TopologyManager; @@ -35,8 +37,12 @@ public class TopologyInstanceTest { fmc = new FloodlightModuleContext(); mockFloodlightProvider = new MockFloodlightProvider(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); + MockThreadPoolService tp = new MockThreadPoolService(); topologyManager = new TopologyManager(); + fmc.addService(IThreadPoolService.class, tp); topologyManager.init(fmc); + tp.init(fmc); + tp.startUp(fmc); } protected void verifyClusters(int[][] clusters) { diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java index 2d367d3a8e46d3453ed9d90eb64b863a16bf9a56..816eadea8ec7ba08b85c0f2ce5c401d7385cf04e 100644 --- a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java +++ b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java @@ -4,7 +4,9 @@ import static org.junit.Assert.*; import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.module.FloodlightModuleContext; import net.floodlightcontroller.core.test.MockFloodlightProvider; +import net.floodlightcontroller.core.test.MockThreadPoolService; import net.floodlightcontroller.linkdiscovery.ILinkDiscovery; +import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.TopologyManager; import org.junit.Before; @@ -23,8 +25,12 @@ public class TopologyManagerTest { mockFloodlightProvider = new MockFloodlightProvider(); fmc = new FloodlightModuleContext(); fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider); + MockThreadPoolService tp = new MockThreadPoolService(); + fmc.addService(IThreadPoolService.class, tp); topologyManager = new TopologyManager(); + tp.init(fmc); topologyManager.init(fmc); + tp.startUp(fmc); } public TopologyManager getTopologyManager() {