Search in sources :

Example 21 with SparseAnnotations

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

the class BasicDeviceOperator method combine.

/**
 * Generates a DeviceDescription containing fields from a DeviceDescription and
 * a DeviceConfig.
 *
 * @param cfg   the device config entity from network config
 * @param descr a DeviceDescription
 * @return DeviceDescription based on both sources
 */
public static DeviceDescription combine(BasicDeviceConfig cfg, DeviceDescription descr) {
    if (cfg == null || descr == null) {
        return descr;
    }
    Device.Type type = descr.type();
    if (cfg.type() != null && cfg.type() != type) {
        type = cfg.type();
    }
    String manufacturer = descr.manufacturer();
    if (cfg.manufacturer() != null && !cfg.manufacturer().equals(manufacturer)) {
        manufacturer = cfg.manufacturer();
    }
    String hwVersion = descr.hwVersion();
    if (cfg.hwVersion() != null && !cfg.hwVersion().equals(hwVersion)) {
        hwVersion = cfg.hwVersion();
    }
    String swVersion = descr.swVersion();
    if (cfg.swVersion() != null && !cfg.swVersion().equals(swVersion)) {
        swVersion = cfg.swVersion();
    }
    String serial = descr.serialNumber();
    if (cfg.serial() != null && !cfg.serial().equals(serial)) {
        serial = cfg.serial();
    }
    SparseAnnotations sa = combine(cfg, descr.annotations());
    return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer, hwVersion, swVersion, serial, descr.chassisId(), descr.isDefaultAvailable(), sa);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 22 with SparseAnnotations

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

the class BasicLinkOperator method combine.

/**
 * Generates a LinkDescription containing fields from a LinkDescription and
 * a LinkConfig.
 *
 * @param cfg the link config entity from network config
 * @param descr a LinkDescription
 * @return LinkDescription based on both sources
 */
public static LinkDescription combine(BasicLinkConfig cfg, LinkDescription descr) {
    if (cfg == null) {
        return descr;
    }
    Link.Type type = descr.type();
    if (cfg.isTypeConfigured()) {
        if (cfg.type() != type) {
            type = cfg.type();
        }
    }
    SparseAnnotations sa = combine(cfg, descr.annotations());
    return new DefaultLinkDescription(descr.src(), descr.dst(), type, sa);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Link(org.onosproject.net.Link) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 23 with SparseAnnotations

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

the class PortProtoTranslator method translate.

/**
 * Translates gRPC PortDescription message to {@link PortDescription}.
 *
 * @param portDescription gRPC message
 * @return {@link PortDescription}
 */
public static PortDescription translate(PortDescriptionProto portDescription) {
    PortNumber number = PortNumber.fromString(portDescription.getPortNumber());
    boolean isEnabled = portDescription.getIsEnabled();
    Port.Type type = translate(portDescription.getType()).get();
    long portSpeed = portDescription.getPortSpeed();
    SparseAnnotations annotations = AnnotationsTranslator.asAnnotations(portDescription.getAnnotationsMap());
    // TODO How to deal with more specific Port...
    return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(type).portSpeed(portSpeed).annotations(annotations).build();
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Port(org.onosproject.net.Port) PortNumber(org.onosproject.net.PortNumber)

Example 24 with SparseAnnotations

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

the class KryoSerializerTest method testAnnotations.

@Test
public void testAnnotations() {
    // Annotations does not have equals defined, manually test equality
    final byte[] a1Bytes = serializer.encode(A1);
    SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
    assertAnnotationsEquals(copiedA1, A1);
    final byte[] a12Bytes = serializer.encode(A1_2);
    SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
    assertAnnotationsEquals(copiedA12, A1_2);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Test(org.junit.Test)

Example 25 with SparseAnnotations

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

the class DeviceDescriptionDiscoveryAristaImpl method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    Map<String, MacAddress> macAddressMap = getMacAddressesByInterface();
    List<PortDescription> ports = Lists.newArrayList();
    DeviceId deviceId = checkNotNull(handler().data().deviceId());
    try {
        Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_INTERFACES_STATUS);
        if (!result.isPresent()) {
            log.warn("{} Device unable to get interfaces status information.", deviceId);
            return ports;
        }
        JsonNode jsonNode = result.get().findValue(INTERFACE_STATUSES);
        jsonNode.fieldNames().forEachRemaining(name -> {
            JsonNode interfaceNode = jsonNode.get(name);
            Long bandwidth = interfaceNode.path(BANDWIDTH).asLong() / MBPS;
            String macAddress = macAddressMap.containsKey(name) ? macAddressMap.get(name).toString() : "";
            SparseAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.BANDWIDTH, bandwidth.toString()).set(AnnotationKeys.NAME, name).set(AnnotationKeys.PORT_NAME, name).set(AnnotationKeys.PORT_MAC, macAddress).set(LINK_STATUS, interfaceNode.path(LINK_STATUS).asText()).set(LINE_PROTOCOL_STATUS, interfaceNode.path(LINE_PROTOCOL_STATUS).asText()).set(INTERFACE_TYPE, interfaceNode.path(INTERFACE_TYPE).asText()).build();
            int portNumber;
            try {
                portNumber = getPortNumber(name);
            } catch (Exception e) {
                log.debug("Interface does not have port number: {}", name);
                return;
            }
            PortDescription portDescription = DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(portNumber)).isEnabled(true).type(Port.Type.FIBER).portSpeed(bandwidth).annotations(annotations).build();
            ports.add(portDescription);
        });
    } catch (Exception e) {
        log.error("Exception occurred because of {}, trace: {}", e, e.getStackTrace());
    }
    return ports;
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DeviceId(org.onosproject.net.DeviceId) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress)

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