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.TimeUnit; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 7 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 8 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 9 | import net.floodlightcontroller.core.IOFSwitch; |
| 10 | import net.floodlightcontroller.core.IOFSwitchListener; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 11 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 12 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 14 | import net.floodlightcontroller.core.module.IFloodlightService; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.util.SingletonTask; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 17 | import net.onrc.onos.datagrid.IDatagridService; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 18 | import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 19 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener; |
| 20 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 02a59e4 | 2014-03-26 18:50:23 -0700 | [diff] [blame] | 21 | import net.onrc.onos.ofcontroller.linkdiscovery.Link; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 22 | import net.onrc.onos.registry.controller.IControllerRegistryService; |
| 23 | import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 24 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 25 | import org.openflow.protocol.OFPhysicalPort; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
Jonathan Hart | 02a59e4 | 2014-03-26 18:50:23 -0700 | [diff] [blame] | 29 | public class OldNetworkGraphPublisher implements |
Pavlin Radoslavov | 2806940 | 2013-10-18 18:43:11 -0700 | [diff] [blame] | 30 | IOFSwitchListener, |
| 31 | IOFSwitchPortListener, |
| 32 | ILinkDiscoveryListener, |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 33 | IFloodlightModule { |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 34 | |
Pavlin Radoslavov | c0aa4bf | 2014-03-26 18:32:49 -0700 | [diff] [blame] | 35 | protected final static Logger log = LoggerFactory.getLogger(OldNetworkGraphPublisher.class); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 36 | //protected IDeviceService deviceService; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 37 | protected IControllerRegistryService registryService; |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 38 | // protected DBOperation op; |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 39 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 40 | protected static final String DBConfigFile = "dbconf"; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 41 | protected static final String GraphDBStore = "graph_db_store"; |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 42 | protected static final String CleanupEnabled = "EnableCleanup"; |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 43 | protected IThreadPoolService threadPool; |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 44 | protected IFloodlightProviderService floodlightProvider; |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 45 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 46 | protected final int CLEANUP_TASK_INTERVAL = 60; // 1 min |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 47 | protected SingletonTask cleanupTask; |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 48 | protected ILinkDiscoveryService linkDiscovery; |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 49 | |
| 50 | protected IDatagridService datagridService; |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 53 | * Cleanup and synch switch state from registry |
| 54 | */ |
| 55 | protected class SwitchCleanup implements ControlChangeCallback, Runnable { |
| 56 | @Override |
| 57 | public void run() { |
Yuta HIGUCHI | 61509a4 | 2013-12-17 10:41:04 -0800 | [diff] [blame] | 58 | String old = Thread.currentThread().getName(); |
Yuta HIGUCHI | 1412e8c | 2014-01-03 17:19:01 -0800 | [diff] [blame] | 59 | Thread.currentThread().setName("SwitchCleanup@" + old); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 60 | try { |
| 61 | log.debug("Running cleanup thread"); |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 62 | // op = GraphDBManager.getDBOperation(); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 63 | switchCleanup(); |
| 64 | } |
| 65 | catch (Exception e) { |
| 66 | log.error("Error in cleanup thread", e); |
| 67 | } finally { |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 68 | // op.close(); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 69 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 70 | TimeUnit.SECONDS); |
Yuta HIGUCHI | 61509a4 | 2013-12-17 10:41:04 -0800 | [diff] [blame] | 71 | Thread.currentThread().setName(old); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void controlChanged(long dpid, boolean hasControl) { |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 77 | /* |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 78 | if (hasControl) { |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 79 | log.debug("got control to set inactive sw {}", HexString.toHexString(dpid)); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 80 | try { |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 81 | // Get the affected ports |
| 82 | List<Short> ports = swStore.getPorts(HexString.toHexString(dpid)); |
| 83 | // Get the affected links |
| 84 | List<Link> links = linkStore.getLinks(HexString.toHexString(dpid)); |
| 85 | // Get the affected reverse links |
| 86 | List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(dpid)); |
| 87 | links.addAll(reverseLinks); |
| 88 | |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 89 | //if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) { |
| 90 | if (swStore.deactivateSwitch(HexString.toHexString(dpid))) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 91 | registryService.releaseControl(dpid); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 92 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 93 | // TODO publish UPDATE_SWITCH event here |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 94 | // |
| 95 | // NOTE: Here we explicitly send |
| 96 | // notification to remove the |
| 97 | // switch, because it is inactive |
| 98 | // |
| 99 | TopologyElement topologyElement = |
| 100 | new TopologyElement(dpid); |
| 101 | datagridService.notificationSendTopologyElementRemoved(topologyElement); |
| 102 | |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 103 | // Publish: remove the affected ports |
| 104 | for (Short port : ports) { |
| 105 | TopologyElement topologyElementPort = |
| 106 | new TopologyElement(dpid, port); |
| 107 | datagridService.notificationSendTopologyElementRemoved(topologyElementPort); |
| 108 | } |
| 109 | // Publish: remove the affected links |
| 110 | for (Link link : links) { |
| 111 | TopologyElement topologyElementLink = |
| 112 | new TopologyElement(link.getSrc(), |
| 113 | link.getSrcPort(), |
| 114 | link.getDst(), |
| 115 | link.getDstPort()); |
| 116 | datagridService.notificationSendTopologyElementRemoved(topologyElementLink); |
| 117 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 118 | } |
| 119 | } catch (Exception e) { |
| 120 | log.error("Error in SwitchCleanup:controlChanged ", e); |
| 121 | } |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 122 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 123 | */ |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 126 | |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 127 | protected void switchCleanup() { |
Pavlin Radoslavov | 4cf8ee5 | 2014-03-26 18:19:58 -0700 | [diff] [blame] | 128 | /* |
yoshi | 8b972bc | 2013-12-05 17:10:04 -0800 | [diff] [blame] | 129 | //op.close(); |
Pavlin Radoslavov | 4cf8ee5 | 2014-03-26 18:19:58 -0700 | [diff] [blame] | 130 | Iterable<ISwitchObject> switches = op.getActiveSwitches(); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 131 | |
Jonathan Hart | f02a093 | 2013-03-18 18:30:48 -0700 | [diff] [blame] | 132 | log.debug("Checking for inactive switches"); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 133 | // For each switch check if a controller exists in controller registry |
| 134 | for (ISwitchObject sw: switches) { |
Jonathan Hart | f02a093 | 2013-03-18 18:30:48 -0700 | [diff] [blame] | 135 | //log.debug("checking if switch is inactive: {}", sw.getDPID()); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 136 | try { |
| 137 | long dpid = HexString.toLong(sw.getDPID()); |
| 138 | String controller = registryService.getControllerForSwitch(dpid); |
| 139 | if (controller == null) { |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 140 | log.debug("request Control to set inactive sw {}", HexString.toHexString(dpid)); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 141 | registryService.requestControl(dpid, new SwitchCleanup()); |
Umesh Krishnaswamy | 255b988 | 2013-04-02 19:55:43 -0700 | [diff] [blame] | 142 | //} else { |
| 143 | // log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 144 | } |
| 145 | } catch (NumberFormatException e) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 146 | log.debug("Caught NumberFormatException trying to requestControl in cleanup thread"); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 147 | e.printStackTrace(); |
| 148 | } catch (RegistryException e) { |
Jonathan Hart | 4baf3be | 2013-03-21 18:26:13 -0700 | [diff] [blame] | 149 | log.debug("Caught RegistryException trying to requestControl in cleanup thread"); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 150 | e.printStackTrace(); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 151 | } |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 152 | } |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 153 | // op.close(); |
Pavlin Radoslavov | 4cf8ee5 | 2014-03-26 18:19:58 -0700 | [diff] [blame] | 154 | */ |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 155 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 156 | |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 157 | @Override |
| 158 | public void linkDiscoveryUpdate(LDUpdate update) { |
| 159 | Link lt = new Link(update.getSrc(),update.getSrcPort(),update.getDst(),update.getDstPort()); |
| 160 | //log.debug("{}:LinkDicoveryUpdate(): Updating Link {}",this.getClass(), lt); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 161 | |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 162 | switch (update.getOperation()) { |
| 163 | case LINK_REMOVED: |
| 164 | log.debug("LinkDiscoveryUpdate(): Removing link {}", lt); |
| 165 | |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 166 | /* |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 167 | if (linkStore.deleteLink(lt)) { |
| 168 | // TODO publish DELETE_LINK event here |
| 169 | TopologyElement topologyElement = |
| 170 | new TopologyElement(update.getSrc(), |
| 171 | update.getSrcPort(), |
| 172 | update.getDst(), |
| 173 | update.getDstPort()); |
| 174 | datagridService.notificationSendTopologyElementRemoved(topologyElement); |
| 175 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 176 | */ |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 177 | break; |
| 178 | case LINK_UPDATED: |
| 179 | log.debug("LinkDiscoveryUpdate(): Updating link {}", lt); |
| 180 | |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 181 | /* |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 182 | LinkInfo linfo = linkStore.getLinkInfo(lt); |
| 183 | // TODO update "linfo" using portState derived using "update" |
| 184 | if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) { |
| 185 | // TODO publish UPDATE_LINK event here |
| 186 | // |
| 187 | // TODO NOTE: Here we assume that updated |
| 188 | // link is UP. |
| 189 | // |
| 190 | TopologyElement topologyElement = |
| 191 | new TopologyElement(update.getSrc(), |
| 192 | update.getSrcPort(), |
| 193 | update.getDst(), |
| 194 | update.getDstPort()); |
| 195 | datagridService.notificationSendTopologyElementUpdated(topologyElement); |
| 196 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 197 | */ |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 198 | break; |
| 199 | case LINK_ADDED: |
| 200 | log.debug("LinkDiscoveryUpdate(): Adding link {}", lt); |
| 201 | |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 202 | /* |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 203 | if (linkStore.addLink(lt)) { |
| 204 | // TODO publish ADD_LINK event here |
| 205 | TopologyElement topologyElement = |
| 206 | new TopologyElement(update.getSrc(), |
| 207 | update.getSrcPort(), |
| 208 | update.getDst(), |
| 209 | update.getDstPort()); |
| 210 | datagridService.notificationSendTopologyElementAdded(topologyElement); |
| 211 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 212 | */ |
pingping-lin | 0092603 | 2013-12-18 12:13:08 +0800 | [diff] [blame] | 213 | |
| 214 | break; |
| 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 220 | |
| 221 | @Override |
| 222 | public void addedSwitch(IOFSwitch sw) { |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 223 | /* |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 224 | if (registryService.hasControl(sw.getId())) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 225 | if (swStore.addSwitch(sw)) { |
| 226 | // TODO publish ADD_SWITCH event here |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 227 | TopologyElement topologyElement = |
| 228 | new TopologyElement(sw.getId()); |
Pavlin Radoslavov | 649c97d | 2013-11-04 16:00:23 -0800 | [diff] [blame] | 229 | datagridService.notificationSendTopologyElementAdded(topologyElement); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 230 | |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 231 | // Publish: add the ports |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 232 | // TODO: Add only ports that are UP? |
| 233 | for (OFPhysicalPort port : sw.getPorts()) { |
Jonathan Hart | 8a5d097 | 2013-12-04 10:02:44 -0800 | [diff] [blame] | 234 | TopologyElement topologyElementPort = |
| 235 | new TopologyElement(sw.getId(), port.getPortNumber()); |
| 236 | datagridService.notificationSendTopologyElementAdded(topologyElementPort); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 237 | |
Jonathan Hart | 8a5d097 | 2013-12-04 10:02:44 -0800 | [diff] [blame] | 238 | // Allow links to be discovered on this port now that it's |
| 239 | // in the database |
| 240 | linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber()); |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 241 | } |
Pavlin Radoslavov | 649c97d | 2013-11-04 16:00:23 -0800 | [diff] [blame] | 242 | |
Pavlin Radoslavov | 0fe7002 | 2013-11-02 16:13:12 -0700 | [diff] [blame] | 243 | // Add all links that might be connected already |
| 244 | List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId())); |
| 245 | // Add all reverse links as well |
| 246 | List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId())); |
| 247 | links.addAll(reverseLinks); |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 248 | |
| 249 | // Publish: add the links |
Pavlin Radoslavov | 0fe7002 | 2013-11-02 16:13:12 -0700 | [diff] [blame] | 250 | for (Link link : links) { |
| 251 | TopologyElement topologyElementLink = |
| 252 | new TopologyElement(link.getSrc(), |
| 253 | link.getSrcPort(), |
| 254 | link.getDst(), |
| 255 | link.getDstPort()); |
| 256 | datagridService.notificationSendTopologyElementAdded(topologyElementLink); |
| 257 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 258 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 259 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 260 | */ |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void removedSwitch(IOFSwitch sw) { |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 265 | /* |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 266 | if (registryService.hasControl(sw.getId())) { |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 267 | // Get the affected ports |
| 268 | List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId())); |
| 269 | // Get the affected links |
| 270 | List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId())); |
| 271 | // Get the affected reverse links |
| 272 | List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId())); |
| 273 | links.addAll(reverseLinks); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 274 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 275 | if (swStore.deleteSwitch(sw.getStringId())) { |
| 276 | // TODO publish DELETE_SWITCH event here |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 277 | TopologyElement topologyElement = |
| 278 | new TopologyElement(sw.getId()); |
| 279 | datagridService.notificationSendTopologyElementRemoved(topologyElement); |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 280 | |
| 281 | // Publish: remove the affected ports |
| 282 | for (Short port : ports) { |
| 283 | TopologyElement topologyElementPort = |
| 284 | new TopologyElement(sw.getId(), port); |
| 285 | datagridService.notificationSendTopologyElementRemoved(topologyElementPort); |
| 286 | } |
| 287 | // Publish: remove the affected links |
| 288 | for (Link link : links) { |
| 289 | TopologyElement topologyElementLink = |
| 290 | new TopologyElement(link.getSrc(), |
| 291 | link.getSrcPort(), |
| 292 | link.getDst(), |
| 293 | link.getDstPort()); |
| 294 | datagridService.notificationSendTopologyElementRemoved(topologyElementLink); |
| 295 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
Jonathan Hart | adc6389 | 2013-11-08 14:03:55 -0800 | [diff] [blame] | 298 | */ |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void switchPortChanged(Long switchId) { |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 303 | // 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] | 304 | } |
| 305 | |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 306 | |
| 307 | @Override |
| 308 | public void switchPortAdded(Long switchId, OFPhysicalPort port) { |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 309 | /* |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 310 | if (swStore.addPort(HexString.toHexString(switchId), port)) { |
Jonathan Hart | 8a5d097 | 2013-12-04 10:02:44 -0800 | [diff] [blame] | 311 | // Allow links to be discovered on this port now that it's |
| 312 | // in the database |
| 313 | linkDiscovery.RemoveFromSuppressLLDPs(switchId, port.getPortNumber()); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 314 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 315 | // TODO publish ADD_PORT event here |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 316 | TopologyElement topologyElement = |
| 317 | new TopologyElement(switchId, port.getPortNumber()); |
| 318 | datagridService.notificationSendTopologyElementAdded(topologyElement); |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 319 | |
| 320 | // Add all links that might be connected already |
| 321 | List<Link> links = linkStore.getLinks(switchId, port.getPortNumber()); |
| 322 | // Add all reverse links as well |
| 323 | List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber()); |
| 324 | links.addAll(reverseLinks); |
| 325 | |
| 326 | // Publish: add the links |
| 327 | for (Link link : links) { |
| 328 | TopologyElement topologyElementLink = |
| 329 | new TopologyElement(link.getSrc(), |
| 330 | link.getSrcPort(), |
| 331 | link.getDst(), |
| 332 | link.getDstPort()); |
| 333 | datagridService.notificationSendTopologyElementAdded(topologyElementLink); |
| 334 | } |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 335 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 336 | */ |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public void switchPortRemoved(Long switchId, OFPhysicalPort port) { |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 341 | // Remove all links that might be connected already |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 342 | |
| 343 | /* |
Pavlin Radoslavov | e249767 | 2014-01-12 18:03:35 -0800 | [diff] [blame] | 344 | PerformanceMonitor.start("SwitchPortRemoved.DbAccess"); |
| 345 | |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 346 | List<Link> links = linkStore.getLinks(switchId, port.getPortNumber()); |
| 347 | // Remove all reverse links as well |
| 348 | List<Link> reverseLinks = linkStore.getReverseLinks(switchId, port.getPortNumber()); |
| 349 | links.addAll(reverseLinks); |
| 350 | |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 351 | if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) { |
Pavlin Radoslavov | e249767 | 2014-01-12 18:03:35 -0800 | [diff] [blame] | 352 | PerformanceMonitor.stop("SwitchPortRemoved.DbAccess"); |
| 353 | PerformanceMonitor.start("SwitchPortRemoved.NotificationSend"); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 354 | // TODO publish DELETE_PORT event here |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 355 | TopologyElement topologyElement = |
| 356 | new TopologyElement(switchId, port.getPortNumber()); |
| 357 | datagridService.notificationSendTopologyElementRemoved(topologyElement); |
Pavlin Radoslavov | fb15728 | 2013-11-05 08:40:13 -0800 | [diff] [blame] | 358 | |
| 359 | // Publish: remove the links |
| 360 | for (Link link : links) { |
| 361 | TopologyElement topologyElementLink = |
| 362 | new TopologyElement(link.getSrc(), |
| 363 | link.getSrcPort(), |
| 364 | link.getDst(), |
| 365 | link.getDstPort()); |
| 366 | datagridService.notificationSendTopologyElementRemoved(topologyElementLink); |
| 367 | } |
Pavlin Radoslavov | e249767 | 2014-01-12 18:03:35 -0800 | [diff] [blame] | 368 | PerformanceMonitor.stop("SwitchPortRemoved.NotificationSend"); |
Pavlin Radoslavov | 8bd6d11 | 2014-01-12 20:12:37 -0800 | [diff] [blame] | 369 | PerformanceMonitor.report("SwitchPortRemoved.DbAccess"); |
| 370 | PerformanceMonitor.report("TopologyEntryRemoved.NotificationReceived"); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 371 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 372 | */ |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 375 | @Override |
| 376 | public String getName() { |
Pavlin Radoslavov | c0aa4bf | 2014-03-26 18:32:49 -0700 | [diff] [blame] | 377 | return "OldNetworkGraphPublisher"; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 381 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 382 | return null; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 387 | return null; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 392 | Collection<Class<? extends IFloodlightService>> l = |
| 393 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | c35229e | 2014-02-06 16:19:37 -0800 | [diff] [blame] | 394 | l.add(IFloodlightProviderService.class); |
| 395 | //l.add(IDeviceService.class); |
| 396 | l.add(IDatagridService.class); |
| 397 | l.add(IThreadPoolService.class); |
| 398 | l.add(ILinkDiscoveryService.class); |
| 399 | return l; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public void init(FloodlightModuleContext context) |
| 404 | throws FloodlightModuleException { |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 405 | Map<String, String> configMap = context.getConfigParams(this); |
| 406 | String conf = configMap.get(DBConfigFile); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 407 | String dbStore = configMap.get(GraphDBStore); |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 408 | // op = GraphDBManager.getDBOperation(); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 409 | |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 410 | floodlightProvider = |
| 411 | context.getServiceImpl(IFloodlightProviderService.class); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 412 | //deviceService = context.getServiceImpl(IDeviceService.class); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 413 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
Pankaj Berde | f08d5ff | 2013-03-14 17:03:07 -0700 | [diff] [blame] | 414 | threadPool = context.getServiceImpl(IThreadPoolService.class); |
| 415 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 416 | datagridService = context.getServiceImpl(IDatagridService.class); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 417 | |
Pavlin Radoslavov | c0aa4bf | 2014-03-26 18:32:49 -0700 | [diff] [blame] | 418 | log.debug("Initializing OldNetworkGraphPublisher module with {}", conf); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 419 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public void startUp(FloodlightModuleContext context) { |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 424 | /* |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 425 | Map<String, String> configMap = context.getConfigParams(this); |
| 426 | String cleanupNeeded = configMap.get(CleanupEnabled); |
| 427 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 428 | //deviceService.addListener(this); |
Pankaj Berde | 465ac7c | 2013-05-23 13:47:49 -0700 | [diff] [blame] | 429 | floodlightProvider.addOFSwitchListener(this); |
Pankaj Berde | 00e9088 | 2013-06-10 21:25:05 -0700 | [diff] [blame] | 430 | linkDiscovery.addListener(this); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 431 | |
Pankaj Berde | 9d6b507 | 2013-04-03 11:51:23 -0700 | [diff] [blame] | 432 | log.debug("Adding EventListener"); |
Toshio Koide | 70ba38b | 2013-06-13 14:05:05 -0700 | [diff] [blame] | 433 | IDBConnection conn = op.getDBConnection(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 434 | conn.addEventListener(new LocalTopologyEventListener((DBConnection) conn)); |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 435 | // Setup the Cleanup task. |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 436 | if (cleanupNeeded == null || !cleanupNeeded.equals("False")) { |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 437 | ScheduledExecutorService ses = threadPool.getScheduledExecutor(); |
| 438 | cleanupTask = new SingletonTask(ses, new SwitchCleanup()); |
Pankaj Berde | 99fcee1 | 2013-03-18 09:41:53 -0700 | [diff] [blame] | 439 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, TimeUnit.SECONDS); |
Pankaj Berde | 1e3e5ba | 2013-03-15 13:17:53 -0700 | [diff] [blame] | 440 | } |
Pavlin Radoslavov | 8442e49 | 2013-10-25 21:54:13 -0700 | [diff] [blame] | 441 | |
| 442 | // |
| 443 | // NOTE: No need to register with the Datagrid Service, |
| 444 | // because we don't need to receive any notifications from it. |
| 445 | // |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 446 | */ |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | } |