use of org.onosproject.net.SparseAnnotations 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.SparseAnnotations in project onos by opennetworkinglab.
the class OmsPortHelperTest method testOmsPortDescriptionCanBeConvertedToOmsPort.
@Test
public void testOmsPortDescriptionCanBeConvertedToOmsPort() {
PortNumber pn = PortNumber.portNumber(4900);
boolean isEnabled = true;
String anKey = "Base";
String anValue = "value";
SparseAnnotations an = DefaultAnnotations.builder().set(anKey, anValue).build();
Frequency minF = Frequency.ofGHz(3);
Frequency maxF = Frequency.ofGHz(33);
Frequency grid = Frequency.ofGHz(2);
PortDescription portDescription = OmsPortHelper.omsPortDescription(pn, isEnabled, minF, maxF, grid, an);
Port port = new DefaultPort(DEV, portDescription.portNumber(), portDescription.isEnabled(), portDescription.type(), portDescription.portSpeed(), portDescription.annotations());
Optional<OmsPort> maybeOms = OmsPortHelper.asOmsPort(port);
assertTrue(maybeOms.isPresent());
OmsPort oms = maybeOms.get();
assertThat(oms.isEnabled(), is(isEnabled));
assertThat(oms.number(), is(pn));
assertThat(oms.annotations().value(anKey), is(anValue));
assertThat("type is always OMS", oms.type(), is(Port.Type.OMS));
assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L)));
assertThat(oms.maxFrequency(), is(maxF));
assertThat(oms.minFrequency(), is(minF));
assertThat(oms.grid(), is(grid));
assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
use of org.onosproject.net.SparseAnnotations 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.SparseAnnotations in project onos by opennetworkinglab.
the class BasicHostOperator method combine.
/**
* Generates a HostDescription containing fields from a HostDescription and
* a HostConfig.
*
* @param cfg the host config entity from network config
* @param descr a HostDescription
* @return HostDescription based on both sources
*/
public static HostDescription combine(BasicHostConfig cfg, HostDescription descr) {
if (cfg == null || descr == null) {
return descr;
}
Set<HostLocation> locations = descr.locations();
Set<HostLocation> cfgLocations = cfg.locations();
if (cfgLocations != null) {
locations = cfgLocations.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
}
Set<HostLocation> auxLocations = descr.auxLocations();
Set<HostLocation> cfgAuxLocations = cfg.auxLocations();
if (cfgAuxLocations != null) {
auxLocations = cfgAuxLocations.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
}
Set<IpAddress> ipAddresses = descr.ipAddress();
Set<IpAddress> cfgIpAddresses = cfg.ipAddresses();
if (cfgIpAddresses != null) {
ipAddresses = cfgIpAddresses;
}
SparseAnnotations sa = combine(cfg, descr.annotations());
return new DefaultHostDescription(descr.hwAddress(), descr.vlan(), locations, auxLocations, ipAddresses, descr.innerVlan(), descr.tpid(), descr.configured(), sa);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class DeviceDescriptions method putDeviceDesc.
/**
* Puts DeviceDescription, merging annotations as necessary.
*
* @param newDesc new DeviceDescription
*/
public void putDeviceDesc(Timestamped<DeviceDescription> newDesc) {
Timestamped<DeviceDescription> oldOne = deviceDesc;
Timestamped<DeviceDescription> newOne = newDesc;
if (oldOne != null) {
SparseAnnotations merged = union(oldOne.value().annotations(), newDesc.value().annotations());
newOne = new Timestamped<>(new DefaultDeviceDescription(newDesc.value(), merged), newDesc.timestamp());
}
deviceDesc = newOne;
}
Aggregations