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