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