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