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