Search in sources :

Example 11 with ProviderId

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

the class GossipDeviceStore method createOrUpdateDevice.

@Override
public synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
    NodeId localNode = clusterService.getLocalNode().id();
    NodeId deviceNode = mastershipService.getMasterFor(deviceId);
    boolean isMaster = localNode.equals(deviceNode);
    // Process device update only if we're the master,
    // otherwise signal the actual master.
    DeviceEvent deviceEvent = null;
    // If this node is the master for the device, acquire a new timestamp. Otherwise,
    // use a 0,0 or tombstone timestamp to create the device if it doesn't already exist.
    Timestamp newTimestamp;
    try {
        newTimestamp = isMaster ? deviceClockService.getTimestamp(deviceId) : removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
    } catch (IllegalStateException e) {
        newTimestamp = removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
        isMaster = false;
    }
    final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp);
    final Timestamped<DeviceDescription> mergedDesc;
    final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
    synchronized (device) {
        deviceEvent = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc);
        if (deviceEvent == null) {
            return null;
        }
        mergedDesc = device.get(providerId).getDeviceDesc();
    }
    // If this node is the master for the device, update peers.
    if (isMaster) {
        log.debug("Notifying peers of a device update topology event for providerId: {} and deviceId: {}", providerId, deviceId);
        notifyPeers(new InternalDeviceEvent(providerId, deviceId, mergedDesc));
    }
    notifyDelegateIfNotNull(deviceEvent);
    return deviceEvent;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceDescription(org.onosproject.net.device.DeviceDescription) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) NodeId(org.onosproject.cluster.NodeId) Timestamped(org.onosproject.store.impl.Timestamped) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Example 12 with ProviderId

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

the class GossipDeviceStore method removeDeviceInternal.

private DeviceEvent removeDeviceInternal(DeviceId deviceId, Timestamp timestamp) {
    Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptionsMap(deviceId);
    synchronized (descs) {
        // accept removal request if given timestamp is newer than
        // the latest Timestamp from Primary provider
        DeviceDescriptions primDescs = getPrimaryDescriptions(descs);
        if (primDescs == null) {
            return null;
        }
        Timestamp lastTimestamp = primDescs.getLatestTimestamp();
        // If no timestamp is set, default the timestamp to the last timestamp for the device.
        if (timestamp == null) {
            timestamp = lastTimestamp;
        }
        if (timestamp.compareTo(lastTimestamp) <= 0) {
            // outdated event ignore
            return null;
        }
        removalRequest.put(deviceId, timestamp);
        Device device = devices.remove(deviceId);
        // removing internal description
        deviceDescs.remove(deviceId);
        // should DEVICE_REMOVED carry removed ports?
        Map<PortNumber, Port> ports = devicePorts.get(deviceId);
        if (ports != null) {
            ports.clear();
        }
        markOfflineInternal(deviceId, timestamp);
        descs.clear();
        // Forget about the device
        offline.remove(deviceId);
        return device == null ? null : new DeviceEvent(DeviceEvent.Type.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) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Example 13 with ProviderId

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

the class InternalPortEventSerializer method read.

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

Example 14 with ProviderId

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

the class ECDeviceStore method composePort.

/**
 * Returns a Port, merging descriptions from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number) {
    Map<ProviderId, PortDescription> descriptions = Maps.newHashMap();
    portDescriptions.entrySet().forEach(entry -> {
        PortKey portKey = entry.getKey();
        if (portKey.deviceId().equals(device.id()) && portKey.portNumber().equals(number)) {
            descriptions.put(portKey.providerId(), entry.getValue());
        }
    });
    ProviderId primary = getPrimaryProviderId(device.id());
    PortDescription primaryDescription = descriptions.get(primary);
    // if no primary, assume not enabled
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    if (primaryDescription != null) {
        isEnabled = primaryDescription.isEnabled();
        annotations = merge(annotations, primaryDescription.annotations());
    }
    Port updated = null;
    for (Entry<ProviderId, PortDescription> e : descriptions.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        annotations = merge(annotations, e.getValue().annotations());
        updated = buildTypedPort(device, number, isEnabled, e.getValue(), annotations);
    }
    if (primaryDescription == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations) : updated;
    }
    return updated == null ? buildTypedPort(device, number, isEnabled, primaryDescription, annotations) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Example 15 with ProviderId

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

the class ECDeviceStore method composeDevice.

/**
 * Returns a Device, merging descriptions from multiple Providers.
 *
 * @param deviceId      device identifier
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId) {
    ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
    DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
    Type type = primaryDeviceDescription.type();
    String manufacturer = primaryDeviceDescription.manufacturer();
    String hwVersion = primaryDeviceDescription.hwVersion();
    String swVersion = primaryDeviceDescription.swVersion();
    String serialNumber = primaryDeviceDescription.serialNumber();
    ChassisId chassisId = primaryDeviceDescription.chassisId();
    DefaultAnnotations annotations = mergeAnnotations(deviceId);
    return new DefaultDevice(primaryProviderId, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

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