Search in sources :

Example 6 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class DistributedHostStore method createOrUpdateHost.

// TODO No longer need to return HostEvent
@Override
public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, HostDescription hostDescription, boolean replaceIPs) {
    hostsConsistentMap.computeIf(hostId, existingHost -> shouldUpdate(existingHost, providerId, hostDescription, replaceIPs), (id, existingHost) -> {
        final Set<IpAddress> addresses;
        if (existingHost == null || replaceIPs) {
            addresses = ImmutableSet.copyOf(hostDescription.ipAddress());
        } else {
            addresses = Sets.newHashSet(existingHost.ipAddresses());
            addresses.addAll(hostDescription.ipAddress());
        }
        final Annotations annotations;
        if (existingHost != null) {
            annotations = merge((DefaultAnnotations) existingHost.annotations(), hostDescription.annotations());
        } else {
            annotations = hostDescription.annotations();
        }
        return new DefaultHost(providerId, hostId, hostDescription.hwAddress(), hostDescription.vlan(), hostDescription.locations(), hostDescription.auxLocations(), addresses, hostDescription.innerVlan(), hostDescription.tpid(), hostDescription.configured(), false, annotations);
    });
    return null;
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) Annotations(org.onosproject.net.Annotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) IpAddress(org.onlab.packet.IpAddress)

Example 7 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class FujitsuVoltControllerConfigTest method testSetControllers.

/**
 * Run to verify handling of valid set operation.
 */
@Test
public void testSetControllers() throws Exception {
    List<ControllerInfo> controllers = new ArrayList<>();
    for (int i = ZERO; i < SET_CONTROLLERS.length; i++) {
        String target = SET_CONTROLLERS[i];
        String[] data = target.split(TEST_COLON);
        currentKey = i + ONE;
        Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
        ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
        controllers.add(controller);
    }
    voltConfig.setControllers(controllers);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 8 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class FujitsuVoltControllerConfigTest method testGetControllers.

/**
 * Run to verify handling of valid get operation.
 */
@Test
public void testGetControllers() throws Exception {
    List<ControllerInfo> controllers;
    List<ControllerInfo> expectedControllers = new ArrayList<>();
    for (int i = ZERO; i < GET_CONTROLLERS.length; i++) {
        String target = GET_CONTROLLERS[i];
        String[] data = target.split(TEST_COLON);
        currentKey = i + ONE;
        Annotations annotations = DefaultAnnotations.builder().set(TEST_OFCONFIG_ID, currentKey.toString()).build();
        ControllerInfo controller = new ControllerInfo(IpAddress.valueOf(data[SECOND_PART]), Integer.parseInt(data[THIRD_PART]), data[FIRST_PART], annotations);
        expectedControllers.add(controller);
    }
    controllers = voltConfig.getControllers();
    assertTrue("Incorrect response", controllers.equals(expectedControllers));
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 9 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class OchPortHelper method asOchPort.

public static Optional<OchPort> asOchPort(Port port) {
    if (port instanceof OchPort) {
        return Optional.of((OchPort) port);
    }
    try {
        Annotations an = port.annotations();
        OduSignalType signalType = Enum.valueOf(OduSignalType.class, an.value(SIGNAL_TYPE));
        boolean isTunable = Boolean.valueOf(an.value(TUNABLE));
        ObjectNode obj = (ObjectNode) MAPPER.readTree(an.value(LAMBDA));
        OchSignal lambda = OchSignalCodec.decode(obj);
        // DefaultOchPort should filter them, if necessary.
        return Optional.of(new DefaultOchPort(port, signalType, isTunable, lambda));
    // TODO: it'll be better to verify each inputs properly
    // instead of catching all these Exceptions.
    } catch (IOException | NullPointerException | IllegalArgumentException | ClassCastException e) {
        log.warn("{} was not well-formed OCh port.", port, e);
        return Optional.empty();
    }
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) OduSignalType(org.onosproject.net.OduSignalType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OchSignal(org.onosproject.net.OchSignal) DefaultOchPort(org.onosproject.net.optical.impl.DefaultOchPort) IOException(java.io.IOException) OchPort(org.onosproject.net.optical.OchPort) DefaultOchPort(org.onosproject.net.optical.impl.DefaultOchPort)

Example 10 with Annotations

use of org.onosproject.net.Annotations in project onos by opennetworkinglab.

the class OduCltPortHelper method asOduCltPort.

public static Optional<OduCltPort> asOduCltPort(Port port) {
    if (port instanceof OduCltPort) {
        return Optional.of((OduCltPort) port);
    }
    try {
        Annotations an = port.annotations();
        CltSignalType signalType = Enum.valueOf(CltSignalType.class, an.value(SIGNAL_TYPE));
        // DefaultOduCltPort should filter them, if necessary.
        return Optional.of(new DefaultOduCltPort(port, signalType));
    } catch (NullPointerException | IllegalArgumentException e) {
        log.warn("{} was not well-formed OduClt port.", port, e);
        return Optional.empty();
    }
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultOduCltPort(org.onosproject.net.optical.impl.DefaultOduCltPort) OduCltPort(org.onosproject.net.optical.OduCltPort) DefaultOduCltPort(org.onosproject.net.optical.impl.DefaultOduCltPort) CltSignalType(org.onosproject.net.CltSignalType)

Aggregations

Annotations (org.onosproject.net.Annotations)39 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 Test (org.junit.Test)9 Device (org.onosproject.net.Device)9 Port (org.onosproject.net.Port)8 ArrayList (java.util.ArrayList)6 DefaultDevice (org.onosproject.net.DefaultDevice)6 DefaultPort (org.onosproject.net.DefaultPort)6 SparseAnnotations (org.onosproject.net.SparseAnnotations)5 IpAddress (org.onlab.packet.IpAddress)4 DefaultPath (org.onosproject.net.DefaultPath)4 PortNumber (org.onosproject.net.PortNumber)4 ProviderId (org.onosproject.net.provider.ProviderId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Set (java.util.Set)3 Before (org.junit.Before)3 Frequency (org.onlab.util.Frequency)3 NodeId (org.onosproject.cluster.NodeId)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultHost (org.onosproject.net.DefaultHost)3