alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.net.flowobjective.impl; |
| 17 | |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 20 | import com.google.common.collect.Sets; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.apache.felix.scr.annotations.Service; |
| 27 | import org.onlab.osgi.DefaultServiceDirectory; |
| 28 | import org.onlab.osgi.ServiceDirectory; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 29 | import org.onlab.util.ItemNotFoundException; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 30 | import org.onosproject.cluster.ClusterService; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 31 | import org.onosproject.cluster.NodeId; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 32 | import org.onosproject.mastership.MastershipEvent; |
| 33 | import org.onosproject.mastership.MastershipListener; |
| 34 | import org.onosproject.mastership.MastershipService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 35 | import org.onosproject.net.DeviceId; |
| 36 | import org.onosproject.net.behaviour.Pipeliner; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 37 | import org.onosproject.net.behaviour.PipelinerContext; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 38 | import org.onosproject.net.device.DeviceEvent; |
| 39 | import org.onosproject.net.device.DeviceListener; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 40 | import org.onosproject.net.device.DeviceService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 41 | import org.onosproject.net.driver.DriverHandler; |
| 42 | import org.onosproject.net.driver.DriverService; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 43 | import org.onosproject.net.flow.FlowRuleService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 45 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 46 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 47 | import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 48 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 49 | import org.onosproject.net.flowobjective.NextObjective; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.Objective; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 51 | import org.onosproject.net.flowobjective.ObjectiveEvent; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 52 | import org.onosproject.net.group.GroupService; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | import org.slf4j.LoggerFactory; |
| 55 | |
| 56 | import java.util.Collection; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 57 | import java.util.Collections; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 58 | import java.util.Map; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 59 | import java.util.Set; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 60 | |
| 61 | import static com.google.common.base.Preconditions.checkState; |
| 62 | |
| 63 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 64 | * Provides implementation of the flow objective programming service. |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 65 | */ |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 66 | @Component(immediate = true) |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 67 | @Service |
| 68 | public class FlowObjectiveManager implements FlowObjectiveService { |
| 69 | |
| 70 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 71 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 72 | public static final String NOT_INITIALIZED = "Driver not initialized"; |
| 73 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 75 | protected DriverService driverService; |
| 76 | |
| 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 78 | protected DeviceService deviceService; |
| 79 | |
| 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 81 | protected MastershipService mastershipService; |
| 82 | |
| 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 84 | protected ClusterService clusterService; |
| 85 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 86 | // Note: The following dependencies are added on behalf of the pipeline |
| 87 | // driver behaviours to assure these services are available for their |
| 88 | // initialization. |
| 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 90 | protected FlowRuleService flowRuleService; |
| 91 | |
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | protected GroupService groupService; |
| 94 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 96 | protected FlowObjectiveStore flowObjectiveStore; |
| 97 | |
| 98 | private final FlowObjectiveStoreDelegate delegate = new InternalStoreDelegate(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 99 | |
| 100 | private final Map<DeviceId, DriverHandler> driverHandlers = Maps.newConcurrentMap(); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 101 | private final Map<DeviceId, Pipeliner> pipeliners = Maps.newConcurrentMap(); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 102 | |
| 103 | private final PipelinerContext context = new InnerPipelineContext(); |
| 104 | private final MastershipListener mastershipListener = new InnerMastershipListener(); |
| 105 | private final DeviceListener deviceListener = new InnerDeviceListener(); |
| 106 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 107 | protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 108 | |
| 109 | private final Map<DeviceId, Collection<Objective>> pendingObjectives = |
| 110 | Maps.newConcurrentMap(); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 111 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 112 | private NodeId localNode; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 113 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 114 | private Map<Integer, Set<PendingNext>> pendingForwards = |
| 115 | Maps.newConcurrentMap(); |
| 116 | |
| 117 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 118 | @Activate |
| 119 | protected void activate() { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 120 | flowObjectiveStore.setDelegate(delegate); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 121 | localNode = clusterService.getLocalNode().id(); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 122 | mastershipService.addListener(mastershipListener); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 123 | deviceService.addListener(deviceListener); |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 124 | deviceService.getDevices().forEach(device -> setupPipelineHandler(device.id())); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 125 | log.info("Started"); |
| 126 | } |
| 127 | |
| 128 | @Deactivate |
| 129 | protected void deactivate() { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 130 | flowObjectiveStore.unsetDelegate(delegate); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 131 | mastershipService.removeListener(mastershipListener); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 132 | deviceService.removeListener(deviceListener); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 133 | log.info("Stopped"); |
| 134 | } |
| 135 | |
| 136 | @Override |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 137 | public void filter(DeviceId deviceId, |
| 138 | FilteringObjective filteringObjective) { |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 139 | if (deviceService.isAvailable(deviceId)) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 140 | getDevicePipeliner(deviceId).filter(filteringObjective); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 141 | } else { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 142 | updatePendingMap(deviceId, filteringObjective); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 143 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 144 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 148 | public void forward(DeviceId deviceId, |
| 149 | ForwardingObjective forwardingObjective) { |
| 150 | |
| 151 | if (queueObjective(deviceId, forwardingObjective)) { |
| 152 | return; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 153 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 154 | |
| 155 | if (deviceService.isAvailable(deviceId)) { |
| 156 | getDevicePipeliner(deviceId).forward(forwardingObjective); |
| 157 | } else { |
| 158 | updatePendingMap(deviceId, forwardingObjective); |
| 159 | } |
| 160 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 161 | } |
| 162 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 163 | @Override |
| 164 | public void next(DeviceId deviceId, |
| 165 | NextObjective nextObjective) { |
| 166 | if (deviceService.isAvailable(deviceId)) { |
| 167 | getDevicePipeliner(deviceId).next(nextObjective); |
| 168 | } else { |
| 169 | updatePendingMap(deviceId, nextObjective); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) { |
| 174 | if (fwd.nextId() != null && |
| 175 | flowObjectiveStore.getNextGroup(fwd.nextId()) == null) { |
| 176 | log.warn("Queuing forwarding objective."); |
| 177 | if (pendingForwards.putIfAbsent(fwd.nextId(), |
| 178 | Sets.newHashSet(new PendingNext(deviceId, fwd))) != null) { |
| 179 | Set<PendingNext> pending = pendingForwards.get(fwd.nextId()); |
| 180 | pending.add(new PendingNext(deviceId, fwd)); |
| 181 | } |
| 182 | return true; |
| 183 | } |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 188 | private void updatePendingMap(DeviceId deviceId, Objective pending) { |
| 189 | if (pendingObjectives.putIfAbsent(deviceId, Lists.newArrayList(pending)) != null) { |
| 190 | Collection<Objective> objectives = pendingObjectives.get(deviceId); |
| 191 | objectives.add(pending); |
| 192 | } |
| 193 | |
| 194 | } |
| 195 | |
| 196 | // Retrieves the device pipeline behaviour from the cache. |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 197 | private Pipeliner getDevicePipeliner(DeviceId deviceId) { |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 198 | Pipeliner pipeliner = pipeliners.get(deviceId); |
| 199 | checkState(pipeliner != null, NOT_INITIALIZED); |
| 200 | return pipeliner; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 201 | } |
| 202 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 203 | private void setupPipelineHandler(DeviceId deviceId) { |
| 204 | if (localNode.equals(mastershipService.getMasterFor(deviceId))) { |
| 205 | // Attempt to lookup the handler in the cache |
| 206 | DriverHandler handler = driverHandlers.get(deviceId); |
| 207 | if (handler == null) { |
| 208 | try { |
| 209 | // Otherwise create it and if it has pipeline behaviour, cache it |
| 210 | handler = driverService.createHandler(deviceId); |
| 211 | if (!handler.driver().hasBehaviour(Pipeliner.class)) { |
| 212 | log.warn("Pipeline behaviour not supported for device {}", |
| 213 | deviceId); |
| 214 | return; |
| 215 | } |
| 216 | } catch (ItemNotFoundException e) { |
| 217 | log.warn("No applicable driver for device {}", deviceId); |
| 218 | return; |
| 219 | } |
| 220 | driverHandlers.put(deviceId, handler); |
| 221 | } |
| 222 | |
| 223 | // Always (re)initialize the pipeline behaviour |
| 224 | Pipeliner pipeliner = handler.behaviour(Pipeliner.class); |
| 225 | pipeliner.init(deviceId, context); |
| 226 | pipeliners.putIfAbsent(deviceId, pipeliner); |
| 227 | log.info("Driver {} bound to device {}", handler.driver().name(), deviceId); |
| 228 | } |
| 229 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 230 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 231 | // Triggers driver setup when the local node becomes a device master. |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 232 | private class InnerMastershipListener implements MastershipListener { |
| 233 | @Override |
| 234 | public void event(MastershipEvent event) { |
| 235 | switch (event.type()) { |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 236 | case MASTER_CHANGED: |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 237 | if (event.roleInfo().master() != null) { |
| 238 | setupPipelineHandler(event.subject()); |
| 239 | } |
| 240 | break; |
| 241 | case BACKUPS_CHANGED: |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 242 | break; |
| 243 | default: |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 244 | break; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 247 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 248 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 249 | // Triggers driver setup when a device is (re)detected. |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 250 | private class InnerDeviceListener implements DeviceListener { |
| 251 | @Override |
| 252 | public void event(DeviceEvent event) { |
| 253 | switch (event.type()) { |
| 254 | case DEVICE_ADDED: |
| 255 | case DEVICE_AVAILABILITY_CHANGED: |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 256 | if (deviceService.isAvailable(event.subject().id())) { |
| 257 | setupPipelineHandler(event.subject().id()); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 258 | processPendingObjectives(event.subject().id()); |
alshabib | 4313d10 | 2015-04-08 18:55:08 -0700 | [diff] [blame] | 259 | } |
| 260 | break; |
| 261 | case DEVICE_UPDATED: |
| 262 | break; |
| 263 | case DEVICE_REMOVED: |
| 264 | break; |
| 265 | case DEVICE_SUSPENDED: |
| 266 | break; |
| 267 | case PORT_ADDED: |
| 268 | break; |
| 269 | case PORT_UPDATED: |
| 270 | break; |
| 271 | case PORT_REMOVED: |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 272 | break; |
| 273 | default: |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 274 | break; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 275 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 276 | } |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 277 | |
| 278 | private void processPendingObjectives(DeviceId deviceId) { |
alshabib | 1097c97 | 2015-04-10 14:41:32 -0700 | [diff] [blame] | 279 | pendingObjectives.getOrDefault(deviceId, |
| 280 | Collections.emptySet()).forEach(obj -> { |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 281 | if (obj instanceof NextObjective) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 282 | next(deviceId, (NextObjective) obj); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 283 | } else if (obj instanceof ForwardingObjective) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 284 | forward(deviceId, (ForwardingObjective) obj); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 285 | } else { |
| 286 | getDevicePipeliner(deviceId) |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 287 | .filter((FilteringObjective) obj); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 288 | } |
| 289 | }); |
| 290 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 291 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 292 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 293 | // Processing context for initializing pipeline driver behaviours. |
| 294 | private class InnerPipelineContext implements PipelinerContext { |
| 295 | @Override |
| 296 | public ServiceDirectory directory() { |
| 297 | return serviceDirectory; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 298 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame^] | 299 | |
| 300 | @Override |
| 301 | public FlowObjectiveStore store() { |
| 302 | return flowObjectiveStore; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | } |
| 307 | |
| 308 | private class InternalStoreDelegate implements FlowObjectiveStoreDelegate { |
| 309 | @Override |
| 310 | public void notify(ObjectiveEvent event) { |
| 311 | Set<PendingNext> pending = pendingForwards.remove(event.subject()); |
| 312 | |
| 313 | if (pending == null) { |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | log.info("Processing pending objectives {}", pending.size()); |
| 318 | |
| 319 | pending.forEach(p -> getDevicePipeliner(p.deviceId()) |
| 320 | .forward(p.forwardingObjective())); |
| 321 | |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Data class used to hold a pending forwarding objective that could not |
| 327 | * be processed because the associated next object was not present. |
| 328 | */ |
| 329 | private class PendingNext { |
| 330 | private final DeviceId deviceId; |
| 331 | private final ForwardingObjective fwd; |
| 332 | |
| 333 | public PendingNext(DeviceId deviceId, ForwardingObjective fwd) { |
| 334 | this.deviceId = deviceId; |
| 335 | this.fwd = fwd; |
| 336 | } |
| 337 | |
| 338 | public DeviceId deviceId() { |
| 339 | return deviceId; |
| 340 | } |
| 341 | |
| 342 | public ForwardingObjective forwardingObjective() { |
| 343 | return fwd; |
| 344 | } |
| 345 | |
| 346 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 347 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 348 | } |