Search in sources :

Example 16 with Timestamp

use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.

the class GossipDeviceStore method updatePorts.

@Override
public synchronized List<DeviceEvent> updatePorts(ProviderId providerId, DeviceId deviceId, List<PortDescription> portDescriptions) {
    NodeId localNode = clusterService.getLocalNode().id();
    // TODO: It might be negligible, but this will have negative impact to topology discovery performance,
    // since it will trigger distributed store read.
    // Also, it'll probably be better if side-way communication happened on ConfigurationProvider, etc.
    // outside Device subsystem. so that we don't have to modify both Device and Link stores.
    // If we don't care much about topology performance, then it might be OK.
    NodeId deviceNode = mastershipService.getMasterFor(deviceId);
    // Process port update only if we're the master of the device,
    // otherwise signal the actual master.
    List<DeviceEvent> deviceEvents = null;
    if (localNode.equals(deviceNode)) {
        final Timestamp newTimestamp;
        try {
            newTimestamp = deviceClockService.getTimestamp(deviceId);
        } catch (IllegalStateException e) {
            log.info("Timestamp was not available for device {}", deviceId);
            log.debug("  discarding {}", portDescriptions);
            return Collections.emptyList();
        }
        log.debug("timestamp for {} {}", deviceId, newTimestamp);
        final Timestamped<List<PortDescription>> timestampedInput = new Timestamped<>(portDescriptions, newTimestamp);
        final Timestamped<List<PortDescription>> merged;
        final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
        synchronized (device) {
            deviceEvents = updatePortsInternal(providerId, deviceId, timestampedInput);
            final DeviceDescriptions descs = device.get(providerId);
            List<PortDescription> mergedList = FluentIterable.from(portDescriptions).transform(input -> descs.getPortDesc(input.portNumber()).value()).toList();
            merged = new Timestamped<>(mergedList, newTimestamp);
        }
        if (!deviceEvents.isEmpty()) {
            log.debug("Notifying peers of a ports update topology event for providerId: {} and deviceId: {}", providerId, deviceId);
            notifyPeers(new InternalPortEvent(providerId, deviceId, merged));
        }
    } else {
        return Collections.emptyList();
    }
    return deviceEvents;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DEVICE_STATUS_CHANGE(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_STATUS_CHANGE) DeviceStore(org.onosproject.net.device.DeviceStore) DefaultDevice(org.onosproject.net.DefaultDevice) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) FluentIterable(com.google.common.collect.FluentIterable) Port(org.onosproject.net.Port) Map(java.util.Map) PORT_STATUS_UPDATE(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DistributedStoreSerializers(org.onosproject.store.serializers.custom.DistributedStoreSerializers) DeviceDescription(org.onosproject.net.device.DeviceDescription) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) DEVICE_UPDATE(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_UPDATE) Collection(java.util.Collection) MastershipTermService(org.onosproject.mastership.MastershipTermService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DEVICE_REMOVED(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVED) Set(java.util.Set) PUT(org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) PORT_UPDATE(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_UPDATE) PORT_REMOVED(org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) DeviceClockService(org.onosproject.net.device.DeviceClockService) List(java.util.List) DEVICE_ADVERTISE(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE) Stream(java.util.stream.Stream) Annotations(org.onosproject.net.Annotations) DeviceEvent(org.onosproject.net.device.DeviceEvent) Entry(java.util.Map.Entry) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DEVICE_AVAILABILITY_CHANGED(org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) ChassisId(org.onlab.packet.ChassisId) RandomUtils(org.apache.commons.lang3.RandomUtils) PortStatistics(org.onosproject.net.device.PortStatistics) HashMap(java.util.HashMap) KryoNamespace(org.onlab.util.KryoNamespace) Predicates.notNull(com.google.common.base.Predicates.notNull) ControllerNode(org.onosproject.cluster.ControllerNode) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) PortDescription(org.onosproject.net.device.PortDescription) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Timestamp(org.onosproject.store.Timestamp) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) PORT_STATS_UPDATED(org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MastershipRole(org.onosproject.net.MastershipRole) Tools.minPriority(org.onlab.util.Tools.minPriority) DEVICE_REMOVE_REQ(org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) PORT_ADDED(org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) AnnotationsUtil(org.onosproject.net.AnnotationsUtil) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Timestamped(org.onosproject.store.impl.Timestamped) Reference(org.osgi.service.component.annotations.Reference) PORT_UPDATED(org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED) Collections(java.util.Collections) DeviceEvent(org.onosproject.net.device.DeviceEvent) 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) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) NodeId(org.onosproject.cluster.NodeId) Timestamped(org.onosproject.store.impl.Timestamped) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 17 with Timestamp

use of org.onosproject.store.Timestamp 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 18 with Timestamp

use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.

the class GossipDeviceStore method handleDeviceStatusChangeEvent.

private void handleDeviceStatusChangeEvent(InternalDeviceStatusChangeEvent event) {
    DeviceId deviceId = event.deviceId();
    Timestamp timestamp = event.timestamp();
    Boolean available = event.available();
    try {
        if (available) {
            notifyDelegateIfNotNull(markOnlineInternal(deviceId, timestamp));
        } else {
            notifyDelegateIfNotNull(markOfflineInternal(deviceId, timestamp));
        }
    } catch (Exception e) {
        log.warn("Exception thrown handling device status change event", e);
    }
}
Also used : 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) IOException(java.io.IOException)

Example 19 with Timestamp

use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.

the class GossipDeviceStore method handleDeviceRemovedEvent.

private void handleDeviceRemovedEvent(InternalDeviceRemovedEvent event) {
    DeviceId deviceId = event.deviceId();
    Timestamp timestamp = event.timestamp();
    try {
        notifyDelegateIfNotNull(removeDeviceInternal(deviceId, timestamp));
    } catch (Exception e) {
        log.warn("Exception thrown handling device removed", e);
    }
}
Also used : 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) IOException(java.io.IOException)

Example 20 with Timestamp

use of org.onosproject.store.Timestamp 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)

Aggregations

Timestamp (org.onosproject.store.Timestamp)32 Test (org.junit.Test)15 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)14 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)13 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)13 ProviderId (org.onosproject.net.provider.ProviderId)9 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)8 Intent (org.onosproject.net.intent.Intent)8 IntentData (org.onosproject.net.intent.IntentData)8 IntentEvent (org.onosproject.net.intent.IntentEvent)8 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)8 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)8 SystemClockTimestamp (org.onosproject.store.trivial.SystemClockTimestamp)8 DeviceId (org.onosproject.net.DeviceId)6 ArrayList (java.util.ArrayList)5 ControllerNodeToNodeId.toNodeId (org.onosproject.cluster.ControllerNodeToNodeId.toNodeId)5 NodeId (org.onosproject.cluster.NodeId)5 DefaultDevice (org.onosproject.net.DefaultDevice)5 Device (org.onosproject.net.Device)5