use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class SimpleDeviceStoreTest method testUpdatePortStatus.
@Test
public final void testUpdatePortStatus() {
putDevice(DID1, SW1);
List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
deviceStore.updatePorts(PID, DID1, pds);
DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build());
assertEquals(PORT_UPDATED, event.type());
assertDevice(DID1, SW1, event.subject());
assertEquals(P1, event.port().number());
assertFalse("Port is disabled", event.port().isEnabled());
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class SimpleDeviceStore method updateDevice.
// Updates the device and returns the appropriate event if necessary.
// Guarded by deviceDescs value (=Device lock)
private DeviceEvent updateDevice(ProviderId providerId, Device oldDevice, Device newDevice) {
// We allow only certain attributes to trigger update
boolean propertiesChanged = !Objects.equals(oldDevice.hwVersion(), newDevice.hwVersion()) || !Objects.equals(oldDevice.swVersion(), newDevice.swVersion());
boolean annotationsChanged = !AnnotationsUtil.isEqual(oldDevice.annotations(), newDevice.annotations());
// should respond only to annotation changes.
if ((providerId.isAncillary() && annotationsChanged) || (!providerId.isAncillary() && (propertiesChanged || annotationsChanged))) {
boolean replaced = devices.replace(newDevice.id(), oldDevice, newDevice);
if (!replaced) {
// FIXME: Is the enclosing if required here?
verify(replaced, "Replacing devices cache failed. PID:%s [expected:%s, found:%s, new=%s]", providerId, oldDevice, devices.get(newDevice.id()), newDevice);
}
if (!providerId.isAncillary()) {
availableDevices.add(newDevice.id());
}
return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, newDevice, null);
}
// Otherwise merely attempt to change availability if primary provider
if (!providerId.isAncillary()) {
boolean added = availableDevices.add(newDevice.id());
return !added ? null : new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, newDevice, null);
}
return null;
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class SimpleDeviceStore method removeDevice.
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId);
synchronized (descs) {
Device device = devices.remove(deviceId);
// should DEVICE_REMOVED carry removed ports?
Map<PortNumber, Port> ports = devicePorts.get(deviceId);
if (ports != null) {
ports.clear();
}
availableDevices.remove(deviceId);
descs.clear();
return device == null ? null : new DeviceEvent(DEVICE_REMOVED, device, null);
}
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class SimpleDeviceStore method createOrUpdateDevice.
@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptions(deviceId);
synchronized (providerDescs) {
// locking per device
DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(providerDescs, providerId, deviceDescription);
Device oldDevice = devices.get(deviceId);
// update description
descs.putDeviceDesc(deviceDescription);
Device newDevice = composeDevice(deviceId, providerDescs);
DeviceEvent event = null;
if (oldDevice == null) {
// ADD
event = createDevice(providerId, newDevice);
} else {
// UPDATE or ignore (no change or stale)
event = updateDevice(providerId, oldDevice, newDevice);
}
notifyDelegateIfNotNull(event);
return event;
}
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class OvsdbDeviceProviderTest method testDiscoverPortsAfterDeviceAdded.
@Test
public void testDiscoverPortsAfterDeviceAdded() {
final int portCount = 5;
provider.executor = MoreExecutors.newDirectExecutorService();
prepareMocks(portCount);
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, ovsdbDevice);
if (deviceService.listener.isRelevant(event)) {
deviceService.listener.event(event);
}
event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, notOvsdbDevice);
if (deviceService.listener.isRelevant(event)) {
deviceService.listener.event(event);
}
assertEquals(portCount, registry.ports.get(ovsdbDevice.id()).size());
assertEquals(0, registry.ports.get(notOvsdbDevice.id()).size());
}
Aggregations