Search in sources :

Example 6 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class GeneralDeviceProvider method forgeDeviceDescription.

private DeviceDescription forgeDeviceDescription(DeviceId deviceId, boolean defaultAvailable) {
    // Uses handshaker and provider config to get driver data.
    final DeviceHandshaker handshaker = getBehaviour(deviceId, DeviceHandshaker.class);
    final Driver driver = handshaker != null ? handshaker.handler().driver() : null;
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, driver != null ? driver.manufacturer() : UNKNOWN, driver != null ? driver.hwVersion() : UNKNOWN, driver != null ? driver.swVersion() : UNKNOWN, UNKNOWN, new ChassisId(), defaultAvailable, DefaultAnnotations.EMPTY);
}
Also used : DeviceHandshaker(org.onosproject.net.device.DeviceHandshaker) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Driver(org.onosproject.net.driver.Driver)

Example 7 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceDiscovery 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() {
    boolean defaultAvailable = true;
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    log.debug("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
    // Other option "OTN" or "OTHER", we use TERMINAL_DEVICE
    org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
    // Some defaults
    String vendor = "NOVENDOR";
    String serialNumber = "0xCAFEBEEF";
    String hwVersion = "0.2.1";
    String swVersion = "0.2.1";
    String chassisId = "128";
    // Get the session,
    NetconfSession session = getNetconfSession(did());
    try {
        String reply = session.get(getDeviceDetailsBuilder());
        log.debug("REPLY to DeviceDescription {}", reply);
        // <rpc-reply> as root node, software hardare version requires openconfig >= 2018
        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);
        swVersion = xconf.getString("data.components.component.state.software-version", swVersion);
        hwVersion = xconf.getString("data.components.component.state.hardware-version", hwVersion);
    } catch (Exception e) {
        log.error("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails - Failed to retrieve session {}", did());
        throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
    }
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    log.info("Device retrieved details");
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    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 8 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class OpenRoadmDeviceDescription method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    boolean defaultAvailable = true;
    NetconfDevice ncDevice = getNetconfDevice();
    if (ncDevice == null) {
        log.error("ONOS Error: Device reachable, deviceID {} is not in Map", did());
        return null;
    }
    DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
    // Some defaults
    String vendor = "UNKNOWN";
    String hwVersion = "2.2.0";
    String swVersion = "2.2.0";
    String serialNumber = "0x0000";
    String chassisId = "0";
    String nodeType = "rdm";
    // Get the session, if null, at least we can use the defaults.
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.rpc(getDeviceDetailsBuilder()).get();
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            String nodeId = xconf.getString("data.org-openroadm-device.info.node-id", "");
            if (nodeId.equals("")) {
                log.error("[OPENROADM] {} org-openroadm-device node-id undefined, returning", did());
                return null;
            }
            annotationsBuilder.set(AnnotationKeys.OPENROADM_NODEID, nodeId);
            nodeType = xconf.getString("data.org-openroadm-device.info.node-type", "");
            if (nodeType.equals("")) {
                log.error("[OPENROADM] {} empty node-type", did());
                return null;
            }
            vendor = xconf.getString("data.org-openroadm-device.info.vendor", vendor);
            hwVersion = xconf.getString("data.org-openroadm-device.info.model", hwVersion);
            swVersion = xconf.getString("data.org-openroadm-device.info.softwareVersion", swVersion);
            serialNumber = xconf.getString("data.org-openroadm-device.info.serial-id", serialNumber);
            chassisId = xconf.getString("data.org-openroadm-device.info.node-number", chassisId);
            // GEOLOCATION
            String longitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.longitude");
            String latitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.latitude");
            if (longitudeStr != null && latitudeStr != null) {
                annotationsBuilder.set(org.onosproject.net.AnnotationKeys.LONGITUDE, longitudeStr).set(org.onosproject.net.AnnotationKeys.LATITUDE, latitudeStr);
            }
        } catch (NetconfException | InterruptedException | ExecutionException e) {
            log.error("[OPENROADM] {} exception", did());
            return null;
        }
    } else {
        log.debug("[OPENROADM] - No  session {}", did());
    }
    log.debug("[OPENROADM] {} - VENDOR {} HWVERSION {} SWVERSION {} SERIAL {} CHASSIS {}", did(), vendor, hwVersion, swVersion, serialNumber, chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    /*
         * OpenROADM defines multiple devices (node types). This driver has been tested with
         * ROADMS, (node type, "rdm"). Other devices can also be discovered, and this code is here
         * for future developments - untested - it is likely that the XML documents
         * are model specific.
         */
    org.onosproject.net.Device.Type type;
    if (nodeType.equals("rdm")) {
        type = org.onosproject.net.Device.Type.ROADM;
    } else if (nodeType.equals("ila")) {
        type = org.onosproject.net.Device.Type.OPTICAL_AMPLIFIER;
    } else if (nodeType.equals("xpdr")) {
        type = org.onosproject.net.Device.Type.TERMINAL_DEVICE;
    } else if (nodeType.equals("extplug")) {
        type = org.onosproject.net.Device.Type.OTHER;
    } else {
        log.error("[OPENROADM] {} unsupported node-type", did());
        return null;
    }
    DeviceDescription desc = new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotationsBuilder.build());
    return desc;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfDevice(org.onosproject.netconf.NetconfDevice) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class Tl1DeviceProvider method connectDevice.

// Register a device in the core and in the TL1 controller.
private void connectDevice(Tl1Device device) {
    try {
        // Add device to TL1 controller
        DeviceId deviceId = DeviceId.deviceId(new URI(Tl1DeviceConfig.TL1, device.ip() + ":" + device.port(), null));
        if (controller.addDevice(deviceId, device)) {
            SparseAnnotations ann = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, Tl1DeviceConfig.TL1.toUpperCase()).build();
            // Register device in the core with default parameters and mark it as unavailable
            DeviceDescription dd = new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), false, ann);
            providerService.deviceConnected(deviceId, dd);
        }
    } catch (URISyntaxException e) {
        log.error("Skipping device {}", device, e);
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class CzechLightDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Cannot request NETCONF session for {}", data().deviceId());
        return null;
    }
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
    try {
        Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
        var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
        if (!data.containsKey(YANGLIB_KEY_REVISION)) {
            log.error("Not talking to a supported CzechLight device, is that a teapot?");
            return noDevice;
        }
        final var revision = data.getString(YANGLIB_KEY_REVISION);
        if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
            if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
                return noDevice;
            }
            final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
            isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
            isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
            if (!isLineDegree && !isAddDrop) {
                log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
                return noDevice;
            }
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
            if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
                return noDevice;
            }
            isCoherentAddDrop = true;
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
            if (!revision.equals(MOD_INLINE_AMP_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
                return noDevice;
            }
            isInlineAmp = true;
        }
        if (isLineDegree) {
            log.info("Talking to a Line/Degree ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
        } else if (isAddDrop) {
            log.info("Talking to an Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
        } else if (isCoherentAddDrop) {
            log.info("Talking to a Coherent Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
        } else if (isInlineAmp) {
            log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
        } else {
            log.error("Device type not recognized");
            return noDevice;
        }
    } catch (NetconfException e) {
        log.error("Cannot request ietf-yang-library data", e);
        return noDevice;
    }
    // FIXME: initialize these
    String vendor = "CzechLight";
    String hwVersion = "n/a";
    String swVersion = "n/a";
    String serialNumber = "n/a";
    ChassisId chassisId = null;
    return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) Arrays(java.util.Arrays) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AnnotationKeys(org.onosproject.net.AnnotationKeys) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Frequency(org.onlab.util.Frequency) Lists(com.google.common.collect.Lists) NetconfController(org.onosproject.netconf.NetconfController) PortDescription(org.onosproject.net.device.PortDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) DatastoreId(org.onosproject.netconf.DatastoreId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ChannelSpacing(org.onosproject.net.ChannelSpacing) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Aggregations

ChassisId (org.onlab.packet.ChassisId)48 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)19 DefaultDevice (org.onosproject.net.DefaultDevice)13 DeviceDescription (org.onosproject.net.device.DeviceDescription)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)11 DeviceService (org.onosproject.net.device.DeviceService)11 Test (org.junit.Test)10 SparseAnnotations (org.onosproject.net.SparseAnnotations)10 NetconfException (org.onosproject.netconf.NetconfException)10 NetconfSession (org.onosproject.netconf.NetconfSession)10 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 Type (org.onosproject.net.Device.Type)6 ProviderId (org.onosproject.net.provider.ProviderId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayList (java.util.ArrayList)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4