HIGUCHI Yuta
Committed by Gerrit Code Review

[Emu] new ResourceService related bug fixes

- ResourceDeviceListener should also react to availability events.
- Should check if device supports the behavior before
  retrieving Behaviour class
- ResourceManager should unregister when requested
- opticalUtils was specifying wrong driver name. Should've been "linc-oe"

Change-Id: I9364b6307cb537b04b57ac00f2451c13e3379471
......@@ -35,7 +35,7 @@ public class ResourceAllocation {
* Creates an instance with the specified subject, resource and consumer.
*
* @param resource resource of the subject
* @param consumer consumer ot this resource
* @param consumer consumer of this resource
*/
public ResourceAllocation(ResourcePath resource, ResourceConsumer consumer) {
this.resource = checkNotNull(resource);
......
......@@ -24,6 +24,7 @@ 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.onlab.util.ItemNotFoundException;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
......@@ -166,8 +167,13 @@ public class DriverManager extends DefaultDriverProvider implements DriverAdminS
Device device = nullIsNotFound(deviceService.getDevice(deviceId), NO_DEVICE);
String driverName = device.annotations().value(DRIVER);
if (driverName != null) {
return getDriver(driverName);
try {
return getDriver(driverName);
} catch (ItemNotFoundException e) {
log.warn("Specified driver {} not found, falling back.", driverName);
}
}
return nullIsNotFound(getDriver(device.manufacturer(),
device.hwVersion(), device.swVersion()),
NO_DRIVER);
......
......@@ -32,6 +32,8 @@ import org.onosproject.net.behaviour.MplsQuery;
import org.onosproject.net.behaviour.VlanQuery;
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.newresource.ResourceAdminService;
......@@ -67,18 +69,22 @@ final class ResourceDeviceListener implements DeviceListener {
private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots();
private final ResourceAdminService adminService;
private final DeviceService deviceService;
private final DriverService driverService;
private final ExecutorService executor;
/**
* Creates an instance with the specified ResourceAdminService and ExecutorService.
*
* @param adminService instance invoked to register resources
* @param deviceService {@link DeviceService} to be used.
* @param executor executor used for processing resource registration
*/
ResourceDeviceListener(ResourceAdminService adminService, DriverService driverService,
ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService,
ExecutorService executor) {
this.adminService = checkNotNull(adminService);
this.deviceService = checkNotNull(deviceService);
this.driverService = checkNotNull(driverService);
this.executor = checkNotNull(executor);
}
......@@ -93,8 +99,21 @@ final class ResourceDeviceListener implements DeviceListener {
case DEVICE_REMOVED:
unregisterDeviceResource(device);
break;
case DEVICE_AVAILABILITY_CHANGED:
if (deviceService.isAvailable(device.id())) {
registerDeviceResource(device);
// TODO: do we need to walk the ports?
} else {
unregisterDeviceResource(device);
}
break;
case PORT_ADDED:
registerPortResource(device, event.port());
case PORT_UPDATED:
if (event.port().isEnabled()) {
registerPortResource(device, event.port());
} else {
unregisterPortResource(device, event.port());
}
break;
case PORT_REMOVED:
unregisterPortResource(device, event.port());
......@@ -168,12 +187,22 @@ final class ResourceDeviceListener implements DeviceListener {
private SortedSet<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
try {
// DriverHandler does not provide a way to check if a
// behaviour is supported.
Driver driver = driverService.getDriver(did);
if (driver == null || !driver.hasBehaviour(LambdaQuery.class)) {
return Collections.emptySortedSet();
}
DriverHandler handler = driverService.createHandler(did);
if (handler == null) {
return Collections.emptySortedSet();
}
LambdaQuery query = handler.behaviour(LambdaQuery.class);
return query.queryLambdas(port);
if (query != null) {
return query.queryLambdas(port);
} else {
return Collections.emptySortedSet();
}
} catch (ItemNotFoundException e) {
return Collections.emptySortedSet();
}
......@@ -181,6 +210,14 @@ final class ResourceDeviceListener implements DeviceListener {
private boolean isVlanEnabled(DeviceId device, PortNumber port) {
try {
// DriverHandler does not provide a way to check if a
// behaviour is supported.
Driver driver = driverService.getDriver(device);
if (driver == null || !driver.hasBehaviour(VlanQuery.class)) {
// device does not support this
return false;
}
DriverHandler handler = driverService.createHandler(device);
if (handler == null) {
return false;
......@@ -195,6 +232,13 @@ final class ResourceDeviceListener implements DeviceListener {
private boolean isMplsEnabled(DeviceId device, PortNumber port) {
try {
// DriverHandler does not provide a way to check if a
// behaviour is supported.
Driver driver = driverService.getDriver(device);
if (driver == null || !driver.hasBehaviour(MplsQuery.class)) {
// device does not support this
return false;
}
DriverHandler handler = driverService.createHandler(device);
if (handler == null) {
return false;
......
......@@ -172,7 +172,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
public boolean unregisterResources(List<ResourcePath> resources) {
checkNotNull(resources);
return store.register(resources);
return store.unregister(resources);
}
private class InternalStoreDelegate implements ResourceStoreDelegate {
......
......@@ -53,12 +53,13 @@ public final class ResourceRegistrar {
@Activate
public void activate() {
deviceListener = new ResourceDeviceListener(adminService, driverService, executor);
deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor);
deviceService.addListener(deviceListener);
}
@Deactivate
public void deactivate() {
deviceService.removeListener(deviceListener);
executor.shutdownNow();
}
}
......
......@@ -197,7 +197,7 @@ class LINCSwitch(OpticalSwitch):
self.configDict[ 'uri' ] = 'of:' + self.dpid
self.configDict[ 'annotations' ] = self.annotations
self.configDict[ 'annotations' ].setdefault('name', self.name)
self.configDict[ 'hw' ] = 'LINC-OE'
self.configDict[ 'hw' ] = 'linc-oe'
self.configDict[ 'mfr' ] = 'Linc'
self.configDict[ 'mac' ] = 'ffffffffffff' + self.dpid[-2] + self.dpid[-1]
self.configDict[ 'type' ] = self.switchType
......