use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class DistributedOpenstackVtapStore method createOrUpdateVtap.
private OpenstackVtap createOrUpdateVtap(boolean update, OpenstackVtap description, boolean replaceDevices) {
DefaultOpenstackVtap result = vtapMap.compute(description.id(), (id, existing) -> {
// Check create or update validity
if (update && existing == null) {
return null;
} else if (!update && existing != null) {
return existing;
}
if (shouldUpdateVtap(existing, description, replaceDevices)) {
// Replace or add devices
final Set<DeviceId> txDeviceIds;
if (existing == null || replaceDevices) {
txDeviceIds = description.txDeviceIds();
} else {
txDeviceIds = Sets.newHashSet(existing.txDeviceIds());
txDeviceIds.addAll(description.txDeviceIds());
}
final Set<DeviceId> rxDeviceIds;
if (existing == null || replaceDevices) {
rxDeviceIds = description.rxDeviceIds();
} else {
rxDeviceIds = Sets.newHashSet(existing.rxDeviceIds());
rxDeviceIds.addAll(description.rxDeviceIds());
}
// Replace or add annotations
final SparseAnnotations annotations;
if (existing != null) {
annotations = merge((DefaultAnnotations) existing.annotations(), (SparseAnnotations) description.annotations());
} else {
annotations = (SparseAnnotations) description.annotations();
}
return DefaultOpenstackVtap.builder(description).txDeviceIds(txDeviceIds).rxDeviceIds(rxDeviceIds).annotations(annotations).build();
}
return existing;
});
return result;
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class OchPortHelper method ochPortDescription.
/**
* Creates OCh port DefaultPortDescription based on the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param signalType ODU signal type
* @param isTunable tunable wavelength capability
* @param lambda OCh signal
* @param annotationsIn key/value annotations map
* @return OCh port DefaultPortDescription with OCh annotations
*/
public static PortDescription ochPortDescription(PortNumber number, boolean isEnabled, OduSignalType signalType, boolean isTunable, OchSignal lambda, SparseAnnotations annotationsIn) {
Builder builder = DefaultAnnotations.builder();
builder.putAll(annotationsIn);
builder.set(TUNABLE, String.valueOf(isTunable));
builder.set(LAMBDA, OchSignalCodec.encode(lambda).toString());
builder.set(SIGNAL_TYPE, signalType.toString());
DefaultAnnotations annotations = builder.build();
long portSpeed = signalType.bitRate();
return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(Port.Type.OCH).portSpeed(portSpeed).annotations(annotations).build();
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class DistributedTunnelStore method handleCreateOrUpdateTunnel.
private TunnelId handleCreateOrUpdateTunnel(Tunnel tunnel, State state) {
// tunnelIdAsKeyStore.
if (tunnel.tunnelId() != null && !"".equals(tunnel.tunnelId().toString())) {
Tunnel old = tunnelIdAsKeyStore.get(tunnel.tunnelId());
if (old == null) {
log.info("This tunnel[" + tunnel.tunnelId() + "] is not available.");
return tunnel.tunnelId();
}
DefaultAnnotations oldAnno = (DefaultAnnotations) old.annotations();
SparseAnnotations newAnno = (SparseAnnotations) tunnel.annotations();
State newTunnelState = (state != null) ? state : old.state();
Tunnel newT = new DefaultTunnel(old.providerId(), old.src(), old.dst(), old.type(), newTunnelState, old.groupId(), old.tunnelId(), old.tunnelName(), old.path(), old.resource(), DefaultAnnotations.merge(oldAnno, newAnno));
tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
notifyDelegate(event);
return tunnel.tunnelId();
} else {
TunnelId tunnelId = TunnelId.valueOf(String.valueOf(idGenerator.getNewId()));
State tunnelState = (state != null) ? state : tunnel.state();
Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(), tunnelState, tunnel.groupId(), tunnelId, tunnel.tunnelName(), tunnel.path(), tunnel.resource(), tunnel.annotations());
tunnelIdAsKeyStore.put(tunnelId, newT);
TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
notifyDelegate(event);
return tunnelId;
}
}
use of org.onosproject.net.DefaultAnnotations in project onos by opennetworkinglab.
the class SimpleHostStore method updateHost.
// checks for type of update to host, sends appropriate event
private HostEvent updateHost(ProviderId providerId, StoredHost host, HostDescription descr, boolean replaceIps) {
HostEvent event;
if (!host.location().equals(descr.location())) {
host.setLocation(descr.location());
return new HostEvent(HOST_MOVED, host);
}
if (host.ipAddresses().containsAll(descr.ipAddress()) && descr.annotations().keys().isEmpty()) {
return null;
}
final Set<IpAddress> addresses;
if (replaceIps) {
addresses = ImmutableSet.copyOf(descr.ipAddress());
} else {
addresses = new HashSet<>(host.ipAddresses());
addresses.addAll(descr.ipAddress());
}
Annotations annotations = merge((DefaultAnnotations) host.annotations(), descr.annotations());
StoredHost updated = new StoredHost(providerId, host.id(), host.mac(), host.vlan(), descr.location(), addresses, descr.configured(), annotations);
event = new HostEvent(HOST_UPDATED, updated);
synchronized (this) {
hosts.put(host.id(), updated);
locations.remove(host.location(), host);
locations.put(updated.location(), updated);
}
return event;
}
use of org.onosproject.net.DefaultAnnotations 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