Search in sources :

Example 51 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.

the class GossipDeviceStore method markOffline.

private DeviceEvent markOffline(DeviceId deviceId, Timestamp timestamp) {
    final DeviceEvent event = markOfflineInternal(deviceId, timestamp);
    if (event != null) {
        log.debug("Notifying peers of a device offline topology event for deviceId: {} {}", deviceId, timestamp);
        notifyPeers(new InternalDeviceStatusChangeEvent(deviceId, timestamp, false));
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent)

Example 52 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.

the class GossipDeviceStore method registerDevice.

private DeviceEvent registerDevice(ProviderId providerId, Device newDevice, Timestamp newTimestamp) {
    // update composed device cache
    Device oldDevice = devices.putIfAbsent(newDevice.id(), newDevice);
    verify(oldDevice == null, "Unexpected Device in cache. PID:%s [old=%s, new=%s]", providerId, oldDevice, newDevice);
    if (!providerId.isAncillary()) {
        markOffline(newDevice.id(), newTimestamp);
    }
    return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, newDevice, null);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device)

Example 53 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.

the class GossipDeviceStore method updatePortsInternal.

private List<DeviceEvent> updatePortsInternal(ProviderId providerId, DeviceId deviceId, Timestamped<List<PortDescription>> portDescriptions) {
    Device device = devices.get(deviceId);
    if (device == null) {
        log.debug("Device is no longer valid: {}", deviceId);
        return Collections.emptyList();
    }
    Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
    checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
    List<DeviceEvent> events = new ArrayList<>();
    synchronized (descsMap) {
        if (isDeviceRemoved(deviceId, portDescriptions.timestamp())) {
            log.debug("Ignoring outdated events: {}", portDescriptions);
            return Collections.emptyList();
        }
        DeviceDescriptions descs = descsMap.get(providerId);
        // every provider must provide DeviceDescription.
        checkArgument(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
        Map<PortNumber, Port> ports = getPortMap(deviceId);
        final Timestamp newTimestamp = portDescriptions.timestamp();
        // Add new ports
        Set<PortNumber> processed = new HashSet<>();
        for (PortDescription portDescription : portDescriptions.value()) {
            final PortNumber number = portDescription.portNumber();
            processed.add(number);
            final Port oldPort = ports.get(number);
            final Port newPort;
            boolean isRemoved = portDescription.isRemoved();
            final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number);
            if (existingPortDesc == null || newTimestamp.compareTo(existingPortDesc.timestamp()) >= 0) {
                // on new port or valid update
                // update description
                descs.putPortDesc(new Timestamped<>(portDescription, portDescriptions.timestamp()));
                newPort = composePort(device, number, descsMap);
            } else {
                // outdated event, ignored.
                continue;
            }
            if (isRemoved && oldPort != null) {
                events.add(removePort(deviceId, oldPort.number(), providerId, descsMap));
            } else if (!isRemoved) {
                events.add(oldPort == null ? createPort(device, newPort, ports) : updatePort(device, oldPort, newPort, ports));
            }
        }
        events.addAll(pruneOldPorts(device, ports, processed));
    }
    return FluentIterable.from(events).filter(notNull()).toList();
}
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) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 54 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventHostAvailableMatch.

/**
 * Tests an event for a host becoming available that matches an intent.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventHostAvailableMatch() throws Exception {
    final Device host = device("host1");
    final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, host);
    reasons.add(deviceEvent);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(host.id());
    tracker.addTrackedResources(key, resources);
    deviceListener.event(deviceEvent);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(true));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 55 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventHostUnavailableMatch.

/**
 * Tests an event for a host becoming unavailable that matches an intent.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventHostUnavailableMatch() throws Exception {
    final Device host = device("host1");
    final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, host);
    reasons.add(deviceEvent);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(host.id());
    tracker.addTrackedResources(key, resources);
    deviceListener.event(deviceEvent);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

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