Search in sources :

Example 36 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class GossipDeviceStore method updatePortStatusInternal.

private DeviceEvent updatePortStatusInternal(ProviderId providerId, DeviceId deviceId, Timestamped<PortDescription> deltaDesc) {
    Device device = devices.get(deviceId);
    checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
    Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
    checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
    synchronized (descsMap) {
        if (isDeviceRemoved(deviceId, deltaDesc.timestamp())) {
            log.debug("Ignoring outdated event: {}", deltaDesc);
            return null;
        }
        DeviceDescriptions descs = descsMap.get(providerId);
        // assuming all providers must to give DeviceDescription
        verify(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
        ConcurrentMap<PortNumber, Port> ports = getPortMap(deviceId);
        final PortNumber number = deltaDesc.value().portNumber();
        final Port oldPort = ports.get(number);
        final Port newPort;
        final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number);
        boolean toDelete;
        if (existingPortDesc == null || deltaDesc.isNewer(existingPortDesc)) {
            // on new port or valid update
            // update description
            descs.putPortDesc(deltaDesc);
            newPort = composePort(device, number, descsMap);
            toDelete = deltaDesc.value().isRemoved();
        } else {
            // same or outdated event, ignored.
            log.trace("ignore same or outdated {} >= {}", existingPortDesc, deltaDesc);
            return null;
        }
        if (!toDelete) {
            return oldPort == null ? createPort(device, newPort, ports) : updatePort(device, oldPort, newPort, ports);
        } else {
            return removePort(deviceId, number, providerId, descsMap);
        }
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber)

Example 37 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class GossipDeviceStore method markOfflineInternal.

private DeviceEvent markOfflineInternal(DeviceId deviceId, Timestamp timestamp) {
    Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptionsMap(deviceId);
    // locking device
    synchronized (providerDescs) {
        // accept off-line if given timestamp is newer than
        // the latest Timestamp from Primary provider
        DeviceDescriptions primDescs = getPrimaryDescriptions(providerDescs);
        if (primDescs != null) {
            Timestamp lastTimestamp = primDescs.getLatestTimestamp();
            if (lastTimestamp == null) {
                lastTimestamp = deviceClockService.getTimestamp(deviceId);
            }
            if (timestamp.compareTo(lastTimestamp) <= 0) {
                // outdated event ignore
                return null;
            }
        }
        offline.put(deviceId, timestamp);
        Device device = devices.get(deviceId);
        if (device == null) {
            // Single Instance ONOS, device is removed from devices map and is null here but
            // must still be marked offline
            availableDevices.remove(deviceId);
            return null;
        }
        boolean removed = availableDevices.remove(deviceId);
        if (removed) {
            return new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
        }
        return 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) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Example 38 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class GossipDeviceStore method createAdvertisement.

private DeviceAntiEntropyAdvertisement createAdvertisement() {
    final NodeId self = clusterService.getLocalNode().id();
    final int numDevices = deviceDescs.size();
    Map<DeviceFragmentId, Timestamp> adDevices = new HashMap<>(numDevices);
    // random factor to minimize reallocation
    final int portsPerDevice = 8;
    Map<PortFragmentId, Timestamp> adPorts = new HashMap<>(numDevices * portsPerDevice);
    Map<DeviceId, Timestamp> adOffline = new HashMap<>(numDevices);
    deviceDescs.forEach((deviceId, devDescs) -> {
        // for each Device...
        synchronized (devDescs) {
            // send device offline timestamp
            Timestamp lOffline = this.offline.get(deviceId);
            if (lOffline != null) {
                adOffline.put(deviceId, lOffline);
            }
            for (Entry<ProviderId, DeviceDescriptions> prov : devDescs.entrySet()) {
                // for each Provider Descriptions...
                final ProviderId provId = prov.getKey();
                final DeviceDescriptions descs = prov.getValue();
                adDevices.put(new DeviceFragmentId(deviceId, provId), descs.getDeviceDesc().timestamp());
                for (Entry<PortNumber, Timestamped<PortDescription>> portDesc : descs.getPortDescs().entrySet()) {
                    final PortNumber number = portDesc.getKey();
                    adPorts.put(new PortFragmentId(deviceId, provId, number), portDesc.getValue().timestamp());
                }
            }
        }
    });
    return new DeviceAntiEntropyAdvertisement(self, adDevices, adPorts, adOffline);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) NodeId(org.onosproject.cluster.NodeId) Timestamped(org.onosproject.store.impl.Timestamped) PortNumber(org.onosproject.net.PortNumber)

Example 39 with ProviderId

use of org.onosproject.net.provider.ProviderId 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 40 with ProviderId

use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.

the class InternalDeviceEventSerializer method read.

@Override
public InternalDeviceEvent read(Kryo kryo, Input input, Class<InternalDeviceEvent> type) {
    ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
    DeviceId deviceId = kryo.readObject(input, DeviceId.class, deviceIdSerializer());
    @SuppressWarnings("unchecked") Timestamped<DeviceDescription> deviceDescription = (Timestamped<DeviceDescription>) kryo.readClassAndObject(input);
    return new InternalDeviceEvent(providerId, deviceId, deviceDescription);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceId(org.onosproject.net.DeviceId) Timestamped(org.onosproject.store.impl.Timestamped)

Aggregations

ProviderId (org.onosproject.net.provider.ProviderId)62 DefaultDevice (org.onosproject.net.DefaultDevice)15 DeviceId (org.onosproject.net.DeviceId)13 Tunnel (org.onosproject.incubator.net.tunnel.Tunnel)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)12 Device (org.onosproject.net.Device)12 PortDescription (org.onosproject.net.device.PortDescription)12 TunnelProvider (org.onosproject.incubator.net.tunnel.TunnelProvider)10 DefaultPort (org.onosproject.net.DefaultPort)10 Port (org.onosproject.net.Port)10 DeviceEvent (org.onosproject.net.device.DeviceEvent)10 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)10 PortNumber (org.onosproject.net.PortNumber)9 DeviceDescription (org.onosproject.net.device.DeviceDescription)9 Timestamp (org.onosproject.store.Timestamp)9 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)9 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)9 DefaultTunnel (org.onosproject.incubator.net.tunnel.DefaultTunnel)7 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)7