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
......
...@@ -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 +
176 - 184 + ForwardingObjective forwarding = DefaultForwardingObjective.builder()
177 - flowService.applyFlowRules(flow); 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 + });
200 +
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 }
......