Search in sources :

Example 1 with DefaultAnnotations

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;
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId)

Example 2 with DefaultAnnotations

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();
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 3 with DefaultAnnotations

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;
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) State(org.onosproject.incubator.net.tunnel.Tunnel.State) TunnelEvent(org.onosproject.incubator.net.tunnel.TunnelEvent) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId)

Example 4 with DefaultAnnotations

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;
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) IpAddress(org.onlab.packet.IpAddress)

Example 5 with DefaultAnnotations

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();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.Link.Type) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

DefaultAnnotations (org.onosproject.net.DefaultAnnotations)33 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortDescription (org.onosproject.net.device.PortDescription)9 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)6 LinkDescription (org.onosproject.net.link.LinkDescription)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 Device (org.onosproject.net.Device)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 ArrayList (java.util.ArrayList)3 ChassisId (org.onlab.packet.ChassisId)3 DefaultDevice (org.onosproject.net.DefaultDevice)3 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceService (org.onosproject.net.device.DeviceService)3 XPath (javax.xml.xpath.XPath)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2