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