blob: 7d0713b567a24bcee2d84e9011469c7b2d884610 [file] [log] [blame]
alshabib77b88482015-04-07 15:47:50 -07001/*
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 */
16package org.onosproject.net.flowobjective.impl;
17
18import com.google.common.collect.Maps;
alshabib2a441c62015-04-13 18:39:38 -070019import com.google.common.collect.Sets;
alshabib77b88482015-04-07 15:47:50 -070020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onlab.osgi.DefaultServiceDirectory;
27import org.onlab.osgi.ServiceDirectory;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070028import org.onlab.util.ItemNotFoundException;
alshabib77b88482015-04-07 15:47:50 -070029import org.onosproject.cluster.ClusterService;
Changhoon Yoon541ef712015-05-23 17:18:34 +090030import org.onosproject.core.Permission;
alshabib77b88482015-04-07 15:47:50 -070031import org.onosproject.mastership.MastershipEvent;
32import org.onosproject.mastership.MastershipListener;
33import org.onosproject.mastership.MastershipService;
alshabib77b88482015-04-07 15:47:50 -070034import org.onosproject.net.DeviceId;
35import org.onosproject.net.behaviour.Pipeliner;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070036import org.onosproject.net.behaviour.PipelinerContext;
alshabibaebe7752015-04-07 17:45:42 -070037import org.onosproject.net.device.DeviceEvent;
38import org.onosproject.net.device.DeviceListener;
alshabib77b88482015-04-07 15:47:50 -070039import org.onosproject.net.device.DeviceService;
Thomas Vachuska866b46a2015-04-30 00:26:55 -070040import org.onosproject.net.driver.DefaultDriverProviderService;
alshabib77b88482015-04-07 15:47:50 -070041import org.onosproject.net.driver.DriverHandler;
42import org.onosproject.net.driver.DriverService;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070043import org.onosproject.net.flow.FlowRuleService;
alshabib77b88482015-04-07 15:47:50 -070044import org.onosproject.net.flowobjective.FilteringObjective;
45import org.onosproject.net.flowobjective.FlowObjectiveService;
alshabib2a441c62015-04-13 18:39:38 -070046import org.onosproject.net.flowobjective.FlowObjectiveStore;
47import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate;
alshabib77b88482015-04-07 15:47:50 -070048import org.onosproject.net.flowobjective.ForwardingObjective;
49import org.onosproject.net.flowobjective.NextObjective;
alshabib910aff12015-04-09 16:55:57 -070050import org.onosproject.net.flowobjective.Objective;
Jonathan Hart17d00452015-04-21 17:10:00 -070051import org.onosproject.net.flowobjective.ObjectiveError;
alshabib2a441c62015-04-13 18:39:38 -070052import org.onosproject.net.flowobjective.ObjectiveEvent;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070053import org.onosproject.net.group.GroupService;
alshabib77b88482015-04-07 15:47:50 -070054import org.slf4j.Logger;
55import org.slf4j.LoggerFactory;
56
alshabib77b88482015-04-07 15:47:50 -070057import java.util.Map;
alshabib2a441c62015-04-13 18:39:38 -070058import java.util.Set;
Jonathan Hart17d00452015-04-21 17:10:00 -070059import java.util.concurrent.ExecutorService;
alshabib77b88482015-04-07 15:47:50 -070060
Sho SHIMIZUf45d85d2015-07-01 14:39:11 -070061import static com.google.common.base.Preconditions.checkNotNull;
Thomas Vachuska866b46a2015-04-30 00:26:55 -070062import static java.util.concurrent.Executors.newFixedThreadPool;
Jonathan Hart17d00452015-04-21 17:10:00 -070063import static org.onlab.util.Tools.groupedThreads;
Changhoon Yoon541ef712015-05-23 17:18:34 +090064import static org.onosproject.security.AppGuard.checkPermission;
65
alshabib77b88482015-04-07 15:47:50 -070066
67/**
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070068 * Provides implementation of the flow objective programming service.
alshabib77b88482015-04-07 15:47:50 -070069 */
alshabib2a441c62015-04-13 18:39:38 -070070@Component(immediate = true)
alshabib77b88482015-04-07 15:47:50 -070071@Service
72public class FlowObjectiveManager implements FlowObjectiveService {
73
Saurav Dasbd7f7422015-04-23 16:31:47 -070074 public static final int INSTALL_RETRY_ATTEMPTS = 5;
Jonathan Hart17d00452015-04-21 17:10:00 -070075 public static final long INSTALL_RETRY_INTERVAL = 1000; // ms
alshabib77b88482015-04-07 15:47:50 -070076
Jonathan Hart17d00452015-04-21 17:10:00 -070077 private final Logger log = LoggerFactory.getLogger(getClass());
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070078
alshabib77b88482015-04-07 15:47:50 -070079 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 protected DriverService driverService;
81
82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected DeviceService deviceService;
84
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 protected MastershipService mastershipService;
87
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 protected ClusterService clusterService;
90
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070091 // Note: The following dependencies are added on behalf of the pipeline
92 // driver behaviours to assure these services are available for their
93 // initialization.
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected FlowRuleService flowRuleService;
96
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 protected GroupService groupService;
99
alshabib2a441c62015-04-13 18:39:38 -0700100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 protected FlowObjectiveStore flowObjectiveStore;
102
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700103 // Note: This must remain an optional dependency to allow re-install of default drivers.
104 // Note: For now disabled until we can move to OPTIONAL_UNARY dependency
105 // @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected DefaultDriverProviderService defaultDriverService;
108
alshabib2a441c62015-04-13 18:39:38 -0700109 private final FlowObjectiveStoreDelegate delegate = new InternalStoreDelegate();
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700110
111 private final Map<DeviceId, DriverHandler> driverHandlers = Maps.newConcurrentMap();
alshabib910aff12015-04-09 16:55:57 -0700112 private final Map<DeviceId, Pipeliner> pipeliners = Maps.newConcurrentMap();
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700113
114 private final PipelinerContext context = new InnerPipelineContext();
115 private final MastershipListener mastershipListener = new InnerMastershipListener();
116 private final DeviceListener deviceListener = new InnerDeviceListener();
117
alshabib77b88482015-04-07 15:47:50 -0700118 protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
alshabib910aff12015-04-09 16:55:57 -0700119
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700120 private Map<Integer, Set<PendingNext>> pendingForwards = Maps.newConcurrentMap();
alshabib2a441c62015-04-13 18:39:38 -0700121
Jonathan Hart17d00452015-04-21 17:10:00 -0700122 private ExecutorService executorService;
alshabib2a441c62015-04-13 18:39:38 -0700123
alshabib77b88482015-04-07 15:47:50 -0700124 @Activate
125 protected void activate() {
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700126 executorService = newFixedThreadPool(4, groupedThreads("onos/objective-installer", "%d"));
alshabib2a441c62015-04-13 18:39:38 -0700127 flowObjectiveStore.setDelegate(delegate);
alshabib77b88482015-04-07 15:47:50 -0700128 mastershipService.addListener(mastershipListener);
alshabibaebe7752015-04-07 17:45:42 -0700129 deviceService.addListener(deviceListener);
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700130 deviceService.getDevices().forEach(device -> setupPipelineHandler(device.id()));
alshabib77b88482015-04-07 15:47:50 -0700131 log.info("Started");
132 }
133
134 @Deactivate
135 protected void deactivate() {
alshabib2a441c62015-04-13 18:39:38 -0700136 flowObjectiveStore.unsetDelegate(delegate);
alshabib77b88482015-04-07 15:47:50 -0700137 mastershipService.removeListener(mastershipListener);
alshabibaebe7752015-04-07 17:45:42 -0700138 deviceService.removeListener(deviceListener);
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700139 executorService.shutdown();
140 pipeliners.clear();
141 driverHandlers.clear();
alshabib77b88482015-04-07 15:47:50 -0700142 log.info("Stopped");
143 }
144
Jonathan Hart17d00452015-04-21 17:10:00 -0700145 /**
146 * Task that passes the flow objective down to the driver. The task will
147 * make a few attempts to find the appropriate driver, then eventually give
148 * up and report an error if no suitable driver could be found.
149 */
150 private class ObjectiveInstaller implements Runnable {
151 private final DeviceId deviceId;
152 private final Objective objective;
153
Sho SHIMIZUf45d85d2015-07-01 14:39:11 -0700154 private final int numAttempts;
Jonathan Hart17d00452015-04-21 17:10:00 -0700155
156 public ObjectiveInstaller(DeviceId deviceId, Objective objective) {
Sho SHIMIZUf45d85d2015-07-01 14:39:11 -0700157 this(deviceId, objective, 1);
158 }
159
160 public ObjectiveInstaller(DeviceId deviceId, Objective objective, int attemps) {
161 this.deviceId = checkNotNull(deviceId);
162 this.objective = checkNotNull(objective);
163 this.numAttempts = checkNotNull(attemps);
alshabib910aff12015-04-09 16:55:57 -0700164 }
alshabib77b88482015-04-07 15:47:50 -0700165
Jonathan Hart17d00452015-04-21 17:10:00 -0700166 @Override
167 public void run() {
168 try {
Jonathan Hart17d00452015-04-21 17:10:00 -0700169 Pipeliner pipeliner = getDevicePipeliner(deviceId);
170
171 if (pipeliner != null) {
172 if (objective instanceof NextObjective) {
173 pipeliner.next((NextObjective) objective);
174 } else if (objective instanceof ForwardingObjective) {
175 pipeliner.forward((ForwardingObjective) objective);
176 } else {
177 pipeliner.filter((FilteringObjective) objective);
178 }
179 } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) {
Saurav Das3d038262015-04-23 12:36:58 -0700180 Thread.sleep(INSTALL_RETRY_INTERVAL);
Sho SHIMIZUf45d85d2015-07-01 14:39:11 -0700181 executorService.submit(new ObjectiveInstaller(deviceId, objective, numAttempts + 1));
Jonathan Hart17d00452015-04-21 17:10:00 -0700182 } else {
183 // Otherwise we've tried a few times and failed, report an
184 // error back to the user.
185 objective.context().ifPresent(
186 c -> c.onError(objective, ObjectiveError.DEVICEMISSING));
187 }
188 } catch (Exception e) {
189 log.warn("Exception while installing flow objective", e);
190 }
191 }
192 }
193
194 @Override
195 public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900196 checkPermission(Permission.FLOWRULE_WRITE);
Jonathan Hart17d00452015-04-21 17:10:00 -0700197 executorService.submit(new ObjectiveInstaller(deviceId, filteringObjective));
alshabib77b88482015-04-07 15:47:50 -0700198 }
199
200 @Override
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700201 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900202 checkPermission(Permission.FLOWRULE_WRITE);
alshabib2a441c62015-04-13 18:39:38 -0700203 if (queueObjective(deviceId, forwardingObjective)) {
204 return;
alshabib910aff12015-04-09 16:55:57 -0700205 }
Jonathan Hart17d00452015-04-21 17:10:00 -0700206 executorService.submit(new ObjectiveInstaller(deviceId, forwardingObjective));
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700207 }
208
alshabib2a441c62015-04-13 18:39:38 -0700209 @Override
Jonathan Hart17d00452015-04-21 17:10:00 -0700210 public void next(DeviceId deviceId, NextObjective nextObjective) {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900211 checkPermission(Permission.FLOWRULE_WRITE);
Jonathan Hart17d00452015-04-21 17:10:00 -0700212 executorService.submit(new ObjectiveInstaller(deviceId, nextObjective));
alshabib2a441c62015-04-13 18:39:38 -0700213 }
214
alshabibf6ea9e62015-04-21 17:08:26 -0700215 @Override
216 public int allocateNextId() {
Changhoon Yoon541ef712015-05-23 17:18:34 +0900217 checkPermission(Permission.FLOWRULE_WRITE);
alshabibf6ea9e62015-04-21 17:08:26 -0700218 return flowObjectiveStore.allocateNextId();
219 }
220
Xin Jin313708b2015-07-09 13:43:04 -0700221 @Override
222 public void initPolicy(String policy) {}
223
alshabib2a441c62015-04-13 18:39:38 -0700224 private boolean queueObjective(DeviceId deviceId, ForwardingObjective fwd) {
225 if (fwd.nextId() != null &&
226 flowObjectiveStore.getNextGroup(fwd.nextId()) == null) {
Saurav Das3ea46622015-04-22 14:01:34 -0700227 log.trace("Queuing forwarding objective for nextId {}", fwd.nextId());
alshabib2a441c62015-04-13 18:39:38 -0700228 if (pendingForwards.putIfAbsent(fwd.nextId(),
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700229 Sets.newHashSet(new PendingNext(deviceId, fwd))) != null) {
alshabib2a441c62015-04-13 18:39:38 -0700230 Set<PendingNext> pending = pendingForwards.get(fwd.nextId());
231 pending.add(new PendingNext(deviceId, fwd));
232 }
233 return true;
234 }
235 return false;
236 }
237
alshabib910aff12015-04-09 16:55:57 -0700238 // Retrieves the device pipeline behaviour from the cache.
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700239 private Pipeliner getDevicePipeliner(DeviceId deviceId) {
Thomas Vachuska94c3cf42015-07-20 13:01:12 -0700240 return pipeliners.get(deviceId);
alshabib77b88482015-04-07 15:47:50 -0700241 }
242
alshabib2a441c62015-04-13 18:39:38 -0700243 private void setupPipelineHandler(DeviceId deviceId) {
Thomas Vachuska866b46a2015-04-30 00:26:55 -0700244 if (defaultDriverService == null) {
245 // We're not ready to go to work yet.
246 return;
247 }
248
Jonathan Hart17d00452015-04-21 17:10:00 -0700249 // Attempt to lookup the handler in the cache
250 DriverHandler handler = driverHandlers.get(deviceId);
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700251 cTime = now();
252
Jonathan Hart17d00452015-04-21 17:10:00 -0700253 if (handler == null) {
254 try {
255 // Otherwise create it and if it has pipeline behaviour, cache it
256 handler = driverService.createHandler(deviceId);
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700257 dTime = now();
Jonathan Hart17d00452015-04-21 17:10:00 -0700258 if (!handler.driver().hasBehaviour(Pipeliner.class)) {
259 log.warn("Pipeline behaviour not supported for device {}",
260 deviceId);
alshabib2a441c62015-04-13 18:39:38 -0700261 return;
262 }
Jonathan Hart17d00452015-04-21 17:10:00 -0700263 } catch (ItemNotFoundException e) {
264 log.warn("No applicable driver for device {}", deviceId);
265 return;
alshabib2a441c62015-04-13 18:39:38 -0700266 }
267
Jonathan Hart17d00452015-04-21 17:10:00 -0700268 driverHandlers.put(deviceId, handler);
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700269 eTime = now();
alshabib2a441c62015-04-13 18:39:38 -0700270 }
Jonathan Hart17d00452015-04-21 17:10:00 -0700271
272 // Always (re)initialize the pipeline behaviour
273 log.info("Driver {} bound to device {} ... initializing driver",
274 handler.driver().name(), deviceId);
Thomas Vachuska0121a612015-07-21 11:18:09 -0700275 hTime = now();
Jonathan Hart17d00452015-04-21 17:10:00 -0700276 Pipeliner pipeliner = handler.behaviour(Pipeliner.class);
Thomas Vachuska94c3cf42015-07-20 13:01:12 -0700277 hbTime = now();
Jonathan Hart17d00452015-04-21 17:10:00 -0700278 pipeliner.init(deviceId, context);
279 pipeliners.putIfAbsent(deviceId, pipeliner);
alshabib2a441c62015-04-13 18:39:38 -0700280 }
alshabibaebe7752015-04-07 17:45:42 -0700281
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700282 // Triggers driver setup when the local node becomes a device master.
alshabib77b88482015-04-07 15:47:50 -0700283 private class InnerMastershipListener implements MastershipListener {
284 @Override
285 public void event(MastershipEvent event) {
286 switch (event.type()) {
alshabib77b88482015-04-07 15:47:50 -0700287 case MASTER_CHANGED:
Madan Jampani0174f452015-05-29 11:52:05 -0700288 log.debug("mastership changed on device {}", event.subject());
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700289 start = now();
Saurav Das3d038262015-04-23 12:36:58 -0700290 if (deviceService.isAvailable(event.subject())) {
291 setupPipelineHandler(event.subject());
292 }
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700293 stopWatch();
alshabib4313d102015-04-08 18:55:08 -0700294 break;
295 case BACKUPS_CHANGED:
alshabib77b88482015-04-07 15:47:50 -0700296 break;
297 default:
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700298 break;
alshabib77b88482015-04-07 15:47:50 -0700299 }
300 }
alshabibaebe7752015-04-07 17:45:42 -0700301 }
alshabib77b88482015-04-07 15:47:50 -0700302
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700303 // Triggers driver setup when a device is (re)detected.
alshabibaebe7752015-04-07 17:45:42 -0700304 private class InnerDeviceListener implements DeviceListener {
305 @Override
306 public void event(DeviceEvent event) {
307 switch (event.type()) {
308 case DEVICE_ADDED:
309 case DEVICE_AVAILABILITY_CHANGED:
Madan Jampani0174f452015-05-29 11:52:05 -0700310 log.debug("Device either added or availability changed {}",
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700311 event.subject().id());
312 start = now();
alshabib4313d102015-04-08 18:55:08 -0700313 if (deviceService.isAvailable(event.subject().id())) {
Madan Jampani0174f452015-05-29 11:52:05 -0700314 log.debug("Device is now available {}", event.subject().id());
alshabib4313d102015-04-08 18:55:08 -0700315 setupPipelineHandler(event.subject().id());
316 }
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700317 stopWatch();
alshabib4313d102015-04-08 18:55:08 -0700318 break;
319 case DEVICE_UPDATED:
320 break;
321 case DEVICE_REMOVED:
322 break;
323 case DEVICE_SUSPENDED:
324 break;
325 case PORT_ADDED:
326 break;
327 case PORT_UPDATED:
328 break;
329 case PORT_REMOVED:
alshabibaebe7752015-04-07 17:45:42 -0700330 break;
331 default:
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700332 break;
alshabibaebe7752015-04-07 17:45:42 -0700333 }
alshabib77b88482015-04-07 15:47:50 -0700334 }
335 }
alshabibaebe7752015-04-07 17:45:42 -0700336
Thomas Vachuska174bb912015-07-16 21:27:14 -0700337 // Temporary mechanism to monitor pipeliner setup time-cost; there are
338 // intermittent time where this takes in excess of 2 seconds. Why?
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700339 private long start = 0, totals = 0, count = 0;
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700340 private long cTime, dTime, eTime, hTime, hbTime;
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700341 private static final long LIMIT = 500;
Thomas Vachuska174bb912015-07-16 21:27:14 -0700342
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700343 private long now() {
Thomas Vachuska174bb912015-07-16 21:27:14 -0700344 return System.currentTimeMillis();
345 }
346
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700347 private void stopWatch() {
Thomas Vachuska174bb912015-07-16 21:27:14 -0700348 long duration = System.currentTimeMillis() - start;
349 totals += duration;
350 count += 1;
351 if (duration > LIMIT) {
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700352 log.info("Pipeline setup took {} ms; avg {} ms; cTime={}, dTime={}, eTime={}, hTime={}, hbTime={}",
353 duration, totals / count, diff(cTime), diff(dTime), diff(eTime), diff(hTime), diff(hbTime));
Thomas Vachuska174bb912015-07-16 21:27:14 -0700354 }
355 }
356
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700357 private long diff(long bTime) {
Thomas Vachuskab19bffb2015-07-22 10:56:16 -0700358 long diff = bTime - start;
359 return diff < 0 ? 0 : diff;
Thomas Vachuska9c9ff7c2015-07-20 10:38:59 -0700360 }
361
Thomas Vachuskaca88bb72015-04-08 19:38:02 -0700362 // Processing context for initializing pipeline driver behaviours.
363 private class InnerPipelineContext implements PipelinerContext {
364 @Override
365 public ServiceDirectory directory() {
366 return serviceDirectory;
alshabibaebe7752015-04-07 17:45:42 -0700367 }
alshabib2a441c62015-04-13 18:39:38 -0700368
369 @Override
370 public FlowObjectiveStore store() {
371 return flowObjectiveStore;
372 }
alshabib2a441c62015-04-13 18:39:38 -0700373 }
374
375 private class InternalStoreDelegate implements FlowObjectiveStoreDelegate {
376 @Override
377 public void notify(ObjectiveEvent event) {
Saurav Das3ea46622015-04-22 14:01:34 -0700378 log.debug("Received notification of obj event {}", event);
alshabib2a441c62015-04-13 18:39:38 -0700379 Set<PendingNext> pending = pendingForwards.remove(event.subject());
380
381 if (pending == null) {
Saurav Das3ea46622015-04-22 14:01:34 -0700382 log.debug("Nothing pending for this obj event");
alshabib2a441c62015-04-13 18:39:38 -0700383 return;
384 }
385
Saurav Das3ea46622015-04-22 14:01:34 -0700386 log.debug("Processing pending forwarding objectives {}", pending.size());
alshabib2a441c62015-04-13 18:39:38 -0700387
388 pending.forEach(p -> getDevicePipeliner(p.deviceId())
389 .forward(p.forwardingObjective()));
390
391 }
392 }
393
394 /**
395 * Data class used to hold a pending forwarding objective that could not
396 * be processed because the associated next object was not present.
397 */
398 private class PendingNext {
399 private final DeviceId deviceId;
400 private final ForwardingObjective fwd;
401
402 public PendingNext(DeviceId deviceId, ForwardingObjective fwd) {
403 this.deviceId = deviceId;
404 this.fwd = fwd;
405 }
406
407 public DeviceId deviceId() {
408 return deviceId;
409 }
410
411 public ForwardingObjective forwardingObjective() {
412 return fwd;
413 }
alshabibaebe7752015-04-07 17:45:42 -0700414 }
alshabib77b88482015-04-07 15:47:50 -0700415}