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 | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 6 | import java.util.HashMap; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 7 | import java.util.LinkedList; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 8 | import java.util.List; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 9 | import java.util.Map; |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 10 | import java.util.Map.Entry; |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 11 | import java.util.concurrent.BlockingQueue; |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 12 | import java.util.concurrent.ConcurrentHashMap; |
| 13 | import java.util.concurrent.ConcurrentMap; |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 14 | import java.util.concurrent.LinkedBlockingQueue; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 15 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 16 | |
| 17 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 18 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 19 | import net.floodlightcontroller.core.IOFSwitch; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 20 | import net.floodlightcontroller.core.IOFSwitch.PortChangeType; |
| 21 | import net.floodlightcontroller.core.IOFSwitchListener; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 22 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 23 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 24 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 25 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 26 | import net.floodlightcontroller.core.util.SingletonTask; |
| 27 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 28 | import net.onrc.onos.api.batchoperation.BatchOperationEntry; |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 29 | import net.onrc.onos.core.configmanager.INetworkConfigService; |
| 30 | import net.onrc.onos.core.configmanager.INetworkConfigService.LinkConfigStatus; |
| 31 | import net.onrc.onos.core.configmanager.INetworkConfigService.NetworkConfigState; |
| 32 | import net.onrc.onos.core.configmanager.INetworkConfigService.SwitchConfigStatus; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 34 | import net.onrc.onos.core.datagrid.IEventChannel; |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 35 | import net.onrc.onos.core.hostmanager.Host; |
| 36 | import net.onrc.onos.core.hostmanager.IHostListener; |
| 37 | import net.onrc.onos.core.hostmanager.IHostService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 38 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryListener; |
| 39 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 40 | import net.onrc.onos.core.linkdiscovery.Link; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 41 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 42 | import net.onrc.onos.core.registry.IControllerRegistryService.ControlChangeCallback; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 43 | import net.onrc.onos.core.registry.RegistryException; |
Yuta HIGUCHI | 5bbbaca | 2014-06-09 16:39:08 -0700 | [diff] [blame] | 44 | import net.onrc.onos.core.util.Dpid; |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 45 | import net.onrc.onos.core.util.OnosInstanceId; |
Yuta HIGUCHI | a507baf | 2014-08-22 13:42:40 -0700 | [diff] [blame] | 46 | import net.onrc.onos.core.util.PortNumberUtils; |
Yuta HIGUCHI | 5c8cbeb | 2014-06-27 11:13:48 -0700 | [diff] [blame] | 47 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 48 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 49 | import org.apache.commons.lang3.concurrent.ConcurrentUtils; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 50 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 51 | import org.projectfloodlight.openflow.util.HexString; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 52 | import org.slf4j.Logger; |
| 53 | import org.slf4j.LoggerFactory; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 54 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 55 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 56 | * Class for publishing topology-related events. |
| 57 | * |
| 58 | * The events are received from the discovery modules, reformatted and |
| 59 | * published to the other ONOS instances. |
| 60 | * |
| 61 | * TODO: Add a synchronization mechanism when publishing the events to |
| 62 | * preserve the ordering and to avoid mismatch in the local "published" state, |
| 63 | * because each of the caller (the discovery modules) might be running |
| 64 | * on a different thread. |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 65 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 66 | public class TopologyPublisher implements IOFSwitchListener, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | ILinkDiscoveryListener, |
| 68 | IFloodlightModule, |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 69 | IHostListener, |
| 70 | ITopologyPublisherService { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 71 | private static final Logger log = |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 72 | LoggerFactory.getLogger(TopologyPublisher.class); |
Yuta HIGUCHI | cb95198 | 2014-02-11 13:31:44 -0800 | [diff] [blame] | 73 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 74 | private IFloodlightProviderService floodlightProvider; |
| 75 | private ILinkDiscoveryService linkDiscovery; |
| 76 | private IControllerRegistryService registryService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 77 | private ITopologyService topologyService; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 78 | private IDatagridService datagridService; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 80 | private IHostService hostService; |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 81 | private MutableTopology mutableTopology; |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 82 | private INetworkConfigService networkConfigService; |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 83 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 84 | private static final String ENABLE_CLEANUP_PROPERTY = "EnableCleanup"; |
| 85 | private boolean cleanupEnabled = true; |
| 86 | private static final int CLEANUP_TASK_INTERVAL = 60; // in seconds |
| 87 | private SingletonTask cleanupTask; |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 88 | private DelayedOperationsHandler delayedOperationsHandler = |
| 89 | new DelayedOperationsHandler(); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 90 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 91 | private IEventChannel<byte[], TopologyEvent> eventChannel; |
| 92 | |
| 93 | // |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 94 | // Local state for keeping track of locally published events so we can |
| 95 | // cleanup properly when an entry is removed. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 96 | // |
| 97 | // We keep all Port, (incoming) Link and Host events per Switch DPID: |
| 98 | // - If a switch goes down, we remove all corresponding Port, Link and |
| 99 | // Host events. |
| 100 | // - 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] | 101 | // and Host events attached to this port. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 102 | // |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 103 | // TODO: What to do if the Mastership changes? |
| 104 | // - Cleanup state from publishedFoo maps, but do not send REMOVE events? |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 105 | // |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 106 | private ConcurrentMap<Dpid, MastershipData> publishedMastershipDataEntries = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 107 | new ConcurrentHashMap<>(); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 108 | private ConcurrentMap<Dpid, SwitchData> publishedSwitchDataEntries = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 109 | new ConcurrentHashMap<>(); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 110 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, PortData>> |
| 111 | publishedPortDataEntries = new ConcurrentHashMap<>(); |
| 112 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, LinkData>> |
| 113 | publishedLinkDataEntries = new ConcurrentHashMap<>(); |
| 114 | private ConcurrentMap<Dpid, ConcurrentMap<ByteBuffer, HostData>> |
| 115 | publishedHostDataEntries = new ConcurrentHashMap<>(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 116 | |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 117 | private BlockingQueue<TopologyBatchOperation> delayedOperations = |
| 118 | new LinkedBlockingQueue<>(); |
| 119 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 120 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 121 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 122 | * Gets the ONOS Instance ID. |
| 123 | * |
| 124 | * @return the ONOS Instance ID. |
| 125 | */ |
| 126 | private OnosInstanceId getOnosInstanceId() { |
| 127 | return registryService.getOnosInstanceId(); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Cleanup old switches from the topology. Old switches are those which |
| 132 | * have no controller in the registry. |
| 133 | * |
| 134 | * TODO: The overall switch cleanup mechanism needs refactoring/redesign. |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 135 | */ |
| 136 | private class SwitchCleanup implements ControlChangeCallback, Runnable { |
| 137 | @Override |
| 138 | public void run() { |
| 139 | String old = Thread.currentThread().getName(); |
| 140 | Thread.currentThread().setName("SwitchCleanup@" + old); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 141 | |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 142 | try { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 143 | if (log.isTraceEnabled()) { |
| 144 | log.trace("Running cleanup thread"); |
| 145 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 146 | switchCleanup(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 147 | } finally { |
| 148 | cleanupTask.reschedule(CLEANUP_TASK_INTERVAL, |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 149 | TimeUnit.SECONDS); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 150 | Thread.currentThread().setName(old); |
| 151 | } |
| 152 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 153 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 154 | /** |
| 155 | * First half of the switch cleanup operation. This method will attempt |
| 156 | * to get control of any switch it sees without a controller via the |
| 157 | * registry. |
| 158 | */ |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 159 | private void switchCleanup() { |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 160 | Iterable<Switch> switches = mutableTopology.getSwitches(); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 161 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 162 | if (log.isTraceEnabled()) { |
| 163 | log.trace("Checking for inactive switches"); |
| 164 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 165 | // For each switch check if a controller exists in controller |
| 166 | // registry |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 167 | for (Switch sw : switches) { |
Praseed Balakrishnan | e82adc6 | 2014-08-04 10:59:24 -0700 | [diff] [blame] | 168 | // FIXME How to handle case where Switch has never been |
| 169 | // registered to ZK |
| 170 | if (sw.getConfigState() == ConfigState.CONFIGURED) { |
| 171 | continue; |
| 172 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 173 | try { |
| 174 | String controller = |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 175 | registryService.getControllerForSwitch(sw.getDpid().value()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 176 | if (controller == null) { |
| 177 | log.debug("Requesting control to set switch {} INACTIVE", |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 178 | sw.getDpid()); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 179 | registryService.requestControl(sw.getDpid().value(), |
| 180 | this); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 181 | } |
| 182 | } catch (RegistryException e) { |
| 183 | log.error("Caught RegistryException in cleanup thread", e); |
| 184 | } |
| 185 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Second half of the switch cleanup operation. If the registry grants |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 190 | * control of a switch, we can be sure no other instance is writing |
| 191 | * this switch to the topology, so we can remove it now. |
| 192 | * |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 193 | * @param dpid the dpid of the switch we requested control for |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 194 | * @param hasControl whether we got control or not |
| 195 | */ |
| 196 | @Override |
| 197 | public void controlChanged(long dpid, boolean hasControl) { |
| 198 | if (hasControl) { |
| 199 | log.debug("Got control to set switch {} INACTIVE", |
| 200 | HexString.toHexString(dpid)); |
Jonathan Hart | e02cf54 | 2014-04-02 16:24:44 -0700 | [diff] [blame] | 201 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 202 | SwitchData switchData = new SwitchData(new Dpid(dpid)); |
| 203 | publishRemoveSwitchEvent(switchData); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 204 | registryService.releaseControl(dpid); |
| 205 | } |
| 206 | } |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 207 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 208 | |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 209 | /** |
| 210 | * A class to deal with Topology Operations that couldn't be pushed |
| 211 | * to the Global Log writer, because they need to be delayed. |
| 212 | * For example, a link cannot be pushed before the switches on both |
| 213 | * ends are in the Global Log. |
| 214 | * |
| 215 | * TODO: This is an ugly hack that should go away: right now we have to |
| 216 | * keep trying periodically. |
| 217 | * TODO: Currently, we retry only ADD Link Events, everything else |
| 218 | * is thrown away. |
| 219 | */ |
| 220 | private class DelayedOperationsHandler extends Thread { |
| 221 | private static final long RETRY_INTERVAL_MS = 10; // 10ms |
| 222 | |
| 223 | @Override |
| 224 | public void run() { |
| 225 | List<TopologyBatchOperation> operations = new LinkedList<>(); |
| 226 | |
| 227 | this.setName("TopologyPublisher.DelayedOperationsHandler " + |
| 228 | this.getId()); |
| 229 | // |
| 230 | // The main loop |
| 231 | // |
| 232 | while (true) { |
| 233 | try { |
| 234 | // |
| 235 | // Block-waiting for an operation to be added, sleep |
| 236 | // and try to publish it again. |
| 237 | // |
| 238 | TopologyBatchOperation firstTbo = delayedOperations.take(); |
| 239 | Thread.sleep(RETRY_INTERVAL_MS); |
| 240 | operations.add(firstTbo); |
| 241 | delayedOperations.drainTo(operations); |
| 242 | |
| 243 | // Retry only the appropriate operations |
| 244 | for (TopologyBatchOperation tbo : operations) { |
| 245 | for (BatchOperationEntry< |
| 246 | TopologyBatchOperation.Operator, |
| 247 | TopologyEvent> boe : tbo.getOperations()) { |
| 248 | TopologyBatchOperation.Operator oper = |
| 249 | boe.getOperator(); |
| 250 | switch (oper) { |
| 251 | case ADD: |
| 252 | TopologyEvent topologyEvent = boe.getTarget(); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 253 | LinkData linkData = |
| 254 | topologyEvent.getLinkData(); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 255 | // |
| 256 | // Test whether the Link Event still can be |
| 257 | // published. |
| 258 | // TODO: The implementation below has a bug: |
| 259 | // If it happens that the same Link Event was |
| 260 | // removed in the middle of checking, we might |
| 261 | // incorrectly publish it again from here. |
| 262 | // |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 263 | if (linkData == null) { |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 264 | break; |
| 265 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 266 | ConcurrentMap<ByteBuffer, LinkData> |
| 267 | linkDataEntries = publishedLinkDataEntries.get( |
| 268 | linkData.getDst().getDpid()); |
| 269 | if (linkDataEntries == null) { |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 270 | break; |
| 271 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 272 | if (linkDataEntries.get(linkData.getIDasByteBuffer()) == null) { |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 273 | break; |
| 274 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 275 | publishAddLinkEvent(linkData); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 276 | break; |
| 277 | case REMOVE: |
| 278 | break; |
| 279 | default: |
| 280 | log.error("Unknown Topology Batch Operation {}", oper); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } catch (InterruptedException exception) { |
| 286 | log.debug("Exception processing delayed operations: ", |
| 287 | exception); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 293 | @Override |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 294 | public void linkAdded(Link link) { |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 295 | LinkConfigStatus ret = networkConfigService.checkLinkConfig(link); |
| 296 | if (ret.getConfigState() == NetworkConfigState.DENY) { |
| 297 | log.warn("Discovered {} denied by configuration. {} " |
| 298 | + "Not allowing it to proceed.", link, ret.getMsg()); |
| 299 | return; |
| 300 | } |
| 301 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 302 | LinkData linkData = new LinkData( |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 303 | new SwitchPort(link.getSrc(), link.getSrcPort()), |
| 304 | new SwitchPort(link.getDst(), link.getDstPort())); |
| 305 | |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 306 | // FIXME should be merging, with existing attrs, etc.. |
| 307 | // TODO define attr name as constant somewhere. |
| 308 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 309 | linkData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 310 | TopologyElement.TYPE_PACKET_LAYER); |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 311 | if (ret.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 312 | Map<String, String> attr = ret.getLinkConfig().getPublishAttributes(); |
| 313 | for (Entry<String, String> e : attr.entrySet()) { |
| 314 | linkData.createStringAttribute(e.getKey(), e.getValue()); |
| 315 | } |
| 316 | linkData.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 317 | ConfigState.CONFIGURED.toString()); |
| 318 | } else { |
| 319 | linkData.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 320 | ConfigState.NOT_CONFIGURED.toString()); |
| 321 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 322 | linkData.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
Praseed Balakrishnan | 2aa6c0b | 2014-07-17 11:42:05 -0700 | [diff] [blame] | 323 | AdminStatus.ACTIVE.toString()); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 324 | linkData.freeze(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 325 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 326 | publishAddLinkEvent(linkData); |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void linkRemoved(Link link) { |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 331 | LinkData linkData = new LinkData( |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 332 | new SwitchPort(link.getSrc(), link.getSrcPort()), |
| 333 | new SwitchPort(link.getDst(), link.getDstPort())); |
| 334 | |
| 335 | // FIXME should be merging, with existing attrs, etc.. |
| 336 | // TODO define attr name as constant somewhere. |
| 337 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 338 | linkData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 339 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 340 | linkData.freeze(); |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 341 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 342 | publishRemoveLinkEvent(linkData); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 343 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 344 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 345 | /* ***************** |
| 346 | * IOFSwitchListener |
| 347 | * *****************/ |
| 348 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 349 | @Override |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 350 | public void switchActivatedMaster(long swId) { |
| 351 | IOFSwitch sw = floodlightProvider.getSwitch(swId); |
| 352 | final Dpid dpid = new Dpid(swId); |
| 353 | if (sw == null) { |
| 354 | log.warn("Added switch not available {} ", dpid); |
| 355 | return; |
| 356 | } |
| 357 | |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 358 | SwitchConfigStatus ret = networkConfigService.checkSwitchConfig(dpid); |
| 359 | if (ret.getConfigState() == NetworkConfigState.DENY) { |
| 360 | log.warn("Activated switch {} denied by network configuration. {} " |
| 361 | + "Not allowing it to proceed.", dpid, ret.getMsg()); |
| 362 | return; |
| 363 | } |
| 364 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 365 | controllerRoleChanged(dpid, Role.MASTER); |
| 366 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 367 | SwitchData switchData = new SwitchData(dpid); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 368 | // FIXME should be merging, with existing attrs, etc.. |
| 369 | // TODO define attr name as constant somewhere. |
| 370 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 371 | switchData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 372 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 373 | switchData.createStringAttribute("ConnectedSince", |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 374 | sw.getConnectedSince().toString()); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 375 | switchData.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 376 | AdminStatus.ACTIVE.toString()); |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 377 | if (ret.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 378 | Map<String, String> attr = ret.getSwitchConfig().getPublishAttributes(); |
| 379 | for (Entry<String, String> e : attr.entrySet()) { |
| 380 | switchData.createStringAttribute(e.getKey(), e.getValue()); |
| 381 | } |
| 382 | switchData.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 383 | ConfigState.CONFIGURED.toString()); |
| 384 | } else { |
| 385 | switchData.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
| 386 | ConfigState.NOT_CONFIGURED.toString()); |
| 387 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 388 | switchData.freeze(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 389 | // The Port events |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 390 | List<PortData> portDataEntries = new ArrayList<PortData>(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 391 | for (OFPortDesc port : sw.getPorts()) { |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 392 | PortData portData = new PortData(dpid, |
Yuta HIGUCHI | a507baf | 2014-08-22 13:42:40 -0700 | [diff] [blame] | 393 | PortNumberUtils.openFlow(port)); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 394 | // FIXME should be merging, with existing attrs, etc.. |
| 395 | // TODO define attr name as constant somewhere. |
| 396 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 397 | portData.createStringAttribute("name", port.getName()); |
| 398 | portData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 399 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 400 | portData.createStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 401 | ConfigState.NOT_CONFIGURED.toString()); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 402 | portData.createStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 403 | AdminStatus.ACTIVE.toString()); |
| 404 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 405 | portData.freeze(); |
| 406 | portDataEntries.add(portData); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 407 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 408 | publishAddSwitchEvent(switchData, portDataEntries); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void switchActivatedEqual(long swId) { |
| 413 | final Dpid dpid = new Dpid(swId); |
| 414 | controllerRoleChanged(dpid, Role.EQUAL); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void switchMasterToEqual(long swId) { |
| 419 | final Dpid dpid = new Dpid(swId); |
| 420 | controllerRoleChanged(dpid, Role.EQUAL); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void switchEqualToMaster(long swId) { |
| 425 | // for now treat as switchActivatedMaster |
| 426 | switchActivatedMaster(swId); |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void switchDisconnected(long swId) { |
| 431 | final Dpid dpid = new Dpid(swId); |
| 432 | |
| 433 | log.debug("Local switch disconnected: dpid = {} role = {}", dpid); |
| 434 | |
| 435 | Role role = Role.SLAVE; // TODO: Should be Role.UNKNOWN |
| 436 | |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 437 | MastershipData mastershipData = |
| 438 | new MastershipData(dpid, getOnosInstanceId(), role); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 439 | // FIXME should be merging, with existing attrs, etc.. |
| 440 | // TODO define attr name as constant somewhere. |
| 441 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 442 | mastershipData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 443 | TopologyElement.TYPE_ALL_LAYERS); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 444 | mastershipData.freeze(); |
| 445 | publishRemoveSwitchMastershipEvent(mastershipData); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public void switchPortChanged(long swId, OFPortDesc port, |
| 450 | PortChangeType changeType) { |
| 451 | switch (changeType) { |
| 452 | case ADD: |
| 453 | switchPortAdded(swId, port); |
| 454 | break; |
| 455 | case DELETE: |
| 456 | switchPortRemoved(swId, port); |
| 457 | break; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 458 | case UP: |
Pavlin Radoslavov | 7946c61 | 2014-08-13 15:06:00 -0700 | [diff] [blame] | 459 | // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE |
| 460 | switchPortAdded(swId, port); |
| 461 | break; |
| 462 | case DOWN: |
| 463 | // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE |
| 464 | switchPortRemoved(swId, port); |
| 465 | break; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 466 | case OTHER_UPDATE: |
| 467 | default: |
| 468 | // XXX S what is the right set of port change handlers? |
| 469 | log.debug("Topology publisher does not handle these port updates: {}", |
| 470 | changeType); |
| 471 | } |
| 472 | } |
| 473 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 474 | /** |
| 475 | * Prepares an event for adding a port on a switch. |
| 476 | * |
| 477 | * @param switchId the switch ID (DPID) |
| 478 | * @param port the port to add |
| 479 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 480 | private void switchPortAdded(long switchId, OFPortDesc port) { |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 481 | final Dpid dpid = new Dpid(switchId); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 482 | final PortData portData = new PortData(dpid, |
Yuta HIGUCHI | a507baf | 2014-08-22 13:42:40 -0700 | [diff] [blame] | 483 | PortNumberUtils.openFlow(port)); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 484 | // FIXME should be merging, with existing attrs, etc.. |
| 485 | // TODO define attr name as constant somewhere. |
| 486 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 487 | portData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 488 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 489 | portData.createStringAttribute("name", port.getName()); |
| 490 | portData.freeze(); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 491 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 492 | publishAddPortEvent(portData); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 493 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 494 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 495 | /** |
| 496 | * Prepares an event for removing a port on a switch. |
| 497 | * |
| 498 | * @param switchId the switch ID (DPID) |
| 499 | * @param port the port to remove |
| 500 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 501 | private void switchPortRemoved(long switchId, OFPortDesc port) { |
Yuta HIGUCHI | e2a4e17 | 2014-07-03 10:50:39 -0700 | [diff] [blame] | 502 | final Dpid dpid = new Dpid(switchId); |
Yuta HIGUCHI | 5bbbaca | 2014-06-09 16:39:08 -0700 | [diff] [blame] | 503 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 504 | final PortData portData = new PortData(dpid, |
Yuta HIGUCHI | a507baf | 2014-08-22 13:42:40 -0700 | [diff] [blame] | 505 | PortNumberUtils.openFlow(port)); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 506 | // FIXME should be merging, with existing attrs, etc.. |
| 507 | // TODO define attr name as constant somewhere. |
| 508 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 509 | portData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 510 | TopologyElement.TYPE_PACKET_LAYER); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 511 | portData.createStringAttribute("name", port.getName()); |
| 512 | portData.freeze(); |
Yuta HIGUCHI | 1222ac5 | 2014-07-09 16:50:28 -0700 | [diff] [blame] | 513 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 514 | publishRemovePortEvent(portData); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 515 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 516 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 517 | @Override |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 518 | public String getName() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 519 | return "topologyPublisher"; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 520 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 521 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 522 | /* ***************** |
| 523 | * IFloodlightModule |
| 524 | * *****************/ |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 525 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 526 | @Override |
| 527 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 528 | List<Class<? extends IFloodlightService>> services = |
| 529 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 530 | services.add(ITopologyPublisherService.class); |
| 531 | return services; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 532 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 533 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 534 | @Override |
| 535 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 536 | getServiceImpls() { |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 537 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 538 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
| 539 | impls.put(ITopologyPublisherService.class, this); |
| 540 | return impls; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 541 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 542 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 543 | @Override |
| 544 | public Collection<Class<? extends IFloodlightService>> |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 545 | getModuleDependencies() { |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 546 | Collection<Class<? extends IFloodlightService>> l = |
| 547 | new ArrayList<Class<? extends IFloodlightService>>(); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 548 | l.add(IFloodlightProviderService.class); |
| 549 | l.add(ILinkDiscoveryService.class); |
Jonathan Hart | 369875b | 2014-02-13 10:00:31 -0800 | [diff] [blame] | 550 | l.add(IThreadPoolService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 551 | l.add(IControllerRegistryService.class); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 552 | l.add(IDatagridService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 553 | l.add(ITopologyService.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 554 | l.add(IHostService.class); |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 555 | l.add(INetworkConfigService.class); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 556 | return l; |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 557 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 558 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 559 | @Override |
| 560 | public void init(FloodlightModuleContext context) |
| 561 | throws FloodlightModuleException { |
| 562 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 563 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
| 564 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 565 | datagridService = context.getServiceImpl(IDatagridService.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 566 | hostService = context.getServiceImpl(IHostService.class); |
Saurav Das | fb93c25 | 2014-08-18 20:40:13 -0700 | [diff] [blame] | 567 | networkConfigService = context.getServiceImpl(INetworkConfigService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 568 | topologyService = context.getServiceImpl(ITopologyService.class); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 569 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 570 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 571 | @Override |
| 572 | public void startUp(FloodlightModuleContext context) { |
| 573 | floodlightProvider.addOFSwitchListener(this); |
| 574 | linkDiscovery.addListener(this); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 575 | hostService.addHostListener(this); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 576 | |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 577 | eventChannel = datagridService.createChannel( |
| 578 | TopologyManager.EVENT_CHANNEL_NAME, |
| 579 | byte[].class, |
| 580 | TopologyEvent.class); |
| 581 | |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 582 | mutableTopology = topologyService.getTopology(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 583 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 584 | // Run the cleanup thread |
| 585 | String enableCleanup = |
| 586 | context.getConfigParams(this).get(ENABLE_CLEANUP_PROPERTY); |
| 587 | if (enableCleanup != null |
| 588 | && enableCleanup.equalsIgnoreCase("false")) { |
| 589 | cleanupEnabled = false; |
| 590 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 591 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 592 | log.debug("Cleanup thread is {}enabled", (cleanupEnabled) ? "" : "not "); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 593 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 594 | if (cleanupEnabled) { |
| 595 | IThreadPoolService threadPool = |
| 596 | context.getServiceImpl(IThreadPoolService.class); |
| 597 | cleanupTask = new SingletonTask(threadPool.getScheduledExecutor(), |
| 598 | new SwitchCleanup()); |
| 599 | // Run the cleanup task immediately on startup |
| 600 | cleanupTask.reschedule(0, TimeUnit.SECONDS); |
| 601 | } |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 602 | |
| 603 | // Run the Delayed Operations Handler thread |
| 604 | delayedOperationsHandler.start(); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 605 | } |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 606 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 607 | @Override |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 608 | public void hostAdded(Host host) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 609 | log.debug("Host added with MAC {}", host.getMacAddress()); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 610 | |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 611 | SwitchPort sp = new SwitchPort(host.getSwitchDPID(), host.getSwitchPort()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 612 | List<SwitchPort> spLists = new ArrayList<SwitchPort>(); |
| 613 | spLists.add(sp); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 614 | HostData hostData = new HostData(host.getMacAddress()); |
| 615 | hostData.setAttachmentPoints(spLists); |
| 616 | hostData.setLastSeenTime(host.getLastSeenTimestamp().getTime()); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 617 | // Does not use vlan info now. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 618 | hostData.freeze(); |
Jonathan Hart | b3e1b05 | 2014-04-02 16:01:12 -0700 | [diff] [blame] | 619 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 620 | publishAddHostEvent(hostData); |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 621 | } |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 622 | |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 623 | @Override |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 624 | public void hostRemoved(Host host) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 625 | log.debug("Host removed with MAC {}", host.getMacAddress()); |
| 626 | |
| 627 | // |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 628 | // Remove all previously added HostData for this MAC address |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 629 | // |
| 630 | // TODO: Currently, the caller of hostRemoved() might not include |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 631 | // the correct set of Attachment Points in the HostData entry itself. |
| 632 | // Also, we might have multiple HostData entries for the same |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 633 | // host (MAC address), each containing a single (different) Attachment |
| 634 | // Point. |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 635 | // Hence, here we have to cleanup all HostData entries for this |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 636 | // particular host, based on its MAC address. |
| 637 | // |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 638 | List<HostData> removeHostDataEntries = new LinkedList<>(); |
| 639 | for (ConcurrentMap<ByteBuffer, HostData> cm : publishedHostDataEntries.values()) { |
| 640 | for (HostData hostData : cm.values()) { |
| 641 | if (hostData.getMac().equals(host.getMacAddress())) { |
| 642 | removeHostDataEntries.add(hostData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 646 | for (HostData hostData : removeHostDataEntries) { |
| 647 | publishRemoveHostEvent(hostData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 648 | } |
Jonathan Hart | 8877067 | 2014-04-02 18:08:30 -0700 | [diff] [blame] | 649 | } |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 650 | |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 651 | @Override |
| 652 | public boolean publish(TopologyBatchOperation tbo) { |
| 653 | publishTopologyOperations(tbo); |
| 654 | return true; |
| 655 | } |
| 656 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 657 | /** |
| 658 | * Prepares the Controller role changed event for a switch. |
| 659 | * |
| 660 | * @param dpid the switch DPID |
| 661 | * @param role the new role of the controller |
| 662 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 663 | private void controllerRoleChanged(Dpid dpid, Role role) { |
| 664 | log.debug("Local switch controller mastership role changed: dpid = {} role = {}", |
| 665 | dpid, role); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 666 | MastershipData mastershipData = |
| 667 | new MastershipData(dpid, getOnosInstanceId(), role); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 668 | // FIXME should be merging, with existing attrs, etc.. |
| 669 | // TODO define attr name as constant somewhere. |
| 670 | // TODO populate appropriate attributes. |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 671 | mastershipData.createStringAttribute(TopologyElement.TYPE, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 672 | TopologyElement.TYPE_ALL_LAYERS); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 673 | mastershipData.freeze(); |
| 674 | publishAddSwitchMastershipEvent(mastershipData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 678 | * Publishes ADD Mastership Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 679 | * |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 680 | * @param mastershipData the mastership event to publish |
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 | private void publishAddSwitchMastershipEvent( |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 683 | MastershipData mastershipData) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 684 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 685 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 686 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 687 | new TopologyEvent(mastershipData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 688 | tbo.appendAddOperation(topologyEvent); |
| 689 | publishTopologyOperations(tbo); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 690 | publishedMastershipDataEntries.put(mastershipData.getDpid(), |
| 691 | mastershipData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 695 | * Publishes REMOVE Mastership Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 696 | * |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 697 | * @param mastershipData the mastership event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 698 | */ |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 699 | private void publishRemoveSwitchMastershipEvent( |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 700 | MastershipData mastershipData) { |
| 701 | if (publishedMastershipDataEntries.get(mastershipData.getDpid()) == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 702 | return; // Nothing to do |
| 703 | } |
| 704 | |
| 705 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 706 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 707 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 708 | new TopologyEvent(mastershipData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 709 | tbo.appendRemoveOperation(topologyEvent); |
| 710 | publishTopologyOperations(tbo); |
Yuta HIGUCHI | d8fd2f5 | 2014-09-01 23:19:45 -0700 | [diff] [blame] | 711 | publishedMastershipDataEntries.remove(mastershipData.getDpid()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 715 | * Publishes ADD Switch Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 716 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 717 | * @param switchData the switch event to publish |
| 718 | * @param portDataEntries the corresponding port events for the switch to |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 719 | * publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 720 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 721 | private void publishAddSwitchEvent(SwitchData switchData, |
| 722 | Collection<PortData> portDataEntries) { |
| 723 | if (!registryService.hasControl(switchData.getOriginDpid().value())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 724 | log.debug("Not the master for switch {}. Suppressed switch add event {}.", |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 725 | switchData.getOriginDpid(), switchData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 726 | return; |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 729 | // Keep track of the old Port Events that should be removed |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 730 | ConcurrentMap<ByteBuffer, PortData> oldPortDataEntries = |
| 731 | publishedPortDataEntries.get(switchData.getDpid()); |
| 732 | if (oldPortDataEntries == null) { |
| 733 | oldPortDataEntries = new ConcurrentHashMap<>(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 736 | // Publish the information for the switch |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 737 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 738 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 739 | new TopologyEvent(switchData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 740 | tbo.appendAddOperation(topologyEvent); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 741 | |
| 742 | // Publish the information for each port |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 743 | ConcurrentMap<ByteBuffer, PortData> newPortDataEntries = |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 744 | new ConcurrentHashMap<>(); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 745 | for (PortData portData : portDataEntries) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 746 | topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 747 | new TopologyEvent(portData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 748 | tbo.appendAddOperation(topologyEvent); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 749 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 750 | ByteBuffer id = portData.getIDasByteBuffer(); |
| 751 | newPortDataEntries.put(id, portData); |
| 752 | oldPortDataEntries.remove(id); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 753 | } |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 754 | publishTopologyOperations(tbo); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 755 | publishedSwitchDataEntries.put(switchData.getDpid(), switchData); |
| 756 | publishedPortDataEntries.put(switchData.getDpid(), newPortDataEntries); |
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 | // Cleanup for each of the old removed port |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 759 | for (PortData portData : oldPortDataEntries.values()) { |
| 760 | publishRemovePortEvent(portData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
| 764 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 765 | * Publishes REMOVE Switch Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 766 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 767 | * @param switchData the switch event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 768 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 769 | private void publishRemoveSwitchEvent(SwitchData switchData) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 770 | // |
| 771 | // TODO: Removed the check for now, because currently this method is |
| 772 | // also called by the SwitchCleanup thread, and in that case |
| 773 | // the Switch Event was published by some other ONOS instance. |
| 774 | // |
| 775 | /* |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 776 | if (publishedSwitchDataEntries.get(switchData.getDpid()) == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 777 | return; // Nothing to do |
| 778 | } |
| 779 | */ |
| 780 | |
| 781 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 782 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 783 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 784 | new TopologyEvent(switchData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 785 | tbo.appendRemoveOperation(topologyEvent); |
| 786 | publishTopologyOperations(tbo); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 787 | publishedSwitchDataEntries.remove(switchData.getDpid()); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 788 | |
| 789 | // Cleanup for each port |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 790 | ConcurrentMap<ByteBuffer, PortData> portDataEntries = |
| 791 | publishedPortDataEntries.get(switchData.getDpid()); |
| 792 | if (portDataEntries != null) { |
| 793 | for (PortData portData : portDataEntries.values()) { |
| 794 | publishRemovePortEvent(portData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 798 | publishedPortDataEntries.remove(switchData.getDpid()); |
| 799 | publishedLinkDataEntries.remove(switchData.getDpid()); |
| 800 | publishedHostDataEntries.remove(switchData.getDpid()); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Publishes ADD Port Event. |
| 805 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 806 | * @param portData the port event to publish |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 807 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 808 | private void publishAddPortEvent(PortData portData) { |
| 809 | if (!registryService.hasControl(portData.getOriginDpid().value())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 810 | log.debug("Not the master for switch {}. Suppressed port add event {}.", |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 811 | portData.getOriginDpid(), portData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 812 | return; |
| 813 | } |
| 814 | |
| 815 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 816 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 817 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 818 | new TopologyEvent(portData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 819 | tbo.appendAddOperation(topologyEvent); |
| 820 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 821 | |
| 822 | // Store the new Port Event in the local cache |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 823 | ConcurrentMap<ByteBuffer, PortData> portDataEntries = |
| 824 | ConcurrentUtils.putIfAbsent(publishedPortDataEntries, |
| 825 | portData.getDpid(), |
| 826 | new ConcurrentHashMap<ByteBuffer, PortData>()); |
| 827 | portDataEntries.put(portData.getIDasByteBuffer(), portData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 831 | * Publishes REMOVE Port Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 832 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 833 | * @param portData the port event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 834 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 835 | private void publishRemovePortEvent(PortData portData) { |
| 836 | ConcurrentMap<ByteBuffer, PortData> portDataEntries = |
| 837 | publishedPortDataEntries.get(portData.getDpid()); |
| 838 | if (portDataEntries == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 839 | return; // Nothing to do |
| 840 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 841 | if (portDataEntries.get(portData.getIDasByteBuffer()) == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 842 | return; // Nothing to do |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 845 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 846 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 847 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 848 | new TopologyEvent(portData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 849 | tbo.appendRemoveOperation(topologyEvent); |
| 850 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 851 | |
| 852 | // Cleanup for the incoming link(s) |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 853 | ConcurrentMap<ByteBuffer, LinkData> linkDataEntries = |
| 854 | publishedLinkDataEntries.get(portData.getDpid()); |
| 855 | if (linkDataEntries != null) { |
| 856 | for (LinkData linkData : linkDataEntries.values()) { |
| 857 | if (linkData.getDst().equals(portData.getSwitchPort())) { |
| 858 | publishRemoveLinkEvent(linkData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // Cleanup for the connected hosts |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 864 | ConcurrentMap<ByteBuffer, HostData> hostDataEntries = |
| 865 | publishedHostDataEntries.get(portData.getDpid()); |
| 866 | if (hostDataEntries != null) { |
| 867 | for (HostData hostData : hostDataEntries.values()) { |
| 868 | for (SwitchPort swp : hostData.getAttachmentPoints()) { |
| 869 | if (swp.equals(portData.getSwitchPort())) { |
| 870 | publishRemoveHostEvent(hostData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | } |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 874 | } |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 875 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 876 | portDataEntries.remove(portData.getIDasByteBuffer()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 880 | * Publishes ADD Link Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 881 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 882 | * @param linkData the link event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 883 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 884 | private void publishAddLinkEvent(LinkData linkData) { |
| 885 | if (!registryService.hasControl(linkData.getOriginDpid().value())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 886 | log.debug("Not the master for dst switch {}. Suppressed link add event {}.", |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 887 | linkData.getOriginDpid(), linkData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 888 | return; |
| 889 | } |
| 890 | |
| 891 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 892 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 893 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 894 | new TopologyEvent(linkData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 895 | tbo.appendAddOperation(topologyEvent); |
| 896 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 897 | |
| 898 | // Store the new Link Event in the local cache |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 899 | ConcurrentMap<ByteBuffer, LinkData> linkDataEntries = |
| 900 | ConcurrentUtils.putIfAbsent(publishedLinkDataEntries, |
| 901 | linkData.getDst().getDpid(), |
| 902 | new ConcurrentHashMap<ByteBuffer, LinkData>()); |
| 903 | linkDataEntries.put(linkData.getIDasByteBuffer(), linkData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 907 | * Publishes REMOVE Link Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 908 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 909 | * @param linkData the link event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 910 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 911 | private void publishRemoveLinkEvent(LinkData linkData) { |
| 912 | ConcurrentMap<ByteBuffer, LinkData> linkDataEntries = |
| 913 | publishedLinkDataEntries.get(linkData.getDst().getDpid()); |
| 914 | if (linkDataEntries == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 915 | return; // Nothing to do |
| 916 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 917 | if (linkDataEntries.get(linkData.getIDasByteBuffer()) == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 918 | return; // Nothing to do |
| 919 | } |
| 920 | |
| 921 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 922 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 923 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 924 | new TopologyEvent(linkData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 925 | tbo.appendRemoveOperation(topologyEvent); |
| 926 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 927 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 928 | linkDataEntries.remove(linkData.getIDasByteBuffer()); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 932 | * Publishes ADD Host Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 933 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 934 | * @param hostData the host event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 935 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 936 | private void publishAddHostEvent(HostData hostData) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 937 | // |
| 938 | // NOTE: The implementation below assumes that there is just one |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 939 | // attachment point stored in hostData. Currently, this assumption |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 940 | // is true based on the existing implementation of the caller |
| 941 | // hostAdded(). |
| 942 | // |
| 943 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 944 | if (!registryService.hasControl(hostData.getOriginDpid().value())) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 945 | log.debug("Not the master for attachment switch {}. Suppressed host add event {}.", |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 946 | hostData.getOriginDpid(), hostData); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 947 | return; |
| 948 | } |
| 949 | |
| 950 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 951 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 952 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 953 | new TopologyEvent(hostData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 954 | tbo.appendAddOperation(topologyEvent); |
| 955 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 956 | |
| 957 | // Store the new Host Event in the local cache |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 958 | ConcurrentMap<ByteBuffer, HostData> hostDataEntries = |
| 959 | ConcurrentUtils.putIfAbsent(publishedHostDataEntries, |
| 960 | hostData.getOriginDpid(), |
| 961 | new ConcurrentHashMap<ByteBuffer, HostData>()); |
| 962 | hostDataEntries.put(hostData.getIDasByteBuffer(), hostData); |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /** |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 966 | * Publishes REMOVE Host Event. |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 967 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 968 | * @param hostData the host event to publish |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 969 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 970 | private void publishRemoveHostEvent(HostData hostData) { |
| 971 | ConcurrentMap<ByteBuffer, HostData> hostDataEntries = |
| 972 | publishedHostDataEntries.get(hostData.getOriginDpid()); |
| 973 | if (hostDataEntries == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 974 | return; // Nothing to do |
Pavlin Radoslavov | b46f89b | 2014-08-15 23:00:26 -0700 | [diff] [blame] | 975 | } |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 976 | if (hostDataEntries.get(hostData.getIDasByteBuffer()) == null) { |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 977 | return; // Nothing to do |
| 978 | } |
| 979 | |
| 980 | // Publish the information |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 981 | TopologyBatchOperation tbo = new TopologyBatchOperation(); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 982 | TopologyEvent topologyEvent = |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 983 | new TopologyEvent(hostData, getOnosInstanceId()); |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 984 | tbo.appendRemoveOperation(topologyEvent); |
| 985 | publishTopologyOperations(tbo); |
Pavlin Radoslavov | 000fbae | 2014-08-19 19:42:58 -0700 | [diff] [blame] | 986 | |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 987 | hostDataEntries.remove(hostData.getIDasByteBuffer()); |
Pavlin Radoslavov | 695f895 | 2014-07-23 16:57:01 -0700 | [diff] [blame] | 988 | } |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 989 | |
| 990 | /** |
| 991 | * Publishes Topology Operations. |
| 992 | * |
| 993 | * @param tbo the Topology Operations to publish |
| 994 | */ |
| 995 | private void publishTopologyOperations(TopologyBatchOperation tbo) { |
| 996 | // TODO: This flag should be configurable |
| 997 | boolean isGlobalLogWriter = false; |
| 998 | |
| 999 | log.debug("Publishing: {}", tbo); |
| 1000 | |
| 1001 | if (isGlobalLogWriter) { |
| 1002 | if (!topologyService.publish(tbo)) { |
| 1003 | log.debug("Cannot publish: {}", tbo); |
| 1004 | delayedOperations.add(tbo); |
| 1005 | } |
| 1006 | } else { |
| 1007 | // TODO: For now we publish each TopologyEvent independently |
| 1008 | for (BatchOperationEntry<TopologyBatchOperation.Operator, |
| 1009 | TopologyEvent> boe : tbo.getOperations()) { |
| 1010 | TopologyBatchOperation.Operator oper = boe.getOperator(); |
| 1011 | TopologyEvent topologyEvent = boe.getTarget(); |
| 1012 | switch (oper) { |
| 1013 | case ADD: |
| 1014 | eventChannel.addEntry(topologyEvent.getID(), |
| 1015 | topologyEvent); |
| 1016 | break; |
| 1017 | case REMOVE: |
| 1018 | eventChannel.removeEntry(topologyEvent.getID()); |
| 1019 | break; |
| 1020 | default: |
| 1021 | log.error("Unknown Topology Batch Operation {}", oper); |
| 1022 | break; |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 1027 | } |