Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 5 | import java.util.List; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 6 | import java.util.Map; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 7 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 8 | |
| 9 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 10 | import net.floodlightcontroller.core.IOFSwitch; |
| 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; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.util.SingletonTask; |
| 16 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 17 | import net.onrc.onos.core.devicemanager.IOnosDeviceListener; |
| 18 | import net.onrc.onos.core.devicemanager.IOnosDeviceService; |
| 19 | import net.onrc.onos.core.devicemanager.OnosDevice; |
| 20 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryListener; |
| 21 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 22 | import net.onrc.onos.core.main.IOFSwitchPortListener; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 23 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.registry.IControllerRegistryService.ControlChangeCallback; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 25 | import net.onrc.onos.core.registry.RegistryException; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.topology.PortEvent.SwitchPort; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 27 | |
| 28 | import org.openflow.protocol.OFPhysicalPort; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 29 | import org.openflow.util.HexString; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 32 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 33 | /** |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 34 | * The TopologyPublisher subscribes to topology network events from the |
| 35 | * discovery modules. These events are reformatted and relayed to the in-memory |
| 36 | * topology instance. |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 37 | */ |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 38 | public class TopologyPublisher implements /*IOFSwitchListener,*/ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | IOFSwitchPortListener, |
| 40 | ILinkDiscoveryListener, |
| 41 | IFloodlightModule, |
| 42 | IOnosDeviceListener { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 43 | private static final Logger log = |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 44 | LoggerFactory.getLogger(TopologyPublisher.class); |
Yuta HIGUCHI | cb95198 | 2014-02-11 13:31:44 -0800 | [diff] [blame] | 45 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 46 | private IFloodlightProviderService floodlightProvider; |
| 47 | private ILinkDiscoveryService linkDiscovery; |
| 48 | private IControllerRegistryService registryService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 49 | private ITopologyService topologyService; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 50 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 51 | private IOnosDeviceService onosDeviceService; |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 52 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 53 | private Topology topology; |
| 54 | private TopologyDiscoveryInterface topologyDiscoveryInterface; |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 55 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 56 | private static final String ENABLE_CLEANUP_PROPERTY = "EnableCleanup"; |
| 57 | private boolean cleanupEnabled = true; |
| 58 | private static final int CLEANUP_TASK_INTERVAL = 60; // in seconds |
| 59 | private SingletonTask cleanupTask; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 60 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 61 | /** |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 62 | * Cleanup old switches from the topology. Old switches are those |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 63 | * which have no controller in the registry. |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 64 | */ |
| 65 | private class SwitchCleanup implements ControlChangeCallback, Runnable { |
| 66 | @Override |
| 67 | public void run() { |
| 68 | String old = Thread.currentThread().getName(); |
| 69 | Thread.currentThread().setName("SwitchCleanup@" + old); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 70 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 71 | try { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 72 | if (log.isTraceEnabled()) { |
| 73 | log.trace("Running cleanup thread"); |
| 74 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 75 | switchCleanup(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 76 | } finally { |
| 77 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 78 | TimeUnit.SECONDS); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 79 | Thread.currentThread().setName(old); |
| 80 | } |
| 81 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 82 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 83 | /** |
| 84 | * First half of the switch cleanup operation. This method will attempt |
| 85 | * to get control of any switch it sees without a controller via the |
| 86 | * registry. |
| 87 | */ |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 88 | private void switchCleanup() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 89 | Iterable<Switch> switches = topology.getSwitches(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 90 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 91 | if (log.isTraceEnabled()) { |
| 92 | log.trace("Checking for inactive switches"); |
| 93 | } |
| 94 | // For each switch check if a controller exists in controller registry |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 95 | for (Switch sw : switches) { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 96 | try { |
| 97 | String controller = |
| 98 | registryService.getControllerForSwitch(sw.getDpid()); |
| 99 | if (controller == null) { |
| 100 | log.debug("Requesting control to set switch {} INACTIVE", |
| 101 | HexString.toHexString(sw.getDpid())); |
| 102 | registryService.requestControl(sw.getDpid(), this); |
| 103 | } |
| 104 | } catch (RegistryException e) { |
| 105 | log.error("Caught RegistryException in cleanup thread", e); |
| 106 | } |
| 107 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Second half of the switch cleanup operation. If the registry grants |
| 112 | * control of a switch, we can be sure no other instance is writing |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 113 | * this switch to the topology, so we can remove it now. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 114 | * |
| 115 | * @param dpid the dpid of the switch we requested control for |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 116 | * @param hasControl whether we got control or not |
| 117 | */ |
| 118 | @Override |
| 119 | public void controlChanged(long dpid, boolean hasControl) { |
| 120 | if (hasControl) { |
| 121 | log.debug("Got control to set switch {} INACTIVE", |
| 122 | HexString.toHexString(dpid)); |
Jonathan Hart | e02cf54 | 2014-04-02 16:24:44 -0700 | [diff] [blame] | 123 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 124 | SwitchEvent switchEvent = new SwitchEvent(dpid); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 125 | topologyDiscoveryInterface. |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 126 | removeSwitchDiscoveryEvent(switchEvent); |
| 127 | registryService.releaseControl(dpid); |
| 128 | } |
| 129 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 130 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 131 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 132 | @Override |
| 133 | public void linkDiscoveryUpdate(LDUpdate update) { |
Jonathan Hart | 121a024 | 2014-06-06 15:53:42 -0700 | [diff] [blame] | 134 | if (!registryService.hasControl(update.getDst())) { |
| 135 | // Don't process or send a link event if we're not master for the |
| 136 | // destination switch |
| 137 | return; |
| 138 | } |
| 139 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 140 | LinkEvent linkEvent = new LinkEvent(update.getSrc(), |
| 141 | (long) update.getSrcPort(), update.getDst(), |
| 142 | (long) update.getDstPort()); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 143 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 144 | switch (update.getOperation()) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 145 | case LINK_ADDED: |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 146 | topologyDiscoveryInterface.putLinkDiscoveryEvent(linkEvent); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 147 | break; |
| 148 | case LINK_UPDATED: |
| 149 | // We don't use the LINK_UPDATED event (unsure what it means) |
| 150 | break; |
| 151 | case LINK_REMOVED: |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 152 | topologyDiscoveryInterface.removeLinkDiscoveryEvent(linkEvent); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 153 | break; |
| 154 | default: |
| 155 | break; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 158 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 159 | @Override |
| 160 | public void switchPortAdded(Long switchId, OFPhysicalPort port) { |
Jonathan Hart | 67b6cba | 2014-05-30 22:36:37 -0700 | [diff] [blame] | 161 | if (registryService.hasControl(switchId)) { |
| 162 | PortEvent portEvent = new PortEvent(switchId, (long) port.getPortNumber()); |
| 163 | topologyDiscoveryInterface.putPortDiscoveryEvent(portEvent); |
| 164 | linkDiscovery.removeFromSuppressLLDPs(switchId, port.getPortNumber()); |
| 165 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 166 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 167 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 168 | @Override |
| 169 | public void switchPortRemoved(Long switchId, OFPhysicalPort port) { |
Jonathan Hart | 67b6cba | 2014-05-30 22:36:37 -0700 | [diff] [blame] | 170 | if (registryService.hasControl(switchId)) { |
| 171 | PortEvent portEvent = new PortEvent(switchId, (long) port.getPortNumber()); |
| 172 | topologyDiscoveryInterface.removePortDiscoveryEvent(portEvent); |
| 173 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 174 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 175 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 176 | @Override |
| 177 | public void addedSwitch(IOFSwitch sw) { |
| 178 | // TODO Not very robust |
| 179 | if (!registryService.hasControl(sw.getId())) { |
| 180 | return; |
| 181 | } |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 182 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 183 | SwitchEvent switchEvent = new SwitchEvent(sw.getId()); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 184 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 185 | List<PortEvent> portEvents = new ArrayList<PortEvent>(); |
| 186 | for (OFPhysicalPort port : sw.getPorts()) { |
| 187 | portEvents.add(new PortEvent(sw.getId(), (long) port.getPortNumber())); |
| 188 | } |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 189 | topologyDiscoveryInterface |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 190 | .putSwitchDiscoveryEvent(switchEvent, portEvents); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 191 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 192 | for (OFPhysicalPort port : sw.getPorts()) { |
| 193 | // Allow links to be discovered on this port now that it's |
| 194 | // in the database |
Pavlin Radoslavov | 7d21c0a | 2014-04-10 10:32:59 -0700 | [diff] [blame] | 195 | linkDiscovery.removeFromSuppressLLDPs(sw.getId(), port.getPortNumber()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 198 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 199 | @Override |
| 200 | public void removedSwitch(IOFSwitch sw) { |
| 201 | // We don't use this event - switch remove is done by cleanup thread |
| 202 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 203 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 204 | @Override |
| 205 | public void switchPortChanged(Long switchId) { |
| 206 | // We don't use this event |
| 207 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 208 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 209 | @Override |
| 210 | public String getName() { |
| 211 | // TODO Auto-generated method stub |
| 212 | return null; |
| 213 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 214 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 215 | /* ***************** |
| 216 | * IFloodlightModule |
| 217 | * *****************/ |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 218 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 219 | @Override |
| 220 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 221 | return null; |
| 222 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 223 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 224 | @Override |
| 225 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 226 | getServiceImpls() { |
| 227 | return null; |
| 228 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 229 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 230 | @Override |
| 231 | public Collection<Class<? extends IFloodlightService>> |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 232 | getModuleDependencies() { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 233 | Collection<Class<? extends IFloodlightService>> l = |
| 234 | new ArrayList<Class<? extends IFloodlightService>>(); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 235 | l.add(IFloodlightProviderService.class); |
| 236 | l.add(ILinkDiscoveryService.class); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 237 | l.add(IThreadPoolService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 238 | l.add(IControllerRegistryService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 239 | l.add(ITopologyService.class); |
Jonathan Hart | ebbe6a6 | 2014-04-02 16:10:25 -0700 | [diff] [blame] | 240 | l.add(IOnosDeviceService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 241 | return l; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 242 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 243 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 244 | @Override |
| 245 | public void init(FloodlightModuleContext context) |
| 246 | throws FloodlightModuleException { |
| 247 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 248 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
| 249 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
| 250 | onosDeviceService = context.getServiceImpl(IOnosDeviceService.class); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 251 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 252 | topologyService = context.getServiceImpl(ITopologyService.class); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 253 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 254 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 255 | @Override |
| 256 | public void startUp(FloodlightModuleContext context) { |
| 257 | floodlightProvider.addOFSwitchListener(this); |
| 258 | linkDiscovery.addListener(this); |
| 259 | onosDeviceService.addOnosDeviceListener(this); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 260 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 261 | topology = topologyService.getTopology(); |
| 262 | topologyDiscoveryInterface = |
| 263 | topologyService.getTopologyDiscoveryInterface(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 264 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 265 | // Run the cleanup thread |
| 266 | String enableCleanup = |
| 267 | context.getConfigParams(this).get(ENABLE_CLEANUP_PROPERTY); |
| 268 | if (enableCleanup != null |
| 269 | && enableCleanup.equalsIgnoreCase("false")) { |
| 270 | cleanupEnabled = false; |
| 271 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 272 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 273 | log.debug("Cleanup thread is {}enabled", (cleanupEnabled) ? "" : "not "); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 274 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 275 | if (cleanupEnabled) { |
| 276 | IThreadPoolService threadPool = |
| 277 | context.getServiceImpl(IThreadPoolService.class); |
| 278 | cleanupTask = new SingletonTask(threadPool.getScheduledExecutor(), |
| 279 | new SwitchCleanup()); |
| 280 | // Run the cleanup task immediately on startup |
| 281 | cleanupTask.reschedule(0, TimeUnit.SECONDS); |
| 282 | } |
| 283 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 284 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 285 | @Override |
| 286 | public void onosDeviceAdded(OnosDevice device) { |
| 287 | log.debug("Called onosDeviceAdded mac {}", device.getMacAddress()); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 288 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 289 | SwitchPort sp = new SwitchPort(device.getSwitchDPID(), |
| 290 | (long) device.getSwitchPort()); |
| 291 | List<SwitchPort> spLists = new ArrayList<SwitchPort>(); |
| 292 | spLists.add(sp); |
| 293 | DeviceEvent event = new DeviceEvent(device.getMacAddress()); |
| 294 | event.setAttachmentPoints(spLists); |
| 295 | event.setLastSeenTime(device.getLastSeenTimestamp().getTime()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 296 | // Does not use vlan info now. |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 297 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 298 | topologyDiscoveryInterface.putDeviceDiscoveryEvent(event); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 299 | } |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 300 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 301 | @Override |
| 302 | public void onosDeviceRemoved(OnosDevice device) { |
| 303 | log.debug("Called onosDeviceRemoved"); |
| 304 | DeviceEvent event = new DeviceEvent(device.getMacAddress()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 305 | topologyDiscoveryInterface.removeDeviceDiscoveryEvent(event); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 306 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 307 | } |