Search in sources :

Example 11 with DeviceEvent

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

the class GossipDeviceStore method markOnline.

/**
 * Marks the device as available if the given timestamp is not outdated,
 * compared to the time the device has been marked offline.
 *
 * @param deviceId  identifier of the device
 * @param timestamp of the event triggering this change.
 * @param notifyPeers if the event needs to be notified to peers.
 * @return ready to send event describing what occurred; null if no change
 */
private DeviceEvent markOnline(DeviceId deviceId, Timestamp timestamp, boolean notifyPeers) {
    final DeviceEvent event = markOnlineInternal(deviceId, timestamp);
    if (event != null && notifyPeers) {
        log.debug("Notifying peers of a device online topology event for deviceId: {} {}", deviceId, timestamp);
        notifyPeers(new InternalDeviceStatusChangeEvent(deviceId, timestamp, true));
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent)

Example 12 with DeviceEvent

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

the class GossipDeviceStore method markOnlineInternal.

// Guarded by deviceDescs value (=Device lock)
private DeviceEvent markOnlineInternal(DeviceId deviceId, Timestamp timestamp) {
    if (devices.containsKey(deviceId)) {
        Map<?, ?> deviceLock = getOrCreateDeviceDescriptionsMap(deviceId);
        synchronized (deviceLock) {
            // accept on-line if given timestamp is newer than
            // the latest offline request Timestamp
            Timestamp offlineTimestamp = offline.get(deviceId);
            if (offlineTimestamp == null || offlineTimestamp.compareTo(timestamp) < 0) {
                offline.remove(deviceId);
                Device device = devices.get(deviceId);
                boolean add = availableDevices.add(deviceId);
                if (add) {
                    return new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
                }
            }
        }
    } else {
        log.warn("Device {} does not exist in store", deviceId);
    }
    return null;
}
Also used : 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 13 with DeviceEvent

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

the class GossipDeviceStore method removeDevice.

@Override
public synchronized DeviceEvent removeDevice(DeviceId deviceId) {
    final NodeId myId = clusterService.getLocalNode().id();
    NodeId master = mastershipService.getMasterFor(deviceId);
    // if there exist a master, forward
    // if there is no master, try to become one and process
    boolean relinquishAtEnd = false;
    if (master == null) {
        final MastershipRole myRole = mastershipService.getLocalRole(deviceId);
        if (myRole != MastershipRole.NONE) {
            relinquishAtEnd = true;
        }
        log.debug("Temporarily requesting role for {} to remove", deviceId);
        if (mastershipService.requestRoleFor(deviceId).join() == MastershipRole.MASTER) {
            master = myId;
        }
    }
    boolean isMaster = myId.equals(master);
    // If this node is not the master, forward the request.
    if (!isMaster) {
        log.debug("{} has control of {}, forwarding remove request", master, deviceId);
        // TODO check unicast return value
        clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master);
    /* error log:
             log.error("Failed to forward {} remove request to {}", deviceId, master, e);
             */
    }
    // If this node is the master, get a timestamp. Otherwise, default to the current device timestamp.
    Timestamp timestamp = isMaster ? deviceClockService.getTimestamp(deviceId) : null;
    DeviceEvent event = removeDeviceInternal(deviceId, timestamp);
    // If this node is the master, update peers.
    if (isMaster && event != null) {
        log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId);
        notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp));
    }
    notifyDelegateIfNotNull(event);
    // Relinquish mastership if acquired to remove the device.
    if (relinquishAtEnd) {
        log.debug("Relinquishing temporary role acquired for {}", deviceId);
        mastershipService.relinquishMastership(deviceId);
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Example 14 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent 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 15 with DeviceEvent

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

the class GossipDeviceStore method removePort.

private DeviceEvent removePort(DeviceId deviceId, PortNumber portNumber, ProviderId providerId, Map<ProviderId, DeviceDescriptions> descsMap) {
    log.info("Deleted port: " + deviceId.toString() + "/" + portNumber.toString());
    Port deletedPort = devicePorts.get(deviceId).remove(portNumber);
    descsMap.computeIfPresent(providerId, (provider, deviceDescriptions) -> {
        deviceDescriptions.removePortDesc(portNumber);
        return deviceDescriptions;
    });
    return new DeviceEvent(PORT_REMOVED, getDevice(deviceId), deletedPort);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort)

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