HIGUCHI Yuta | 155cfc5 | 2013-06-14 15:54:16 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.floodlightlistener; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.Map; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 6 | import java.util.concurrent.ScheduledExecutorService; |
| 7 | import java.util.concurrent.TimeUnit; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 8 | |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 9 | import org.openflow.protocol.OFPhysicalPort; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 10 | import org.openflow.util.HexString; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | |
| 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 15 | import net.floodlightcontroller.core.IOFSwitch; |
| 16 | import net.floodlightcontroller.core.IOFSwitchListener; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 17 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 18 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 19 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 20 | import net.floodlightcontroller.core.module.IFloodlightService; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 21 | import net.floodlightcontroller.core.util.SingletonTask; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 22 | import net.floodlightcontroller.devicemanager.IDevice; |
| 23 | import net.floodlightcontroller.devicemanager.IDeviceListener; |
| 24 | import net.floodlightcontroller.devicemanager.IDeviceService; |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 25 | import net.floodlightcontroller.routing.Link; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 26 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 27 | import net.onrc.onos.graph.DBOperation; |
| 28 | import net.onrc.onos.graph.DBConnection; |
| 29 | import net.onrc.onos.graph.GraphDBManager; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 30 | import net.onrc.onos.graph.IDBConnection; |
| 31 | import net.onrc.onos.graph.LocalTopologyEventListener; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 32 | import net.onrc.onos.ofcontroller.core.IDeviceStorage; |
| 33 | import net.onrc.onos.ofcontroller.core.ILinkStorage; |
HIGUCHI Yuta | 36cf076 | 2013-06-14 14:25:38 -0700 | [diff] [blame] | 34 | import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 35 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
| 36 | import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 37 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 38 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 39 | import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl; |
| 40 | import net.onrc.onos.ofcontroller.core.internal.LinkStorageImpl; |
HIGUCHI Yuta | ed49ef7 | 2013-06-12 11:34:10 -0700 | [diff] [blame] | 41 | import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 42 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener; |
| 43 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 44 | import net.onrc.onos.registry.controller.IControllerRegistryService; |
| 45 | import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback; |
| 46 | import net.onrc.onos.registry.controller.RegistryException; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 47 | |
HIGUCHI Yuta | 155cfc5 | 2013-06-14 15:54:16 -0700 | [diff] [blame] | 48 | public class NetworkGraphPublisher implements IDeviceListener, IOFSwitchListener, IOFSwitchPortListener, |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 49 | ILinkDiscoveryListener, IFloodlightModule { |
| 50 | |
| 51 | protected IDeviceStorage devStore; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 52 | protected ISwitchStorage swStore; |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 53 | protected ILinkStorage linkStore; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 54 | protected static Logger log; |
| 55 | protected IDeviceService deviceService; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 56 | protected IControllerRegistryService registryService; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 57 | protected DBOperation op; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 58 | |
| 59 | protected static final String DBConfigFile = "dbconf"; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 60 | protected static final String GraphDBStore = "graph_db_store"; |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 61 | protected static final String CleanupEnabled = "EnableCleanup"; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 62 | protected IThreadPoolService threadPool; |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 63 | protected IFloodlightProviderService floodlightProvider; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 64 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 65 | protected final int CLEANUP_TASK_INTERVAL = 60; // 1 min |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 66 | protected SingletonTask cleanupTask; |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 67 | protected ILinkDiscoveryService linkDiscovery; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Cleanup and synch switch state from registry |
| 71 | */ |
| 72 | protected class SwitchCleanup implements ControlChangeCallback, Runnable { |
| 73 | @Override |
| 74 | public void run() { |
| 75 | try { |
| 76 | log.debug("Running cleanup thread"); |
| 77 | switchCleanup(); |
| 78 | } |
| 79 | catch (Exception e) { |
| 80 | log.error("Error in cleanup thread", e); |
| 81 | } finally { |
Toshio Koide | 70ba38b | 2013-06-13 14:05:05 -0700 | [diff] [blame] | 82 | op.close(); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 83 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 84 | TimeUnit.SECONDS); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void controlChanged(long dpid, boolean hasControl) { |
| 90 | // TODO Auto-generated method stub |
| 91 | |
| 92 | if (hasControl) { |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 93 | log.debug("got control to set inactive sw {}", HexString.toHexString(dpid)); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 94 | swStore.update(HexString.toHexString(dpid),SwitchState.INACTIVE, DM_OPERATION.UPDATE); |
| 95 | registryService.releaseControl(dpid); |
| 96 | } |
| 97 | } |
| 98 | } |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 99 | |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 100 | protected void switchCleanup() { |
Toshio Koide | 70ba38b | 2013-06-13 14:05:05 -0700 | [diff] [blame] | 101 | op.close(); |
| 102 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Jonathan Hart | f02a093 | 2013-03-18 18:30:48 -0700 | [diff] [blame] | 103 | |
| 104 | log.debug("Checking for inactive switches"); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 105 | // For each switch check if a controller exists in controller registry |
| 106 | for (ISwitchObject sw: switches) { |
Jonathan Hart | f02a093 | 2013-03-18 18:30:48 -0700 | [diff] [blame] | 107 | //log.debug("checking if switch is inactive: {}", sw.getDPID()); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 108 | try { |
| 109 | long dpid = HexString.toLong(sw.getDPID()); |
| 110 | String controller = registryService.getControllerForSwitch(dpid); |
| 111 | if (controller == null) { |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 112 | log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid)); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 113 | registryService.requestControl(dpid, new SwitchCleanup()); |
Umesh Krishnaswamy | 255b988 | 2013-04-02 19:55:43 -0700 | [diff] [blame] | 114 | //} else { |
| 115 | // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 116 | } |
| 117 | } catch (NumberFormatException e) { |
| 118 | // TODO Auto-generated catch block |
| 119 | e.printStackTrace(); |
| 120 | } catch (RegistryException e) { |
Jonathan Hart | 4baf3be | 2013-03-21 18:26:13 -0700 | [diff] [blame] | 121 | log.debug("Caught RegistryException trying to requestControl in cleanup thread"); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 122 | e.printStackTrace(); |
| 123 | } |
| 124 | } |
Toshio Koide | 70ba38b | 2013-06-13 14:05:05 -0700 | [diff] [blame] | 125 | op.close(); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 126 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 127 | |
| 128 | @Override |
| 129 | public void linkDiscoveryUpdate(LDUpdate update) { |
| 130 | // TODO Auto-generated method stub |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 131 | Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort()); |
Jonathan Hart | e7c2d2f | 2013-07-27 18:08:34 +1200 | [diff] [blame] | 132 | //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 133 | |
Jonathan Hart | e7c2d2f | 2013-07-27 18:08:34 +1200 | [diff] [blame] | 134 | switch (update.getOperation()) { |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 135 | case LINK_REMOVED: |
Jonathan Hart | e7c2d2f | 2013-07-27 18:08:34 +1200 | [diff] [blame] | 136 | log.debug("LinkDiscoveryUpdate(): Removing link {}", lt); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 137 | linkStore.update(lt, DM_OPERATION.DELETE); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 138 | // TODO: Move network map link removal here |
| 139 | // reconcile paths here |
| 140 | // IPortObject srcPort = conn.utils().searchPort(conn, HexString.toHexString(update.getSrc()), update.getSrcPort()); |
| 141 | break; |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 142 | case LINK_UPDATED: |
Jonathan Hart | e7c2d2f | 2013-07-27 18:08:34 +1200 | [diff] [blame] | 143 | log.debug("LinkDiscoveryUpdate(): Updating link {}", lt); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 144 | linkStore.update(lt, DM_OPERATION.UPDATE); |
| 145 | break; |
| 146 | case LINK_ADDED: |
Jonathan Hart | e7c2d2f | 2013-07-27 18:08:34 +1200 | [diff] [blame] | 147 | log.debug("LinkDiscoveryUpdate(): Adding link {}", lt); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 148 | linkStore.update(lt, DM_OPERATION.INSERT); |
| 149 | break; |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 150 | |
| 151 | default: |
| 152 | break; |
| 153 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 154 | |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void addedSwitch(IOFSwitch sw) { |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 159 | |
| 160 | if (registryService.hasControl(sw.getId())) { |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 161 | swStore.addSwitch(sw); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 162 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 163 | |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void removedSwitch(IOFSwitch sw) { |
| 168 | // TODO Auto-generated method stub |
| 169 | |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void switchPortChanged(Long switchId) { |
| 174 | // TODO Auto-generated method stub |
| 175 | |
| 176 | } |
| 177 | |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 178 | |
| 179 | @Override |
| 180 | public void switchPortAdded(Long switchId, OFPhysicalPort port) { |
| 181 | // TODO Auto-generated method stub |
| 182 | swStore.addPort(HexString.toHexString(switchId), port); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public void switchPortRemoved(Long switchId, OFPhysicalPort port) { |
| 187 | // TODO Auto-generated method stub |
| 188 | swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber()); |
| 189 | } |
| 190 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 191 | @Override |
| 192 | public String getName() { |
HIGUCHI Yuta | 155cfc5 | 2013-06-14 15:54:16 -0700 | [diff] [blame] | 193 | return "NetworkGraphPublisher"; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void deviceAdded(IDevice device) { |
| 198 | // TODO Auto-generated method stub |
| 199 | log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString()); |
| 200 | devStore.addDevice(device); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void deviceRemoved(IDevice device) { |
| 205 | // TODO Auto-generated method stub |
| 206 | |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void deviceMoved(IDevice device) { |
| 211 | // TODO Auto-generated method stub |
| 212 | devStore.changeDeviceAttachments(device); |
| 213 | |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void deviceIPV4AddrChanged(IDevice device) { |
| 218 | // TODO Auto-generated method stub |
| 219 | devStore.changeDeviceIPv4Address(device); |
| 220 | |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void deviceVlanChanged(IDevice device) { |
| 225 | // TODO Auto-generated method stub |
| 226 | } |
| 227 | |
| 228 | |
| 229 | @Override |
| 230 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 231 | // TODO Auto-generated method stub |
| 232 | return null; |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 237 | // TODO Auto-generated method stub |
| 238 | return null; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 243 | Collection<Class<? extends IFloodlightService>> l = |
| 244 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 245 | l.add(IFloodlightProviderService.class); |
| 246 | l.add(IDeviceService.class); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 247 | l.add(IThreadPoolService.class); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 248 | return l; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void init(FloodlightModuleContext context) |
| 253 | throws FloodlightModuleException { |
| 254 | // TODO Auto-generated method stub |
| 255 | Map<String, String> configMap = context.getConfigParams(this); |
| 256 | String conf = configMap.get(DBConfigFile); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 257 | String dbStore = configMap.get(GraphDBStore); |
| 258 | op = GraphDBManager.getDBOperation(dbStore, conf); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 259 | |
HIGUCHI Yuta | 155cfc5 | 2013-06-14 15:54:16 -0700 | [diff] [blame] | 260 | log = LoggerFactory.getLogger(NetworkGraphPublisher.class); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 261 | floodlightProvider = |
| 262 | context.getServiceImpl(IFloodlightProviderService.class); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 263 | deviceService = context.getServiceImpl(IDeviceService.class); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 264 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 265 | threadPool = context.getServiceImpl(IThreadPoolService.class); |
| 266 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 267 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 268 | devStore = new DeviceStorageImpl(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 269 | devStore.init(dbStore, conf); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 270 | |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 271 | swStore = new SwitchStorageImpl(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 272 | swStore.init(dbStore, conf); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 273 | |
| 274 | linkStore = new LinkStorageImpl(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 275 | linkStore.init(dbStore, conf); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 276 | |
HIGUCHI Yuta | 155cfc5 | 2013-06-14 15:54:16 -0700 | [diff] [blame] | 277 | log.debug("Initializing NetworkGraphPublisher module with {}", conf); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 278 | |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public void startUp(FloodlightModuleContext context) { |
| 283 | // TODO Auto-generated method stub |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 284 | Map<String, String> configMap = context.getConfigParams(this); |
| 285 | String cleanupNeeded = configMap.get(CleanupEnabled); |
| 286 | |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 287 | deviceService.addListener(this); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 288 | floodlightProvider.addOFSwitchListener(this); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 289 | linkDiscovery.addListener(this); |
Pankaj Berde | 9d6b507 | 2013-04-03 11:51:23 -0700 | [diff] [blame] | 290 | |
| 291 | log.debug("Adding EventListener"); |
Toshio Koide | 70ba38b | 2013-06-13 14:05:05 -0700 | [diff] [blame] | 292 | IDBConnection conn = op.getDBConnection(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame^] | 293 | conn.addEventListener(new LocalTopologyEventListener((DBConnection) conn)); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 294 | // Setup the Cleanup task. |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 295 | if (cleanupNeeded == null || !cleanupNeeded.equals("False")) { |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 296 | ScheduledExecutorService ses = threadPool.getScheduledExecutor(); |
| 297 | cleanupTask = new SingletonTask(ses, new SwitchCleanup()); |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 298 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS); |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 299 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | } |