Search in sources :

Example 1 with SparseAnnotations

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

Example 2 with SparseAnnotations

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));
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) OmsPort(org.onosproject.net.optical.OmsPort) DefaultPort(org.onosproject.net.DefaultPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) Frequency(org.onlab.util.Frequency) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 3 with SparseAnnotations

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;
    }
}
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 SparseAnnotations

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);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress)

Example 5 with SparseAnnotations

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

Aggregations

SparseAnnotations (org.onosproject.net.SparseAnnotations)30 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 ChassisId (org.onlab.packet.ChassisId)10 DeviceId (org.onosproject.net.DeviceId)8 Device (org.onosproject.net.Device)6 Test (org.junit.Test)5 DefaultTunnelDescription (org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)4 TunnelDescription (org.onosproject.incubator.net.tunnel.TunnelDescription)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 PortDescription (org.onosproject.net.device.PortDescription)4 NetconfException (org.onosproject.netconf.NetconfException)4 NetconfSession (org.onosproject.netconf.NetconfSession)4 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)3 GroupId (org.onosproject.core.GroupId)3 IpTunnelEndPoint (org.onosproject.incubator.net.tunnel.IpTunnelEndPoint)3 TunnelEndPoint (org.onosproject.incubator.net.tunnel.TunnelEndPoint)3 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)3 Link (org.onosproject.net.Link)3 PortNumber (org.onosproject.net.PortNumber)3 NetconfDevice (org.onosproject.netconf.NetconfDevice)3