Search in sources :

Example 1 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class ServerBasicSystemOperations method time.

@Override
public CompletableFuture<Long> time() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's time
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_TIME_DISCOVERY, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get the time of device: {}", deviceId);
        return null;
    }
    // Load the JSON into object
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
    } catch (IOException ioEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    if (jsonNode == null) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    long time = jsonNode.path(PARAM_TIME).asLong();
    checkArgument(time > 0, "Invalid time format: {}", time);
    return completedFuture(new Long(time));
}
Also used : DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice 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 3 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class ServerHandshaker method isReachable.

@Override
public boolean isReachable() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    return deviceIsActive(device);
}
Also used : DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice)

Example 4 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class ServerTableStatisticsDiscovery method getTableStatistics.

@Override
public List<TableStatisticsEntry> getTableStatistics() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's NIC table statistics
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_RULE_TABLE_STATS, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // Load the JSON into object
    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 get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (jsonNode == null) {
        log.error("Failed to get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    List<TableStatisticsEntry> tableStats = Lists.newArrayList();
    JsonNode nicNode = objNode.path(PARAM_NICS);
    for (JsonNode nn : nicNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        // The index of the NIC that hosts rules table(s)
        long nicIndex = nicObjNode.path(Constants.PARAM_ID).asLong();
        JsonNode tableNode = nicObjNode.path(PARAM_NIC_TABLE);
        if (tableNode == null) {
            throw new IllegalArgumentException("No tables reported for NIC " + nicIndex);
        }
        for (JsonNode tn : tableNode) {
            ObjectNode tableObjNode = (ObjectNode) tn;
            // NIC table attributes
            int tableIndex = tableObjNode.path(PARAM_ID).asInt();
            checkArgument(tableIndex >= 0, MSG_NIC_TABLE_INDEX_NEGATIVE);
            long tableActiveEntries = tableObjNode.path(PARAM_NIC_TABLE_ACTIVE_ENTRIES).asLong();
            checkArgument(tableActiveEntries >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tablePktsLookedUp = tableObjNode.path(PARAM_NIC_TABLE_PKTS_LOOKED_UP).asLong();
            checkArgument(tablePktsLookedUp >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tablePktsMatched = tableObjNode.path(PARAM_NIC_TABLE_PKTS_MATCHED).asLong();
            checkArgument(tablePktsMatched >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tableMaxsize = tableObjNode.path(PARAM_NIC_TABLE_MAX_SIZE).asLong();
            checkArgument(tableMaxsize >= 0, MSG_NIC_TABLE_SIZE_NEGATIVE);
            // Server's device ID and NIC ID compose a NIC device ID
            DeviceId nicDeviceId = DeviceId.deviceId(deviceId.toString() + ":nic" + String.valueOf(nicIndex));
            TableStatisticsEntry tableStat = DefaultTableStatisticsEntry.builder().withDeviceId(nicDeviceId).withTableId(IndexTableId.of(tableIndex)).withActiveFlowEntries(tableActiveEntries).withPacketsLookedUpCount(tablePktsLookedUp).withPacketsMatchedCount(tablePktsMatched).withMaxSize(tableMaxsize > 0 ? tableMaxsize : -1).build();
            tableStats.add(tableStat);
            log.debug("[Device {}] NIC {} with table statistics: {}", deviceId, nicIndex, tableStat);
        }
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 5 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class ServerQueueConfig method getQueues.

@Override
public Collection<QueueDescription> getQueues() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides queue administration
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_NIC_QUEUE_ADMIN, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // Load the JSON into object
    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 get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (objNode == null) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    Collection<QueueDescription> queueDescs = Sets.newHashSet();
    // Fetch NICs' array
    JsonNode nicsNode = objNode.path(PARAM_NICS);
    for (JsonNode nn : nicsNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        int nicId = nicObjNode.path(PARAM_ID).asInt();
        JsonNode queuesNode = nicObjNode.path(PARAM_QUEUES);
        // Each NIC has a set of queues
        for (JsonNode qn : queuesNode) {
            ObjectNode queueObjNode = (ObjectNode) qn;
            // Get the attributes of a queue
            int queueIdInt = queueObjNode.path(PARAM_ID).asInt();
            String queueTypeStr = get(qn, PARAM_TYPE);
            long queueRateInt = queueObjNode.path(PARAM_NIC_MAX_RATE).asLong();
            QueueId queueId = QueueId.queueId("nic" + nicId + ":" + queueIdInt);
            EnumSet<Type> queueTypes = getQueueTypesFromString(queueTypeStr);
            Bandwidth queueRate = Bandwidth.mbps(queueRateInt);
            queueDescs.add(DefaultQueueDescription.builder().queueId(queueId).type(queueTypes).maxRate(queueRate).build());
        }
    }
    log.info("[Device {}] NIC queues: {}", deviceId, queueDescs);
    return ImmutableList.copyOf(queueDescs);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) QueueId(org.onosproject.net.behaviour.QueueId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultQueueDescription(org.onosproject.net.behaviour.DefaultQueueDescription) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Type(org.onosproject.net.behaviour.QueueDescription.Type) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Bandwidth(org.onlab.util.Bandwidth) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

RestSBDevice (org.onosproject.protocol.rest.RestSBDevice)8 DeviceId (org.onosproject.net.DeviceId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Map (java.util.Map)4 ProcessingException (javax.ws.rs.ProcessingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ChassisId (org.onlab.packet.ChassisId)2 DefaultRestSBDevice (org.onosproject.protocol.rest.DefaultRestSBDevice)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Bandwidth (org.onlab.util.Bandwidth)1 RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)1 ServerDeviceDescription (org.onosproject.drivers.server.devices.ServerDeviceDescription)1 CpuCacheHierarchyDevice (org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice)1 CpuDevice (org.onosproject.drivers.server.devices.cpu.CpuDevice)1 MemoryHierarchyDevice (org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice)1 NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)1