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