use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class ECDeviceStore method updatePorts.
@Override
public List<DeviceEvent> updatePorts(ProviderId providerId, DeviceId deviceId, List<PortDescription> descriptions) {
NodeId master = mastershipService.getMasterFor(deviceId);
List<DeviceEvent> deviceEvents = null;
if (localNodeId.equals(master)) {
descriptions.forEach(description -> {
PortKey portKey = new PortKey(providerId, deviceId, description.portNumber());
portDescriptions.put(portKey, description);
});
deviceEvents = refreshDevicePortCache(providerId, deviceId, Optional.empty());
} else {
return Collections.emptyList();
}
return deviceEvents == null ? Collections.emptyList() : deviceEvents;
}
use of org.onosproject.net.device.DeviceEvent 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;
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class GossipDeviceStore method handleRemoveRequest.
private void handleRemoveRequest(DeviceId did) {
try {
DeviceEvent event = removeDevice(did);
notifyDelegateIfNotNull(event);
} catch (Exception e) {
log.warn("Exception thrown handling device remove", e);
}
}
use of org.onosproject.net.device.DeviceEvent 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;
}
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class GossipDeviceStore method createDevice.
// Creates the device and returns the appropriate event if necessary.
// Guarded by deviceDescs value (=Device lock)
private DeviceEvent createDevice(ProviderId providerId, Device newDevice, Timestamp timestamp) {
// update composed device cache
Device oldDevice = devices.putIfAbsent(newDevice.id(), newDevice);
verify(oldDevice == null, "Unexpected Device in cache. PID:%s [old=%s, new=%s]", providerId, oldDevice, newDevice);
if (!providerId.isAncillary()) {
markOnline(newDevice.id(), timestamp, false);
}
log.debug("Device {} added", newDevice.id());
return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, newDevice, null);
}
Aggregations