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