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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations