Search in sources :

Example 36 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class TerminalDeviceDiscovery method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 *
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <data>
 * <components xmlns="http://openconfig.net/yang/platform">
 *  <component>
 *   <state>
 *     <name>FIRMWARE</name>
 *     <type>oc-platform-types:OPERATING_SYSTEM</type>
 *     <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
 *     <version>0.0.1</version>
 *   </state>
 *  </component>
 * </components>
 * </data>
 *}</pre>
 * //CHECKSTYLE:ON
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
    boolean defaultAvailable = true;
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    // Other option "OTHER", we use ROADM for now
    org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
    // Some defaults
    String vendor = "NOVENDOR";
    String hwVersion = "0.2.1";
    String swVersion = "0.2.1";
    String serialNumber = "0xCAFEBEEF";
    String chassisId = "128";
    // Get the session,
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.get(getDeviceDetailsBuilder());
            // <rpc-reply> as root node
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
            serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
            // Requires OpenConfig >= 2018
            swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
            hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
        } catch (Exception e) {
            throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
        }
    } else {
        log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
    }
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfException(org.onosproject.netconf.NetconfException) SparseAnnotations(org.onosproject.net.SparseAnnotations) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 37 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class TapiDeviceDescriptionDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    log.debug("Getting device description");
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        // TODO need to obtain from the device.
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.OLS, "Tapi", "0", "2.1", "Unknown", new ChassisId(), DefaultAnnotations.builder().set("protocol", "REST").build());
    } else {
        return new DefaultDeviceDescription(device.id().uri(), Device.Type.OLS, device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId());
    }
}
Also used : ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceService(org.onosproject.net.device.DeviceService)

Example 38 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class DeviceManagerTest method connectDevice.

private void connectDevice(DeviceId deviceId, String swVersion) {
    DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID);
    providerService.deviceConnected(deviceId, description);
    assertNotNull("device should be found", service.getDevice(DID1));
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 39 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription 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 40 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription in project onos by opennetworkinglab.

the class DeviceProtoTranslator method translate.

/**
 * Translates gRPC DeviceDescription to {@link DeviceDescriptionProtoOuterClass}.
 *
 * @param deviceDescription gRPC message
 * @return {@link DeviceDescriptionProtoOuterClass}
 */
public static DeviceDescription translate(DeviceDescriptionProto deviceDescription) {
    URI uri = URI.create(deviceDescription.getDeviceUri());
    Type type = translate(deviceDescription.getType());
    String manufacturer = deviceDescription.getManufacturer();
    String hwVersion = deviceDescription.getHwVersion();
    String swVersion = deviceDescription.getSwVersion();
    String serialNumber = deviceDescription.getSerialNumber();
    ChassisId chassis = new ChassisId(deviceDescription.getChassisId());
    boolean defaultAvailable = deviceDescription.getIsDefaultAvailable();
    return new DefaultDeviceDescription(uri, type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable, AnnotationsTranslator.asAnnotations(deviceDescription.getAnnotationsMap()));
}
Also used : Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) URI(java.net.URI)

Aggregations

DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)52 ChassisId (org.onlab.packet.ChassisId)33 DeviceDescription (org.onosproject.net.device.DeviceDescription)26 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)20 SparseAnnotations (org.onosproject.net.SparseAnnotations)14 DeviceService (org.onosproject.net.device.DeviceService)11 NetconfException (org.onosproject.netconf.NetconfException)11 NetconfSession (org.onosproject.netconf.NetconfSession)11 Test (org.junit.Test)9 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)8 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 DeviceEvent (org.onosproject.net.device.DeviceEvent)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 List (java.util.List)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 XPath (javax.xml.xpath.XPath)4