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