Search in sources :

Example 31 with DeviceEvent

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());
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Test(org.junit.Test)

Example 32 with DeviceEvent

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;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent)

Example 33 with DeviceEvent

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);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortNumber(org.onosproject.net.PortNumber)

Example 34 with DeviceEvent

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;
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device)

Example 35 with DeviceEvent

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());
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Test(org.junit.Test)

Aggregations

DeviceEvent (org.onosproject.net.device.DeviceEvent)77 Test (org.junit.Test)42 Device (org.onosproject.net.Device)26 DefaultDevice (org.onosproject.net.DefaultDevice)17 DefaultPort (org.onosproject.net.DefaultPort)17 PortDescription (org.onosproject.net.device.PortDescription)14 PortNumber (org.onosproject.net.PortNumber)11 Port (org.onosproject.net.Port)10 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)10 ProviderId (org.onosproject.net.provider.ProviderId)10 ArrayList (java.util.ArrayList)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 Timestamp (org.onosproject.store.Timestamp)8 MessageSubject (org.onosproject.store.cluster.messaging.MessageSubject)8 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)8 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)8 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)8 BiFunction (java.util.function.BiFunction)7 Function (java.util.function.Function)7 DeviceDescription (org.onosproject.net.device.DeviceDescription)7