use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.
the class SimpleDeviceStore method removeDevice.
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId);
synchronized (descs) {
Device device = devices.remove(deviceId);
// should DEVICE_REMOVED carry removed ports?
Map<PortNumber, Port> ports = devicePorts.get(deviceId);
if (ports != null) {
ports.clear();
}
availableDevices.remove(deviceId);
descs.clear();
return device == null ? null : new DeviceEvent(DEVICE_REMOVED, device, null);
}
}
use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.
the class SimpleDeviceStore method updatePortStatus.
@Override
public DeviceEvent updatePortStatus(ProviderId providerId, DeviceId deviceId, PortDescription portDescription) {
Device device = devices.get(deviceId);
checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
synchronized (descsMap) {
DeviceDescriptions descs = descsMap.get(providerId);
// assuming all providers must give DeviceDescription first
checkArgument(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
ConcurrentMap<PortNumber, Port> ports = getPortMap(deviceId);
final PortNumber number = portDescription.portNumber();
final Port oldPort = ports.get(number);
final Port newPort;
// update description
descs.putPortDesc(portDescription);
newPort = composePort(device, number, descsMap);
if (oldPort == null) {
return createPort(device, newPort, ports);
} else {
return updatePort(device, oldPort, newPort, ports);
}
}
}
use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.
the class SimpleDeviceStore method createOrUpdateDevice.
@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptions(deviceId);
synchronized (providerDescs) {
// locking per device
DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(providerDescs, providerId, deviceDescription);
Device oldDevice = devices.get(deviceId);
// update description
descs.putDeviceDesc(deviceDescription);
Device newDevice = composeDevice(deviceId, providerDescs);
DeviceEvent event = null;
if (oldDevice == null) {
// ADD
event = createDevice(providerId, newDevice);
} else {
// UPDATE or ignore (no change or stale)
event = updateDevice(providerId, oldDevice, newDevice);
}
notifyDelegateIfNotNull(event);
return event;
}
}
use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.
the class SimpleLinkStore method removeLink.
@Override
public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
final LinkKey key = linkKey(src, dst);
Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key);
synchronized (descs) {
Link link = links.remove(key);
descs.clear();
if (link != null) {
srcLinks.remove(link.src().deviceId(), key);
dstLinks.remove(link.dst().deviceId(), key);
return new LinkEvent(LINK_REMOVED, link);
}
return null;
}
}
use of org.onosproject.net.provider.ProviderId in project onos by opennetworkinglab.
the class SimpleLinkStore method composeLink.
// Guarded by linkDescs value (=locking each Link)
private Link composeLink(Map<ProviderId, LinkDescription> descs) {
ProviderId primary = getBaseProviderId(descs);
LinkDescription base = descs.get(verifyNotNull(primary));
ConnectPoint src = base.src();
ConnectPoint dst = base.dst();
Type type = base.type();
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
annotations = merge(annotations, base.annotations());
for (Entry<ProviderId, LinkDescription> e : descs.entrySet()) {
if (primary.equals(e.getKey())) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
annotations = merge(annotations, e.getValue().annotations());
}
boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
return DefaultLink.builder().providerId(primary).src(src).dst(dst).type(type).state(ACTIVE).isExpected(isDurable).annotations(annotations).build();
}
Aggregations