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