Search in sources :

Example 16 with DefaultDeviceDescription

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

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

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

the class CiscoNxosDeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_VERSION_CMD);
    String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
    String response = NxApiRequest.post(controller, deviceId, req);
    String mrf = UNKNOWN;
    String hwVer = UNKNOWN;
    String swVer = UNKNOWN;
    String serialNum = UNKNOWN;
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode body = json.findValue("body");
        if (body != null) {
            mrf = body.get(MANUFACTURER).asText();
            hwVer = body.get(CHASSIS_ID).asText();
            swVer = body.get(KICKSTART_VER).asText();
        }
    } catch (IOException e) {
        log.error("Failed to to retrieve Device Information {}", e);
    }
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH, mrf, hwVer, swVer, serialNum, new ChassisId(), (SparseAnnotations) device.annotations());
}
Also used : ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DriverHandler(org.onosproject.net.driver.DriverHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with DefaultDeviceDescription

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

the class DeviceDescriptionDiscoveryCiscoImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_VERSION_CMD);
    cmd.add(SHOW_MODULE_CMD);
    String response = NxApiRequest.postClis(handler(), cmd);
    String mrf = UNKNOWN;
    String hwVer = UNKNOWN;
    String swVer = UNKNOWN;
    String serialNum = UNKNOWN;
    String module = UNKNOWN;
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode body = json.at("/0/body");
        if (!body.isMissingNode()) {
            mrf = body.at("/" + MANUFACTURER).asText();
            hwVer = body.at("/" + CHASSIS_ID).asText();
            swVer = body.at("/" + KICKSTART_VER).asText();
            serialNum = body.at("/" + CISCO_SERIAL_BOARD).asText();
        }
        JsonNode modInfo = json.at("/1/" + JSON_ROW_MODULE);
        JsonNode modMacInfo = json.at("/1/" + JSON_ROW_MODULE_MAC);
        if (!modInfo.isMissingNode()) {
            List<String> modulesAnn = prepareModuleAnnotation(modInfo, modMacInfo);
            module = String.format(MODULE_BRACKET_FORMAT, String.join(",", modulesAnn));
        }
    } catch (JsonParseException e) {
        log.error("Failed to parse Json", e);
    } catch (JsonMappingException e) {
        log.error("Failed to map Json", e);
    } catch (JsonProcessingException e) {
        log.error("Failed to processing Json", e);
    }
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        annotations.putAll(device.annotations());
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, mrf, hwVer, swVer, serialNum, new ChassisId(), annotations.build());
}
Also used : ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with DefaultDeviceDescription

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

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