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 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 3 | import java.nio.ByteBuffer; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 4 | import java.util.ArrayList; |
| 5 | import java.util.Collection; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 6 | import java.util.LinkedList; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 7 | import java.util.List; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 8 | import java.util.Map; |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 9 | import java.util.concurrent.ConcurrentHashMap; |
| 10 | import java.util.concurrent.ConcurrentMap; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 11 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 12 | |
| 13 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFSwitch; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.core.IOFSwitch.PortChangeType; |
| 17 | import net.floodlightcontroller.core.IOFSwitchListener; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 18 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 19 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 20 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 21 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 22 | import net.floodlightcontroller.core.util.SingletonTask; |
| 23 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 24 | |
| 25 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 26 | import net.onrc.onos.core.datagrid.IEventChannel; |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.hostmanager.Host; |
| 28 | import net.onrc.onos.core.hostmanager.IHostListener; |
| 29 | import net.onrc.onos.core.hostmanager.IHostService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 30 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryListener; |
| 31 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.linkdiscovery.Link; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.registry.IControllerRegistryService.ControlChangeCallback; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 35 | import net.onrc.onos.core.registry.RegistryException; |
Yuta HIGUCHI | 5bbbaca | 2014-06-09 16:39:08 -0700 | [diff] [blame] | 36 | import net.onrc.onos.core.util.Dpid; |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 37 | import net.onrc.onos.core.util.OnosInstanceId; |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 38 | import net.onrc.onos.core.util.PortNumber; |
Yuta HIGUCHI | 5c8cbeb | 2014-06-27 11:13:48 -0700 | [diff] [blame] | 39 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 40 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 41 | import org.apache.commons.lang3.concurrent.ConcurrentUtils; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 43 | import org.projectfloodlight.openflow.util.HexString; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 46 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 47 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 48 | * Class for publishing topology-related events. |
| 49 | * |
| 50 | * The events are received from the discovery modules, reformatted and |
| 51 | * published to the other ONOS instances. |
| 52 | * |
| 53 | * TODO: Add a synchronization mechanism when publishing the events to |
| 54 | * preserve the ordering and to avoid mismatch in the local "published" state, |
| 55 | * because each of the caller (the discovery modules) might be running |
| 56 | * on a different thread. |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 57 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 58 | public class TopologyPublisher implements IOFSwitchListener, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | ILinkDiscoveryListener, |
| 60 | IFloodlightModule, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 61 | IHostListener { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 62 | private static final Logger log = |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 63 | LoggerFactory.getLogger(TopologyPublisher.class); |
Yuta HIGUCHI | cb95198 | 2014-02-11 13:31:44 -0800 | [diff] [blame] | 64 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 65 | private IFloodlightProviderService floodlightProvider; |
| 66 | private ILinkDiscoveryService linkDiscovery; |
| 67 | private IControllerRegistryService registryService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 68 | private ITopologyService topologyService; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 69 | private IDatagridService datagridService; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 70 | |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 71 | private IHostService hostService; |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 72 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 73 | private Topology topology; |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 74 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 75 | private static final String ENABLE_CLEANUP_PROPERTY = "EnableCleanup"; |
| 76 | private boolean cleanupEnabled = true; |
| 77 | private static final int CLEANUP_TASK_INTERVAL = 60; // in seconds |
| 78 | private SingletonTask cleanupTask; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 79 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 80 | private IEventChannel<byte[], TopologyEvent> eventChannel; |
| 81 | |
| 82 | // |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 83 | // Local state for keeping track of locally published events so we can |
| 84 | // cleanup properly when an entry is removed. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 85 | // |
| 86 | // We keep all Port, (incoming) Link and Host events per Switch DPID: |
| 87 | // - If a switch goes down, we remove all corresponding Port, Link and |
| 88 | // Host events. |
| 89 | // - If a port on a switch goes down, we remove all corresponding Link |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 90 | // and Host events attached to this port. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 91 | // |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 92 | // TODO: What to do if the Mastership changes? |
| 93 | // - Cleanup state from publishedFoo maps, but do not send REMOVE events? |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 94 | // |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 95 | private ConcurrentMap<Dpid, MastershipEvent> publishedMastershipEvents = |
| 96 | new ConcurrentHashMap<>(); |
| 97 | private ConcurrentMap<Dpid, SwitchEvent> publishedSwitchEvents = |
| 98 | new ConcurrentHashMap<>(); |
| 99 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, PortEvent>> |
| 100 | publishedPortEvents = new ConcurrentHashMap<>(); |
| 101 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, LinkEvent>> |
| 102 | publishedLinkEvents = new ConcurrentHashMap<>(); |
| 103 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, HostEvent>> |
| 104 | publishedHostEvents = new ConcurrentHashMap<>(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 105 | |
| 106 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 107 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 108 | * Gets the ONOS Instance ID. |
| 109 | * |
| 110 | * @return the ONOS Instance ID. |
| 111 | */ |
| 112 | private OnosInstanceId getOnosInstanceId() { |
| 113 | return registryService.getOnosInstanceId(); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Cleanup old switches from the topology. Old switches are those which |
| 118 | * have no controller in the registry. |
| 119 | * |
| 120 | * TODO: The overall switch cleanup mechanism needs refactoring/redesign. |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 121 | */ |
| 122 | private class SwitchCleanup implements ControlChangeCallback, Runnable { |
| 123 | @Override |
| 124 | public void run() { |
| 125 | String old = Thread.currentThread().getName(); |
| 126 | Thread.currentThread().setName("SwitchCleanup@" + old); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 127 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 128 | try { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 129 | if (log.isTraceEnabled()) { |
| 130 | log.trace("Running cleanup thread"); |
| 131 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 132 | switchCleanup(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 133 | } finally { |
| 134 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 135 | TimeUnit.SECONDS); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 136 | Thread.currentThread().setName(old); |
| 137 | } |
| 138 | } |
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 | /** |
| 141 | * First half of the switch cleanup operation. This method will attempt |
| 142 | * to get control of any switch it sees without a controller via the |
| 143 | * registry. |
| 144 | */ |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 145 | private void switchCleanup() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 146 | Iterable<Switch> switches = topology.getSwitches(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 147 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 148 | if (log.isTraceEnabled()) { |
| 149 | log.trace("Checking for inactive switches"); |
| 150 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 151 | // For each switch check if a controller exists in controller |
| 152 | // registry |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 153 | for (Switch sw : switches) { |
Praseed Balakrishnan | e82adc6 | 2014-08-04 10:59:24 -0700 | [diff] [blame] | 154 | // FIXME How to handle case where Switch has never been |
| 155 | // registered to ZK |
| 156 | if (sw.getConfigState() == ConfigState.CONFIGURED) { |
| 157 | continue; |
| 158 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 159 | try { |
| 160 | String controller = |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 161 | registryService.getControllerForSwitch(sw.getDpid().value()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 162 | if (controller == null) { |
| 163 | log.debug("Requesting control to set switch {} INACTIVE", |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 164 | sw.getDpid()); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 165 | registryService.requestControl(sw.getDpid().value(), |
| 166 | this); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 167 | } |
| 168 | } catch (RegistryException e) { |
| 169 | log.error("Caught RegistryException in cleanup thread", e); |
| 170 | } |
| 171 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 174 | /** |
| 175 | * Second half of the switch cleanup operation. If the registry grants |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 176 | * control of a switch, we can be sure no other instance is writing |
| 177 | * this switch to the topology, so we can remove it now. |
| 178 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 179 | * @param dpid the dpid of the switch we requested control for |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 180 | * @param hasControl whether we got control or not |
| 181 | */ |
| 182 | @Override |
| 183 | public void controlChanged(long dpid, boolean hasControl) { |
| 184 | if (hasControl) { |
| 185 | log.debug("Got control to set switch {} INACTIVE", |
| 186 | HexString.toHexString(dpid)); |
Jonathan Hart | e02cf54 | 2014-04-02 16:24:44 -0700 | [diff] [blame] | 187 | |
Yuta HIGUCHI | e2a4e17 | 2014-07-03 10:50:39 -0700 | [diff] [blame] | 188 | SwitchEvent switchEvent = new SwitchEvent(new Dpid(dpid)); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 189 | publishRemoveSwitchEvent(switchEvent); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 190 | registryService.releaseControl(dpid); |
| 191 | } |
| 192 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 193 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 194 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 195 | @Override |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 196 | public void linkAdded(Link link) { |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 197 | LinkEvent linkEvent = new LinkEvent( |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 198 | new SwitchPort(link.getSrc(), link.getSrcPort()), |
| 199 | new SwitchPort(link.getDst(), link.getDstPort())); |
| 200 | |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 201 | // FIXME should be merging, with existing attrs, etc.. |
| 202 | // TODO define attr name as constant somewhere. |
| 203 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 204 | linkEvent.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 205 | TopologyElement.TYPE_PACKET_LAYER); |
Praseed Balakrishnan | 2aa6c0b | 2014-07-17 11:42:05 -0700 | [diff] [blame] | 206 | linkEvent.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 207 | ConfigState.NOT_CONFIGURED.toString()); |
| 208 | linkEvent.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
| 209 | AdminStatus.ACTIVE.toString()); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 210 | linkEvent.freeze(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 211 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 212 | publishAddLinkEvent(linkEvent); |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public void linkRemoved(Link link) { |
| 217 | LinkEvent linkEvent = new LinkEvent( |
| 218 | new SwitchPort(link.getSrc(), link.getSrcPort()), |
| 219 | new SwitchPort(link.getDst(), link.getDstPort())); |
| 220 | |
| 221 | // FIXME should be merging, with existing attrs, etc.. |
| 222 | // TODO define attr name as constant somewhere. |
| 223 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 224 | linkEvent.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 225 | TopologyElement.TYPE_PACKET_LAYER); |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 226 | linkEvent.freeze(); |
| 227 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 228 | publishRemoveLinkEvent(linkEvent); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 229 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 230 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 231 | /* ***************** |
| 232 | * IOFSwitchListener |
| 233 | * *****************/ |
| 234 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 235 | @Override |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 236 | public void switchActivatedMaster(long swId) { |
| 237 | IOFSwitch sw = floodlightProvider.getSwitch(swId); |
| 238 | final Dpid dpid = new Dpid(swId); |
| 239 | if (sw == null) { |
| 240 | log.warn("Added switch not available {} ", dpid); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | controllerRoleChanged(dpid, Role.MASTER); |
| 245 | |
| 246 | SwitchEvent switchEvent = new SwitchEvent(dpid); |
| 247 | // FIXME should be merging, with existing attrs, etc.. |
| 248 | // TODO define attr name as constant somewhere. |
| 249 | // TODO populate appropriate attributes. |
| 250 | switchEvent.createStringAttribute(TopologyElement.TYPE, |
| 251 | TopologyElement.TYPE_PACKET_LAYER); |
| 252 | switchEvent.createStringAttribute("ConnectedSince", |
| 253 | sw.getConnectedSince().toString()); |
| 254 | switchEvent.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 255 | ConfigState.NOT_CONFIGURED.toString()); |
| 256 | switchEvent.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
| 257 | AdminStatus.ACTIVE.toString()); |
| 258 | switchEvent.freeze(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 259 | // The Port events |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 260 | List<PortEvent> portEvents = new ArrayList<PortEvent>(); |
| 261 | for (OFPortDesc port : sw.getPorts()) { |
| 262 | PortEvent portEvent = new PortEvent(dpid, |
| 263 | new PortNumber(port.getPortNo().getShortPortNumber())); |
| 264 | // FIXME should be merging, with existing attrs, etc.. |
| 265 | // TODO define attr name as constant somewhere. |
| 266 | // TODO populate appropriate attributes. |
| 267 | portEvent.createStringAttribute("name", port.getName()); |
| 268 | portEvent.createStringAttribute(TopologyElement.TYPE, |
| 269 | TopologyElement.TYPE_PACKET_LAYER); |
| 270 | portEvent.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 271 | ConfigState.NOT_CONFIGURED.toString()); |
| 272 | portEvent.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
| 273 | AdminStatus.ACTIVE.toString()); |
| 274 | |
| 275 | portEvent.freeze(); |
| 276 | portEvents.add(portEvent); |
| 277 | } |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 278 | publishAddSwitchEvent(switchEvent, portEvents); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public void switchActivatedEqual(long swId) { |
| 283 | final Dpid dpid = new Dpid(swId); |
| 284 | controllerRoleChanged(dpid, Role.EQUAL); |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public void switchMasterToEqual(long swId) { |
| 289 | final Dpid dpid = new Dpid(swId); |
| 290 | controllerRoleChanged(dpid, Role.EQUAL); |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void switchEqualToMaster(long swId) { |
| 295 | // for now treat as switchActivatedMaster |
| 296 | switchActivatedMaster(swId); |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void switchDisconnected(long swId) { |
| 301 | final Dpid dpid = new Dpid(swId); |
| 302 | |
| 303 | log.debug("Local switch disconnected: dpid = {} role = {}", dpid); |
| 304 | |
| 305 | Role role = Role.SLAVE; // TODO: Should be Role.UNKNOWN |
| 306 | |
| 307 | MastershipEvent mastershipEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 308 | new MastershipEvent(dpid, getOnosInstanceId(), role); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 309 | // FIXME should be merging, with existing attrs, etc.. |
| 310 | // TODO define attr name as constant somewhere. |
| 311 | // TODO populate appropriate attributes. |
| 312 | mastershipEvent.createStringAttribute(TopologyElement.TYPE, |
| 313 | TopologyElement.TYPE_ALL_LAYERS); |
| 314 | mastershipEvent.freeze(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 315 | publishRemoveSwitchMastershipEvent(mastershipEvent); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public void switchPortChanged(long swId, OFPortDesc port, |
| 320 | PortChangeType changeType) { |
| 321 | switch (changeType) { |
| 322 | case ADD: |
| 323 | switchPortAdded(swId, port); |
| 324 | break; |
| 325 | case DELETE: |
| 326 | switchPortRemoved(swId, port); |
| 327 | break; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 328 | case UP: |
Pavlin Radoslavov | 7946c61 | 2014-08-13 15:06:00 -0700 | [diff] [blame] | 329 | // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE |
| 330 | switchPortAdded(swId, port); |
| 331 | break; |
| 332 | case DOWN: |
| 333 | // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE |
| 334 | switchPortRemoved(swId, port); |
| 335 | break; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 336 | case OTHER_UPDATE: |
| 337 | default: |
| 338 | // XXX S what is the right set of port change handlers? |
| 339 | log.debug("Topology publisher does not handle these port updates: {}", |
| 340 | changeType); |
| 341 | } |
| 342 | } |
| 343 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 344 | /** |
| 345 | * Prepares an event for adding a port on a switch. |
| 346 | * |
| 347 | * @param switchId the switch ID (DPID) |
| 348 | * @param port the port to add |
| 349 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 350 | private void switchPortAdded(long switchId, OFPortDesc port) { |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 351 | final Dpid dpid = new Dpid(switchId); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 352 | PortEvent portEvent = new PortEvent(dpid, |
| 353 | new PortNumber(port.getPortNo().getShortPortNumber())); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 354 | // FIXME should be merging, with existing attrs, etc.. |
| 355 | // TODO define attr name as constant somewhere. |
| 356 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 357 | portEvent.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 358 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 359 | portEvent.createStringAttribute("name", port.getName()); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 360 | portEvent.freeze(); |
| 361 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 362 | publishAddPortEvent(portEvent); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 363 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 364 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 365 | /** |
| 366 | * Prepares an event for removing a port on a switch. |
| 367 | * |
| 368 | * @param switchId the switch ID (DPID) |
| 369 | * @param port the port to remove |
| 370 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 371 | private void switchPortRemoved(long switchId, OFPortDesc port) { |
Yuta HIGUCHI | e2a4e17 | 2014-07-03 10:50:39 -0700 | [diff] [blame] | 372 | final Dpid dpid = new Dpid(switchId); |
Yuta HIGUCHI | 5bbbaca | 2014-06-09 16:39:08 -0700 | [diff] [blame] | 373 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 374 | PortEvent portEvent = new PortEvent(dpid, new PortNumber( |
| 375 | port.getPortNo().getShortPortNumber())); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 376 | // FIXME should be merging, with existing attrs, etc.. |
| 377 | // TODO define attr name as constant somewhere. |
| 378 | // TODO populate appropriate attributes. |
| 379 | portEvent.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 380 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 381 | portEvent.createStringAttribute("name", port.getName()); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 382 | portEvent.freeze(); |
| 383 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 384 | publishRemovePortEvent(portEvent); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 385 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 386 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 387 | @Override |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 388 | public String getName() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 389 | return "topologyPublisher"; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 390 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 391 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 392 | /* ***************** |
| 393 | * IFloodlightModule |
| 394 | * *****************/ |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 395 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 396 | @Override |
| 397 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 398 | return null; |
| 399 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 400 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 401 | @Override |
| 402 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 403 | getServiceImpls() { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 404 | return null; |
| 405 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 406 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 407 | @Override |
| 408 | public Collection<Class<? extends IFloodlightService>> |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 409 | getModuleDependencies() { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 410 | Collection<Class<? extends IFloodlightService>> l = |
| 411 | new ArrayList<Class<? extends IFloodlightService>>(); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 412 | l.add(IFloodlightProviderService.class); |
| 413 | l.add(ILinkDiscoveryService.class); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 414 | l.add(IThreadPoolService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 415 | l.add(IControllerRegistryService.class); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 416 | l.add(IDatagridService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 417 | l.add(ITopologyService.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 418 | l.add(IHostService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 419 | return l; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 420 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 421 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 422 | @Override |
| 423 | public void init(FloodlightModuleContext context) |
| 424 | throws FloodlightModuleException { |
| 425 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 426 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
| 427 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 428 | datagridService = context.getServiceImpl(IDatagridService.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 429 | hostService = context.getServiceImpl(IHostService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 430 | topologyService = context.getServiceImpl(ITopologyService.class); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 431 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 432 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 433 | @Override |
| 434 | public void startUp(FloodlightModuleContext context) { |
| 435 | floodlightProvider.addOFSwitchListener(this); |
| 436 | linkDiscovery.addListener(this); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 437 | hostService.addHostListener(this); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 438 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 439 | eventChannel = datagridService.createChannel( |
| 440 | TopologyManager.EVENT_CHANNEL_NAME, |
| 441 | byte[].class, |
| 442 | TopologyEvent.class); |
| 443 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 444 | topology = topologyService.getTopology(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 445 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 446 | // Run the cleanup thread |
| 447 | String enableCleanup = |
| 448 | context.getConfigParams(this).get(ENABLE_CLEANUP_PROPERTY); |
| 449 | if (enableCleanup != null |
| 450 | && enableCleanup.equalsIgnoreCase("false")) { |
| 451 | cleanupEnabled = false; |
| 452 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 453 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 454 | log.debug("Cleanup thread is {}enabled", (cleanupEnabled) ? "" : "not "); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 455 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 456 | if (cleanupEnabled) { |
| 457 | IThreadPoolService threadPool = |
| 458 | context.getServiceImpl(IThreadPoolService.class); |
| 459 | cleanupTask = new SingletonTask(threadPool.getScheduledExecutor(), |
| 460 | new SwitchCleanup()); |
| 461 | // Run the cleanup task immediately on startup |
| 462 | cleanupTask.reschedule(0, TimeUnit.SECONDS); |
| 463 | } |
| 464 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 465 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 466 | @Override |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 467 | public void hostAdded(Host host) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 468 | log.debug("Host added with MAC {}", host.getMacAddress()); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 469 | |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 470 | SwitchPort sp = new SwitchPort(host.getSwitchDPID(), host.getSwitchPort()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 471 | List<SwitchPort> spLists = new ArrayList<SwitchPort>(); |
| 472 | spLists.add(sp); |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 473 | HostEvent event = new HostEvent(host.getMacAddress()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 474 | event.setAttachmentPoints(spLists); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 475 | event.setLastSeenTime(host.getLastSeenTimestamp().getTime()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 476 | // Does not use vlan info now. |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 477 | event.freeze(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 478 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 479 | publishAddHostEvent(event); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 480 | } |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 481 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 482 | @Override |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 483 | public void hostRemoved(Host host) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 484 | log.debug("Host removed with MAC {}", host.getMacAddress()); |
| 485 | |
| 486 | // |
| 487 | // Remove all previously added HostEvent for this MAC address |
| 488 | // |
| 489 | // TODO: Currently, the caller of hostRemoved() might not include |
| 490 | // the correct set of Attachment Points in the HostEvent entry itself. |
| 491 | // Also, we might have multiple HostEvent entries for the same |
| 492 | // host (MAC address), each containing a single (different) Attachment |
| 493 | // Point. |
| 494 | // Hence, here we have to cleanup all HostEvent entries for this |
| 495 | // particular host, based on its MAC address. |
| 496 | // |
| 497 | List<HostEvent> removeHostEvents = new LinkedList<>(); |
| 498 | for (ConcurrentMap<ByteBuffer, HostEvent> cm : publishedHostEvents.values()) { |
| 499 | for (HostEvent hostEvent : cm.values()) { |
| 500 | if (hostEvent.getMac().equals(host.getMacAddress())) { |
| 501 | removeHostEvents.add(hostEvent); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | for (HostEvent event : removeHostEvents) { |
| 506 | publishRemoveHostEvent(event); |
| 507 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 508 | } |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 509 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 510 | /** |
| 511 | * Prepares the Controller role changed event for a switch. |
| 512 | * |
| 513 | * @param dpid the switch DPID |
| 514 | * @param role the new role of the controller |
| 515 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 516 | private void controllerRoleChanged(Dpid dpid, Role role) { |
| 517 | log.debug("Local switch controller mastership role changed: dpid = {} role = {}", |
| 518 | dpid, role); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 519 | MastershipEvent mastershipEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 520 | new MastershipEvent(dpid, getOnosInstanceId(), role); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 521 | // FIXME should be merging, with existing attrs, etc.. |
| 522 | // TODO define attr name as constant somewhere. |
| 523 | // TODO populate appropriate attributes. |
| 524 | mastershipEvent.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 525 | TopologyElement.TYPE_ALL_LAYERS); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 526 | mastershipEvent.freeze(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 527 | publishAddSwitchMastershipEvent(mastershipEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 531 | * Publishes ADD Mastership Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 532 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 533 | * @param mastershipEvent the mastership event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 534 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 535 | private void publishAddSwitchMastershipEvent( |
| 536 | MastershipEvent mastershipEvent) { |
| 537 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 538 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 539 | new TopologyEvent(mastershipEvent, getOnosInstanceId()); |
| 540 | log.debug("Publishing add mastership: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 541 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 542 | publishedMastershipEvents.put(mastershipEvent.getDpid(), |
| 543 | mastershipEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 547 | * Publishes REMOVE Mastership Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 548 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 549 | * @param mastershipEvent the mastership event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 550 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 551 | private void publishRemoveSwitchMastershipEvent( |
| 552 | MastershipEvent mastershipEvent) { |
| 553 | if (publishedMastershipEvents.get(mastershipEvent.getDpid()) == null) { |
| 554 | return; // Nothing to do |
| 555 | } |
| 556 | |
| 557 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 558 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 559 | new TopologyEvent(mastershipEvent, getOnosInstanceId()); |
| 560 | log.debug("Publishing remove mastership: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 561 | eventChannel.removeEntry(topologyEvent.getID()); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 562 | publishedMastershipEvents.remove(mastershipEvent.getDpid()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 566 | * Publishes ADD Switch Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 567 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 568 | * @param switchEvent the switch event to publish |
| 569 | * @param portEvents the corresponding port events for the switch to |
| 570 | * publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 571 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 572 | private void publishAddSwitchEvent(SwitchEvent switchEvent, |
| 573 | Collection<PortEvent> portEvents) { |
| 574 | if (!registryService.hasControl(switchEvent.getOriginDpid().value())) { |
| 575 | log.debug("Not the master for switch {}. Suppressed switch add event {}.", |
| 576 | switchEvent.getOriginDpid(), switchEvent); |
| 577 | return; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 580 | // Keep track of the old Port Events that should be removed |
| 581 | ConcurrentMap<ByteBuffer, PortEvent> oldPortEvents = |
| 582 | publishedPortEvents.get(switchEvent.getDpid()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 583 | if (oldPortEvents == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 584 | oldPortEvents = new ConcurrentHashMap<>(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 587 | // Publish the information for the switch |
| 588 | TopologyEvent topologyEvent = |
| 589 | new TopologyEvent(switchEvent, getOnosInstanceId()); |
| 590 | log.debug("Publishing add switch: {}", topologyEvent); |
| 591 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
| 592 | publishedSwitchEvents.put(switchEvent.getDpid(), switchEvent); |
| 593 | |
| 594 | // Publish the information for each port |
| 595 | ConcurrentMap<ByteBuffer, PortEvent> newPortEvents = |
| 596 | new ConcurrentHashMap<>(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 597 | for (PortEvent portEvent : portEvents) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 598 | topologyEvent = |
| 599 | new TopologyEvent(portEvent, getOnosInstanceId()); |
| 600 | log.debug("Publishing add port: {}", topologyEvent); |
| 601 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
| 602 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 603 | ByteBuffer id = portEvent.getIDasByteBuffer(); |
| 604 | newPortEvents.put(id, portEvent); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 605 | oldPortEvents.remove(id); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 606 | } |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 607 | publishedPortEvents.put(switchEvent.getDpid(), newPortEvents); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 608 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 609 | // Cleanup for each of the old removed port |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 610 | for (PortEvent portEvent : oldPortEvents.values()) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 611 | publishRemovePortEvent(portEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
| 615 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 616 | * Publishes REMOVE Switch Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 617 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 618 | * @param switchEvent the switch event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 619 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 620 | private void publishRemoveSwitchEvent(SwitchEvent switchEvent) { |
| 621 | // |
| 622 | // TODO: Removed the check for now, because currently this method is |
| 623 | // also called by the SwitchCleanup thread, and in that case |
| 624 | // the Switch Event was published by some other ONOS instance. |
| 625 | // |
| 626 | /* |
| 627 | if (publishedSwitchEvents.get(switchEvent.getDpid()) == null) { |
| 628 | return; // Nothing to do |
| 629 | } |
| 630 | */ |
| 631 | |
| 632 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 633 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 634 | new TopologyEvent(switchEvent, getOnosInstanceId()); |
| 635 | log.debug("Publishing remove switch: {}", topologyEvent); |
| 636 | eventChannel.removeEntry(topologyEvent.getID()); |
| 637 | publishedSwitchEvents.remove(switchEvent.getDpid()); |
| 638 | |
| 639 | // Cleanup for each port |
| 640 | ConcurrentMap<ByteBuffer, PortEvent> portEvents = |
| 641 | publishedPortEvents.get(switchEvent.getDpid()); |
| 642 | if (portEvents != null) { |
| 643 | for (PortEvent portEvent : portEvents.values()) { |
| 644 | publishRemovePortEvent(portEvent); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | publishedPortEvents.remove(switchEvent.getDpid()); |
| 649 | publishedLinkEvents.remove(switchEvent.getDpid()); |
| 650 | publishedHostEvents.remove(switchEvent.getDpid()); |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Publishes ADD Port Event. |
| 655 | * |
| 656 | * @param portEvent the port event to publish |
| 657 | */ |
| 658 | private void publishAddPortEvent(PortEvent portEvent) { |
| 659 | if (!registryService.hasControl(portEvent.getOriginDpid().value())) { |
| 660 | log.debug("Not the master for switch {}. Suppressed port add event {}.", |
| 661 | portEvent.getOriginDpid(), portEvent); |
| 662 | return; |
| 663 | } |
| 664 | |
| 665 | // Publish the information |
| 666 | TopologyEvent topologyEvent = |
| 667 | new TopologyEvent(portEvent, getOnosInstanceId()); |
| 668 | log.debug("Publishing add port: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 669 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
| 670 | |
| 671 | // Store the new Port Event in the local cache |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 672 | ConcurrentMap<ByteBuffer, PortEvent> portEvents = |
| 673 | ConcurrentUtils.putIfAbsent(publishedPortEvents, |
| 674 | portEvent.getDpid(), |
| 675 | new ConcurrentHashMap<ByteBuffer, PortEvent>()); |
| 676 | portEvents.put(portEvent.getIDasByteBuffer(), portEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 680 | * Publishes REMOVE Port Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 681 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 682 | * @param portEvent the port event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 683 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 684 | private void publishRemovePortEvent(PortEvent portEvent) { |
| 685 | ConcurrentMap<ByteBuffer, PortEvent> portEvents = |
| 686 | publishedPortEvents.get(portEvent.getDpid()); |
| 687 | if (portEvents == null) { |
| 688 | return; // Nothing to do |
| 689 | } |
| 690 | if (portEvents.get(portEvent.getIDasByteBuffer()) == null) { |
| 691 | return; // Nothing to do |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 694 | // Publish the information |
| 695 | TopologyEvent topologyEvent = |
| 696 | new TopologyEvent(portEvent, getOnosInstanceId()); |
| 697 | log.debug("Publishing remove port: {}", topologyEvent); |
| 698 | eventChannel.removeEntry(topologyEvent.getID()); |
| 699 | |
| 700 | // Cleanup for the incoming link(s) |
| 701 | ConcurrentMap<ByteBuffer, LinkEvent> linkEvents = |
| 702 | publishedLinkEvents.get(portEvent.getDpid()); |
| 703 | if (linkEvents != null) { |
| 704 | for (LinkEvent linkEvent : linkEvents.values()) { |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 705 | if (linkEvent.getDst().equals(portEvent.getSwitchPort())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 706 | publishRemoveLinkEvent(linkEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // Cleanup for the connected hosts |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 712 | ConcurrentMap<ByteBuffer, HostEvent> hostEvents = |
| 713 | publishedHostEvents.get(portEvent.getDpid()); |
| 714 | if (hostEvents != null) { |
| 715 | for (HostEvent hostEvent : hostEvents.values()) { |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 716 | for (SwitchPort swp : hostEvent.getAttachmentPoints()) { |
| 717 | if (swp.equals(portEvent.getSwitchPort())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 718 | publishRemoveHostEvent(hostEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | } |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 722 | } |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 723 | |
| 724 | portEvents.remove(portEvent.getIDasByteBuffer()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 728 | * Publishes ADD Link Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 729 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 730 | * @param linkEvent the link event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 731 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 732 | private void publishAddLinkEvent(LinkEvent linkEvent) { |
| 733 | if (!registryService.hasControl(linkEvent.getOriginDpid().value())) { |
| 734 | log.debug("Not the master for dst switch {}. Suppressed link add event {}.", |
| 735 | linkEvent.getOriginDpid(), linkEvent); |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 740 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 741 | new TopologyEvent(linkEvent, getOnosInstanceId()); |
| 742 | log.debug("Publishing add link: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 743 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
| 744 | |
| 745 | // Store the new Link Event in the local cache |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 746 | ConcurrentMap<ByteBuffer, LinkEvent> linkEvents = |
| 747 | ConcurrentUtils.putIfAbsent(publishedLinkEvents, |
| 748 | linkEvent.getDst().getDpid(), |
| 749 | new ConcurrentHashMap<ByteBuffer, LinkEvent>()); |
| 750 | linkEvents.put(linkEvent.getIDasByteBuffer(), linkEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 754 | * Publishes REMOVE Link Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 755 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 756 | * @param linkEvent the link event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 757 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 758 | private void publishRemoveLinkEvent(LinkEvent linkEvent) { |
| 759 | ConcurrentMap<ByteBuffer, LinkEvent> linkEvents = |
| 760 | publishedLinkEvents.get(linkEvent.getDst().getDpid()); |
| 761 | if (linkEvents == null) { |
| 762 | return; // Nothing to do |
| 763 | } |
| 764 | if (linkEvents.get(linkEvent.getIDasByteBuffer()) == null) { |
| 765 | return; // Nothing to do |
| 766 | } |
| 767 | |
| 768 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 769 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 770 | new TopologyEvent(linkEvent, getOnosInstanceId()); |
| 771 | log.debug("Publishing remove link: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 772 | eventChannel.removeEntry(topologyEvent.getID()); |
| 773 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 774 | linkEvents.remove(linkEvent.getIDasByteBuffer()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 778 | * Publishes ADD Host Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 779 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 780 | * @param hostEvent the host event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 781 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 782 | private void publishAddHostEvent(HostEvent hostEvent) { |
| 783 | // |
| 784 | // NOTE: The implementation below assumes that there is just one |
| 785 | // attachment point stored in hostEvent. Currently, this assumption |
| 786 | // is true based on the existing implementation of the caller |
| 787 | // hostAdded(). |
| 788 | // |
| 789 | |
| 790 | if (!registryService.hasControl(hostEvent.getOriginDpid().value())) { |
| 791 | log.debug("Not the master for attachment switch {}. Suppressed host add event {}.", |
| 792 | hostEvent.getOriginDpid(), hostEvent); |
| 793 | return; |
| 794 | } |
| 795 | |
| 796 | // Publish the information |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 797 | TopologyEvent topologyEvent = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 798 | new TopologyEvent(hostEvent, getOnosInstanceId()); |
| 799 | log.debug("Publishing add host: {}", topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 800 | eventChannel.addEntry(topologyEvent.getID(), topologyEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 801 | |
| 802 | // Store the new Host Event in the local cache |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 803 | ConcurrentMap<ByteBuffer, HostEvent> hostEvents = |
| 804 | ConcurrentUtils.putIfAbsent(publishedHostEvents, |
| 805 | hostEvent.getOriginDpid(), |
| 806 | new ConcurrentHashMap<ByteBuffer, HostEvent>()); |
| 807 | hostEvents.put(hostEvent.getIDasByteBuffer(), hostEvent); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 811 | * Publishes REMOVE Host Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 812 | * |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 813 | * @param hostEvent the host event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 814 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 815 | private void publishRemoveHostEvent(HostEvent hostEvent) { |
| 816 | ConcurrentMap<ByteBuffer, HostEvent> hostEvents = |
| 817 | publishedHostEvents.get(hostEvent.getOriginDpid()); |
| 818 | if (hostEvents == null) { |
| 819 | return; // Nothing to do |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 820 | } |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame^] | 821 | if (hostEvents.get(hostEvent.getIDasByteBuffer()) == null) { |
| 822 | return; // Nothing to do |
| 823 | } |
| 824 | |
| 825 | // Publish the information |
| 826 | TopologyEvent topologyEvent = |
| 827 | new TopologyEvent(hostEvent, getOnosInstanceId()); |
| 828 | log.debug("Publishing remove host: {}", topologyEvent); |
| 829 | eventChannel.removeEntry(topologyEvent.getID()); |
| 830 | |
| 831 | hostEvents.remove(hostEvent.getIDasByteBuffer()); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 832 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 833 | } |