Search in sources :

Example 16 with DeviceDescription

use of org.onosproject.net.device.DeviceDescription 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)

Example 17 with DeviceDescription

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

the class SimpleDeviceStoreTest method putDeviceAncillary.

private void putDeviceAncillary(DeviceId deviceId, String swVersion, SparseAnnotations... annotations) {
    DeviceDescription description = new DefaultDeviceDescription(deviceId.uri(), SWITCH, MFR, HW, swVersion, SN, CID, annotations);
    deviceStore.createOrUpdateDevice(PIDA, deviceId, description);
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 18 with DeviceDescription

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

the class DeviceDiscoveryJuniperImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId devId = handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(devId);
    String sysInfo;
    String chassisMacAddresses;
    try {
        sysInfo = session.get(requestBuilder(REQ_SYS_INFO));
        chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve device details for {}", devId);
        return null;
    }
    log.trace("Device {} system-information {}", devId, sysInfo);
    DeviceDescription description = JuniperUtils.parseJuniperDescription(devId, loadXmlString(sysInfo), chassisMacAddresses);
    log.debug("Device {} description {}", devId, description);
    return description;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceDescription(org.onosproject.net.device.DeviceDescription) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

Example 19 with DeviceDescription

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

the class LispDeviceProvider method connectDevice.

/**
 * Adds a LISP router into device store.
 */
private void connectDevice(LispRouterId routerId) {
    DeviceId deviceId = getDeviceId(routerId.id().toString());
    Preconditions.checkNotNull(deviceId, IS_NULL_MSG);
    // formulate LISP router object
    ChassisId cid = new ChassisId();
    String ipAddress = routerId.id().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).build();
    DeviceDescription deviceDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.ROUTER, MANUFACTURER, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, false, annotations);
    if (deviceService.getDevice(deviceId) == null) {
        providerService.deviceConnected(deviceId, deviceDescription);
    }
    checkAndUpdateDevice(deviceId, deviceDescription);
}
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)

Example 20 with DeviceDescription

use of org.onosproject.net.device.DeviceDescription 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)

Aggregations

DeviceDescription (org.onosproject.net.device.DeviceDescription)44 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 ChassisId (org.onlab.packet.ChassisId)14 DeviceId (org.onosproject.net.DeviceId)14 Test (org.junit.Test)11 ProviderId (org.onosproject.net.provider.ProviderId)10 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)9 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 SparseAnnotations (org.onosproject.net.SparseAnnotations)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 Device (org.onosproject.net.Device)5 PortDescription (org.onosproject.net.device.PortDescription)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 NodeId (org.onosproject.cluster.NodeId)4 NetconfException (org.onosproject.netconf.NetconfException)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3