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