Jonathan Hart
Committed by Gerrit Code Review

Upgrade packet requests to use flow objectives API.

Addressed a few issues found while using the flow objectives across a cluster:
 * Flow objectives should be installable from any node, not just the master.
   Therefore we need to ensure all nodes initialize a driver for each switch.
 * We no longer store a list of objectives that are waiting for the switch
   to arrive. If the we don't know about the switch yet we'll try a few times
   over a few seconds to find it, but after that we'll give up and report an
   error to the client.
 * Default drivers need to be available when the FlowObjectiveManager starts
   up, otherwise it is common to get flow objective requests before any
   drivers have been loaded.

Change-Id: I1c2ea6a223232402c31e8139729e4b6251ab8b0f
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 +
17 +package org.onosproject.net.driver;
18 +
19 +/**
20 + * Service capable of providing a set of default drivers.
21 + */
22 +public interface DefaultDriverProviderService extends DriverProvider {
23 +}
...@@ -36,7 +36,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -36,7 +36,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
36 private final int timeout; 36 private final int timeout;
37 private final ApplicationId appId; 37 private final ApplicationId appId;
38 private final int priority; 38 private final int priority;
39 - private final int nextId; 39 + private final Integer nextId;
40 private final TrafficTreatment treatment; 40 private final TrafficTreatment treatment;
41 private final Operation op; 41 private final Operation op;
42 private final Optional<ObjectiveContext> context; 42 private final Optional<ObjectiveContext> context;
...@@ -46,7 +46,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -46,7 +46,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
46 private DefaultForwardingObjective(TrafficSelector selector, 46 private DefaultForwardingObjective(TrafficSelector selector,
47 Flag flag, boolean permanent, 47 Flag flag, boolean permanent,
48 int timeout, ApplicationId appId, 48 int timeout, ApplicationId appId,
49 - int priority, int nextId, 49 + int priority, Integer nextId,
50 TrafficTreatment treatment, Operation op) { 50 TrafficTreatment treatment, Operation op) {
51 this.selector = selector; 51 this.selector = selector;
52 this.flag = flag; 52 this.flag = flag;
...@@ -67,7 +67,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective { ...@@ -67,7 +67,7 @@ public final class DefaultForwardingObjective implements ForwardingObjective {
67 private DefaultForwardingObjective(TrafficSelector selector, 67 private DefaultForwardingObjective(TrafficSelector selector,
68 Flag flag, boolean permanent, 68 Flag flag, boolean permanent,
69 int timeout, ApplicationId appId, 69 int timeout, ApplicationId appId,
70 - int priority, int nextId, 70 + int priority, Integer nextId,
71 TrafficTreatment treatment, 71 TrafficTreatment treatment,
72 ObjectiveContext context, Operation op) { 72 ObjectiveContext context, Operation op) {
73 this.selector = selector; 73 this.selector = selector;
......
...@@ -41,6 +41,11 @@ public enum ObjectiveError { ...@@ -41,6 +41,11 @@ public enum ObjectiveError {
41 GROUPMISSING, 41 GROUPMISSING,
42 42
43 /** 43 /**
44 + * The device was not available to install objectives to.
45 + */
46 + DEVICEMISSING,
47 +
48 + /**
44 * An unknown error occurred. 49 * An unknown error occurred.
45 */ 50 */
46 UNKNOWN 51 UNKNOWN
......
...@@ -31,6 +31,7 @@ import org.onosproject.net.driver.Behaviour; ...@@ -31,6 +31,7 @@ import org.onosproject.net.driver.Behaviour;
31 import org.onosproject.net.driver.DefaultDriverData; 31 import org.onosproject.net.driver.DefaultDriverData;
32 import org.onosproject.net.driver.DefaultDriverHandler; 32 import org.onosproject.net.driver.DefaultDriverHandler;
33 import org.onosproject.net.driver.DefaultDriverProvider; 33 import org.onosproject.net.driver.DefaultDriverProvider;
34 +import org.onosproject.net.driver.DefaultDriverProviderService;
34 import org.onosproject.net.driver.Driver; 35 import org.onosproject.net.driver.Driver;
35 import org.onosproject.net.driver.DriverAdminService; 36 import org.onosproject.net.driver.DriverAdminService;
36 import org.onosproject.net.driver.DriverHandler; 37 import org.onosproject.net.driver.DriverHandler;
...@@ -62,16 +63,21 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS ...@@ -62,16 +63,21 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected DeviceService deviceService; 64 protected DeviceService deviceService;
64 65
66 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 + protected DefaultDriverProviderService defaultDriverService;
68 +
65 private Set<DriverProvider> providers = Sets.newConcurrentHashSet(); 69 private Set<DriverProvider> providers = Sets.newConcurrentHashSet();
66 private Map<String, Driver> driverByKey = Maps.newConcurrentMap(); 70 private Map<String, Driver> driverByKey = Maps.newConcurrentMap();
67 71
68 @Activate 72 @Activate
69 protected void activate() { 73 protected void activate() {
74 + registerProvider(defaultDriverService);
70 log.info("Started"); 75 log.info("Started");
71 } 76 }
72 77
73 @Deactivate 78 @Deactivate
74 protected void deactivate() { 79 protected void deactivate() {
80 + unregisterProvider(defaultDriverService);
75 log.info("Stopped"); 81 log.info("Stopped");
76 } 82 }
77 83
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.flowobjective.impl; 16 package org.onosproject.net.flowobjective.impl;
17 17
18 -import com.google.common.collect.Lists;
19 import com.google.common.collect.Maps; 18 import com.google.common.collect.Maps;
20 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
21 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
...@@ -48,17 +47,18 @@ import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate; ...@@ -48,17 +47,18 @@ import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate;
48 import org.onosproject.net.flowobjective.ForwardingObjective; 47 import org.onosproject.net.flowobjective.ForwardingObjective;
49 import org.onosproject.net.flowobjective.NextObjective; 48 import org.onosproject.net.flowobjective.NextObjective;
50 import org.onosproject.net.flowobjective.Objective; 49 import org.onosproject.net.flowobjective.Objective;
50 +import org.onosproject.net.flowobjective.ObjectiveError;
51 import org.onosproject.net.flowobjective.ObjectiveEvent; 51 import org.onosproject.net.flowobjective.ObjectiveEvent;
52 import org.onosproject.net.group.GroupService; 52 import org.onosproject.net.group.GroupService;
53 import org.slf4j.Logger; 53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory; 54 import org.slf4j.LoggerFactory;
55 55
56 -import java.util.Collection;
57 -import java.util.Collections;
58 import java.util.Map; 56 import java.util.Map;
59 import java.util.Set; 57 import java.util.Set;
58 +import java.util.concurrent.ExecutorService;
59 +import java.util.concurrent.Executors;
60 60
61 -import static com.google.common.base.Preconditions.checkState; 61 +import static org.onlab.util.Tools.groupedThreads;
62 62
63 /** 63 /**
64 * Provides implementation of the flow objective programming service. 64 * Provides implementation of the flow objective programming service.
...@@ -67,9 +67,10 @@ import static com.google.common.base.Preconditions.checkState; ...@@ -67,9 +67,10 @@ import static com.google.common.base.Preconditions.checkState;
67 @Service 67 @Service
68 public class FlowObjectiveManager implements FlowObjectiveService { 68 public class FlowObjectiveManager implements FlowObjectiveService {
69 69
70 - private final Logger log = LoggerFactory.getLogger(getClass()); 70 + public static final int INSTALL_RETRY_ATTEMPTS = 5;
71 + public static final long INSTALL_RETRY_INTERVAL = 1000; // ms
71 72
72 - public static final String NOT_INITIALIZED = "Driver not initialized"; 73 + private final Logger log = LoggerFactory.getLogger(getClass());
73 74
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 protected DriverService driverService; 76 protected DriverService driverService;
...@@ -106,17 +107,18 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -106,17 +107,18 @@ public class FlowObjectiveManager implements FlowObjectiveService {
106 107
107 protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); 108 protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
108 109
109 - private final Map<DeviceId, Collection<Objective>> pendingObjectives =
110 - Maps.newConcurrentMap();
111 -
112 private NodeId localNode; 110 private NodeId localNode;
113 111
114 private Map<Integer, Set<PendingNext>> pendingForwards = 112 private Map<Integer, Set<PendingNext>> pendingForwards =
115 Maps.newConcurrentMap(); 113 Maps.newConcurrentMap();
116 114
115 + private ExecutorService executorService;
117 116
118 @Activate 117 @Activate
119 protected void activate() { 118 protected void activate() {
119 + executorService = Executors.newFixedThreadPool(
120 + 4, groupedThreads("onos/objective-installer", "%d"));
121 +
120 flowObjectiveStore.setDelegate(delegate); 122 flowObjectiveStore.setDelegate(delegate);
121 localNode = clusterService.getLocalNode().id(); 123 localNode = clusterService.getLocalNode().id();
122 mastershipService.addListener(mastershipListener); 124 mastershipService.addListener(mastershipListener);
...@@ -133,15 +135,55 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -133,15 +135,55 @@ public class FlowObjectiveManager implements FlowObjectiveService {
133 log.info("Stopped"); 135 log.info("Stopped");
134 } 136 }
135 137
138 + /**
139 + * Task that passes the flow objective down to the driver. The task will
140 + * make a few attempts to find the appropriate driver, then eventually give
141 + * up and report an error if no suitable driver could be found.
142 + */
143 + private class ObjectiveInstaller implements Runnable {
144 + private final DeviceId deviceId;
145 + private final Objective objective;
146 +
147 + private int numAttempts = 0;
148 +
149 + public ObjectiveInstaller(DeviceId deviceId, Objective objective) {
150 + this.deviceId = deviceId;
151 + this.objective = objective;
152 + }
153 +
136 @Override 154 @Override
137 - public void filter(DeviceId deviceId, 155 + public void run() {
138 - FilteringObjective filteringObjective) { 156 + try {
139 - if (deviceService.isAvailable(deviceId)) { 157 + numAttempts++;
140 - getDevicePipeliner(deviceId).filter(filteringObjective); 158 +
159 + Pipeliner pipeliner = getDevicePipeliner(deviceId);
160 +
161 + if (pipeliner != null) {
162 + if (objective instanceof NextObjective) {
163 + pipeliner.next((NextObjective) objective);
164 + } else if (objective instanceof ForwardingObjective) {
165 + pipeliner.forward((ForwardingObjective) objective);
166 + } else {
167 + pipeliner.filter((FilteringObjective) objective);
168 + }
169 + } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) {
170 + Thread.currentThread().sleep(INSTALL_RETRY_INTERVAL);
171 + executorService.submit(this);
141 } else { 172 } else {
142 - updatePendingMap(deviceId, filteringObjective); 173 + // Otherwise we've tried a few times and failed, report an
174 + // error back to the user.
175 + objective.context().ifPresent(
176 + c -> c.onError(objective, ObjectiveError.DEVICEMISSING));
177 + }
178 + } catch (Exception e) {
179 + log.warn("Exception while installing flow objective", e);
180 + }
181 + }
143 } 182 }
144 183
184 + @Override
185 + public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
186 + executorService.submit(new ObjectiveInstaller(deviceId, filteringObjective));
145 } 187 }
146 188
147 @Override 189 @Override
...@@ -152,22 +194,12 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -152,22 +194,12 @@ public class FlowObjectiveManager implements FlowObjectiveService {
152 return; 194 return;
153 } 195 }
154 196
155 - if (deviceService.isAvailable(deviceId)) { 197 + executorService.submit(new ObjectiveInstaller(deviceId, forwardingObjective));
156 - getDevicePipeliner(deviceId).forward(forwardingObjective);
157 - } else {
158 - updatePendingMap(deviceId, forwardingObjective);
159 - }
160 -
161 } 198 }
162 199
163 @Override 200 @Override
164 - public void next(DeviceId deviceId, 201 + public void next(DeviceId deviceId, NextObjective nextObjective) {
165 - NextObjective nextObjective) { 202 + executorService.submit(new ObjectiveInstaller(deviceId, nextObjective));
166 - if (deviceService.isAvailable(deviceId)) {
167 - getDevicePipeliner(deviceId).next(nextObjective);
168 - } else {
169 - updatePendingMap(deviceId, nextObjective);
170 - }
171 } 203 }
172 204
173 @Override 205 @Override
...@@ -189,24 +221,13 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -189,24 +221,13 @@ public class FlowObjectiveManager implements FlowObjectiveService {
189 return false; 221 return false;
190 } 222 }
191 223
192 -
193 - private void updatePendingMap(DeviceId deviceId, Objective pending) {
194 - if (pendingObjectives.putIfAbsent(deviceId, Lists.newArrayList(pending)) != null) {
195 - Collection<Objective> objectives = pendingObjectives.get(deviceId);
196 - objectives.add(pending);
197 - }
198 -
199 - }
200 -
201 // Retrieves the device pipeline behaviour from the cache. 224 // Retrieves the device pipeline behaviour from the cache.
202 private Pipeliner getDevicePipeliner(DeviceId deviceId) { 225 private Pipeliner getDevicePipeliner(DeviceId deviceId) {
203 Pipeliner pipeliner = pipeliners.get(deviceId); 226 Pipeliner pipeliner = pipeliners.get(deviceId);
204 - checkState(pipeliner != null, NOT_INITIALIZED);
205 return pipeliner; 227 return pipeliner;
206 } 228 }
207 229
208 private void setupPipelineHandler(DeviceId deviceId) { 230 private void setupPipelineHandler(DeviceId deviceId) {
209 - if (localNode.equals(mastershipService.getMasterFor(deviceId))) {
210 // Attempt to lookup the handler in the cache 231 // Attempt to lookup the handler in the cache
211 DriverHandler handler = driverHandlers.get(deviceId); 232 DriverHandler handler = driverHandlers.get(deviceId);
212 if (handler == null) { 233 if (handler == null) {
...@@ -222,6 +243,7 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -222,6 +243,7 @@ public class FlowObjectiveManager implements FlowObjectiveService {
222 log.warn("No applicable driver for device {}", deviceId); 243 log.warn("No applicable driver for device {}", deviceId);
223 return; 244 return;
224 } 245 }
246 +
225 driverHandlers.put(deviceId, handler); 247 driverHandlers.put(deviceId, handler);
226 } 248 }
227 249
...@@ -232,7 +254,6 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -232,7 +254,6 @@ public class FlowObjectiveManager implements FlowObjectiveService {
232 pipeliner.init(deviceId, context); 254 pipeliner.init(deviceId, context);
233 pipeliners.putIfAbsent(deviceId, pipeliner); 255 pipeliners.putIfAbsent(deviceId, pipeliner);
234 } 256 }
235 - }
236 257
237 // Triggers driver setup when the local node becomes a device master. 258 // Triggers driver setup when the local node becomes a device master.
238 private class InnerMastershipListener implements MastershipListener { 259 private class InnerMastershipListener implements MastershipListener {
...@@ -240,10 +261,8 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -240,10 +261,8 @@ public class FlowObjectiveManager implements FlowObjectiveService {
240 public void event(MastershipEvent event) { 261 public void event(MastershipEvent event) {
241 switch (event.type()) { 262 switch (event.type()) {
242 case MASTER_CHANGED: 263 case MASTER_CHANGED:
243 - if (event.roleInfo().master() != null) {
244 - setupPipelineHandler(event.subject());
245 log.info("mastership changed on device {}", event.subject()); 264 log.info("mastership changed on device {}", event.subject());
246 - } 265 + setupPipelineHandler(event.subject());
247 break; 266 break;
248 case BACKUPS_CHANGED: 267 case BACKUPS_CHANGED:
249 break; 268 break;
...@@ -259,13 +278,14 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -259,13 +278,14 @@ public class FlowObjectiveManager implements FlowObjectiveService {
259 public void event(DeviceEvent event) { 278 public void event(DeviceEvent event) {
260 switch (event.type()) { 279 switch (event.type()) {
261 case DEVICE_ADDED: 280 case DEVICE_ADDED:
281 + setupPipelineHandler(event.subject().id());
282 + break;
262 case DEVICE_AVAILABILITY_CHANGED: 283 case DEVICE_AVAILABILITY_CHANGED:
263 log.info("Device either added or availability changed {}", 284 log.info("Device either added or availability changed {}",
264 event.subject().id()); 285 event.subject().id());
265 if (deviceService.isAvailable(event.subject().id())) { 286 if (deviceService.isAvailable(event.subject().id())) {
266 log.info("Device is now available {}", event.subject().id()); 287 log.info("Device is now available {}", event.subject().id());
267 setupPipelineHandler(event.subject().id()); 288 setupPipelineHandler(event.subject().id());
268 - processPendingObjectives(event.subject().id());
269 } 289 }
270 break; 290 break;
271 case DEVICE_UPDATED: 291 case DEVICE_UPDATED:
...@@ -284,22 +304,6 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -284,22 +304,6 @@ public class FlowObjectiveManager implements FlowObjectiveService {
284 break; 304 break;
285 } 305 }
286 } 306 }
287 -
288 - private void processPendingObjectives(DeviceId deviceId) {
289 - log.debug("Processing pending objectives for device {}", deviceId);
290 -
291 - pendingObjectives.getOrDefault(deviceId,
292 - Collections.emptySet()).forEach(obj -> {
293 - if (obj instanceof NextObjective) {
294 - next(deviceId, (NextObjective) obj);
295 - } else if (obj instanceof ForwardingObjective) {
296 - forward(deviceId, (ForwardingObjective) obj);
297 - } else {
298 - getDevicePipeliner(deviceId)
299 - .filter((FilteringObjective) obj);
300 - }
301 - });
302 - }
303 } 307 }
304 308
305 // Processing context for initializing pipeline driver behaviours. 309 // Processing context for initializing pipeline driver behaviours.
...@@ -313,8 +317,6 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -313,8 +317,6 @@ public class FlowObjectiveManager implements FlowObjectiveService {
313 public FlowObjectiveStore store() { 317 public FlowObjectiveStore store() {
314 return flowObjectiveStore; 318 return flowObjectiveStore;
315 } 319 }
316 -
317 -
318 } 320 }
319 321
320 private class InternalStoreDelegate implements FlowObjectiveStoreDelegate { 322 private class InternalStoreDelegate implements FlowObjectiveStoreDelegate {
...@@ -356,7 +358,5 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -356,7 +358,5 @@ public class FlowObjectiveManager implements FlowObjectiveService {
356 public ForwardingObjective forwardingObjective() { 358 public ForwardingObjective forwardingObjective() {
357 return fwd; 359 return fwd;
358 } 360 }
359 -
360 -
361 } 361 }
362 } 362 }
......
...@@ -27,12 +27,17 @@ import org.onosproject.net.Device; ...@@ -27,12 +27,17 @@ import org.onosproject.net.Device;
27 import org.onosproject.net.device.DeviceEvent; 27 import org.onosproject.net.device.DeviceEvent;
28 import org.onosproject.net.device.DeviceListener; 28 import org.onosproject.net.device.DeviceListener;
29 import org.onosproject.net.device.DeviceService; 29 import org.onosproject.net.device.DeviceService;
30 -import org.onosproject.net.flow.DefaultFlowRule;
31 import org.onosproject.net.flow.DefaultTrafficTreatment; 30 import org.onosproject.net.flow.DefaultTrafficTreatment;
32 import org.onosproject.net.flow.FlowRule; 31 import org.onosproject.net.flow.FlowRule;
33 import org.onosproject.net.flow.FlowRuleService; 32 import org.onosproject.net.flow.FlowRuleService;
34 import org.onosproject.net.flow.TrafficSelector; 33 import org.onosproject.net.flow.TrafficSelector;
35 import org.onosproject.net.flow.TrafficTreatment; 34 import org.onosproject.net.flow.TrafficTreatment;
35 +import org.onosproject.net.flowobjective.DefaultForwardingObjective;
36 +import org.onosproject.net.flowobjective.FlowObjectiveService;
37 +import org.onosproject.net.flowobjective.ForwardingObjective;
38 +import org.onosproject.net.flowobjective.Objective;
39 +import org.onosproject.net.flowobjective.ObjectiveContext;
40 +import org.onosproject.net.flowobjective.ObjectiveError;
36 import org.onosproject.net.packet.DefaultPacketRequest; 41 import org.onosproject.net.packet.DefaultPacketRequest;
37 import org.onosproject.net.packet.OutboundPacket; 42 import org.onosproject.net.packet.OutboundPacket;
38 import org.onosproject.net.packet.PacketContext; 43 import org.onosproject.net.packet.PacketContext;
...@@ -73,6 +78,9 @@ public class PacketManager ...@@ -73,6 +78,9 @@ public class PacketManager
73 private CoreService coreService; 78 private CoreService coreService;
74 79
75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
81 + private FlowObjectiveService objectiveService;
82 +
83 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
76 private DeviceService deviceService; 84 private DeviceService deviceService;
77 85
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -169,12 +177,28 @@ public class PacketManager ...@@ -169,12 +177,28 @@ public class PacketManager
169 return; 177 return;
170 } 178 }
171 179
172 - TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build(); 180 + TrafficTreatment treatment = DefaultTrafficTreatment.builder()
173 - FlowRule flow = new DefaultFlowRule(device.id(), request.selector(), treatment, 181 + .punt()
174 - request.priority().priorityValue(), 182 + .build();
175 - appId, 0, true, request.tableType()); 183 +
184 + ForwardingObjective forwarding = DefaultForwardingObjective.builder()
185 + .withPriority(request.priority().priorityValue())
186 + .withSelector(request.selector())
187 + .fromApp(appId)
188 + .withFlag(ForwardingObjective.Flag.VERSATILE)
189 + .withTreatment(treatment)
190 + .makePermanent()
191 + .add(new ObjectiveContext() {
192 + @Override
193 + public void onSuccess(Objective objective) { }
194 +
195 + @Override
196 + public void onError(Objective objective, ObjectiveError error) {
197 + log.warn("Failed to install packet request flow: {}", error);
198 + }
199 + });
176 200
177 - flowService.applyFlowRules(flow); 201 + objectiveService.forward(device.id(), forwarding);
178 } 202 }
179 203
180 @Override 204 @Override
......
...@@ -16,32 +16,31 @@ ...@@ -16,32 +16,31 @@
16 package org.onosproject.driver.pipeline; 16 package org.onosproject.driver.pipeline;
17 17
18 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
19 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
20 -import org.apache.felix.scr.annotations.Reference; 21 +import org.apache.felix.scr.annotations.Service;
21 -import org.apache.felix.scr.annotations.ReferenceCardinality; 22 +import org.onosproject.net.driver.DefaultDriverProviderService;
22 -import org.onosproject.net.driver.DriverAdminService; 23 +import org.onosproject.net.driver.Driver;
23 import org.onosproject.net.driver.DriverProvider; 24 import org.onosproject.net.driver.DriverProvider;
24 import org.onosproject.net.driver.XmlDriverLoader; 25 import org.onosproject.net.driver.XmlDriverLoader;
25 -import org.apache.felix.scr.annotations.Component;
26 import org.slf4j.Logger; 26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory; 27 import org.slf4j.LoggerFactory;
28 28
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.io.InputStream; 30 import java.io.InputStream;
31 +import java.util.Set;
31 32
32 /** 33 /**
33 * Bootstrap for built in drivers. 34 * Bootstrap for built in drivers.
34 */ 35 */
35 -@Component(immediate = true) 36 +@Service
36 -public class DefaultDrivers { 37 +@Component(immediate = false)
38 +public class DefaultDrivers implements DefaultDriverProviderService {
37 39
38 private final Logger log = LoggerFactory.getLogger(getClass()); 40 private final Logger log = LoggerFactory.getLogger(getClass());
39 41
40 private static final String DRIVERS_XML = "/onos-drivers.xml"; 42 private static final String DRIVERS_XML = "/onos-drivers.xml";
41 43
42 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
43 - protected DriverAdminService driverService;
44 -
45 private DriverProvider provider; 44 private DriverProvider provider;
46 45
47 @Activate 46 @Activate
...@@ -50,7 +49,6 @@ public class DefaultDrivers { ...@@ -50,7 +49,6 @@ public class DefaultDrivers {
50 try { 49 try {
51 InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML); 50 InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML);
52 provider = new XmlDriverLoader(classLoader).loadDrivers(stream); 51 provider = new XmlDriverLoader(classLoader).loadDrivers(stream);
53 - driverService.registerProvider(provider);
54 } catch (IOException e) { 52 } catch (IOException e) {
55 log.error("Unable to load default drivers", e); 53 log.error("Unable to load default drivers", e);
56 } 54 }
...@@ -59,10 +57,11 @@ public class DefaultDrivers { ...@@ -59,10 +57,11 @@ public class DefaultDrivers {
59 57
60 @Deactivate 58 @Deactivate
61 protected void deactivate() { 59 protected void deactivate() {
62 - if (provider != null) {
63 - driverService.unregisterProvider(provider);
64 - }
65 log.info("Stopped"); 60 log.info("Stopped");
66 } 61 }
67 62
63 + @Override
64 + public Set<Driver> getDrivers() {
65 + return provider.getDrivers();
66 + }
68 } 67 }
......