Search in sources :

Example 1 with NicDevice

use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getDeviceDetails.

/**
 * Query a server to retrieve its features.
 *
 * @param deviceId the device ID to be queried
 * @return a DeviceDescription with the device's features
 */
private DeviceDescription getDeviceDetails(DeviceId deviceId) {
    // Retrieve the device ID, if null given
    if (deviceId == null) {
        deviceId = getDeviceId();
        checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    }
    // Get the device
    RestSBDevice device = getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_RESOURCE_DISCOVERY, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    if (jsonMap == null) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Get all the attributes
    String id = get(jsonNode, PARAM_ID);
    String vendor = get(jsonNode, PARAM_MANUFACTURER);
    String hw = get(jsonNode, PARAM_HW_VENDOR);
    String sw = get(jsonNode, PARAM_SW_VENDOR);
    String serial = get(jsonNode, PARAM_SERIAL);
    long chassisId = objNode.path(PARAM_CHASSIS_ID).asLong();
    // Pass the southbound protocol as an annotation
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    annotations.set(AnnotationKeys.PROTOCOL, "REST");
    // Parse CPU devices
    Collection<CpuDevice> cpuSet = parseCpuDevices(objNode);
    // Parse memory hierarchy device
    MemoryHierarchyDevice memHierarchyDev = parseMemoryHierarchyDevice(objNode);
    // Parse CPU cache hierachy device
    CpuCacheHierarchyDevice cacheHierarchyDev = parseCpuCacheHierarchyDevice(objNode);
    // NICs are composite attributes too
    Collection<NicDevice> nicSet = parseNicDevices(mapper, objNode, annotations);
    // Construct a server device,
    // i.e., a RestSBDevice extended with CPU, cache, memory, and NIC information
    RestServerSBDevice dev = new DefaultRestServerSBDevice(device.ip(), device.port(), device.username(), device.password(), device.protocol(), device.url(), device.isActive(), device.testUrl().orElse(""), vendor, hw, sw, cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet);
    checkNotNull(dev, MSG_DEVICE_NULL);
    // Set alive
    raiseDeviceReconnect(dev);
    // Updates the controller with the complete device information
    getController().removeDevice(deviceId);
    getController().addDevice((RestSBDevice) dev);
    // Create a description for this server device
    ServerDeviceDescription desc = null;
    try {
        desc = new DefaultServerDeviceDescription(new URI(id), Device.Type.SERVER, vendor, hw, sw, serial, new ChassisId(chassisId), cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet, annotations.build());
    } catch (URISyntaxException uEx) {
        log.error("Failed to create a server device description for: {}", deviceId);
        return null;
    }
    log.info("Device's {} details sent to the controller", deviceId);
    return desc;
}
Also used : DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) ServerDeviceDescription(org.onosproject.drivers.server.devices.ServerDeviceDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) CpuCacheHierarchyDevice(org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice) DefaultCpuCacheHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuCacheHierarchyDevice) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultCpuDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuDevice) CpuDevice(org.onosproject.drivers.server.devices.cpu.CpuDevice) URISyntaxException(java.net.URISyntaxException) DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) URI(java.net.URI) NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException) MemoryHierarchyDevice(org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice) DefaultMemoryHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultMemoryHierarchyDevice) ChassisId(org.onlab.packet.ChassisId) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map)

Example 2 with NicDevice

use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and object
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to discover ports for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for port discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No ports available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<PortDescription> portDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        // Include the name of this device as an annotation
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, nic.name());
        // Create a port description and add it to the list
        portDescriptions.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(nic.portNumber())).isEnabled(nic.status()).type(nic.portType()).portSpeed(nic.speed()).annotations(annotations.build()).build());
        log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", deviceId, nic.portNumber(), nic.status() ? "up" : "down", nic.speed());
    }
    return ImmutableList.copyOf(portDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Example 3 with NicDevice

use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.

the class ServerPortAdmin method isEnabled.

@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
    // Retrieve the device ID
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // ...and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to discover ports for device {}", deviceId);
        return completedFuture(false);
    }
    // Iterate server's NICs to find the correct port
    for (NicDevice nic : device.nics()) {
        if (nic.portNumber() == number.toLong()) {
            return completedFuture(nic.status());
        }
    }
    return completedFuture(false);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Example 4 with NicDevice

use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.

the class ServerInterfaceConfig method getInterfaces.

@Override
public List<DeviceInterfaceDescription> getInterfaces() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to get interfaces for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for interface discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No interfaces available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
        Mode devMode = getDeviceMode(devVlanIds);
        // Create an interface description and add it to the list
        intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
    }
    return ImmutableList.copyOf(intfDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) Mode(org.onosproject.net.device.DeviceInterfaceDescription.Mode) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) VlanId(org.onlab.packet.VlanId)

Example 5 with NicDevice

use of org.onosproject.drivers.server.devices.nic.NicDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method parseNicDevices.

/**
 * Parse the input JSON object, looking for NIC-related
 * information. Upon success, construct and return a list
 * of NIC devices.
 *
 * @param mapper input JSON object mapper
 * @param objNode input JSON node with NIC device information
 * @param annotations device annotations
 * @return list of CPU devices
 */
private Collection<NicDevice> parseNicDevices(ObjectMapper mapper, ObjectNode objNode, DefaultAnnotations.Builder annotations) {
    Collection<NicDevice> nicSet = Sets.newHashSet();
    JsonNode nicNode = objNode.path(PARAM_NICS);
    // Construct NIC objects
    for (JsonNode nn : nicNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        // All the NIC attributes
        String nicName = get(nn, PARAM_NAME);
        long nicIndex = nicObjNode.path(PARAM_ID).asLong();
        long speed = nicObjNode.path(PARAM_SPEED).asLong();
        String portTypeStr = get(nn, PARAM_NIC_PORT_TYPE);
        boolean status = nicObjNode.path(PARAM_STATUS).asInt() > 0;
        String hwAddr = get(nn, PARAM_NIC_HW_ADDR);
        JsonNode tagNode = nicObjNode.path(PARAM_NIC_RX_FILTER);
        if (tagNode == null) {
            throw new IllegalArgumentException("The Rx filters of NIC " + nicName + " are not reported");
        }
        // Convert the JSON list into an array of strings
        List<String> rxFilters = null;
        try {
            rxFilters = mapper.readValue(tagNode.traverse(), new TypeReference<ArrayList<String>>() {
            });
        } catch (IOException ioEx) {
            continue;
        }
        // Store NIC name to number mapping as an annotation
        annotations.set(nicName, Long.toString(nicIndex));
        // Construct a NIC device and add it to the set
        nicSet.add(DefaultNicDevice.builder().setName(nicName).setPortNumber(nicIndex).setPortNumber(nicIndex).setPortType(portTypeStr).setSpeed(speed).setStatus(status).setMacAddress(hwAddr).setRxFilters(rxFilters).build());
    }
    return nicSet;
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException)

Aggregations

NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)5 RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)4 DefaultNicDevice (org.onosproject.drivers.server.impl.devices.DefaultNicDevice)3 DeviceId (org.onosproject.net.DeviceId)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 TreeSet (java.util.TreeSet)2 DefaultRestServerSBDevice (org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice)2 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 ProcessingException (javax.ws.rs.ProcessingException)1 ChassisId (org.onlab.packet.ChassisId)1 VlanId (org.onlab.packet.VlanId)1 ServerDeviceDescription (org.onosproject.drivers.server.devices.ServerDeviceDescription)1