Thomas Vachuska

Cleaning up and enhancing driver subsystem and the flow objective subsystem.

Change-Id: Ica600ef1aaa46d19e764cd7a197454a4e0f85a08
Showing 22 changed files with 359 additions and 128 deletions
......@@ -50,6 +50,11 @@ public final class AnnotationKeys {
public static final String PROTOCOL = "protocol";
/**
* Annotation key for the device driver name.
*/
public static final String DRIVER = "driver";
/**
* Annotation key for durable links.
*/
public static final String DURABLE = "durable";
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.behaviour;
import org.onlab.osgi.ServiceDirectory;
import org.onosproject.net.DeviceId;
import org.onosproject.net.driver.HandlerBehaviour;
import org.onosproject.net.flowobjective.FilteringObjective;
......@@ -31,20 +30,20 @@ import java.util.concurrent.Future;
public interface Pipeliner extends HandlerBehaviour {
/**
* Injecting the service directory into the driver.
* Initializes the driver with context required for its operation.
*
* @param deviceId the deviceId
* @param serviceDirectory the service directory.
* @param context processing context
*/
void init(DeviceId deviceId, ServiceDirectory serviceDirectory);
void init(DeviceId deviceId, PipelinerContext context);
/**
* Installs the filtering rules onto the device.
*
* @param filteringObjectives the collection of filters
* @param filterObjectives the collection of filters
* @return a future indicating the success of the operation
*/
Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives);
Future<Boolean> filter(Collection<FilteringObjective> filterObjectives);
/**
* Installs the forwarding rules onto the device.
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.behaviour;
import org.onlab.osgi.ServiceDirectory;
/**
* Processing context and supporting services for the pipeline behaviour.
*/
public interface PipelinerContext {
/**
* Returns the service directory which can be used to obtain references
* to various supporting services.
*
* @return service directory
*/
ServiceDirectory directory();
// TODO: add means to store and access shared state
}
......@@ -29,27 +29,27 @@ import static com.google.common.base.MoreObjects.toStringHelper;
*/
public class DefaultDriverData implements DriverData {
private final Driver type;
private final Driver driver;
private final Map<String, String> properties;
/**
* Creates new driver data.
*
* @param type parent driver type
* @param driver parent driver type
*/
public DefaultDriverData(Driver type) {
this.type = type;
public DefaultDriverData(Driver driver) {
this.driver = driver;
this.properties = new HashMap<>();
}
@Override
public Driver type() {
return type;
public Driver driver() {
return driver;
}
@Override
public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
return type.createBehaviour(this, behaviourClass, false);
return driver.createBehaviour(this, behaviourClass, false);
}
@Override
......@@ -83,7 +83,7 @@ public class DefaultDriverData implements DriverData {
@Override
public String toString() {
return toStringHelper(this)
.add("type", type)
.add("type", driver)
.add("properties", properties)
.toString();
}
......
......@@ -34,13 +34,18 @@ public class DefaultDriverHandler implements DriverHandler {
}
@Override
public Driver driver() {
return data.driver();
}
@Override
public DriverData data() {
return data;
}
@Override
public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
return data.type().createBehaviour(this.data, behaviourClass, true);
return data.driver().createBehaviour(this.data, behaviourClass, true);
}
@Override
......
......@@ -28,7 +28,7 @@ public interface DriverData extends MutableAnnotations {
*
* @return device driver
*/
Driver type();
Driver driver();
/**
* Returns the specified facet of behaviour to access the device data.
......
......@@ -21,6 +21,13 @@ package org.onosproject.net.driver;
public interface DriverHandler {
/**
* Returns the parent device driver.
*
* @return device driver
*/
Driver driver();
/**
* Returns the device driver data.
*
* @return device driver data
......
......@@ -38,6 +38,8 @@ public interface DriverService {
*
* @param driverName driver name
* @return driver
* @throws org.onlab.util.ItemNotFoundException if driver with the given
* name is not found
*/
Driver getDriver(String driverName);
......@@ -53,25 +55,33 @@ public interface DriverService {
Driver getDriver(String mfr, String hw, String sw);
/**
* Creates a new driver handler for the specified driver.
* Returns the driver for the specified device. If the device carries
* {@code driver} annotation, its value is used to look-up the driver.
* Otherwise, the device manufacturer, hardware and software version
* attributes are used to look-up the driver. First using their literal
* values and if no driver is found, using ERE matching against the
* driver manufacturer, hardware and software version fields.
*
* @param driverName driver name
* @param deviceId device identifier
* @param credentials optional login credentials in string form
* @return driver handler
* @return driver or null of no matching one is found
* @throws org.onlab.util.ItemNotFoundException if device or driver for it
* are not found
*/
DriverHandler createHandler(String driverName, DeviceId deviceId,
String... credentials);
Driver getDriver(DeviceId deviceId);
/**
* Creates a new driver handler for the specified driver data.
* Creates a new driver handler for interacting with the specified device.
* The driver is looked-up using the same semantics as
* {@link #getDriver(DeviceId)} method.
*
* @param data driver data
* @param deviceId device identifier
* @param credentials optional login credentials in string form
* @return driver handler
* @throws org.onlab.util.ItemNotFoundException if device or driver for it
* are not found
*/
DriverHandler createHandler(DriverData data, DeviceId deviceId,
String... credentials);
DriverHandler createHandler(DeviceId deviceId, String... credentials);
// TODO: Devise a mechanism for retaining DriverData for devices
}
......
......@@ -21,14 +21,36 @@ import java.util.Collection;
import java.util.concurrent.Future;
/**
* Created by ash on 07/04/15.
* Service for programming data plane flow rules in manner independent of
* specific device table pipeline configuration.
*/
public interface FlowObjectiveService {
Future<Boolean> filter(DeviceId deviceId, Collection<FilteringObjective> filterObjectives);
/**
* Installs the filtering rules onto the specified device.
*
* @param deviceId device identifier
* @param filteringObjectives the collection of filters
* @return a future indicating the success of the operation
*/
Future<Boolean> filter(DeviceId deviceId, Collection<FilteringObjective> filteringObjectives);
/**
* Installs the forwarding rules onto the specified device.
*
* @param deviceId device identifier
* @param forwardingObjectives the collection of forwarding objectives
* @return a future indicating the success of the operation
*/
Future<Boolean> forward(DeviceId deviceId, Collection<ForwardingObjective> forwardingObjectives);
/**
* Installs the next hop elements into the specified device.
*
* @param deviceId device identifier
* @param nextObjectives the collection of next objectives
* @return a future indicating the success of the operation
*/
Future<Boolean> next(DeviceId deviceId, Collection<NextObjective> nextObjectives);
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Abstractions for objective-based flow programming of data plane without
* requiring device pipeline structure awareness.
*/
package org.onosproject.net.flowobjective;
\ No newline at end of file
......@@ -37,7 +37,7 @@ public class DefaultDriverDataTest {
@Test
public void basics() {
assertSame("incorrect type", ddc, data.type());
assertSame("incorrect type", ddc, data.driver());
assertTrue("incorrect toString", data.toString().contains("foo.bar"));
}
......
......@@ -21,29 +21,45 @@ import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.Behaviour;
import org.onosproject.net.driver.DefaultDriverData;
import org.onosproject.net.driver.DefaultDriverHandler;
import org.onosproject.net.driver.Driver;
import org.onosproject.net.driver.DriverAdminService;
import org.onosproject.net.driver.DriverData;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
import static org.onosproject.net.AnnotationKeys.DRIVER;
/**
* Manages inventory of device drivers.
*/
@Component(immediate = true)
@Service
public class DriverManager implements DriverAdminService {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String NO_DRIVER = "Driver not found";
private static final String NO_DEVICE = "Device not found";
private static final String DEFAULT = "default";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
private Set<DriverProvider> providers = Sets.newConcurrentHashSet();
private Map<String, Driver> driverByName = Maps.newConcurrentMap();
private Map<String, Driver> driverByKey = Maps.newConcurrentMap();
......@@ -88,30 +104,63 @@ public class DriverManager implements DriverAdminService {
@Override
public Set<Driver> getDrivers(Class<? extends Behaviour>... withBehaviours) {
//TODO
return null;
ImmutableSet.Builder<Driver> builder = ImmutableSet.builder();
for (Class<? extends Behaviour> behaviour : withBehaviours) {
driverByName.forEach((name, driver) -> {
if (driver.hasBehaviour(behaviour)) {
builder.add(driver);
}
});
}
return builder.build();
}
@Override
public Driver getDriver(String driverName) {
//TODO: replace with fallback driver.
return driverByName.getOrDefault(driverName, driverByName.get("default"));
return nullIsNotFound(driverByName.get(driverName), NO_DRIVER);
}
@Override
public Driver getDriver(String mfr, String hw, String sw) {
return driverByKey.getOrDefault(key(mfr, hw, sw), driverByName.get("default"));
// First attempt a literal search.
Driver driver = driverByKey.get(key(mfr, hw, sw));
if (driver != null) {
return driver;
}
// Otherwise, sweep through the key space and attempt to match using
// regular expression matching.
Optional<Driver> optional = driverByKey.values().stream()
.filter(d -> matches(d, mfr, hw, sw)).findFirst();
// If no matching driver is found, return default.
return optional.isPresent() ? optional.get() : driverByName.get(DEFAULT);
}
// Matches the given driver using ERE matching against the given criteria.
private boolean matches(Driver d, String mfr, String hw, String sw) {
// TODO: consider pre-compiling the expressions in the future
return mfr.matches(d.manufacturer()) &&
hw.matches(d.hwVersion()) &&
sw.matches(d.swVersion());
}
@Override
public DriverHandler createHandler(String driverName, DeviceId deviceId, String... credentials) {
Driver driver = driverByName.get(driverName);
return new DefaultDriverHandler(new DefaultDriverData(driver));
public Driver getDriver(DeviceId deviceId) {
Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE);
String driverName = device.annotations().value(DRIVER);
if (driverName != null) {
return getDriver(driverName);
}
return nullIsNotFound(getDriver(device.manufacturer(),
device.hwVersion(), device.swVersion()),
NO_DRIVER);
}
@Override
public DriverHandler createHandler(DriverData data, DeviceId deviceId, String... credentials) {
return null;
public DriverHandler createHandler(DeviceId deviceId, String... credentials) {
Driver driver = getDriver(deviceId);
return new DefaultDriverHandler(new DefaultDriverData(driver));
}
private String key(String mfr, String hw, String sw) {
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementation of the device driver management subsystem.
*/
package org.onosproject.net.driver.impl;
\ No newline at end of file
......@@ -24,23 +24,26 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.util.ItemNotFoundException;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.behaviour.PipelinerContext;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.Driver;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.net.group.GroupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -51,7 +54,7 @@ import java.util.concurrent.Future;
import static com.google.common.base.Preconditions.checkState;
/**
* Created by ash on 07/04/15.
* Provides implementation of the flow objective programming service.
*/
@Component(immediate = true)
@Service
......@@ -59,6 +62,8 @@ public class FlowObjectiveManager implements FlowObjectiveService {
private final Logger log = LoggerFactory.getLogger(getClass());
public static final String NOT_INITIALIZED = "Driver not initialized";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService;
......@@ -71,20 +76,31 @@ public class FlowObjectiveManager implements FlowObjectiveService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
// Note: The following dependencies are added on behalf of the pipeline
// driver behaviours to assure these services are available for their
// initialization.
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected GroupService groupService;
private MastershipListener mastershipListener = new InnerMastershipListener();
private DeviceListener deviceListener = new InnerDeviceListener();
private final Map<DeviceId, DriverHandler> driverHandlers = Maps.newConcurrentMap();
private Map<DeviceId, DriverHandler> driverHandlers =
Maps.newConcurrentMap();
private final PipelinerContext context = new InnerPipelineContext();
private final MastershipListener mastershipListener = new InnerMastershipListener();
private final DeviceListener deviceListener = new InnerDeviceListener();
protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
private NodeId localNode;
@Activate
protected void activate() {
localNode = clusterService.getLocalNode().id();
mastershipService.addListener(mastershipListener);
deviceService.addListener(deviceListener);
deviceService.getDevices().forEach(device -> setupDriver(device.id()));
deviceService.getDevices().forEach(device -> setupPipelineHandler(device.id()));
log.info("Started");
}
......@@ -97,113 +113,90 @@ public class FlowObjectiveManager implements FlowObjectiveService {
@Override
public Future<Boolean> filter(DeviceId deviceId,
Collection<FilteringObjective> filterObjectives) {
DriverHandler handler = driverHandlers.get(deviceId);
checkState(handler != null, "Driver not initialized");
Pipeliner pipe = handler.behaviour(Pipeliner.class);
return pipe.filter(filterObjectives);
Collection<FilteringObjective> filteringObjectives) {
return getDevicePipeliner(deviceId).filter(filteringObjectives);
}
@Override
public Future<Boolean> forward(DeviceId deviceId,
Collection<ForwardingObjective> forwardingObjectives) {
DriverHandler handler = driverHandlers.get(deviceId);
checkState(handler != null, "Driver not initialized");
Pipeliner pipe = handler.behaviour(Pipeliner.class);
return pipe.forward(forwardingObjectives);
return getDevicePipeliner(deviceId).forward(forwardingObjectives);
}
@Override
public Future<Boolean> next(DeviceId deviceId,
Collection<NextObjective> nextObjectives) {
DriverHandler handler = driverHandlers.get(deviceId);
checkState(handler != null, "Driver not initialized");
Pipeliner pipe = handler.behaviour(Pipeliner.class);
return pipe.next(nextObjectives);
return getDevicePipeliner(deviceId).next(nextObjectives);
}
// Retrieves the device handler pipeline behaviour from the cache.
private Pipeliner getDevicePipeliner(DeviceId deviceId) {
DriverHandler handler = driverHandlers.get(deviceId);
checkState(handler != null, NOT_INITIALIZED);
return handler != null ? handler.behaviour(Pipeliner.class) : null;
}
// Triggers driver setup when the local node becomes a device master.
private class InnerMastershipListener implements MastershipListener {
@Override
public void event(MastershipEvent event) {
switch (event.type()) {
case MASTER_CHANGED:
setupDriver(event.subject());
break;
case BACKUPS_CHANGED:
setupPipelineHandler(event.subject());
break;
default:
log.warn("Unknown mastership type {}", event.type());
break;
}
}
}
// Triggers driver setup when a device is (re)detected.
private class InnerDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
switch (event.type()) {
case DEVICE_ADDED:
case DEVICE_AVAILABILITY_CHANGED:
setupDriver(event.subject().id());
break;
case DEVICE_UPDATED:
break;
case DEVICE_REMOVED:
break;
case DEVICE_SUSPENDED:
break;
case PORT_ADDED:
break;
case PORT_UPDATED:
break;
case PORT_REMOVED:
setupPipelineHandler(event.subject().id());
break;
default:
log.warn("Unknown event type {}", event.type());
break;
}
}
}
private void setupDriver(DeviceId deviceId) {
//TODO: Refactor this to make it nicer and use a cache.
if (mastershipService.getMasterFor(
deviceId).equals(clusterService.getLocalNode().id())) {
DriverHandler handler = lookupDriver(deviceId);
if (handler != null) {
Pipeliner pipe = handler.behaviour(Pipeliner.class);
pipe.init(deviceId, serviceDirectory);
private void setupPipelineHandler(DeviceId deviceId) {
if (localNode.equals(mastershipService.getMasterFor(deviceId))) {
// Attempt to lookup the handler in the cache
DriverHandler handler = driverHandlers.get(deviceId);
if (handler == null) {
try {
// Otherwise create it and if it has pipeline behaviour, cache it
handler = driverService.createHandler(deviceId);
if (!handler.driver().hasBehaviour(Pipeliner.class)) {
log.warn("Pipeline behaviour not supported for device {}",
deviceId);
return;
}
} catch (ItemNotFoundException e) {
log.warn("No applicable driver for device {}", deviceId);
return;
}
driverHandlers.put(deviceId, handler);
log.info("Driver {} bound to device {}",
handler.data().type().name(), deviceId);
} else {
log.error("No driver for device {}", deviceId);
}
// Always (re)initialize the pipeline behaviour
handler.behaviour(Pipeliner.class).init(deviceId, context);
log.info("Driver {} bound to device {}", handler.driver().name(), deviceId);
}
}
private DriverHandler lookupDriver(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (device == null) {
log.warn("Device is null!");
return null;
// Processing context for initializing pipeline driver behaviours.
private class InnerPipelineContext implements PipelinerContext {
@Override
public ServiceDirectory directory() {
return serviceDirectory;
}
Driver driver = driverService.getDriver(device.manufacturer(),
device.hwVersion(), device.swVersion());
return driverService.createHandler(driver.name(), deviceId);
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementations of the flow objective programming subsystem.
*/
package org.onosproject.net.flowobjective.impl;
\ No newline at end of file
......@@ -61,7 +61,7 @@
<group>
<title>Core Subsystems</title>
<packages>
org.onosproject.impl:org.onosproject.core.impl:org.onosproject.cluster.impl:org.onosproject.net.device.impl:org.onosproject.net.link.impl:org.onosproject.net.host.impl:org.onosproject.net.topology.impl:org.onosproject.net.packet.impl:org.onosproject.net.flow.impl:org.onosproject.net.*.impl:org.onosproject.event.impl:org.onosproject.net.intent.impl*:org.onosproject.net.proxyarp.impl:org.onosproject.mastership.impl:org.onosproject.net.resource.impl:org.onosproject.json:org.onosproject.json.*:org.onosproject.provider.host.impl:org.onosproject.provider.lldp.impl:org.onosproject.net.statistic.impl:org.onosproject.app.impl:org.onosproject.common.*:org.onosproject.net.group.impl:org.onosproject.cfg.impl
org.onosproject.impl:org.onosproject.core.impl:org.onosproject.cluster.impl:org.onosproject.net.device.impl:org.onosproject.net.link.impl:org.onosproject.net.host.impl:org.onosproject.net.topology.impl:org.onosproject.net.packet.impl:org.onosproject.net.flow.impl:org.onosproject.net.*.impl:org.onosproject.event.impl:org.onosproject.net.intent.impl*:org.onosproject.net.proxyarp.impl:org.onosproject.mastership.impl:org.onosproject.net.resource.impl:org.onosproject.json:org.onosproject.json.*:org.onosproject.provider.host.impl:org.onosproject.provider.lldp.impl:org.onosproject.net.statistic.impl:org.onosproject.app.impl:org.onosproject.common.*:org.onosproject.net.group.impl:org.onosproject.cfg.impl:org.onosproject.net.driver.impl:org.onosproject.net.flowobjective.impl:org.onosproject.net.flowext.impl
</packages>
</group>
<group>
......@@ -83,6 +83,12 @@
</packages>
</group>
<group>
<title>Built-in Device Drivers</title>
<packages>
org.onosproject.driver.*
</packages>
</group>
<group>
<title>Utilities</title>
<packages>
org.onlab.*
......
......@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
/**
* Bootstrap for built in drivers.
......@@ -36,6 +37,8 @@ public class DefaultDrivers {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String DRIVERS_XML = "/onos-drivers.xml";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverAdminService driverService;
......@@ -43,25 +46,23 @@ public class DefaultDrivers {
@Activate
protected void activate() {
XmlDriverLoader xmlDriverLoader =
new XmlDriverLoader(getClass().getClassLoader());
ClassLoader classLoader = getClass().getClassLoader();
try {
provider = xmlDriverLoader.loadDrivers(
getClass().getResourceAsStream("/default.xml"));
driverService.registerProvider(
provider);
InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML);
provider = new XmlDriverLoader(classLoader).loadDrivers(stream);
driverService.registerProvider(provider);
} catch (IOException e) {
log.warn("Unable to load drivers");
log.error("Unable to load default drivers", e);
}
log.info("Started");
}
@Deactivate
protected void deactivate() {
if (provider != null) {
driverService.unregisterProvider(provider);
}
log.info("Stopped");
}
}
......
......@@ -20,6 +20,7 @@ import org.onlab.osgi.ServiceDirectory;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.behaviour.PipelinerContext;
import org.onosproject.net.driver.DriverData;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.FlowRule;
......@@ -49,8 +50,8 @@ public class DefaultSingleTablePipeline implements Pipeliner {
private DeviceId deviceId;
@Override
public void init(DeviceId deviceId, ServiceDirectory serviceDirectory) {
this.serviceDirectory = serviceDirectory;
public void init(DeviceId deviceId, PipelinerContext context) {
this.serviceDirectory = context.directory();
this.deviceId = deviceId;
flowRuleService = serviceDirectory.get(FlowRuleService.class);
......
......@@ -23,6 +23,7 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.behaviour.PipelinerContext;
import org.onosproject.net.driver.DriverData;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
......@@ -61,8 +62,8 @@ public class OVSCorsaPipeline implements Pipeliner {
private ApplicationId appId;
@Override
public void init(DeviceId deviceId, ServiceDirectory serviceDirectory) {
this.serviceDirectory = serviceDirectory;
public void init(DeviceId deviceId, PipelinerContext context) {
this.serviceDirectory = context.directory();
this.deviceId = deviceId;
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementations of the pipeline driver behaviours.
*/
package org.onosproject.driver.pipeline;
\ No newline at end of file
......@@ -112,6 +112,23 @@ public abstract class Tools {
}
/**
* Returns the specified item if that items is null; otherwise throws
* not found exception.
*
* @param item item to check
* @param message not found message
* @param <T> item type
* @return item if not null
* @throws org.onlab.util.ItemNotFoundException if item is null
*/
public static <T> T nullIsNotFound(T item, String message) {
if (item == null) {
throw new ItemNotFoundException(message);
}
return item;
}
/**
* Converts a string from hex to long.
*
* @param string hex number in string form; sans 0x
......